2013-02-01 21:17:34 +00:00
|
|
|
/* 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';
|
|
|
|
|
2014-03-03 19:22:07 +00:00
|
|
|
const { Ci, Cu } = require('chrome');
|
2013-10-04 23:48:52 +00:00
|
|
|
const { safeMerge } = require('sdk/util/object');
|
2013-02-01 21:17:34 +00:00
|
|
|
const windows = require('sdk/windows').browserWindows;
|
2013-02-22 18:22:25 +00:00
|
|
|
const tabs = require('sdk/tabs');
|
2013-02-01 21:17:34 +00:00
|
|
|
const winUtils = require('sdk/window/utils');
|
2013-03-07 23:09:34 +00:00
|
|
|
const { isWindowPrivate } = winUtils;
|
2013-02-21 15:54:55 +00:00
|
|
|
const { isPrivateBrowsingSupported } = require('sdk/self');
|
|
|
|
const { is } = require('sdk/system/xul-app');
|
|
|
|
const { isPrivate } = require('sdk/private-browsing');
|
2013-03-07 23:09:34 +00:00
|
|
|
const { getOwnerWindow } = require('sdk/private-browsing/window/utils');
|
|
|
|
const { LoaderWithHookedConsole } = require("sdk/test/loader");
|
|
|
|
const { getMode, isGlobalPBSupported,
|
|
|
|
isWindowPBSupported, isTabPBSupported } = require('sdk/private-browsing/utils');
|
|
|
|
const { pb } = require('./private-browsing/helper');
|
2013-07-10 02:15:10 +00:00
|
|
|
const prefs = require('sdk/preferences/service');
|
2013-09-06 18:09:20 +00:00
|
|
|
const { set: setPref } = require("sdk/preferences/service");
|
|
|
|
const DEPRECATE_PREF = "devtools.errorconsole.deprecation_warnings";
|
2013-07-10 02:15:10 +00:00
|
|
|
|
2014-03-03 19:22:07 +00:00
|
|
|
const { Services } = Cu.import("resource://gre/modules/Services.jsm", {});
|
|
|
|
|
2013-07-10 02:15:10 +00:00
|
|
|
const kAutoStartPref = "browser.privatebrowsing.autostart";
|
2013-02-01 21:17:34 +00:00
|
|
|
|
|
|
|
// is global pb is enabled?
|
2013-03-07 23:09:34 +00:00
|
|
|
if (isGlobalPBSupported) {
|
2013-10-04 23:48:52 +00:00
|
|
|
safeMerge(module.exports, require('./private-browsing/global'));
|
2013-02-21 15:54:55 +00:00
|
|
|
|
2013-10-04 23:48:52 +00:00
|
|
|
exports.testGlobalOnlyOnFirefox = function(assert) {
|
|
|
|
assert.ok(is("Firefox"), "isGlobalPBSupported is only true on Firefox");
|
2013-02-21 15:54:55 +00:00
|
|
|
}
|
2013-02-01 21:17:34 +00:00
|
|
|
}
|
2013-03-07 23:09:34 +00:00
|
|
|
else if (isWindowPBSupported) {
|
2013-10-04 23:48:52 +00:00
|
|
|
safeMerge(module.exports, require('./private-browsing/windows'));
|
2013-02-21 15:54:55 +00:00
|
|
|
|
2013-10-04 23:48:52 +00:00
|
|
|
exports.testPWOnlyOnFirefox = function(assert) {
|
|
|
|
assert.ok(is("Firefox"), "isWindowPBSupported is only true on Firefox");
|
2013-02-21 15:54:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// only on Fennec
|
2013-03-07 23:09:34 +00:00
|
|
|
else if (isTabPBSupported) {
|
2013-10-04 23:48:52 +00:00
|
|
|
safeMerge(module.exports, require('./private-browsing/tabs'));
|
2013-02-21 15:54:55 +00:00
|
|
|
|
2013-10-04 23:48:52 +00:00
|
|
|
exports.testPTOnlyOnFennec = function(assert) {
|
|
|
|
assert.ok(is("Fennec"), "isTabPBSupported is only true on Fennec");
|
2013-02-21 15:54:55 +00:00
|
|
|
}
|
2013-02-01 21:17:34 +00:00
|
|
|
}
|
|
|
|
|
2013-10-04 23:48:52 +00:00
|
|
|
exports.testIsPrivateDefaults = function(assert) {
|
|
|
|
assert.equal(isPrivate(), false, 'undefined is not private');
|
|
|
|
assert.equal(isPrivate('test'), false, 'strings are not private');
|
|
|
|
assert.equal(isPrivate({}), false, 'random objects are not private');
|
|
|
|
assert.equal(isPrivate(4), false, 'numbers are not private');
|
|
|
|
assert.equal(isPrivate(/abc/), false, 'regex are not private');
|
|
|
|
assert.equal(isPrivate(function() {}), false, 'functions are not private');
|
2013-02-21 15:54:55 +00:00
|
|
|
};
|
|
|
|
|
2013-10-04 23:48:52 +00:00
|
|
|
exports.testWindowDefaults = function(assert) {
|
2013-09-06 18:09:20 +00:00
|
|
|
setPref(DEPRECATE_PREF, true);
|
2013-03-07 23:09:34 +00:00
|
|
|
// Ensure that browserWindow still works while being deprecated
|
|
|
|
let { loader, messages } = LoaderWithHookedConsole(module);
|
|
|
|
let windows = loader.require("sdk/windows").browserWindows;
|
2013-10-04 23:48:52 +00:00
|
|
|
assert.equal(windows.activeWindow.isPrivateBrowsing, false,
|
2013-03-07 23:09:34 +00:00
|
|
|
'window is not private browsing by default');
|
2013-10-04 23:48:52 +00:00
|
|
|
assert.ok(/DEPRECATED.+isPrivateBrowsing/.test(messages[0].msg),
|
2013-03-07 23:09:34 +00:00
|
|
|
'isPrivateBrowsing is deprecated');
|
|
|
|
|
2013-02-01 21:17:34 +00:00
|
|
|
let chromeWin = winUtils.getMostRecentBrowserWindow();
|
2013-10-04 23:48:52 +00:00
|
|
|
assert.equal(getMode(chromeWin), false);
|
|
|
|
assert.equal(isWindowPrivate(chromeWin), false);
|
|
|
|
};
|
2013-02-01 21:17:34 +00:00
|
|
|
|
|
|
|
// tests for the case where private browsing doesn't exist
|
2013-10-04 23:48:52 +00:00
|
|
|
exports.testIsActiveDefault = function(assert) {
|
|
|
|
assert.equal(pb.isActive, false,
|
2013-02-01 21:17:34 +00:00
|
|
|
'pb.isActive returns false when private browsing isn\'t supported');
|
|
|
|
};
|
2013-02-14 18:03:26 +00:00
|
|
|
|
2013-10-04 23:48:52 +00:00
|
|
|
exports.testIsPrivateBrowsingFalseDefault = function(assert) {
|
|
|
|
assert.equal(isPrivateBrowsingSupported, false,
|
2013-03-07 23:09:34 +00:00
|
|
|
'isPrivateBrowsingSupported property is false by default');
|
2013-02-21 15:54:55 +00:00
|
|
|
};
|
|
|
|
|
2013-10-04 23:48:52 +00:00
|
|
|
exports.testGetOwnerWindow = function(assert, done) {
|
2013-02-21 15:54:55 +00:00
|
|
|
let window = windows.activeWindow;
|
|
|
|
let chromeWindow = getOwnerWindow(window);
|
2013-10-04 23:48:52 +00:00
|
|
|
assert.ok(chromeWindow instanceof Ci.nsIDOMWindow, 'associated window is found');
|
2013-02-21 15:54:55 +00:00
|
|
|
|
2013-02-22 18:22:25 +00:00
|
|
|
tabs.open({
|
2013-02-21 15:54:55 +00:00
|
|
|
url: 'about:blank',
|
2013-02-22 18:22:25 +00:00
|
|
|
isPrivate: true,
|
2013-02-21 15:54:55 +00:00
|
|
|
onOpen: function(tab) {
|
|
|
|
// test that getOwnerWindow works as expected
|
|
|
|
if (is('Fennec')) {
|
2014-03-03 19:22:07 +00:00
|
|
|
assert.notStrictEqual(chromeWindow, getOwnerWindow(tab));
|
|
|
|
assert.ok(getOwnerWindow(tab) instanceof Ci.nsIDOMWindow);
|
2013-02-21 15:54:55 +00:00
|
|
|
}
|
|
|
|
else {
|
2013-10-04 23:48:52 +00:00
|
|
|
assert.strictEqual(chromeWindow, getOwnerWindow(tab), 'associated window is the same for window and window\'s tab');
|
2013-02-21 15:54:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// test that the tab is not private
|
|
|
|
// private flag should be ignored by default
|
2013-10-04 23:48:52 +00:00
|
|
|
assert.ok(!isPrivate(tab));
|
|
|
|
assert.ok(!isPrivate(getOwnerWindow(tab)));
|
2013-02-21 15:54:55 +00:00
|
|
|
|
2013-10-04 23:48:52 +00:00
|
|
|
tab.close(done);
|
2013-02-21 15:54:55 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
2013-07-10 02:15:10 +00:00
|
|
|
|
2014-03-03 19:22:07 +00:00
|
|
|
exports.testNSIPrivateBrowsingChannel = function(assert) {
|
|
|
|
let channel = Services.io.newChannel("about:blank", null, null);
|
|
|
|
channel.QueryInterface(Ci.nsIPrivateBrowsingChannel);
|
|
|
|
assert.equal(isPrivate(channel), false, 'isPrivate detects non-private channels');
|
|
|
|
channel.setPrivate(true);
|
|
|
|
assert.ok(isPrivate(channel), 'isPrivate detects private channels');
|
|
|
|
}
|
|
|
|
|
2013-10-04 23:48:52 +00:00
|
|
|
exports.testNewGlobalPBService = function(assert) {
|
|
|
|
assert.equal(isPrivate(), false, 'isPrivate() is false by default');
|
2013-07-10 02:15:10 +00:00
|
|
|
prefs.set(kAutoStartPref, true);
|
2013-10-04 23:48:52 +00:00
|
|
|
assert.equal(prefs.get(kAutoStartPref, false), true, kAutoStartPref + ' is true now');
|
|
|
|
assert.equal(isPrivate(), true, 'isPrivate() is true now');
|
2013-07-10 02:15:10 +00:00
|
|
|
prefs.set(kAutoStartPref, false);
|
2013-10-04 23:48:52 +00:00
|
|
|
assert.equal(isPrivate(), false, 'isPrivate() is false again');
|
|
|
|
};
|
|
|
|
|
|
|
|
require('sdk/test').run(exports);
|