1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/addon-sdk/source/test/addons/simple-prefs-l10n/main.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,65 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 +'use strict'; 1.8 + 1.9 +const { Cu } = require('chrome'); 1.10 +const sp = require('sdk/simple-prefs'); 1.11 +const app = require('sdk/system/xul-app'); 1.12 +const self = require('sdk/self'); 1.13 +const tabs = require('sdk/tabs'); 1.14 +const { preferencesBranch } = require('sdk/self'); 1.15 + 1.16 +const { AddonManager } = Cu.import('resource://gre/modules/AddonManager.jsm', {}); 1.17 + 1.18 +// Once Bug 903018 is resolved, just move the application testing to 1.19 +// module.metadata.engines 1.20 +// 1.21 +// This should work in Fennec, needs to be refactored to work, via bug 979645 1.22 +if (app.is('Firefox')) { 1.23 + exports.testAOMLocalization = function(assert, done) { 1.24 + tabs.open({ 1.25 + url: 'about:addons', 1.26 + onReady: function(tab) { 1.27 + tab.attach({ 1.28 + contentScriptWhen: 'end', 1.29 + contentScript: 'function onLoad() {\n' + 1.30 + 'unsafeWindow.removeEventListener("load", onLoad, false);\n' + 1.31 + 'AddonManager.getAddonByID("' + self.id + '", function(aAddon) {\n' + 1.32 + 'unsafeWindow.gViewController.viewObjects.detail.node.addEventListener("ViewChanged", function whenViewChanges() {\n' + 1.33 + 'unsafeWindow.gViewController.viewObjects.detail.node.removeEventListener("ViewChanged", whenViewChanges, false);\n' + 1.34 + 'setTimeout(function() {\n' + // TODO: figure out why this is necessary.. 1.35 + 'self.postMessage({\n' + 1.36 + 'somePreference: getAttributes(unsafeWindow.document.querySelector("setting[data-jetpack-id=\'' + self.id + '\']"))\n' + 1.37 + '});\n' + 1.38 + '}, 250);\n' + 1.39 + '}, false);\n' + 1.40 + 'unsafeWindow.gViewController.commands.cmd_showItemDetails.doCommand(aAddon, true);\n' + 1.41 + '});\n' + 1.42 + 'function getAttributes(ele) {\n' + 1.43 + 'if (!ele) return {};\n' + 1.44 + 'return {\n' + 1.45 + 'title: ele.getAttribute("title")\n' + 1.46 + '}\n' + 1.47 + '}\n' + 1.48 + '}\n' + 1.49 + // Wait for the load event ? 1.50 + 'if (document.readyState == "complete") {\n' + 1.51 + 'onLoad()\n' + 1.52 + '} else {\n' + 1.53 + 'unsafeWindow.addEventListener("load", onLoad, false);\n' + 1.54 + '}\n', 1.55 + onMessage: function(msg) { 1.56 + // test somePreference 1.57 + assert.equal(msg.somePreference.title, 'A', 'somePreference title is correct'); 1.58 + tab.close(done); 1.59 + } 1.60 + }); 1.61 + } 1.62 + }); 1.63 + } 1.64 +} else { 1.65 + exports['test unsupported'] = (assert) => assert.pass('This test is unsupported.'); 1.66 +} 1.67 + 1.68 +require('sdk/test/runner').runTestsFromModule(module);