Skip to content

Loading…

Bug 853336: widget module failed with pb permission #882

Closed
wants to merge 2 commits into from

4 participants

@erikvold

This depends on #881

@KWierso
Mozilla member

cfx testaddons passes for me on both Firefox 19 and 20 with this branch, though it spams lots of deprecation warnings (with tracebacks) when run against 19.

@KWierso
Mozilla member

And cfx testall passes everything on both 19 and 20 with this branch.

@erikvold

hmmm, the widget module shouldn't know anything about the panel module imo.

@erikvold
{ show: function (node) {node.ownerDocument.defaultView.Component.doCrazyThings()} }

very good point, I'll try adding a showById method to panel.

@erikvold

so it looks like panel.show(widget) would be better, and this is bug 638142

@Gozala
Mozilla member

@erikvold I have submitted a erikvold/jetpack-sdk#2

@ochameau
Mozilla member

Just saying, ok: function(v) !v || v instanceof require("./panel").Panel would have fix the issue without introducing a workaround that is hard to understand.
We shouldn't forget we are landing for 1.14 which is at risk and we should aim to land minimal changes now.
method isn't on stabilization yet, so pulling this will pull method revision and eventual dependencies.
this.panel.show(getNodeView.implement({}, function() domNode));
First time I have to understand this yet another new abstration thingy and I already have hard time with it.

@erikvold erikvold closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 21, 2013
  1. @erikvold

    Bug 839746: global private windows (Fx <=19) are not ignored, per wid…

    erikvold committed
    …now private windows (on Fx > 19) still are
  2. @erikvold

    Bug 853336: widget module depeneded on panel module, which meant addo…

    erikvold committed
    …ns using widget with pb permissions would fail to load..
This page is out of date. Refresh to see the latest.
View
4 lib/sdk/deprecated/window-utils.js
@@ -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'].
@@ -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.
View
2 lib/sdk/private-browsing/utils.js
@@ -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;
View
8 lib/sdk/widget.js
@@ -36,7 +36,6 @@ const EVENTS = {
};
const { validateOptions } = require("./deprecated/api-utils");
-const panels = require("./panel");
const { EventEmitter, EventEmitterTrait } = require("./deprecated/events");
const { Trait } = require("./deprecated/traits");
const LightTrait = require('./deprecated/light-traits').Trait;
@@ -65,8 +64,7 @@ const valid = {
msg: ERR_LABEL
},
panel: {
- is: ["null", "undefined", "object"],
- ok: function(v) !v || v instanceof panels.Panel
+ is: ["null", "undefined", "object"]
},
width: {
is: ["null", "undefined", "number"],
@@ -333,7 +331,7 @@ const WidgetTrait = LightTrait.compose(EventEmitterTrait, LightTrait({
},
destroy: function destroy() {
- if (this.panel)
+ if (this.panel && this.panel.destroy)
this.panel.destroy();
// Dispatch destroy calls to views
@@ -431,7 +429,7 @@ const WidgetViewTrait = LightTrait.compose(EventEmitterTrait, LightTrait({
// Special case for click events: if the widget doesn't have a click
// handler, but it does have a panel, display the panel.
- if ("click" == type && !this._listeners("click").length && this.panel)
+ if ("click" == type && !this._listeners("click").length && this.panel && this.panel.show)
this.panel.show(domNode);
},
View
2 lib/sdk/windows/tabs-firefox.js
@@ -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";
View
163 test/addons/private-browsing-supported/main.js
@@ -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);
View
151 test/addons/private-browsing-supported/test-global-private-browsing.js
@@ -0,0 +1,151 @@
+/* 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 pb = require('sdk/private-browsing');
+const { Widget } = require('sdk/widget');
+const { fromIterator: toArray } = require('sdk/util/array');
+
+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) {
+ const { Panel } = require('sdk/panel');
+
+ 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");
+ }
+ }
+}
View
164 test/addons/private-browsing-supported/test-private-browsing.js
@@ -0,0 +1,164 @@
+/* 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 { 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 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);
+ }
+ })
+ }
+}
View
16 test/private-browsing/global.js
@@ -6,6 +6,7 @@
const timer = require("sdk/timers");
const { LoaderWithHookedConsole, deactivate, pb, pbUtils } = require("./helper");
const tabs = require("sdk/tabs");
+const { getMostRecentBrowserWindow, isWindowPrivate } = require('sdk/window/utils');
exports["test activate private mode via handler"] = function(test) {
test.waitUntilDone();
@@ -232,3 +233,18 @@ exports.testUnloadWhileActive = function(test) {
pb.activate();
};
+
+exports.testIgnoreWindow = function(test) {
+ test.waitUntilDone();
+ let window = getMostRecentBrowserWindow();
+
+ pb.once('start', function() {
+ test.assert(isWindowPrivate(window), 'window is private');
+ test.assert(!pbUtils.ignoreWindow(window), 'window is not ignored');
+ pb.once('stop', function() {
+ test.done();
+ });
+ pb.deactivate();
+ });
+ pb.activate();
+};
View
15 test/test-widget.js
@@ -686,21 +686,6 @@ exports.testPanelWidget1 = function testPanelWidget1(test) {
test.waitUntilDone();
};
-exports.testPanelWidget2 = function testPanelWidget2(test) {
- const widgets = require("sdk/widget");
- test.assertRaises(
- function() {
- widgets.Widget({
- id: "panel2",
- label: "panel widget 2",
- panel: {}
- });
- },
- "The option \"panel\" must be one of the following types: null, undefined, object",
- "widget.panel must be a Panel object"
- );
-};
-
exports.testPanelWidget3 = function testPanelWidget3(test) {
const widgets = require("sdk/widget");
let onClickCalled = false;
View
152 test/test-window-utils-global-private-browsing.js
@@ -0,0 +1,152 @@
+/* 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 { pb } = require('./private-browsing/helper');
+const { Panel } = require('sdk/panel');
+const { Widget } = require('sdk/widget');
+const { fromIterator: toArray } = require('sdk/util/array');
+
+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");
+ }
+ }
+}
+
+require("test").run(exports);
View
8 test/test-window-utils-private-browsing.js
@@ -30,14 +30,10 @@ exports.testWindowTrackerIgnoresPrivateWindows = function(assert, done) {
let wt = windowUtils.WindowTracker({
onTrack: function(window) {
- if (isWindowPrivate(window)) {
- assert.fail('private window was tracked!');
- }
+ assert.ok(!isWindowPrivate(window), 'private window was not tracked!');
},
onUntrack: function(window) {
- if (isWindowPrivate(window)) {
- assert.fail('private window was tracked!');
- }
+ assert.ok(!isWindowPrivate(window), 'private window was not tracked!');
// PWPB case
if (window === myPrivateWindow && isWindowPBSupported) {
privateWindowClosed = true;
Something went wrong with that request. Please try again.