addon-sdk/source/test/test-self.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

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 const { Cc, Ci, Cu, Cm, components } = require("chrome");
michael@0 7 const xulApp = require("sdk/system/xul-app");
michael@0 8 const self = require("sdk/self");
michael@0 9 const { Loader, main, unload } = require("toolkit/loader");
michael@0 10 const loaderOptions = require("@loader/options");
michael@0 11
michael@0 12 const { AddonManager } = Cu.import("resource://gre/modules/AddonManager.jsm", {});
michael@0 13
michael@0 14 exports.testSelf = function(assert) {
michael@0 15 // Likewise, we can't assert anything about the full URL, because that
michael@0 16 // depends on self.id . We can only assert that it ends in the right
michael@0 17 // thing.
michael@0 18 var url = self.data.url("test-content-symbiont.js");
michael@0 19 assert.equal(typeof(url), "string", "self.data.url('x') returns string");
michael@0 20 assert.equal(/\/test-content-symbiont\.js$/.test(url), true);
michael@0 21
michael@0 22 // Make sure 'undefined' is not in url when no string is provided.
michael@0 23 url = self.data.url();
michael@0 24 assert.equal(typeof(url), "string", "self.data.url() returns string");
michael@0 25 assert.equal(/\/undefined$/.test(url), false);
michael@0 26
michael@0 27 // When tests are run on just the api-utils package, self.name is
michael@0 28 // api-utils. When they're run as 'cfx testall', self.name is testpkgs.
michael@0 29 assert.equal(self.name, "addon-sdk", "self.name is addon-sdk");
michael@0 30
michael@0 31 // loadReason may change here, as we change the way tests addons are installed
michael@0 32 // Bug 854937 fixed loadReason and is now install
michael@0 33 let testLoadReason = xulApp.versionInRange(xulApp.platformVersion,
michael@0 34 "23.0a1", "*") ? "install"
michael@0 35 : "startup";
michael@0 36 assert.equal(self.loadReason, testLoadReason,
michael@0 37 "self.loadReason is either startup or install on test runs");
michael@0 38
michael@0 39 assert.equal(self.isPrivateBrowsingSupported, false,
michael@0 40 'usePrivateBrowsing property is false by default');
michael@0 41 };
michael@0 42
michael@0 43 exports.testSelfID = function(assert, done) {
michael@0 44 var self = require("sdk/self");
michael@0 45 // We can't assert anything about the ID inside the unit test right now,
michael@0 46 // because the ID we get depends upon how the test was invoked. The idea
michael@0 47 // is that it is supposed to come from the main top-level package's
michael@0 48 // package.json file, from the "id" key.
michael@0 49 assert.equal(typeof(self.id), "string", "self.id is a string");
michael@0 50 assert.ok(self.id.length > 0);
michael@0 51
michael@0 52 AddonManager.getAddonByID(self.id, function(addon) {
michael@0 53 if (!addon) {
michael@0 54 assert.fail("did not find addon with self.id");
michael@0 55 }
michael@0 56 else {
michael@0 57 assert.pass("found addon with self.id");
michael@0 58 }
michael@0 59
michael@0 60 done();
michael@0 61 });
michael@0 62 }
michael@0 63
michael@0 64 exports.testSelfHandlesLackingLoaderOptions = function (assert) {
michael@0 65 let root = module.uri.substr(0, module.uri.lastIndexOf('/'));
michael@0 66 let uri = root + '/fixtures/loader/self/';
michael@0 67 let sdkPath = loaderOptions.paths[''] + 'sdk';
michael@0 68 let loader = Loader({ paths: { '': uri, 'sdk': sdkPath }});
michael@0 69 let program = main(loader, 'main');
michael@0 70 let self = program.self;
michael@0 71 assert.pass("No errors thrown when including sdk/self without loader options");
michael@0 72 assert.equal(self.isPrivateBrowsingSupported, false,
michael@0 73 "safely checks sdk/self.isPrivateBrowsingSupported");
michael@0 74 assert.equal(self.packed, false,
michael@0 75 "safely checks sdk/self.packed");
michael@0 76 unload(loader);
michael@0 77 };
michael@0 78
michael@0 79 require("sdk/test").run(exports);

mercurial