summaryrefslogtreecommitdiffstats
path: root/dom/security/test/csp/browser_test_web_manifest_mixed_content.js
blob: 9238acbcdf1d4c8a46117ce42c3f106800eb1ade (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
/*
 * Description of the test:
 *   Check that mixed content blocker works prevents fetches of
 *   mixed content manifests.
 */
/*globals Cu, ok*/
"use strict";
const {
  ManifestObtainer
} = Cu.import("resource://gre/modules/ManifestObtainer.jsm", {});
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(function* () {
  //jscs:enable
  const testPromises = tests.map((test) => {
    const tabOptions = {
      gBrowser,
      url: test.tabURL,
      skipAnimation: true,
    };
    return BrowserTestUtils.withNewTab(tabOptions, (browser) => testObtainingManifest(browser, test));
  });
  yield Promise.all(testPromises);
});

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