tor-browser

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

browser_scrollPositionsReaderMode.js (2396B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 const BASE = "http://example.com/browser/browser/components/sessionstore/test/";
      7 const READER_MODE_URL =
      8  "about:reader?url=" +
      9  encodeURIComponent(BASE + "browser_scrollPositions_readerModeArticle.html");
     10 
     11 // Randomized set of scroll positions we will use in this test.
     12 const SCROLL_READER_MODE_Y = Math.round(400 * (1 + Math.random()));
     13 const SCROLL_READER_MODE_STR = "0," + SCROLL_READER_MODE_Y;
     14 
     15 requestLongerTimeout(2);
     16 
     17 /**
     18 * Test that scroll positions of about reader page after restoring background
     19 * tabs in a restored window (bug 1153393).
     20 */
     21 add_task(async function test_scroll_background_about_reader_tabs() {
     22  await pushPrefs(["browser.sessionstore.restore_on_demand", true]);
     23 
     24  let newWin = await BrowserTestUtils.openNewBrowserWindow();
     25  let tab = BrowserTestUtils.addTab(newWin.gBrowser, READER_MODE_URL);
     26  let browser = tab.linkedBrowser;
     27  await Promise.all([
     28    BrowserTestUtils.browserLoaded(browser),
     29    BrowserTestUtils.waitForContentEvent(browser, "AboutReaderContentReady"),
     30  ]);
     31 
     32  // Scroll down a little.
     33  await setScrollPosition(browser, 0, SCROLL_READER_MODE_Y);
     34  await checkScroll(tab, { scroll: SCROLL_READER_MODE_STR }, "scroll is fine");
     35 
     36  // Close the window
     37  await BrowserTestUtils.closeWindow(newWin);
     38 
     39  await forceSaveState();
     40 
     41  // Now restore the window
     42  newWin = ss.undoCloseWindow(0);
     43 
     44  // Make sure to wait for the window to be restored.
     45  await BrowserTestUtils.waitForEvent(newWin, "SSWindowStateReady");
     46 
     47  is(newWin.gBrowser.tabs.length, 2, "There should be two tabs");
     48 
     49  // The second tab should be the one we loaded URL at still
     50  tab = newWin.gBrowser.tabs[1];
     51 
     52  ok(tab.hasAttribute("pending"), "Tab should be pending");
     53  browser = tab.linkedBrowser;
     54 
     55  // Ensure there are no pending queued messages in the child.
     56  await TabStateFlusher.flush(browser);
     57 
     58  // Now check to see if the background tab remembers where it
     59  // should be scrolled to.
     60  newWin.gBrowser.selectedTab = tab;
     61  await Promise.all([
     62    promiseTabRestored(tab),
     63    BrowserTestUtils.waitForContentEvent(
     64      tab.linkedBrowser,
     65      "AboutReaderContentReady"
     66    ),
     67  ]);
     68 
     69  await checkScroll(
     70    tab,
     71    { scroll: SCROLL_READER_MODE_STR },
     72    "scroll is still fine"
     73  );
     74 
     75  await BrowserTestUtils.closeWindow(newWin);
     76 });