tor-browser

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

browser_title_in_session_history.js (2001B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 add_task(async function test() {
      7  const TEST_PAGE =
      8    getRootDirectory(gTestPath).replace(
      9      "chrome://mochitests/content",
     10      "https://example.com"
     11    ) + "dummy_page.html";
     12  await BrowserTestUtils.withNewTab(TEST_PAGE, async browser => {
     13    let titles = await ContentTask.spawn(browser, null, () => {
     14      return new Promise(resolve => {
     15        let titles = [];
     16        content.document.body.innerHTML = "<div id='foo'>foo</div>";
     17        content.document.title = "Initial";
     18        content.history.pushState("1", "1", "1");
     19        content.document.title = "1";
     20        content.history.pushState("2", "2", "2");
     21        content.document.title = "2";
     22        content.location.hash = "hash";
     23        content.document.title = "3-hash";
     24        content.addEventListener(
     25          "popstate",
     26          () => {
     27            content.addEventListener(
     28              "popstate",
     29              () => {
     30                titles.push(content.document.title);
     31                resolve(titles);
     32              },
     33              { once: true }
     34            );
     35 
     36            titles.push(content.document.title);
     37            // Test going forward a few steps.
     38            content.history.go(2);
     39          },
     40          { once: true }
     41        );
     42        // Test going back a few steps.
     43        content.history.go(-3);
     44      });
     45    });
     46    is(
     47      titles[0],
     48      "3-hash",
     49      "Document.title should have the value to which it was last time set."
     50    );
     51    is(
     52      titles[1],
     53      "3-hash",
     54      "Document.title should have the value to which it was last time set."
     55    );
     56    let sh = browser.browsingContext.sessionHistory;
     57    let count = sh.count;
     58    is(sh.getEntryAtIndex(count - 1).title, "3-hash");
     59    is(sh.getEntryAtIndex(count - 2).title, "2");
     60    is(sh.getEntryAtIndex(count - 3).title, "1");
     61    is(sh.getEntryAtIndex(count - 4).title, "Initial");
     62  });
     63 });