summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/test/mochitest/browser_dbg-bfcache.js
blob: f9fbfe1b0741f1f4a92caa8a0f6d3fa2a2ad97b0 (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/* 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/>. */

// Test the debugger when navigating using the BFCache.

"use strict";

PromiseTestUtils.allowMatchingRejectionsGlobally(/Connection closed/);

add_task(async function() {
  info("Run test with bfcacheInParent DISABLED");
  await pushPref("fission.bfcacheInParent", false);
  await testSourcesOnNavigation();
  await testDebuggerPauseStateOnNavigation();

  // bfcacheInParent only works if sessionHistoryInParent is enable
  // so only test it if both settings are enabled.
  if (Services.appinfo.sessionHistoryInParent) {
    info("Run test with bfcacheInParent ENABLED");
    await pushPref("fission.bfcacheInParent", true);
    await testSourcesOnNavigation();
    await testDebuggerPauseStateOnNavigation();
  }
});

async function testSourcesOnNavigation() {
  info(
    "Test that sources appear in the debugger when navigating using the BFCache"
  );
  const dbg = await initDebugger("doc-bfcache1.html");

  await navigate(dbg, "doc-bfcache2.html", "doc-bfcache2.html");

  invokeInTab("goBack");
  await waitForSources(dbg, "doc-bfcache1.html");

  invokeInTab("goForward");
  await waitForSources(dbg, "doc-bfcache2.html");
  ok(true, "Found sources after BFCache navigations");

  await dbg.toolbox.closeToolbox();
}

async function testDebuggerPauseStateOnNavigation() {
  info("Test the debugger pause state when navigating using the BFCache");

  if (Services.appinfo.sessionHistoryInParent) {
    enableTargetSwitching();
  }
  const dbg = await initDebugger("doc-bfcache1.html");

  await addBreakpoint(dbg, "doc-bfcache1.html", 4);

  await navigate(dbg, "doc-bfcache2.html");
  await waitForSources(dbg, "doc-bfcache2.html");

  await goBack(`${EXAMPLE_URL}doc-bfcache1.html`);
  await waitForSources(dbg, "doc-bfcache1.html");

  await reload(dbg);
  await waitForPaused(dbg);

  ok(dbg.toolbox.isHighlighted("jsdebugger"), "Debugger is highlighted");

  await goForward(`${EXAMPLE_URL}doc-bfcache2.html`);

  await waitUntil(() => !dbg.toolbox.isHighlighted("jsdebugger"));
  ok(true, "Debugger is not highlighted");

  dbg.toolbox.closeToolbox();
}

async function goBack(expectedUrl) {
  const onLocationChange = BrowserTestUtils.waitForLocationChange(
    gBrowser,
    expectedUrl
  );
  gBrowser.goBack();
  await onLocationChange;
}

async function goForward(expectedUrl) {
  const onLocationChange = BrowserTestUtils.waitForLocationChange(
    gBrowser,
    expectedUrl
  );
  gBrowser.goForward();
  await onLocationChange;
}