diff --git a/lib/sdk/self.js b/lib/sdk/self.js index 58a2bacc5..c720be890 100644 --- a/lib/sdk/self.js +++ b/lib/sdk/self.js @@ -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; diff --git a/test/fixtures/loader/self/main.js b/test/fixtures/loader/self/main.js new file mode 100644 index 000000000..ab2b159da --- /dev/null +++ b/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; diff --git a/test/test-self.js b/test/test-self.js index 47b00fe77..0170a27f3 100644 --- a/test/test-self.js +++ b/test/test-self.js @@ -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", {}); @@ -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);