summaryrefslogtreecommitdiffstats
path: root/addon-sdk/source/test/addons/embedded-webextension
diff options
context:
space:
mode:
authorMatt A. Tobin <email@mattatobin.com>2018-02-09 06:46:43 -0500
committerMatt A. Tobin <email@mattatobin.com>2018-02-09 06:46:43 -0500
commitac46df8daea09899ce30dc8fd70986e258c746bf (patch)
tree2750d3125fc253fd5b0671e4bd268eff1fd97296 /addon-sdk/source/test/addons/embedded-webextension
parent8cecf8d5208f3945b35f879bba3015bb1a11bec6 (diff)
downloadUXP-ac46df8daea09899ce30dc8fd70986e258c746bf.tar
UXP-ac46df8daea09899ce30dc8fd70986e258c746bf.tar.gz
UXP-ac46df8daea09899ce30dc8fd70986e258c746bf.tar.lz
UXP-ac46df8daea09899ce30dc8fd70986e258c746bf.tar.xz
UXP-ac46df8daea09899ce30dc8fd70986e258c746bf.zip
Move Add-on SDK source to toolkit/jetpack
Diffstat (limited to 'addon-sdk/source/test/addons/embedded-webextension')
-rw-r--r--addon-sdk/source/test/addons/embedded-webextension/main.js159
-rw-r--r--addon-sdk/source/test/addons/embedded-webextension/package.json6
-rw-r--r--addon-sdk/source/test/addons/embedded-webextension/webextension/background-page.js10
-rw-r--r--addon-sdk/source/test/addons/embedded-webextension/webextension/content-script.js10
-rw-r--r--addon-sdk/source/test/addons/embedded-webextension/webextension/manifest.json18
5 files changed, 0 insertions, 203 deletions
diff --git a/addon-sdk/source/test/addons/embedded-webextension/main.js b/addon-sdk/source/test/addons/embedded-webextension/main.js
deleted file mode 100644
index 11249c504..000000000
--- a/addon-sdk/source/test/addons/embedded-webextension/main.js
+++ /dev/null
@@ -1,159 +0,0 @@
-const tabs = require("sdk/tabs");
-const webExtension = require('sdk/webextension');
-
-exports.testEmbeddedWebExtensionModuleInitializedException = function (assert) {
- let actualErr;
-
- assert.throws(
- () => webExtension.initFromBootstrapAddonParam({webExtension: null}),
- /'sdk\/webextension' module has been already initialized/,
- "Got the expected exception if the module is initialized twice"
- );
-};
-
-exports.testEmbeddedWebExtensionBackgroungPage = function* (assert) {
- try {
- const api = yield webExtension.startup();
- assert.ok(api, `webextension waitForStartup promise successfully resolved`);
-
- const apiSecondStartup = yield webExtension.startup();
- assert.equal(api, apiSecondStartup, "Got the same API object from the second startup call");
-
- const {browser} = api;
-
- let messageListener;
- let waitForBackgroundPageMessage = new Promise((resolve, reject) => {
- let numExpectedMessage = 2;
- messageListener = (msg, sender, sendReply) => {
- numExpectedMessage -= 1;
- if (numExpectedMessage == 1) {
- assert.equal(msg, "bg->sdk message",
- "Got the expected message from the background page");
- sendReply("sdk reply");
- } else if (numExpectedMessage == 0) {
- assert.equal(msg, "sdk reply",
- "The background page received the expected reply message");
- resolve();
- } else {
- console.error("Unexpected message received", {msg,sender, numExpectedMessage});
- assert.ok(false, `unexpected message received`);
- reject();
- }
- };
- browser.runtime.onMessage.addListener(messageListener);
- });
-
- let portListener;
- let waitForBackgroundPagePort = new Promise((resolve, reject) => {
- portListener = (port) => {
- let numExpectedMessages = 2;
- port.onMessage.addListener((msg) => {
- numExpectedMessages -= 1;
-
- if (numExpectedMessages == 1) {
- // Check that the legacy context has been able to receive the first port message
- // and reply with a port message to the background page.
- assert.equal(msg, "bg->sdk port message",
- "Got the expected port message from the background page");
- port.postMessage("sdk->bg port message");
- } else if (numExpectedMessages == 0) {
- // Check that the background page has received the above port message.
- assert.equal(msg, "bg received sdk->bg port message",
- "The background page received the expected port message");
- }
- });
-
- port.onDisconnect.addListener(() => {
- assert.equal(numExpectedMessages, 0, "Got the expected number of port messages");
- resolve();
- });
- };
- browser.runtime.onConnect.addListener(portListener);
- });
-
- yield Promise.all([
- waitForBackgroundPageMessage,
- waitForBackgroundPagePort,
- ]).then(() => {
- browser.runtime.onMessage.removeListener(messageListener);
- browser.runtime.onConnect.removeListener(portListener);
- });
-
- } catch (err) {
- assert.fail(`Unexpected webextension startup exception: ${err} - ${err.stack}`);
- }
-};
-
-exports.testEmbeddedWebExtensionContentScript = function* (assert, done) {
- try {
- const {browser} = yield webExtension.startup();
- assert.ok(browser, `webextension startup promise resolved successfully to the API object`);
-
- let messageListener;
- let waitForContentScriptMessage = new Promise((resolve, reject) => {
- let numExpectedMessage = 2;
- messageListener = (msg, sender, sendReply) => {
- numExpectedMessage -= 1;
- if (numExpectedMessage == 1) {
- assert.equal(msg, "content script->sdk message",
- "Got the expected message from the content script");
- sendReply("sdk reply");
- } else if (numExpectedMessage == 0) {
- assert.equal(msg, "sdk reply",
- "The content script received the expected reply message");
- resolve();
- } else {
- console.error("Unexpected message received", {msg,sender, numExpectedMessage});
- assert.ok(false, `unexpected message received`);
- reject();
- }
- };
- browser.runtime.onMessage.addListener(messageListener);
- });
-
- let portListener;
- let waitForContentScriptPort = new Promise((resolve, reject) => {
- portListener = (port) => {
- let numExpectedMessages = 2;
- port.onMessage.addListener((msg) => {
- numExpectedMessages -= 1;
-
- if (numExpectedMessages == 1) {
- assert.equal(msg, "content script->sdk port message",
- "Got the expected message from the content script port");
- port.postMessage("sdk->content script port message");
- } else if (numExpectedMessages == 0) {
- assert.equal(msg, "content script received sdk->content script port message",
- "The content script received the expected port message");
- }
- });
- port.onDisconnect.addListener(() => {
- assert.equal(numExpectedMessages, 0, "Got the epected number of port messages");
- resolve();
- });
- };
- browser.runtime.onConnect.addListener(portListener);
- });
-
- let url = "http://example.org/";
-
- var openedTab;
- tabs.once('open', function onOpen(tab) {
- openedTab = tab;
- });
- tabs.open(url);
-
- yield Promise.all([
- waitForContentScriptMessage,
- waitForContentScriptPort,
- ]).then(() => {
- browser.runtime.onMessage.removeListener(messageListener);
- browser.runtime.onConnect.removeListener(portListener);
- openedTab.close();
- });
- } catch (err) {
- assert.fail(`Unexpected webextension startup exception: ${err} - ${err.stack}`);
- }
-};
-
-require("sdk/test/runner").runTestsFromModule(module);
diff --git a/addon-sdk/source/test/addons/embedded-webextension/package.json b/addon-sdk/source/test/addons/embedded-webextension/package.json
deleted file mode 100644
index 25dec41c3..000000000
--- a/addon-sdk/source/test/addons/embedded-webextension/package.json
+++ /dev/null
@@ -1,6 +0,0 @@
-{
- "id": "embedded-webextension@jetpack",
- "version": "0.1.0",
- "main": "./main.js",
- "hasEmbeddedWebExtension": true
-}
diff --git a/addon-sdk/source/test/addons/embedded-webextension/webextension/background-page.js b/addon-sdk/source/test/addons/embedded-webextension/webextension/background-page.js
deleted file mode 100644
index 05e7a613b..000000000
--- a/addon-sdk/source/test/addons/embedded-webextension/webextension/background-page.js
+++ /dev/null
@@ -1,10 +0,0 @@
-browser.runtime.sendMessage("bg->sdk message", (reply) => {
- browser.runtime.sendMessage(reply);
-});
-
-let port = browser.runtime.connect();
-port.onMessage.addListener((msg) => {
- port.postMessage(`bg received ${msg}`);
- port.disconnect();
-});
-port.postMessage("bg->sdk port message");
diff --git a/addon-sdk/source/test/addons/embedded-webextension/webextension/content-script.js b/addon-sdk/source/test/addons/embedded-webextension/webextension/content-script.js
deleted file mode 100644
index a8770e623..000000000
--- a/addon-sdk/source/test/addons/embedded-webextension/webextension/content-script.js
+++ /dev/null
@@ -1,10 +0,0 @@
-browser.runtime.sendMessage("content script->sdk message", (reply) => {
- browser.runtime.sendMessage(reply);
-});
-
-let port = browser.runtime.connect();
-port.onMessage.addListener((msg) => {
- port.postMessage(`content script received ${msg}`);
- port.disconnect();
-});
-port.postMessage("content script->sdk port message");
diff --git a/addon-sdk/source/test/addons/embedded-webextension/webextension/manifest.json b/addon-sdk/source/test/addons/embedded-webextension/webextension/manifest.json
deleted file mode 100644
index d2188e7ba..000000000
--- a/addon-sdk/source/test/addons/embedded-webextension/webextension/manifest.json
+++ /dev/null
@@ -1,18 +0,0 @@
-{
- "name": "Test SDK Embedded WebExtension",
- "description": "",
- "version": "0.1.0",
- "applications": {
- "gecko": {
- "id": "embedded-webextension@jetpack"
- }
- },
- "manifest_version": 2,
- "permissions": ["tabs"],
- "background": {
- "scripts": ["background-page.js"]
- },
- "content_scripts": [
- {"matches": ["<all_urls>"], "js": ["content-script.js"]}
- ]
-}