Thu, 15 Jan 2015 15:59:08 +0100
Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4 "use strict";
6 exports["test local vs sdk module"] = function (assert) {
7 assert.notEqual(require("memory"),
8 require("sdk/deprecated/memory"),
9 "Local module takes the priority over sdk modules");
10 assert.ok(require("memory").local,
11 "this module is really the local one");
12 }
14 exports["test 3rd party vs sdk module"] = function (assert) {
15 // We are testing with a 3rd party package called `tabs` with 3 modules
16 // main, page-mod and third-party
18 // the only way to require 3rd party package modules are to use absolute paths
19 // require("tabs/main"), require("tabs/page-mod"),
20 // require("tabs/third-party") and also require("tabs") which will refer
21 // to tabs's main package module.
23 // So require(page-mod) shouldn't map the 3rd party
24 assert.equal(require("page-mod"),
25 require("sdk/page-mod"),
26 "Third party modules don't overload sdk modules");
27 assert.ok(require("page-mod").PageMod,
28 "page-mod module is really the sdk one");
30 assert.equal(require("tabs/page-mod").id, "page-mod",
31 "tabs/page-mod is the 3rd party");
33 // But require(tabs) will map to 3rd party main module
34 // *and* overload the sdk module
35 // and also any local module with the same name
36 assert.equal(require("tabs").id, "tabs-main",
37 "Third party main module overload sdk modules");
38 assert.equal(require("tabs"),
39 require("tabs/main"),
40 "require(tabs) maps to require(tabs/main)");
41 // So that you have to use relative path to ensure getting the local module
42 assert.equal(require("./tabs").id,
43 "local-tabs",
44 "require(./tabs) maps to the local module");
46 // It should still be possible to require sdk module with absolute path
47 assert.ok(require("sdk/tabs").open,
48 "We can bypass this overloading with absolute path to sdk modules");
49 assert.equal(require("sdk/tabs"),
50 require("addon-kit/tabs"),
51 "Old and new layout both work");
52 }
54 // /!\ Always use distinct module for each test.
55 // Otherwise, the linker can correctly parse and allow the first usage of it
56 // but still silently fail on the second.
58 exports.testRelativeRequire = function (assert) {
59 assert.equal(require('./same-folder').id, 'same-folder');
60 }
62 exports.testRelativeSubFolderRequire = function (assert) {
63 assert.equal(require('./sub-folder/module').id, 'sub-folder');
64 }
66 exports.testMultipleRequirePerLine = function (assert) {
67 var a=require('./multiple/a'),b=require('./multiple/b');
68 assert.equal(a.id, 'a');
69 assert.equal(b.id, 'b');
70 }
72 exports.testSDKRequire = function (assert) {
73 assert.deepEqual(Object.keys(require('sdk/page-worker')), ['Page']);
74 assert.equal(require('page-worker'), require('sdk/page-worker'));
75 }
77 require("sdk/test/runner").runTestsFromModule(module);