michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: 'use strict'; michael@0: michael@0: const { Cu } = require('chrome'); michael@0: const sp = require('sdk/simple-prefs'); michael@0: const app = require('sdk/system/xul-app'); michael@0: const self = require('sdk/self'); michael@0: const tabs = require('sdk/tabs'); michael@0: const { preferencesBranch } = require('sdk/self'); michael@0: michael@0: const { AddonManager } = Cu.import('resource://gre/modules/AddonManager.jsm', {}); michael@0: michael@0: // Once Bug 903018 is resolved, just move the application testing to michael@0: // module.metadata.engines michael@0: // michael@0: // This should work in Fennec, needs to be refactored to work, via bug 979645 michael@0: if (app.is('Firefox')) { michael@0: exports.testAOMLocalization = function(assert, done) { michael@0: tabs.open({ michael@0: url: 'about:addons', michael@0: onReady: function(tab) { michael@0: tab.attach({ michael@0: contentScriptWhen: 'end', michael@0: contentScript: 'function onLoad() {\n' + michael@0: 'unsafeWindow.removeEventListener("load", onLoad, false);\n' + michael@0: 'AddonManager.getAddonByID("' + self.id + '", function(aAddon) {\n' + michael@0: 'unsafeWindow.gViewController.viewObjects.detail.node.addEventListener("ViewChanged", function whenViewChanges() {\n' + michael@0: 'unsafeWindow.gViewController.viewObjects.detail.node.removeEventListener("ViewChanged", whenViewChanges, false);\n' + michael@0: 'setTimeout(function() {\n' + // TODO: figure out why this is necessary.. michael@0: 'self.postMessage({\n' + michael@0: 'somePreference: getAttributes(unsafeWindow.document.querySelector("setting[data-jetpack-id=\'' + self.id + '\']"))\n' + michael@0: '});\n' + michael@0: '}, 250);\n' + michael@0: '}, false);\n' + michael@0: 'unsafeWindow.gViewController.commands.cmd_showItemDetails.doCommand(aAddon, true);\n' + michael@0: '});\n' + michael@0: 'function getAttributes(ele) {\n' + michael@0: 'if (!ele) return {};\n' + michael@0: 'return {\n' + michael@0: 'title: ele.getAttribute("title")\n' + michael@0: '}\n' + michael@0: '}\n' + michael@0: '}\n' + michael@0: // Wait for the load event ? michael@0: 'if (document.readyState == "complete") {\n' + michael@0: 'onLoad()\n' + michael@0: '} else {\n' + michael@0: 'unsafeWindow.addEventListener("load", onLoad, false);\n' + michael@0: '}\n', michael@0: onMessage: function(msg) { michael@0: // test somePreference michael@0: assert.equal(msg.somePreference.title, 'A', 'somePreference title is correct'); michael@0: tab.close(done); michael@0: } michael@0: }); michael@0: } michael@0: }); michael@0: } michael@0: } else { michael@0: exports['test unsupported'] = (assert) => assert.pass('This test is unsupported.'); michael@0: } michael@0: michael@0: require('sdk/test/runner').runTestsFromModule(module);