diff options
Diffstat (limited to 'devtools/shared/tests/browser')
-rw-r--r-- | devtools/shared/tests/browser/browser.ini | 10 | ||||
-rw-r--r-- | devtools/shared/tests/browser/browser_async_storage.js | 76 | ||||
-rw-r--r-- | devtools/shared/tests/browser/browser_l10n_localizeMarkup.js | 94 |
3 files changed, 180 insertions, 0 deletions
diff --git a/devtools/shared/tests/browser/browser.ini b/devtools/shared/tests/browser/browser.ini new file mode 100644 index 0000000000..1536980a52 --- /dev/null +++ b/devtools/shared/tests/browser/browser.ini @@ -0,0 +1,10 @@ +[DEFAULT] +tags = devtools +subsuite = devtools +support-files = + !/devtools/client/shared/test/shared-head.js + !/devtools/client/shared/test/telemetry-test-helpers.js + ../../../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 0000000000..87a1ef169f --- /dev/null +++ b/devtools/shared/tests/browser/browser_async_storage.js @@ -0,0 +1,76 @@ +/* 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("resource://devtools/shared/async-storage.js"); +add_task(async 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(async function () { + await asyncStorage.setItem("foo", "bar"); + let value = await asyncStorage.getItem("foo"); + is(value, "bar", "value is correct"); + await asyncStorage.setItem("foo", "overwritten"); + value = await asyncStorage.getItem("foo"); + is(value, "overwritten", "value is correct"); + await asyncStorage.removeItem("foo"); + value = await asyncStorage.getItem("foo"); + is(value, null, "value is correct"); +}); + +add_task(async function () { + const object = { + x: 1, + y: "foo", + z: true, + }; + + await asyncStorage.setItem("myobj", object); + let value = await 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"); + await asyncStorage.removeItem("myobj"); + value = await asyncStorage.getItem("myobj"); + is(value, null, "value is correct"); +}); + +add_task(async function () { + await asyncStorage.clear(); + let len = await asyncStorage.length(); + is(len, 0, "length is correct"); + await asyncStorage.setItem("key1", "value1"); + len = await asyncStorage.length(); + is(len, 1, "length is correct"); + await asyncStorage.setItem("key2", "value2"); + len = await asyncStorage.length(); + is(len, 2, "length is correct"); + await asyncStorage.setItem("key3", "value3"); + len = await asyncStorage.length(); + is(len, 3, "length is correct"); + + let key = await asyncStorage.key(0); + is(key, "key1", "key is correct"); + key = await asyncStorage.key(1); + is(key, "key2", "key is correct"); + key = await asyncStorage.key(2); + is(key, "key3", "key is correct"); + key = await asyncStorage.key(3); + is(key, null, "key is correct"); + await asyncStorage.clear(); + key = await asyncStorage.key(0); + is(key, null, "key is correct"); + + len = await 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 0000000000..9c4118b572 --- /dev/null +++ b/devtools/shared/tests/browser/browser_l10n_localizeMarkup.js @@ -0,0 +1,94 @@ +/* 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("resource://devtools/shared/l10n.js"); +const HTML_NS = "http://www.w3.org/1999/xhtml"; + +add_task(async function () { + info("Check that the strings used for this test are still valid"); + const STARTUP_L10N = new LocalizationHelper( + "devtools/client/locales/startup.properties" + ); + const TOOLBOX_L10N = new LocalizationHelper( + "devtools/client/locales/toolbox.properties" + ); + const str1 = STARTUP_L10N.getStr("inspector.label"); + const str2 = STARTUP_L10N.getStr("inspector.accesskey"); + const 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"); + const div = document.createElementNS(HTML_NS, "div"); + div.setAttribute( + "data-localization-bundle", + "devtools/client/locales/startup.properties" + ); + const div0 = document.createElementNS(HTML_NS, "div"); + div0.setAttribute("id", "d0"); + div0.setAttribute("data-localization", "content=inspector.someInvalidKey"); + div.appendChild(div0); + const div1 = document.createElementNS(HTML_NS, "div"); + div1.setAttribute("id", "d1"); + div1.setAttribute("data-localization", "content=inspector.label"); + div.appendChild(div1); + div1.append("Text will disappear"); + const div2 = document.createElementNS(HTML_NS, "div"); + div2.setAttribute("id", "d2"); + div2.setAttribute( + "data-localization", + "content=inspector.label;title=inspector.accesskey" + ); + div.appendChild(div2); + const div3 = document.createElementNS(HTML_NS, "div"); + div3.setAttribute("id", "d3"); + div3.setAttribute( + "data-localization", + "content=inspector.label;title=inspector.accesskey" + ); + div.appendChild(div3); + const div4 = document.createElementNS(HTML_NS, "div"); + div4.setAttribute("id", "d4"); + div4.setAttribute("data-localization", "aria-label=inspector.label"); + div.appendChild(div4); + div4.append("Some content"); + const toolboxDiv = document.createElementNS(HTML_NS, "div"); + toolboxDiv.setAttribute( + "data-localization-bundle", + "devtools/client/locales/toolbox.properties" + ); + div.appendChild(toolboxDiv); + const div5 = document.createElementNS(HTML_NS, "div"); + div5.setAttribute("id", "d5"); + div5.setAttribute("data-localization", "content=toolbox.defaultTitle"); + toolboxDiv.appendChild(div5); + + info("Use localization helper to localize the test markup"); + localizeMarkup(div); + + 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" + ); +}); |