summaryrefslogtreecommitdiff
path: root/data/extensions/jid1-KtlZuoiikVfFew@jetpack/node_modules/pathfinder/test/test-scheme-about.js
blob: 5d7873fc7bd83675250b8dc3e88318bb244fa71d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
'use strict';

const { Loader } = require('sdk/test/loader');
const tabs = require('sdk/tabs')

function openTabGetContent(url, callback) {
  tabs.open({
    url: 'about:test',
    inBackground: true,
    onReady: function(tab) {
      let worker = tab.attach({
        contentScript: 'self.port.emit("body", document.body.innerHTML)'
      })
      worker.port.on('body', function(msg) {
        tab.close(function() {
          callback(msg);
        });
      });
    }
  })
}

exports.testAddAboutWhat = function(assert, done) {
  const loader = Loader(module);
  const { add } = loader.require('pathfinder/scheme/about');

  add({
  	what: 'test',
    url: 'data:text/html;charset=utf-8,<body>test</body>'
  });

  openTabGetContent('about:test', function(msg) {
    assert.equal(msg, 'test', 'about:test content is "test"');
    loader.unload();
    openTabGetContent('about:test', function(msg) {
      assert.notEqual(msg, 'test', 'about:test content is "test"');
      done();
    });
  });

}

require('test').run(exports);