summaryrefslogtreecommitdiffstats
path: root/devtools/shared/tests/browser
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /devtools/shared/tests/browser
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'devtools/shared/tests/browser')
-rw-r--r--devtools/shared/tests/browser/.eslintrc.js6
-rw-r--r--devtools/shared/tests/browser/browser.ini8
-rw-r--r--devtools/shared/tests/browser/browser_async_storage.js77
-rw-r--r--devtools/shared/tests/browser/browser_l10n_localizeMarkup.js54
4 files changed, 145 insertions, 0 deletions
diff --git a/devtools/shared/tests/browser/.eslintrc.js b/devtools/shared/tests/browser/.eslintrc.js
new file mode 100644
index 000000000..8d15a76d9
--- /dev/null
+++ b/devtools/shared/tests/browser/.eslintrc.js
@@ -0,0 +1,6 @@
+"use strict";
+
+module.exports = {
+ // Extend from the shared list of defined globals for mochitests.
+ "extends": "../../../.eslintrc.mochitests.js"
+};
diff --git a/devtools/shared/tests/browser/browser.ini b/devtools/shared/tests/browser/browser.ini
new file mode 100644
index 000000000..4acac6521
--- /dev/null
+++ b/devtools/shared/tests/browser/browser.ini
@@ -0,0 +1,8 @@
+[DEFAULT]
+tags = devtools
+subsuite = devtools
+support-files =
+ ../../../server/tests/browser/head.js
+
+[browser_async_storage.js]
+[browser_l10n_localizeMarkup.js]
diff --git a/devtools/shared/tests/browser/browser_async_storage.js b/devtools/shared/tests/browser/browser_async_storage.js
new file mode 100644
index 000000000..4329d639a
--- /dev/null
+++ b/devtools/shared/tests/browser/browser_async_storage.js
@@ -0,0 +1,77 @@
+/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+// Test the basic functionality of async-storage.
+// Adapted from https://github.com/mozilla-b2g/gaia/blob/f09993563fb5fec4393eb71816ce76cb00463190/apps/sharedtest/test/unit/async_storage_test.js.
+
+const asyncStorage = require("devtools/shared/async-storage");
+add_task(function* () {
+ is(typeof asyncStorage.length, "function", "API exists.");
+ is(typeof asyncStorage.key, "function", "API exists.");
+ is(typeof asyncStorage.getItem, "function", "API exists.");
+ is(typeof asyncStorage.setItem, "function", "API exists.");
+ is(typeof asyncStorage.removeItem, "function", "API exists.");
+ is(typeof asyncStorage.clear, "function", "API exists.");
+});
+
+add_task(function* () {
+ yield asyncStorage.setItem("foo", "bar");
+ let value = yield asyncStorage.getItem("foo");
+ is(value, "bar", "value is correct");
+ yield asyncStorage.setItem("foo", "overwritten");
+ value = yield asyncStorage.getItem("foo");
+ is(value, "overwritten", "value is correct");
+ yield asyncStorage.removeItem("foo");
+ value = yield asyncStorage.getItem("foo");
+ is(value, null, "value is correct");
+});
+
+add_task(function* () {
+ var object = {
+ x: 1,
+ y: "foo",
+ z: true
+ };
+
+ yield asyncStorage.setItem("myobj", object);
+ let value = yield asyncStorage.getItem("myobj");
+ is(object.x, value.x, "value is correct");
+ is(object.y, value.y, "value is correct");
+ is(object.z, value.z, "value is correct");
+ yield asyncStorage.removeItem("myobj");
+ value = yield asyncStorage.getItem("myobj");
+ is(value, null, "value is correct");
+});
+
+add_task(function* () {
+ yield asyncStorage.clear();
+ let len = yield asyncStorage.length();
+ is(len, 0, "length is correct");
+ yield asyncStorage.setItem("key1", "value1");
+ len = yield asyncStorage.length();
+ is(len, 1, "length is correct");
+ yield asyncStorage.setItem("key2", "value2");
+ len = yield asyncStorage.length();
+ is(len, 2, "length is correct");
+ yield asyncStorage.setItem("key3", "value3");
+ len = yield asyncStorage.length();
+ is(len, 3, "length is correct");
+
+ let key = yield asyncStorage.key(0);
+ is(key, "key1", "key is correct");
+ key = yield asyncStorage.key(1);
+ is(key, "key2", "key is correct");
+ key = yield asyncStorage.key(2);
+ is(key, "key3", "key is correct");
+ key = yield asyncStorage.key(3);
+ is(key, null, "key is correct");
+ yield asyncStorage.clear();
+ key = yield asyncStorage.key(0);
+ is(key, null, "key is correct");
+
+ len = yield asyncStorage.length();
+ is(len, 0, "length is correct");
+});
diff --git a/devtools/shared/tests/browser/browser_l10n_localizeMarkup.js b/devtools/shared/tests/browser/browser_l10n_localizeMarkup.js
new file mode 100644
index 000000000..f33a5a331
--- /dev/null
+++ b/devtools/shared/tests/browser/browser_l10n_localizeMarkup.js
@@ -0,0 +1,54 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+// Tests that the markup localization works properly.
+
+const { localizeMarkup, LocalizationHelper } = require("devtools/shared/l10n");
+
+add_task(function* () {
+ info("Check that the strings used for this test are still valid");
+ let STARTUP_L10N = new LocalizationHelper("devtools/client/locales/startup.properties");
+ let TOOLBOX_L10N = new LocalizationHelper("devtools/client/locales/toolbox.properties");
+ let str1 = STARTUP_L10N.getStr("inspector.label");
+ let str2 = STARTUP_L10N.getStr("inspector.commandkey");
+ let str3 = TOOLBOX_L10N.getStr("toolbox.defaultTitle");
+ ok(str1 && str2 && str3, "If this failed, strings should be updated in the test");
+
+ info("Create the test markup");
+ let div = document.createElement("div");
+ div.innerHTML =
+ `<div data-localization-bundle="devtools/client/locales/startup.properties">
+ <div id="d0" data-localization="content=inspector.someInvalidKey"></div>
+ <div id="d1" data-localization="content=inspector.label">Text will disappear</div>
+ <div id="d2" data-localization="content=inspector.label;title=inspector.commandkey">
+ </div>
+ <!-- keep the following data-localization on two separate lines -->
+ <div id="d3" data-localization="content=inspector.label;
+ title=inspector.commandkey"></div>
+ <div id="d4" data-localization="aria-label=inspector.label">Some content</div>
+ <div data-localization-bundle="devtools/client/locales/toolbox.properties">
+ <div id="d5" data-localization="content=toolbox.defaultTitle"></div>
+ </div>
+ </div>
+ `;
+
+ info("Use localization helper to localize the test markup");
+ localizeMarkup(div);
+
+ let div1 = div.querySelector("#d1");
+ let div2 = div.querySelector("#d2");
+ let div3 = div.querySelector("#d3");
+ let div4 = div.querySelector("#d4");
+ let div5 = div.querySelector("#d5");
+
+ is(div1.innerHTML, str1, "The content of #d1 is localized");
+ is(div2.innerHTML, str1, "The content of #d2 is localized");
+ is(div2.getAttribute("title"), str2, "The title of #d2 is localized");
+ is(div3.innerHTML, str1, "The content of #d3 is localized");
+ is(div3.getAttribute("title"), str2, "The title of #d3 is localized");
+ is(div4.innerHTML, "Some content", "The content of #d4 is not replaced");
+ is(div4.getAttribute("aria-label"), str1, "The aria-label of #d4 is localized");
+ is(div5.innerHTML, str3, "The content of #d5 is localized with another bundle");
+});