summaryrefslogtreecommitdiffstats
path: root/dom/security/test/csp/browser_test_web_manifest_mixed_content.js
blob: 0cf55b80e3cc544b66514b89421239e99626869a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
 * Description of the test:
 *   Check that mixed content blocker works prevents fetches of
 *   mixed content manifests.
 */
/*globals Cu, ok*/
"use strict";
const { ManifestObtainer } = ChromeUtils.importESModule(
  "resource://gre/modules/ManifestObtainer.sys.mjs"
);
const path = "/tests/dom/security/test/csp/";
const mixedContent = `${path}file_web_manifest_mixed_content.html`;
const server = `${path}file_testserver.sjs`;
const secureURL = new URL(`https://example.com${server}`);
const tests = [
  // Trying to load mixed content in file_web_manifest_mixed_content.html
  // needs to result in an error.
  {
    expected: "Mixed Content Blocker prevents fetching manifest.",
    get tabURL() {
      const url = new URL(secureURL);
      url.searchParams.append("file", mixedContent);
      return url.href;
    },
    run(error) {
      // Check reason for error.
      const check = /NetworkError when attempting to fetch resource/.test(
        error.message
      );
      ok(check, this.expected);
    },
  },
];

//jscs:disable
add_task(async function () {
  //jscs:enable
  const testPromises = tests.map(test => {
    const tabOptions = {
      gBrowser,
      url: test.tabURL,
      skipAnimation: true,
    };
    return BrowserTestUtils.withNewTab(tabOptions, browser =>
      testObtainingManifest(browser, test)
    );
  });
  await Promise.all(testPromises);
});

async function testObtainingManifest(aBrowser, aTest) {
  try {
    await ManifestObtainer.browserObtainManifest(aBrowser);
  } catch (e) {
    aTest.run(e);
  }
}