|
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 { Cu } = require('chrome'); |
|
7 const sp = require('sdk/simple-prefs'); |
|
8 const app = require('sdk/system/xul-app'); |
|
9 const self = require('sdk/self'); |
|
10 const tabs = require('sdk/tabs'); |
|
11 const { preferencesBranch } = require('sdk/self'); |
|
12 |
|
13 const { AddonManager } = Cu.import('resource://gre/modules/AddonManager.jsm', {}); |
|
14 |
|
15 // Once Bug 903018 is resolved, just move the application testing to |
|
16 // module.metadata.engines |
|
17 // |
|
18 // This should work in Fennec, needs to be refactored to work, via bug 979645 |
|
19 if (app.is('Firefox')) { |
|
20 exports.testAOMLocalization = function(assert, done) { |
|
21 tabs.open({ |
|
22 url: 'about:addons', |
|
23 onReady: function(tab) { |
|
24 tab.attach({ |
|
25 contentScriptWhen: 'end', |
|
26 contentScript: 'function onLoad() {\n' + |
|
27 'unsafeWindow.removeEventListener("load", onLoad, false);\n' + |
|
28 'AddonManager.getAddonByID("' + self.id + '", function(aAddon) {\n' + |
|
29 'unsafeWindow.gViewController.viewObjects.detail.node.addEventListener("ViewChanged", function whenViewChanges() {\n' + |
|
30 'unsafeWindow.gViewController.viewObjects.detail.node.removeEventListener("ViewChanged", whenViewChanges, false);\n' + |
|
31 'setTimeout(function() {\n' + // TODO: figure out why this is necessary.. |
|
32 'self.postMessage({\n' + |
|
33 'somePreference: getAttributes(unsafeWindow.document.querySelector("setting[data-jetpack-id=\'' + self.id + '\']"))\n' + |
|
34 '});\n' + |
|
35 '}, 250);\n' + |
|
36 '}, false);\n' + |
|
37 'unsafeWindow.gViewController.commands.cmd_showItemDetails.doCommand(aAddon, true);\n' + |
|
38 '});\n' + |
|
39 'function getAttributes(ele) {\n' + |
|
40 'if (!ele) return {};\n' + |
|
41 'return {\n' + |
|
42 'title: ele.getAttribute("title")\n' + |
|
43 '}\n' + |
|
44 '}\n' + |
|
45 '}\n' + |
|
46 // Wait for the load event ? |
|
47 'if (document.readyState == "complete") {\n' + |
|
48 'onLoad()\n' + |
|
49 '} else {\n' + |
|
50 'unsafeWindow.addEventListener("load", onLoad, false);\n' + |
|
51 '}\n', |
|
52 onMessage: function(msg) { |
|
53 // test somePreference |
|
54 assert.equal(msg.somePreference.title, 'A', 'somePreference title is correct'); |
|
55 tab.close(done); |
|
56 } |
|
57 }); |
|
58 } |
|
59 }); |
|
60 } |
|
61 } else { |
|
62 exports['test unsupported'] = (assert) => assert.pass('This test is unsupported.'); |
|
63 } |
|
64 |
|
65 require('sdk/test/runner').runTestsFromModule(module); |