main.js 2.8 KB

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