diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /devtools/server/tests/browser/browser_application_manifest.js | |
parent | Initial commit. (diff) | |
download | firefox-upstream/124.0.1.tar.xz firefox-upstream/124.0.1.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'devtools/server/tests/browser/browser_application_manifest.js')
-rw-r--r-- | devtools/server/tests/browser/browser_application_manifest.js | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/devtools/server/tests/browser/browser_application_manifest.js b/devtools/server/tests/browser/browser_application_manifest.js new file mode 100644 index 0000000000..c92a3c0a2f --- /dev/null +++ b/devtools/server/tests/browser/browser_application_manifest.js @@ -0,0 +1,87 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +// Enable web manifest processing. +Services.prefs.setBoolPref("dom.manifest.enabled", true); + +add_task(async function () { + info("Testing fetching a valid manifest"); + const response = await fetchManifest("application-manifest-basic.html"); + + ok( + response.manifest && response.manifest.name == "FooApp", + "Returns an object populated with the manifest data" + ); +}); + +add_task(async function () { + info("Testing fetching an existing manifest with invalid values"); + const response = await fetchManifest("application-manifest-warnings.html"); + + ok( + response.manifest && response.manifest.moz_validation, + "Returns an object populated with the manifest data" + ); + + const warnings = response.manifest.moz_validation; + ok( + warnings.length === 1 && + warnings[0].warn && + warnings[0].warn.includes("name member to be a string"), + "The returned object contains the expected warning info" + ); +}); + +add_task(async function () { + info("Testing fetching a manifest in a page that does not have one"); + const response = await fetchManifest("application-manifest-no-manifest.html"); + + is(response.manifest, null, "Returns an object with a `null` manifest"); + ok(!response.errorMessage, "Does not return an error message"); +}); + +add_task(async function () { + info("Testing an error happening fetching a manifest"); + // the page that we are testing contains an invalid URL for the manifest + const response = await fetchManifest( + "application-manifest-404-manifest.html" + ); + + is(response.manifest, null, "Returns an object with a `null` manifest"); + ok( + response.errorMessage && + response.errorMessage.toLowerCase().includes("404 - not found"), + "Returns the expected error message" + ); +}); + +add_task(async function () { + info("Testing a validation error when fetching a manifest with invalid JSON"); + const response = await fetchManifest( + "application-manifest-invalid-json.html" + ); + ok( + response.manifest && response.manifest.moz_validation, + "Returns an object with validation data" + ); + const validation = response.manifest.moz_validation; + ok( + validation.find(x => x.error && x.type === "json"), + "Has the expected error in the validation field" + ); +}); + +async function fetchManifest(filename) { + const url = MAIN_DOMAIN + filename; + const target = await addTabTarget(url); + + info("Initializing manifest front for tab"); + const manifestFront = await target.getFront("manifest"); + + info("Fetching manifest"); + const response = await manifestFront.fetchCanonicalManifest(); + + return response; +} |