addon-sdk/source/test/addons/require/main.js

Thu, 15 Jan 2015 15:59:08 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:59:08 +0100
branch
TOR_BUG_9701
changeset 10
ac0c01689b40
permissions
-rw-r--r--

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.

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

mercurial