summaryrefslogtreecommitdiffstats
path: root/devtools/client/webconsole/test/browser/browser_webconsole_sandbox_update_after_navigation.js
blob: ccea9eb4000c87d22d45ab90375b9a966b5233b0 (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
58
59
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

// Tests if the JSTerm sandbox is updated when the user navigates from one
// domain to another, in order to avoid permission denied errors with a sandbox
// created for a different origin. See Bug 664688.

"use strict";

const BASE_URI =
  "browser/devtools/client/webconsole/test/browser/test-console.html";
const TEST_URI1 = "https://example.com/" + BASE_URI;
const TEST_URI2 = "https://example.org/" + BASE_URI;

add_task(async function () {
  await pushPref("devtools.webconsole.persistlog", false);

  const hud = await openNewTabAndConsole(TEST_URI1);

  await executeAndWaitForResultMessage(hud, "window.location.href", TEST_URI1);

  // load second url
  await navigateTo(TEST_URI2);

  ok(
    !findErrorMessage(hud, "Permission denied"),
    "no permission denied errors"
  );

  info("wait for window.location.href after page navigation");
  await clearOutput(hud);
  await executeAndWaitForResultMessage(hud, "window.location.href", TEST_URI2);

  ok(
    !findErrorMessage(hud, "Permission denied"),
    "no permission denied errors"
  );

  // Navigation clears messages. Wait for that clear to happen before
  // continuing the test or it might destroy messages we wait later on (Bug
  // 1270234).
  const promises = [
    hud.ui.once("messages-cleared"),
    hud.commands.targetCommand.once("switched-target"),
  ];

  gBrowser.goBack();

  info("Waiting for messages-cleared event due to navigation");
  await Promise.all(promises);

  info("Messages cleared after navigation; checking location");
  await executeAndWaitForResultMessage(hud, "window.location.href", TEST_URI1);

  ok(
    !findErrorMessage(hud, "Permission denied"),
    "no permission denied errors"
  );
});