summaryrefslogtreecommitdiffstats
path: root/dom/browser-element/mochitest/browserElement_getWebManifest.js
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 /dom/browser-element/mochitest/browserElement_getWebManifest.js
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 'dom/browser-element/mochitest/browserElement_getWebManifest.js')
-rw-r--r--dom/browser-element/mochitest/browserElement_getWebManifest.js64
1 files changed, 64 insertions, 0 deletions
diff --git a/dom/browser-element/mochitest/browserElement_getWebManifest.js b/dom/browser-element/mochitest/browserElement_getWebManifest.js
new file mode 100644
index 000000000..c2b8f96f3
--- /dev/null
+++ b/dom/browser-element/mochitest/browserElement_getWebManifest.js
@@ -0,0 +1,64 @@
+/* Any copyright is dedicated to the public domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+/*globals async, ok, is, SimpleTest, browserElementTestHelpers*/
+
+// Bug 1169633 - getWebManifest tests
+'use strict';
+SimpleTest.waitForExplicitFinish();
+browserElementTestHelpers.setEnabledPref(true);
+
+// request to load a manifest from a page that doesn't have a manifest.
+// The expected result to be null.
+var test1 = async(function* () {
+ var manifest = yield requestManifest('file_empty.html');
+ is(manifest, null, 'it should be null.');
+});
+
+// request to load a manifest from a page that has a manifest.
+// The expected manifest to have a property name whose value is 'pass'.
+var test2 = async(function* () {
+ var manifest = yield requestManifest('file_web_manifest.html');
+ is(manifest && manifest.name, 'pass', 'it should return a manifest with name pass.');
+});
+
+// Cause an exception by attempting to fetch a file URL,
+// expect onerror to be called.
+var test3 = async(function* () {
+ var gotError = false;
+ try {
+ yield requestManifest('file_illegal_web_manifest.html');
+ } catch (err) {
+ gotError = true;
+ }
+ ok(gotError, 'onerror was called on the DOMRequest.');
+});
+
+// Run the tests
+addEventListener('testready', () => {
+ Promise
+ .all([test1(), test2(), test3()])
+ .then(SimpleTest.finish);
+});
+
+function requestManifest(url) {
+ var iframe = document.createElement('iframe');
+ iframe.setAttribute('mozbrowser', 'true');
+ iframe.src = url;
+ document.body.appendChild(iframe);
+ return new Promise((resolve, reject) => {
+ iframe.addEventListener('mozbrowserloadend', function loadend() {
+ iframe.removeEventListener('mozbrowserloadend', loadend);
+ SimpleTest.executeSoon(() => {
+ var req = iframe.getWebManifest();
+ req.onsuccess = () => {
+ document.body.removeChild(iframe);
+ resolve(req.result);
+ };
+ req.onerror = () => {
+ document.body.removeChild(iframe);
+ reject(new Error(req.error));
+ };
+ });
+ });
+ });
+}