diff options
Diffstat (limited to 'addon-sdk/source/test/addons/chrome')
9 files changed, 137 insertions, 0 deletions
diff --git a/addon-sdk/source/test/addons/chrome/chrome.manifest b/addon-sdk/source/test/addons/chrome/chrome.manifest new file mode 100644 index 000000000..35e59a107 --- /dev/null +++ b/addon-sdk/source/test/addons/chrome/chrome.manifest @@ -0,0 +1,5 @@ +content test chrome/content/ +skin test classic/1.0 chrome/skin/ + +locale test en-US chrome/locale/en-US/ +locale test ja-JP chrome/locale/ja-JP/ diff --git a/addon-sdk/source/test/addons/chrome/chrome/content/new-window.xul b/addon-sdk/source/test/addons/chrome/chrome/content/new-window.xul new file mode 100644 index 000000000..25e219b80 --- /dev/null +++ b/addon-sdk/source/test/addons/chrome/chrome/content/new-window.xul @@ -0,0 +1,4 @@ +<?xml version="1.0"?> +<dialog xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" + windowtype="test:window"> +</dialog> diff --git a/addon-sdk/source/test/addons/chrome/chrome/content/panel.html b/addon-sdk/source/test/addons/chrome/chrome/content/panel.html new file mode 100644 index 000000000..595cc7455 --- /dev/null +++ b/addon-sdk/source/test/addons/chrome/chrome/content/panel.html @@ -0,0 +1,10 @@ +<!-- This Source Code Form is subject to the terms of the Mozilla Public + - License, v. 2.0. If a copy of the MPL was not distributed with this + - file, You can obtain one at http://mozilla.org/MPL/2.0/. --> +<!DOCTYPE html> +<html> + <head> + <meta charset="UTF-8"> + </head> + <body></body> +</html> diff --git a/addon-sdk/source/test/addons/chrome/chrome/locale/en-US/description.properties b/addon-sdk/source/test/addons/chrome/chrome/locale/en-US/description.properties new file mode 100644 index 000000000..148e2a127 --- /dev/null +++ b/addon-sdk/source/test/addons/chrome/chrome/locale/en-US/description.properties @@ -0,0 +1 @@ +test=Test diff --git a/addon-sdk/source/test/addons/chrome/chrome/locale/ja-JP/description.properties b/addon-sdk/source/test/addons/chrome/chrome/locale/ja-JP/description.properties new file mode 100644 index 000000000..cf01ac85b --- /dev/null +++ b/addon-sdk/source/test/addons/chrome/chrome/locale/ja-JP/description.properties @@ -0,0 +1 @@ +test=テスト diff --git a/addon-sdk/source/test/addons/chrome/chrome/skin/style.css b/addon-sdk/source/test/addons/chrome/chrome/skin/style.css new file mode 100644 index 000000000..22abf3596 --- /dev/null +++ b/addon-sdk/source/test/addons/chrome/chrome/skin/style.css @@ -0,0 +1,4 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +test{} diff --git a/addon-sdk/source/test/addons/chrome/data/panel.js b/addon-sdk/source/test/addons/chrome/data/panel.js new file mode 100644 index 000000000..c38eca852 --- /dev/null +++ b/addon-sdk/source/test/addons/chrome/data/panel.js @@ -0,0 +1,10 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +'use strict'; + +self.port.on('echo', _ => { + self.port.emit('echo', ''); +}); + +self.port.emit('start', ''); diff --git a/addon-sdk/source/test/addons/chrome/main.js b/addon-sdk/source/test/addons/chrome/main.js new file mode 100644 index 000000000..84b822458 --- /dev/null +++ b/addon-sdk/source/test/addons/chrome/main.js @@ -0,0 +1,97 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +'use strict' + +const { Cu, Cc, Ci } = require('chrome'); +const Request = require('sdk/request').Request; +const { WindowTracker } = require('sdk/deprecated/window-utils'); +const { close, open } = require('sdk/window/helpers'); +const { data } = require('sdk/self'); +const { Panel } = require('sdk/panel'); + +const XUL_URL = 'chrome://test/content/new-window.xul' + +const { Services } = Cu.import('resource://gre/modules/Services.jsm', {}); +const { NetUtil } = Cu.import('resource://gre/modules/NetUtil.jsm', {}); + +exports.testChromeSkin = function(assert, done) { + let skinURL = 'chrome://test/skin/style.css'; + + Request({ + url: skinURL, + overrideMimeType: 'text/plain', + onComplete: function (response) { + assert.ok(/test\{\}\s*$/.test(response.text), 'chrome.manifest skin folder was registered!'); + done(); + } + }).get(); + + assert.pass('requesting ' + skinURL); +} + +exports.testChromeContent = function(assert, done) { + let wt = WindowTracker({ + onTrack: function(window) { + if (window.document.documentElement.getAttribute('windowtype') === 'test:window') { + assert.pass('test xul window was opened'); + wt.unload(); + + close(window).then(done, assert.fail); + } + } + }); + + open(XUL_URL).then( + assert.pass.bind(assert, 'opened ' + XUL_URL), + assert.fail); + + assert.pass('opening ' + XUL_URL); +} + +exports.testChromeLocale = function(assert) { + let jpLocalePath = Cc['@mozilla.org/chrome/chrome-registry;1']. + getService(Ci.nsIChromeRegistry). + convertChromeURL(NetUtil.newURI('chrome://test/locale/description.properties')). + spec.replace(/(en\-US|ja\-JP)/, 'ja-JP'); + let enLocalePath = jpLocalePath.replace(/ja\-JP/, 'en-US'); + + let jpStringBundle = Services.strings.createBundle(jpLocalePath); + assert.equal(jpStringBundle.GetStringFromName('test'), + 'テスト', + 'locales ja-JP folder was copied correctly'); + + let enStringBundle = Services.strings.createBundle(enLocalePath); + assert.equal(enStringBundle.GetStringFromName('test'), + 'Test', + 'locales en-US folder was copied correctly'); +} + +exports.testChromeInPanel = function*(assert) { + let panel = Panel({ + contentURL: 'chrome://test/content/panel.html', + contentScriptWhen: 'end', + contentScriptFile: data.url('panel.js') + }); + + yield new Promise(resolve => panel.port.once('start', resolve)); + assert.pass('start was emitted'); + + yield new Promise(resolve => { + panel.once('show', resolve); + panel.show(); + }); + assert.pass('panel shown'); + + yield new Promise(resolve => { + panel.port.once('echo', resolve); + panel.port.emit('echo'); + }); + + assert.pass('got echo'); + + panel.destroy(); + assert.pass('panel is destroyed'); +} + +require('sdk/test/runner').runTestsFromModule(module); diff --git a/addon-sdk/source/test/addons/chrome/package.json b/addon-sdk/source/test/addons/chrome/package.json new file mode 100644 index 000000000..82c6db899 --- /dev/null +++ b/addon-sdk/source/test/addons/chrome/package.json @@ -0,0 +1,5 @@ +{ + "id": "test-chrome@jetpack", + "main": "./main.js", + "version": "0.0.1" +} |