Skip to content
This repository has been archived by the owner on Feb 26, 2022. It is now read-only.

Bug 839746: global private windows (Fx <=19) are not ignored #886

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/sdk/panel/window.js
Expand Up @@ -6,11 +6,12 @@
const { getMostRecentBrowserWindow, windows: getWindows } = require('../window/utils');
const { ignoreWindow } = require('../private-browsing/utils');
const { isPrivateBrowsingSupported } = require('../self');
const { isGlobalPBSupported } = require('../private-browsing/utils');

function getWindow(anchor) {
let window;
let windows = getWindows("navigator:browser", {
includePrivate: isPrivateBrowsingSupported
includePrivate: isPrivateBrowsingSupported || isGlobalPBSupported
});

if (anchor) {
Expand Down
3 changes: 2 additions & 1 deletion lib/sdk/tabs/utils.js
Expand Up @@ -16,9 +16,10 @@ const { Ci } = require('chrome');
const { defer } = require("../lang/functional");
const { windows, isBrowser } = require('../window/utils');
const { isPrivateBrowsingSupported } = require('../self');
const { isGlobalPBSupported } = require('../private-browsing/utils');

// Bug 834961: ignore private windows when they are not supported
function getWindows() windows(null, { includePrivate: isPrivateBrowsingSupported });
function getWindows() windows(null, { includePrivate: isPrivateBrowsingSupported || isGlobalPBSupported });

function activateTab(tab, window) {
let gBrowser = getTabBrowserForTab(tab);
Expand Down
50 changes: 47 additions & 3 deletions test/test-page-mod.js
Expand Up @@ -13,12 +13,13 @@ const { open, getFrames, getMostRecentBrowserWindow } = require('sdk/window/util
const windowUtils = require('sdk/deprecated/window-utils');
const { getTabContentWindow, getActiveTab, setTabURL, openTab, closeTab } = require('sdk/tabs/utils');
const xulApp = require("sdk/system/xul-app");
const { data } = require('sdk/self');
const { data, isPrivateBrowsingSupported } = require('sdk/self');
const { isPrivate } = require('sdk/private-browsing');
const { isTabPBSupported, isWindowPBSupported } = require('sdk/private-browsing/utils');
const { isTabPBSupported, isWindowPBSupported, isGlobalPBSupported } = require('sdk/private-browsing/utils');
const promise = require("sdk/core/promise");
const { pb } = require('./private-browsing/helper');
const { openWebpage } = require('./private-browsing/helper');


/* XXX This can be used to delay closing the test Firefox instance for interactive
* testing or visual inspection. This test is registered first so that it runs
* the last. */
Expand Down Expand Up @@ -1083,3 +1084,46 @@ exports["test page-mod on private tab"] = function (test) {
let page1 = openWebpage(privateUri, true);
let page2 = openWebpage(nonPrivateUri, false);
}

exports["test page-mod on private tab in global pb"] = function (test) {
test.waitUntilDone();
if (!isGlobalPBSupported) {
test.pass();
return test.done();
}

let privateUri = "data:text/html;charset=utf-8," +
"<iframe%20src=\"data:text/html;charset=utf-8,frame\"/>";

let pageMod = new PageMod({
include: privateUri,
onAttach: function(worker) {
test.assertEqual(worker.tab.url,
privateUri,
"page-mod should attach");
test.assertEqual(isPrivateBrowsingSupported,
false,
"private browsing is not supported");
test.assert(isPrivate(worker),
"The worker is really non-private");
test.assert(isPrivate(worker.tab),
"The document is really non-private");
pageMod.destroy();

worker.tab.close(function() {
pb.once('stop', function() {
test.pass('global pb stop');
test.done();
});
pb.deactivate();
});
}
});

let page1;
pb.once('start', function() {
test.pass('global pb start');
tabs.open({ url: privateUri });
});
pb.activate();
}
43 changes: 42 additions & 1 deletion test/test-panel.js
Expand Up @@ -10,9 +10,11 @@ const timer = require("sdk/timers");
const self = require('sdk/self');
const { open, close, focus } = require('sdk/window/helpers');
const { isPrivate } = require('sdk/private-browsing');
const { isWindowPBSupported } = require('sdk/private-browsing/utils');
const { isWindowPBSupported, isGlobalPBSupported } = require('sdk/private-browsing/utils');
const { defer } = require('sdk/core/promise');
const { getMostRecentBrowserWindow } = require('sdk/window/utils');
const { getWindow } = require('sdk/panel/window');
const { pb } = require('./private-browsing/helper');

const SVG_URL = self.data.url('mofo_logo.SVG');

Expand Down Expand Up @@ -778,6 +780,45 @@ exports['test Style Applied Only Once'] = function (assert, done) {
}
};

if (isWindowPBSupported) {
exports.testGetWindow = function(assert, done) {
let activeWindow = getMostRecentBrowserWindow();
open(null, { features: {
toolbar: true,
chrome: true,
private: true
} }).then(function(window) {
assert.ok(isPrivate(window), 'window is private');
assert.equal(getWindow(window.gBrowser), null, 'private window elements returns null');
assert.equal(getWindow(activeWindow.gBrowser), activeWindow, 'non-private window elements returns window');
close(window).then(done);
})
}
}
else if (isGlobalPBSupported) {
exports.testGetWindow = function(assert, done) {
let activeWindow = getMostRecentBrowserWindow();

assert.equal(getWindow(activeWindow.gBrowser), activeWindow, 'non-private window elements returns window');
pb.once('start', function() {
assert.ok(isPrivate(activeWindow), 'window is private');
assert.equal(getWindow(activeWindow.gBrowser), activeWindow, 'private window elements returns window');
open(null, { features: {
toolbar: true,
chrome: true
} }).then(function(window) {
assert.ok(isPrivate(window), 'window is private');
assert.equal(getWindow(window.gBrowser), window, 'private window elements returns window');
assert.equal(getWindow(activeWindow.gBrowser), activeWindow, 'active window elements returns window');

pb.once('stop', done);
pb.deactivate();
})
});
pb.activate();
}
}

exports['test Only One Panel Open Concurrently'] = function (assert, done) {
const loader = Loader(module);
const { Panel } = loader.require('sdk/panel')
Expand Down
70 changes: 70 additions & 0 deletions test/test-tab-utils.js
@@ -0,0 +1,70 @@
'use strict';

const { getTabs } = require('sdk/tabs/utils');
const { isGlobalPBSupported, isWindowPBSupported, isTabPBSupported } = require('sdk/private-browsing/utils');
const { browserWindows } = require('sdk/windows');
const tabs = require('sdk/tabs');
const { pb } = require('./private-browsing/helper');
const { isPrivate } = require('sdk/private-browsing');
const { openTab } = require('sdk/tabs/utils');
const { open, close } = require('sdk/window/helpers');
const { windows } = require('sdk/window/utils');
const { getMostRecentBrowserWindow } = require('sdk/window/utils');
const { fromIterator } = require('sdk/util/array');

if (isGlobalPBSupported) {
exports.testGetTabs = function(assert, done) {
pb.once('start', function() {
tabs.open({
url: 'about:blank',
inNewWindow: true,
onOpen: function(tab) {
assert.equal(getTabs().length, 2, 'there are two tabs');
assert.equal(browserWindows.length, 2, 'there are two windows');
pb.once('stop', function() {
done();
});
pb.deactivate();
}
});
});
pb.activate();
};
}
else if (isWindowPBSupported) {
exports.testGetTabs = function(assert, done) {
open(null, {
features: {
private: true,
toolbar: true,
chrome: true
}
}).then(function(window) {
assert.ok(isPrivate(window), 'new tab is private');
assert.equal(getTabs().length, 1, 'there is one tab found');
assert.equal(browserWindows.length, 1, 'there is one window found');
fromIterator(browserWindows).forEach(function(window) {
assert.ok(!isPrivate(window), 'all found windows are not private');
});
assert.equal(windows(null, {includePrivate: true}).length, 2, 'there are really two windows');
close(window).then(done);
});
};
}
else if (isTabPBSupported) {
exports.testGetTabs = function(assert, done) {
tabs.once('open', function(tab) {
assert.ok(isPrivate(tab), 'new tab is private');
assert.equal(getTabs().length, 2, 'there are two tabs found');
assert.equal(browserWindows.length, 1, 'there is one window');
tab.close(function() {
done();
});
});
openTab(getMostRecentBrowserWindow(), 'about:blank', {
isPrivate: true
});
};
}

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