tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

browser_application_manifest.js (2709B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 // Enable web manifest processing.
      7 Services.prefs.setBoolPref("dom.manifest.enabled", true);
      8 
      9 add_task(async function () {
     10  info("Testing fetching a valid manifest");
     11  const response = await fetchManifest("application-manifest-basic.html");
     12 
     13  ok(
     14    response.manifest && response.manifest.name == "FooApp",
     15    "Returns an object populated with the manifest data"
     16  );
     17 });
     18 
     19 add_task(async function () {
     20  info("Testing fetching an existing manifest with invalid values");
     21  const response = await fetchManifest("application-manifest-warnings.html");
     22 
     23  ok(
     24    response.manifest && response.manifest.moz_validation,
     25    "Returns an object populated with the manifest data"
     26  );
     27 
     28  const warnings = response.manifest.moz_validation;
     29  ok(
     30    warnings.length === 1 &&
     31      warnings[0].warn &&
     32      warnings[0].warn.includes("name member to be a string"),
     33    "The returned object contains the expected warning info"
     34  );
     35 });
     36 
     37 add_task(async function () {
     38  info("Testing fetching a manifest in a page that does not have one");
     39  const response = await fetchManifest("application-manifest-no-manifest.html");
     40 
     41  is(response.manifest, null, "Returns an object with a `null` manifest");
     42  ok(!response.errorMessage, "Does not return an error message");
     43 });
     44 
     45 add_task(async function () {
     46  info("Testing an error happening fetching a manifest");
     47  // the page that we are testing contains an invalid URL for the manifest
     48  const response = await fetchManifest(
     49    "application-manifest-404-manifest.html"
     50  );
     51 
     52  is(response.manifest, null, "Returns an object with a `null` manifest");
     53  ok(
     54    response.errorMessage &&
     55      response.errorMessage.toLowerCase().includes("404 - not found"),
     56    "Returns the expected error message"
     57  );
     58 });
     59 
     60 add_task(async function () {
     61  info("Testing a validation error when fetching a manifest with invalid JSON");
     62  const response = await fetchManifest(
     63    "application-manifest-invalid-json.html"
     64  );
     65  ok(
     66    response.manifest && response.manifest.moz_validation,
     67    "Returns an object with validation data"
     68  );
     69  const validation = response.manifest.moz_validation;
     70  ok(
     71    validation.find(x => x.error && x.type === "json"),
     72    "Has the expected error in the validation field"
     73  );
     74 });
     75 
     76 async function fetchManifest(filename) {
     77  const url = MAIN_DOMAIN + filename;
     78  const target = await addTabTarget(url);
     79 
     80  info("Initializing manifest front for tab");
     81  const manifestFront = await target.getFront("manifest");
     82 
     83  info("Fetching manifest");
     84  const response = await manifestFront.fetchCanonicalManifest();
     85 
     86  return response;
     87 }