Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | const { getMostRecentBrowserWindow } = require('sdk/window/utils'); |
michael@0 | 2 | const { PageMod } = require("sdk/page-mod"); |
michael@0 | 3 | const { getActiveTab, setTabURL, openTab, closeTab } = require('sdk/tabs/utils'); |
michael@0 | 4 | const xulApp = require('sdk/system/xul-app'); |
michael@0 | 5 | const windowHelpers = require('sdk/window/helpers'); |
michael@0 | 6 | const { defer } = require("sdk/core/promise"); |
michael@0 | 7 | const { isPrivate } = require('sdk/private-browsing'); |
michael@0 | 8 | const { isTabPBSupported, isWindowPBSupported } = require('sdk/private-browsing/utils'); |
michael@0 | 9 | |
michael@0 | 10 | function openWebpage(url, enablePrivate) { |
michael@0 | 11 | let { promise, resolve, reject } = defer(); |
michael@0 | 12 | |
michael@0 | 13 | if (xulApp.is("Fennec")) { |
michael@0 | 14 | let chromeWindow = getMostRecentBrowserWindow(); |
michael@0 | 15 | let rawTab = openTab(chromeWindow, url, { |
michael@0 | 16 | isPrivate: enablePrivate |
michael@0 | 17 | }); |
michael@0 | 18 | |
michael@0 | 19 | resolve(function() { |
michael@0 | 20 | closeTab(rawTab) |
michael@0 | 21 | }); |
michael@0 | 22 | |
michael@0 | 23 | return promise; |
michael@0 | 24 | } |
michael@0 | 25 | else { |
michael@0 | 26 | windowHelpers.open("", { |
michael@0 | 27 | features: { |
michael@0 | 28 | toolbar: true, |
michael@0 | 29 | private: enablePrivate |
michael@0 | 30 | } |
michael@0 | 31 | }).then(function(chromeWindow) { |
michael@0 | 32 | if (isPrivate(chromeWindow) !== !!enablePrivate) |
michael@0 | 33 | reject(new Error("Window should have Private set to " + !!enablePrivate)); |
michael@0 | 34 | |
michael@0 | 35 | let tab = getActiveTab(chromeWindow); |
michael@0 | 36 | setTabURL(tab, url); |
michael@0 | 37 | |
michael@0 | 38 | resolve(function(){ |
michael@0 | 39 | windowHelpers.close(chromeWindow); |
michael@0 | 40 | }); |
michael@0 | 41 | }); |
michael@0 | 42 | |
michael@0 | 43 | return promise; |
michael@0 | 44 | } |
michael@0 | 45 | } |
michael@0 | 46 | |
michael@0 | 47 | exports["test page-mod on private tab"] = function (assert, done) { |
michael@0 | 48 | // Only set private mode when explicitely supported. |
michael@0 | 49 | // (fennec 19 has some intermediate PB support where isTabPBSupported |
michael@0 | 50 | // will be false, but isPrivate(worker.tab) will be true if we open a private |
michael@0 | 51 | // tab) |
michael@0 | 52 | let setPrivate = isTabPBSupported || isWindowPBSupported; |
michael@0 | 53 | |
michael@0 | 54 | let id = Date.now().toString(36); |
michael@0 | 55 | let frameUri = "data:text/html;charset=utf-8," + id; |
michael@0 | 56 | let uri = "data:text/html;charset=utf-8," + |
michael@0 | 57 | encodeURIComponent(id + "<iframe src='" + frameUri + "'><iframe>"); |
michael@0 | 58 | |
michael@0 | 59 | let count = 0; |
michael@0 | 60 | |
michael@0 | 61 | openWebpage(uri, setPrivate).then(function(close) { |
michael@0 | 62 | PageMod({ |
michael@0 | 63 | include: [uri, frameUri], |
michael@0 | 64 | |
michael@0 | 65 | onAttach: function(worker) { |
michael@0 | 66 | assert.ok(worker.tab.url == uri || worker.tab.url == frameUri, |
michael@0 | 67 | "Got a worker attached to the private window tab"); |
michael@0 | 68 | |
michael@0 | 69 | if (setPrivate) { |
michael@0 | 70 | assert.ok(isPrivate(worker), "The worker is really private"); |
michael@0 | 71 | assert.ok(isPrivate(worker.tab), "The document is really private"); |
michael@0 | 72 | } |
michael@0 | 73 | else { |
michael@0 | 74 | assert.ok(!isPrivate(worker), |
michael@0 | 75 | "private browsing isn't supported, " + |
michael@0 | 76 | "so that the worker isn't private"); |
michael@0 | 77 | assert.ok(!isPrivate(worker.tab), |
michael@0 | 78 | "private browsing isn't supported, " + |
michael@0 | 79 | "so that the document isn't private"); |
michael@0 | 80 | } |
michael@0 | 81 | |
michael@0 | 82 | if (++count == 2) { |
michael@0 | 83 | this.destroy(); |
michael@0 | 84 | close(); |
michael@0 | 85 | done(); |
michael@0 | 86 | } |
michael@0 | 87 | } |
michael@0 | 88 | }); |
michael@0 | 89 | }).then(null, assert.fail); |
michael@0 | 90 | }; |
michael@0 | 91 | |
michael@0 | 92 | exports["test page-mod on non-private tab"] = function (assert, done) { |
michael@0 | 93 | let id = Date.now().toString(36); |
michael@0 | 94 | let url = "data:text/html;charset=utf-8," + encodeURIComponent(id); |
michael@0 | 95 | |
michael@0 | 96 | openWebpage(url, false).then(function(close){ |
michael@0 | 97 | PageMod({ |
michael@0 | 98 | include: url, |
michael@0 | 99 | onAttach: function(worker) { |
michael@0 | 100 | assert.equal(worker.tab.url, url, |
michael@0 | 101 | "Got a worker attached to the private window tab"); |
michael@0 | 102 | assert.ok(!isPrivate(worker), "The worker is really non-private"); |
michael@0 | 103 | assert.ok(!isPrivate(worker.tab), "The document is really non-private"); |
michael@0 | 104 | |
michael@0 | 105 | this.destroy(); |
michael@0 | 106 | close(); |
michael@0 | 107 | done(); |
michael@0 | 108 | } |
michael@0 | 109 | }); |
michael@0 | 110 | }).then(null, assert.fail); |
michael@0 | 111 | } |