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

Commit

Permalink
Merge pull request #1357 from jsantell/961245-remove-assumptions-from…
Browse files Browse the repository at this point in the history
…-self

Fixes Bug 961245 sdk/self makes less assumptions about loader options, r=@erikvold
  • Loading branch information
jsantell committed Jan 22, 2014
2 parents 35c590b + f3cc9cb commit 1a33756
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
5 changes: 2 additions & 3 deletions lib/sdk/self.js
Expand Up @@ -29,12 +29,11 @@ exports.name = name;
exports.loadReason = loadReason;
exports.version = version;
// If `rootURI` is jar:file://...!/ than add-on is packed.
exports.packed = rootURI.indexOf('jar:') === 0
exports.packed = (rootURI || '').indexOf('jar:') === 0;
exports.data = Object.freeze({
url: uri,
load: function read(path) {
return readURISync(uri(path));
}
});
exports.isPrivateBrowsingSupported = ((metadata.permissions || {})['private-browsing'] === true) ?
true : false;
exports.isPrivateBrowsingSupported = ((metadata || {}).permissions || {})['private-browsing'] === true;
8 changes: 8 additions & 0 deletions test/fixtures/loader/self/main.js
@@ -0,0 +1,8 @@
/* 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";

var self = require("sdk/self");
exports.self = self;
17 changes: 17 additions & 0 deletions test/test-self.js
Expand Up @@ -6,6 +6,8 @@
const { Cc, Ci, Cu, Cm, components } = require("chrome");
const xulApp = require("sdk/system/xul-app");
const self = require("sdk/self");
const { Loader, main, unload } = require("toolkit/loader");
const loaderOptions = require("@loader/options");

const { AddonManager } = Cu.import("resource://gre/modules/AddonManager.jsm", {});

Expand Down Expand Up @@ -59,4 +61,19 @@ exports.testSelfID = function(assert, done) {
});
}

exports.testSelfHandlesLackingLoaderOptions = function (assert) {
let root = module.uri.substr(0, module.uri.lastIndexOf('/'));
let uri = root + '/fixtures/loader/self/';
let sdkPath = loaderOptions.paths[''] + 'sdk';
let loader = Loader({ paths: { '': uri, 'sdk': sdkPath }});
let program = main(loader, 'main');
let self = program.self;
assert.pass("No errors thrown when including sdk/self without loader options");
assert.equal(self.isPrivateBrowsingSupported, false,
"safely checks sdk/self.isPrivateBrowsingSupported");
assert.equal(self.packed, false,
"safely checks sdk/self.packed");
unload(loader);
};

require("sdk/test").run(exports);

0 comments on commit 1a33756

Please sign in to comment.