addon-sdk/source/test/addons/chrome/main.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/addon-sdk/source/test/addons/chrome/main.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,68 @@
     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, Cc, Ci } = require('chrome');
    1.10 +const Request = require('sdk/request').Request;
    1.11 +const { WindowTracker } = require('sdk/deprecated/window-utils');
    1.12 +const { close, open } = require('sdk/window/helpers');
    1.13 +
    1.14 +const XUL_URL = 'chrome://test/content/new-window.xul'
    1.15 +
    1.16 +const { Services } = Cu.import('resource://gre/modules/Services.jsm', {});
    1.17 +const { NetUtil } = Cu.import('resource://gre/modules/NetUtil.jsm', {});
    1.18 +
    1.19 +exports.testChromeSkin = function(assert, done) {
    1.20 +  let skinURL = 'chrome://test/skin/style.css';
    1.21 +
    1.22 +  Request({
    1.23 +    url: skinURL,
    1.24 +    overrideMimeType: 'text/plain',
    1.25 +    onComplete: function (response) {
    1.26 +      assert.equal(response.text.trim(), 'test{}', 'chrome.manifest skin folder was registered!');
    1.27 +      done();
    1.28 +    }
    1.29 +  }).get();
    1.30 +
    1.31 +  assert.pass('requesting ' + skinURL);
    1.32 +}
    1.33 +
    1.34 +exports.testChromeContent = function(assert, done) {
    1.35 +  let wt = WindowTracker({
    1.36 +    onTrack: function(window) {
    1.37 +      if (window.document.documentElement.getAttribute('windowtype') === 'test:window') {
    1.38 +      	assert.pass('test xul window was opened');
    1.39 +        wt.unload();
    1.40 +
    1.41 +      	close(window).then(done, assert.fail);
    1.42 +      }
    1.43 +    }
    1.44 +  });
    1.45 +
    1.46 +  open(XUL_URL).then(
    1.47 +    assert.pass.bind(assert, 'opened ' + XUL_URL),
    1.48 +    assert.fail);
    1.49 +
    1.50 +  assert.pass('opening ' + XUL_URL);
    1.51 +}
    1.52 +
    1.53 +exports.testChromeLocale = function(assert) {
    1.54 +  let jpLocalePath = Cc['@mozilla.org/chrome/chrome-registry;1'].
    1.55 +                       getService(Ci.nsIChromeRegistry).
    1.56 +                       convertChromeURL(NetUtil.newURI('chrome://test/locale/description.properties')).
    1.57 +                       spec.replace(/(en\-US|ja\-JP)/, 'ja-JP');
    1.58 +  let enLocalePath = jpLocalePath.replace(/ja\-JP/, 'en-US');
    1.59 +
    1.60 +  let jpStringBundle = Services.strings.createBundle(jpLocalePath);
    1.61 +  assert.equal(jpStringBundle.GetStringFromName('test'),
    1.62 +               'ใƒ†ใ‚นใƒˆ',
    1.63 +               'locales ja-JP folder was copied correctly');
    1.64 +
    1.65 +  let enStringBundle = Services.strings.createBundle(enLocalePath);
    1.66 +  assert.equal(enStringBundle.GetStringFromName('test'),
    1.67 +               'Test',
    1.68 +               'locales en-US folder was copied correctly');
    1.69 +}
    1.70 +
    1.71 +require('sdk/test/runner').runTestsFromModule(module);

mercurial