summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/test/mochitest/browser_dbg-bfcache.js
blob: d66bd294bcaaaa7db6ebe103f6252bfc25ed98fd (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
91
92
93
94
95
96
97
98
/* 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");

  info("Open debugger on the first page");
  const dbg = await initDebugger("doc-bfcache1.html");

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

  info("Navigate to the second page");
  await navigate(dbg, "doc-bfcache2.html");
  await waitForSources(dbg, "doc-bfcache2.html");

  info("Navigate back to the first page (which should resurect from bfcache)");
  await goBack(`${EXAMPLE_URL}doc-bfcache1.html`);
  await waitForSources(dbg, "doc-bfcache1.html");

  // We paused when navigation back to bfcache1.html
  // The previous navigation will prevent the page from completing its load.
  // And we will do the same with this reload, which will pause page load
  // and we will navigate forward and never complete the reload page load.
  info("Reload the first page (which was in bfcache)");
  await reloadWhenPausedBeforePageLoaded(dbg);
  await waitForPaused(dbg);

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

  info(
    "Navigate forward to the second page (which should also coming from bfcache)"
  );
  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;
}