/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ "use strict"; const { getMostRecentBrowserWindow } = require('sdk/window/utils'); const { PageMod } = require("sdk/page-mod"); const { getActiveTab, setTabURL, openTab, closeTab } = require('sdk/tabs/utils'); const xulApp = require('sdk/system/xul-app'); const windowHelpers = require('sdk/window/helpers'); const { defer } = require("sdk/core/promise"); const { isPrivate } = require('sdk/private-browsing'); const { isTabPBSupported, isWindowPBSupported } = require('sdk/private-browsing/utils'); const { cleanUI } = require('sdk/test/utils'); function openWebpage(url, enablePrivate) { return new Promise((resolve, reject) => { if (xulApp.is("Fennec")) { let chromeWindow = getMostRecentBrowserWindow(); let rawTab = openTab(chromeWindow, url, { isPrivate: enablePrivate }); resolve(() => new Promise(resolve => { closeTab(rawTab); resolve(); })); } else { windowHelpers.open("", { features: { toolbar: true, private: enablePrivate } }). then((chromeWindow) => { if (isPrivate(chromeWindow) !== !!enablePrivate) { reject(new Error("Window should have Private set to " + !!enablePrivate)); } let tab = getActiveTab(chromeWindow); setTabURL(tab, url); resolve(() => windowHelpers.close(chromeWindow)); }). catch(reject); } }); } exports["test page-mod on private tab"] = function*(assert) { // Only set private mode when explicitely supported. // (fennec 19 has some intermediate PB support where isTabPBSupported // will be false, but isPrivate(worker.tab) will be true if we open a private // tab) let setPrivate = isTabPBSupported || isWindowPBSupported; let id = Date.now().toString(36); let frameUri = "data:text/html;charset=utf-8," + id; let uri = "data:text/html;charset=utf-8," + encodeURIComponent(id + "