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

Commit

Permalink
bug 840014: checking isPrivateBrowsingSupported before opening a tab …
Browse files Browse the repository at this point in the history
…in private mode
  • Loading branch information
erikvold committed Feb 21, 2013
1 parent 77a72d1 commit 8135fd0
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 9 deletions.
5 changes: 4 additions & 1 deletion lib/sdk/tabs/tabs-firefox.js
Expand Up @@ -8,6 +8,9 @@ const { browserWindows: windows } = require('../windows');
const { tabs } = require('../windows/tabs-firefox');
const { isPrivate } = require('../private-browsing');
const { isWindowPBSupported } = require('../private-browsing/utils')
const { isPrivateBrowsingSupported } = require('sdk/self');

const supportPrivateTabs = isPrivateBrowsingSupported && isWindowPBSupported;

Object.defineProperties(tabs, {
open: { value: function open(options) {
Expand All @@ -25,7 +28,7 @@ Object.defineProperties(tabs, {
let activeWindow = windows.activeWindow;
let privateState = !!options.isPrivate;
// if the active window is in the state that we need then use it
if (!isWindowPBSupported || privateState === isPrivate(activeWindow)) {
if (!supportPrivateTabs || privateState === isPrivate(activeWindow)) {
activeWindow.tabs.open(options);
}
else {
Expand Down
3 changes: 2 additions & 1 deletion lib/sdk/windows/tabs-fennec.js
Expand Up @@ -17,6 +17,7 @@ const { EventTarget } = require('../event/target');
const { when: unload } = require('../system/unload');
const { windowIterator } = require('../deprecated/window-utils');
const { List, addListItem, removeListItem } = require('../util/list');
const { isPrivateBrowsingSupported } = require('sdk/self');

const mainWindow = windowNS(browserWindows.activeWindow).window;

Expand Down Expand Up @@ -54,7 +55,7 @@ const Tabs = Class({

let rawTab = openTab(windowNS(activeWin).window, options.url, {
inBackground: options.inBackground,
isPrivate: options.isPrivate
isPrivate: isPrivateBrowsingSupported && options.isPrivate
});

// by now the tab has been created
Expand Down
42 changes: 42 additions & 0 deletions test/addons/private-browsing-supported/main.js
Expand Up @@ -3,11 +3,53 @@
* 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');

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

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');
}
}

if (isTabPBSupported || isWindowPBSupported) {
// test that the tab is not private
// private flag should be ignored by default
assert.ok(isPrivate(tab));
assert.ok(isPrivate(getOwnerWindow(tab)));
}

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

require('sdk/test/runner').runTestsFromModule(module);
10 changes: 3 additions & 7 deletions test/test-private-browsing.js
Expand Up @@ -81,17 +81,13 @@ exports.testGetOwnerWindow = function(test) {
test.assert(getOwnerWindow(tab) instanceof Ci.nsIDOMWindow);
}
else {
if (pbUtils.isWindowPBSupported) {
test.assertNotStrictEqual(chromeWindow, getOwnerWindow(tab), 'associated window is not the same for window and window\'s tab');
}
else {
test.assertStrictEqual(chromeWindow, getOwnerWindow(tab), 'associated window is the same for window and window\'s tab');
}
test.assertStrictEqual(chromeWindow, getOwnerWindow(tab), 'associated window is the same for window and window\'s tab');
}

// test that the tab is not private
// private flag should be ignored by default
// test.assert(!isPrivate(tab));
test.assert(!isPrivate(tab));
test.assert(!isPrivate(getOwnerWindow(tab)));

tab.close(function() test.done());
}
Expand Down

0 comments on commit 8135fd0

Please sign in to comment.