main.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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, Cc, Ci } = require('chrome');
  6. const Request = require('sdk/request').Request;
  7. const { WindowTracker } = require('sdk/deprecated/window-utils');
  8. const { close, open } = require('sdk/window/helpers');
  9. const XUL_URL = 'chrome://test/content/new-window.xul'
  10. const { Services } = Cu.import('resource://gre/modules/Services.jsm', {});
  11. const { NetUtil } = Cu.import('resource://gre/modules/NetUtil.jsm', {});
  12. exports.testChromeSkin = function(assert, done) {
  13. let skinURL = 'chrome://test/skin/style.css';
  14. Request({
  15. url: skinURL,
  16. overrideMimeType: 'text/plain',
  17. onComplete: function (response) {
  18. assert.equal(response.text, 'test{}\n', 'chrome.manifest skin folder was registered!');
  19. done();
  20. }
  21. }).get();
  22. assert.pass('requesting ' + skinURL);
  23. }
  24. exports.testChromeContent = function(assert, done) {
  25. let wt = WindowTracker({
  26. onTrack: function(window) {
  27. if (window.document.documentElement.getAttribute('windowtype') === 'test:window') {
  28. assert.pass('test xul window was opened');
  29. wt.unload();
  30. close(window).then(done, assert.fail);
  31. }
  32. }
  33. });
  34. open(XUL_URL).then(
  35. assert.pass.bind(assert, 'opened ' + XUL_URL),
  36. assert.fail);
  37. assert.pass('opening ' + XUL_URL);
  38. }
  39. exports.testChromeLocale = function(assert) {
  40. let jpLocalePath = Cc['@mozilla.org/chrome/chrome-registry;1'].
  41. getService(Ci.nsIChromeRegistry).
  42. convertChromeURL(NetUtil.newURI('chrome://test/locale/description.properties')).
  43. spec.replace(/(en\-US|ja\-JP)/, 'ja-JP');
  44. let enLocalePath = jpLocalePath.replace(/ja\-JP/, 'en-US');
  45. let jpStringBundle = Services.strings.createBundle(jpLocalePath);
  46. assert.equal(jpStringBundle.GetStringFromName('test'),
  47. 'テスト',
  48. 'locales ja-JP folder was copied correctly');
  49. let enStringBundle = Services.strings.createBundle(enLocalePath);
  50. assert.equal(enStringBundle.GetStringFromName('test'),
  51. 'Test',
  52. 'locales en-US folder was copied correctly');
  53. }
  54. require('sdk/test/runner').runTestsFromModule(module);