Skip to content

Commit

Permalink
Bug 839746: global private windows (Fx <=19) are not ignored, per wid…
Browse files Browse the repository at this point in the history
…now private windows (on Fx > 19) still are
  • Loading branch information
erikvold committed Mar 22, 2013
1 parent b87a095 commit ad44c4b
Show file tree
Hide file tree
Showing 9 changed files with 494 additions and 170 deletions.
4 changes: 2 additions & 2 deletions lib/sdk/deprecated/window-utils.js
Expand Up @@ -15,7 +15,7 @@ const { getInnerId, getOuterId, windows, isDocumentLoaded, isBrowser,
getMostRecentBrowserWindow, getMostRecentWindow } = require('../window/utils');
const errors = require('../deprecated/errors');
const { deprecateFunction } = require('../util/deprecate');
const { ignoreWindow } = require('sdk/private-browsing/utils');
const { ignoreWindow, isGlobalPBSupported } = require('sdk/private-browsing/utils');
const { isPrivateBrowsingSupported } = require('../self');

const windowWatcher = Cc['@mozilla.org/embedcomp/window-watcher;1'].
Expand All @@ -24,7 +24,7 @@ const appShellService = Cc['@mozilla.org/appshell/appShellService;1'].
getService(Ci.nsIAppShellService);

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

/**
* An iterator for XUL windows currently in the application.
Expand Down
2 changes: 1 addition & 1 deletion lib/sdk/private-browsing/utils.js
Expand Up @@ -54,7 +54,7 @@ let isTabPBSupported = exports.isTabPBSupported =
!pbService && !!PrivateBrowsingUtils && is('Fennec') && satisfiesVersion(version, '>=20.0*');

function ignoreWindow(window) {
return !isPrivateBrowsingSupported && isWindowPrivate(window);
return !isPrivateBrowsingSupported && isWindowPrivate(window) && !isGlobalPBSupported;
}
exports.ignoreWindow = ignoreWindow;

Expand Down
2 changes: 1 addition & 1 deletion lib/sdk/windows/tabs-firefox.js
Expand Up @@ -16,7 +16,7 @@ const { getOwnerWindow, getActiveTab, getTabs,
openTab } = require("../tabs/utils");
const { Options } = require("../tabs/common");
const { observer: tabsObserver } = require("../tabs/observer");
const { ignoreWindow, isWindowPrivate } = require("../private-browsing/utils");
const { ignoreWindow } = require("../private-browsing/utils");

const TAB_BROWSER = "tabbrowser";

Expand Down
163 changes: 3 additions & 160 deletions test/addons/private-browsing-supported/main.js
Expand Up @@ -3,173 +3,16 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
'use strict';

const { Ci } = require('chrome');
const { isPrivateBrowsingSupported } = require('sdk/self');
const tabs = require('sdk/tabs');
const { browserWindows: windows } = require('sdk/windows');
const { isPrivate } = require('sdk/private-browsing');
const { getOwnerWindow } = require('sdk/private-browsing/window/utils');
const { is } = require('sdk/system/xul-app');
const { isWindowPBSupported, isTabPBSupported } = require('sdk/private-browsing/utils');
const { merge } = require('sdk/util/object');

const TAB_URL = 'data:text/html;charset=utf-8,TEST-TAB';

exports.testIsPrivateBrowsingTrue = function(assert) {
assert.ok(isPrivateBrowsingSupported,
'isPrivateBrowsingSupported property is true');
};

// test tab.open with isPrivate: true
// test isPrivate on a tab
// test getOwnerWindow on windows and tabs
exports.testGetOwnerWindow = function(assert, done) {
let window = windows.activeWindow;
let chromeWindow = getOwnerWindow(window);
assert.ok(chromeWindow instanceof Ci.nsIDOMWindow, 'associated window is found');

tabs.open({
url: 'about:blank',
isPrivate: true,
onOpen: function(tab) {
// test that getOwnerWindow works as expected
if (is('Fennec')) {
assert.notStrictEqual(chromeWindow, getOwnerWindow(tab));
assert.ok(getOwnerWindow(tab) instanceof Ci.nsIDOMWindow);
}
else {
if (isWindowPBSupported) {
assert.notStrictEqual(chromeWindow,
getOwnerWindow(tab),
'associated window is not the same for window and window\'s tab');
}
else {
assert.strictEqual(chromeWindow,
getOwnerWindow(tab),
'associated window is the same for window and window\'s tab');
}
}

let pbSupported = isTabPBSupported || isWindowPBSupported;

// test that the tab is private if it should be
assert.equal(isPrivate(tab), pbSupported);
assert.equal(isPrivate(getOwnerWindow(tab)), pbSupported);

tab.close(function() done());
}
});
};

// test that it is possible to open a private tab
exports.testTabOpenPrivate = function(assert, done) {
tabs.open({
url: TAB_URL,
isPrivate: true,
onReady: function(tab) {
assert.equal(tab.url, TAB_URL, 'opened correct tab');
assert.equal(isPrivate(tab), (isWindowPBSupported || isTabPBSupported));

tab.close(function() {
done();
});
}
});
}


// test that it is possible to open a non private tab
exports.testTabOpenPrivateDefault = function(assert, done) {
tabs.open({
url: TAB_URL,
onReady: function(tab) {
assert.equal(tab.url, TAB_URL, 'opened correct tab');
assert.equal(isPrivate(tab), false);

tab.close(function() {
done();
});
}
});
}

// test that it is possible to open a non private tab in explicit case
exports.testTabOpenPrivateOffExplicit = function(assert, done) {
tabs.open({
url: TAB_URL,
isPrivate: false,
onReady: function(tab) {
assert.equal(tab.url, TAB_URL, 'opened correct tab');
assert.equal(isPrivate(tab), false);

tab.close(function() {
done();
});
}
});
}

// test windows.open with isPrivate: true
// test isPrivate on a window
if (!is('Fennec')) {
// test that it is possible to open a private window
exports.testWindowOpenPrivate = function(assert, done) {
windows.open({
url: TAB_URL,
isPrivate: true,
onOpen: function(window) {
let tab = window.tabs[0];
tab.once('ready', function() {
assert.equal(tab.url, TAB_URL, 'opened correct tab');
assert.equal(isPrivate(tab), isWindowPBSupported, 'tab is private');

window.close(function() {
done();
});
});
}
});
};

exports.testIsPrivateOnWindowOn = function(assert, done) {
windows.open({
isPrivate: true,
onOpen: function(window) {
assert.equal(isPrivate(window), isWindowPBSupported, 'isPrivate for a window is true when it should be');
assert.equal(isPrivate(window.tabs[0]), isWindowPBSupported, 'isPrivate for a tab is false when it should be');
window.close(done);
}
});
};

exports.testIsPrivateOnWindowOffImplicit = function(assert, done) {
windows.open({
onOpen: function(window) {
assert.equal(isPrivate(window), false, 'isPrivate for a window is false when it should be');
assert.equal(isPrivate(window.tabs[0]), false, 'isPrivate for a tab is false when it should be');
window.close(done);
}
})
}

exports.testIsPrivateOnWindowOffExplicit = function(assert, done) {
windows.open({
isPrivate: false,
onOpen: function(window) {
assert.equal(isPrivate(window), false, 'isPrivate for a window is false when it should be');
assert.equal(isPrivate(window.tabs[0]), false, 'isPrivate for a tab is false when it should be');
window.close(done);
}
})
}
}

merge(module.exports,
require('./test-windows'),
require('./test-tabs'),
require('./test-page-mod'),
require('./test-selection'),
require('./test-panel')
require('./test-panel'),
require('./test-private-browsing'),
require('./test-global-private-browsing')
);

require('sdk/test/runner').runTestsFromModule(module);
153 changes: 153 additions & 0 deletions test/addons/private-browsing-supported/test-global-private-browsing.js
@@ -0,0 +1,153 @@
/* 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 windowUtils = require('sdk/deprecated/window-utils');
const { isWindowPBSupported, isGlobalPBSupported } = require('sdk/private-browsing/utils');
const { getFrames, getWindowTitle, onFocus, isWindowPrivate, windows, isBrowser } = require('sdk/window/utils');
const { open, close, focus } = require('sdk/window/helpers');
const { isPrivate } = require('sdk/private-browsing');
const { Panel } = require('sdk/panel');
const { Widget } = require('sdk/widget');
const { fromIterator: toArray } = require('sdk/util/array');

let { LoaderWithHookedConsole } = require('sdk/test/loader');
let { loader } = LoaderWithHookedConsole(module, function() {});
const pb = loader.require('sdk/private-browsing');

function makeEmptyBrowserWindow(options) {
options = options || {};
return open('chrome://browser/content/browser.xul', {
features: {
chrome: true,
private: !!options.private,
toolbar: true
}
});
}

exports.testShowPanelAndWidgetOnPrivateWindow = function(assert, done) {
var myPrivateWindow;
var finished = false;
var privateWindow;
var privateWindowClosed = false;

pb.once('start', function() {
assert.pass('private browsing mode started');

// make a new private window
makeEmptyBrowserWindow().then(function(window) {
myPrivateWindow = window;

let wt = windowUtils.WindowTracker({
onTrack: function(window) {
if (!isBrowser(window) || window !== myPrivateWindow) return;

assert.ok(isWindowPrivate(window), 'window is private onTrack!');
let panel = Panel({
onShow: function() {
assert.ok(this.isShowing, 'the panel is showing on the private window');

let count = 0;
let widget = Widget({
id: "testShowPanelAndWidgetOnPrivateWindow-id",
label: "My Hello Widget",
content: "Hello!",
onAttach: function(mod) {
count++;
if (count == 2) {
panel.destroy();
widget.destroy();
close(window);
}
}
});
}
}).show(window.gBrowser);
},
onUntrack: function(window) {
if (window === myPrivateWindow) {
wt.unload();

pb.once('stop', function() {
assert.pass('private browsing mode end');
done();
});

pb.deactivate();
}
}
});

assert.equal(isWindowPrivate(window), true, 'the opened window is private');
assert.equal(isPrivate(window), true, 'the opened window is private');
assert.ok(getFrames(window).length > 1, 'there are frames for private window');
assert.equal(getWindowTitle(window), window.document.title,
'getWindowTitle works');
});
});
pb.activate();
};

exports.testWindowTrackerDoesNotIgnorePrivateWindows = function(assert, done) {
var myPrivateWindow;
var count = 0;

let wt = windowUtils.WindowTracker({
onTrack: function(window) {
if (!isBrowser(window) || !isWindowPrivate(window)) return;
assert.ok(isWindowPrivate(window), 'window is private onTrack!');
if (++count == 1)
close(window);
},
onUntrack: function(window) {
if (count == 1 && isWindowPrivate(window)) {
wt.unload();

pb.once('stop', function() {
assert.pass('private browsing mode end');
done();
});
pb.deactivate();
}
}
});

pb.once('start', function() {
assert.pass('private browsing mode started');
makeEmptyBrowserWindow();
});
pb.activate();
}

exports.testWindowIteratorDoesNotIgnorePrivateWindows = function(assert, done) {
pb.once('start', function() {
// make a new private window
makeEmptyBrowserWindow().then(function(window) {
assert.ok(isWindowPrivate(window), "window is private");
assert.equal(isPrivate(window), true, 'the opened window is private');
assert.ok(toArray(windowUtils.windowIterator()).indexOf(window) > -1,
"window is in windowIterator()");
assert.ok(windows(null, { includePrivate: true }).indexOf(window) > -1,
"window is in windows()");

close(window).then(function() {
pb.once('stop', function() {
done();
});
pb.deactivate();
});
});
});
pb.activate();
};

if (!isGlobalPBSupported) {
module.exports = {
"test Unsupported Test": function UnsupportedTest (assert) {
assert.pass(
"Skipping global private browsing tests");
}
}
}

0 comments on commit ad44c4b

Please sign in to comment.