summaryrefslogtreecommitdiffstats
path: root/devtools/client/inspector/markup/test/browser_markup_iframe_blocked_by_csp.js
blob: 559919f2ef7015df558d875c0a39053ccc34515e (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
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";

// Test that iframe blocked because of CSP doesn't cause the browser to freeze.

const IFRAME_TEST_URI = `https://example.com/document-builder.sjs?html=${encodeURIComponent(`
  <h1>Test expanding CSP-blocked iframe</h1>
  <iframe src="https://example.org/document-builder.sjs?html=HelloIframe"></iframe>
`)}&headers=content-security-policy:default-src 'self'`;
const FRAME_TEST_URI = `https://example.com/document-builder.sjs?html=${encodeURIComponent(`
  <frameset>
    <frame src="https://example.org/document-builder.sjs?html=HelloFrame"></frame>
  </frameset>
`)}&headers=content-security-policy:default-src 'self'`;

const BYPASS_WALKERFRONT_CHILDREN_IFRAME_GUARD_PREF =
  "devtools.testing.bypass-walker-children-iframe-guard";

add_task(async function () {
  await pushPref(BYPASS_WALKERFRONT_CHILDREN_IFRAME_GUARD_PREF, true);
  const { inspector } = await openInspectorForURL(IFRAME_TEST_URI);
  await testElementBlockedByCSP("iframe", inspector);

  // Don't wait for the load event as it doesn't happen because the frame is blocked.
  await navigateTo(FRAME_TEST_URI, { waitForLoad: false });
  await testElementBlockedByCSP("frame", inspector);
});

async function testElementBlockedByCSP(selector, inspector) {
  await inspector.markup.expandAll();
  info(`Check that markup node for "${selector}" can't be expanded`);
  let container = await getContainerForSelector(selector, inspector);

  is(
    container.expander.style.visibility,
    "hidden",
    "Expand icon is hidden, even without the safe guard in WalkerFront#children"
  );

  info("Reload the page and do same assertion with the guard");
  Services.prefs.clearUserPref(BYPASS_WALKERFRONT_CHILDREN_IFRAME_GUARD_PREF);
  await reloadBrowser();

  await inspector.markup.expandAll();
  container = await getContainerForSelector(selector, inspector);
  is(
    container.expander.style.visibility,
    "hidden",
    "Expand icon is still hidden"
  );
}