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