tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

browser_dbg-bfcache.js (3200B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
      4 
      5 // Test the debugger when navigating using the BFCache.
      6 
      7 "use strict";
      8 
      9 PromiseTestUtils.allowMatchingRejectionsGlobally(/Connection closed/);
     10 
     11 add_task(async function () {
     12  info("Run test with bfcacheInParent DISABLED");
     13  await pushPref("fission.bfcacheInParent", false);
     14  await testSourcesOnNavigation();
     15  await testDebuggerPauseStateOnNavigation();
     16 
     17  // bfcacheInParent only works if sessionHistoryInParent is enable
     18  // so only test it if both settings are enabled.
     19  if (Services.appinfo.sessionHistoryInParent) {
     20    info("Run test with bfcacheInParent ENABLED");
     21    await pushPref("fission.bfcacheInParent", true);
     22    await testSourcesOnNavigation();
     23    await testDebuggerPauseStateOnNavigation();
     24  }
     25 });
     26 
     27 async function testSourcesOnNavigation() {
     28  info(
     29    "Test that sources appear in the debugger when navigating using the BFCache"
     30  );
     31  const dbg = await initDebugger("doc-bfcache1.html");
     32 
     33  await navigate(dbg, "doc-bfcache2.html", "doc-bfcache2.html");
     34 
     35  invokeInTab("goBack");
     36  await waitForSources(dbg, "doc-bfcache1.html");
     37 
     38  invokeInTab("goForward");
     39  await waitForSources(dbg, "doc-bfcache2.html");
     40  ok(true, "Found sources after BFCache navigations");
     41 
     42  await dbg.toolbox.closeToolbox();
     43 }
     44 
     45 async function testDebuggerPauseStateOnNavigation() {
     46  info("Test the debugger pause state when navigating using the BFCache");
     47 
     48  info("Open debugger on the first page");
     49  const dbg = await initDebugger("doc-bfcache1.html");
     50 
     51  await addBreakpoint(dbg, "doc-bfcache1.html", 4);
     52 
     53  info("Navigate to the second page");
     54  await navigate(dbg, "doc-bfcache2.html");
     55  await waitForSources(dbg, "doc-bfcache2.html");
     56 
     57  info("Navigate back to the first page (which should resurect from bfcache)");
     58  await goBack(`${EXAMPLE_URL}doc-bfcache1.html`);
     59  await waitForSources(dbg, "doc-bfcache1.html");
     60 
     61  // We paused when navigation back to bfcache1.html
     62  // The previous navigation will prevent the page from completing its load.
     63  // And we will do the same with this reload, which will pause page load
     64  // and we will navigate forward and never complete the reload page load.
     65  info("Reload the first page (which was in bfcache)");
     66  await reloadWhenPausedBeforePageLoaded(dbg);
     67  await waitForPaused(dbg);
     68 
     69  ok(dbg.toolbox.isHighlighted("jsdebugger"), "Debugger is highlighted");
     70 
     71  info(
     72    "Navigate forward to the second page (which should also coming from bfcache)"
     73  );
     74  await goForward(`${EXAMPLE_URL}doc-bfcache2.html`);
     75 
     76  await waitUntil(() => !dbg.toolbox.isHighlighted("jsdebugger"));
     77  ok(true, "Debugger is not highlighted");
     78 
     79  dbg.toolbox.closeToolbox();
     80 }
     81 
     82 async function goBack(expectedUrl) {
     83  const onLocationChange = BrowserTestUtils.waitForLocationChange(
     84    gBrowser,
     85    expectedUrl
     86  );
     87  gBrowser.goBack();
     88  await onLocationChange;
     89 }
     90 
     91 async function goForward(expectedUrl) {
     92  const onLocationChange = BrowserTestUtils.waitForLocationChange(
     93    gBrowser,
     94    expectedUrl
     95  );
     96  gBrowser.goForward();
     97  await onLocationChange;
     98 }