tor-browser

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

browser_test_shentry_wireframe.js (3866B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 const BUILDER = "http://mochi.test:8888/document-builder.sjs?html=";
      7 const PAGE_1 = BUILDER + encodeURIComponent(`<html><body>Page 1</body></html>`);
      8 const PAGE_2 = BUILDER + encodeURIComponent(`<html><body>Page 2</body></html>`);
      9 
     10 add_setup(async function () {
     11  await SpecialPowers.pushPrefEnv({
     12    set: [["browser.history.collectWireframes", true]],
     13  });
     14 });
     15 
     16 /**
     17 * Test that capturing wireframes on nsISHEntriy's in the parent process
     18 * happens at the right times.
     19 */
     20 add_task(async function () {
     21  await BrowserTestUtils.withNewTab(PAGE_1, async browser => {
     22    let sh = browser.browsingContext.sessionHistory;
     23    Assert.equal(
     24      sh.count,
     25      1,
     26      "Got the right SessionHistory entry count after initial tab load."
     27    );
     28    Assert.ok(
     29      !sh.getEntryAtIndex(0).wireframe,
     30      "No wireframe for the loaded entry after initial tab load."
     31    );
     32 
     33    let loaded = BrowserTestUtils.browserLoaded(browser, false, PAGE_2);
     34    BrowserTestUtils.startLoadingURIString(browser, PAGE_2);
     35    await loaded;
     36 
     37    Assert.equal(
     38      sh.count,
     39      2,
     40      "Got the right SessionHistory entry count after loading page 2."
     41    );
     42    Assert.ok(
     43      sh.getEntryAtIndex(0).wireframe,
     44      "A wireframe was captured for the first entry after loading page 2."
     45    );
     46    Assert.ok(
     47      !sh.getEntryAtIndex(1).wireframe,
     48      "No wireframe for the loaded entry after loading page 2."
     49    );
     50 
     51    // Now go back
     52    loaded = BrowserTestUtils.waitForContentEvent(browser, "pageshow");
     53    browser.goBack();
     54    await loaded;
     55    Assert.ok(
     56      sh.getEntryAtIndex(1).wireframe,
     57      "A wireframe was captured for the second entry after going back."
     58    );
     59    Assert.ok(
     60      !sh.getEntryAtIndex(0).wireframe,
     61      "No wireframe for the loaded entry after going back."
     62    );
     63 
     64    // Now forward again
     65    loaded = BrowserTestUtils.waitForContentEvent(browser, "pageshow");
     66    browser.goForward();
     67    await loaded;
     68 
     69    Assert.equal(
     70      sh.count,
     71      2,
     72      "Got the right SessionHistory entry count after going forward again."
     73    );
     74    Assert.ok(
     75      sh.getEntryAtIndex(0).wireframe,
     76      "A wireframe was captured for the first entry after going forward again."
     77    );
     78    Assert.ok(
     79      !sh.getEntryAtIndex(1).wireframe,
     80      "No wireframe for the loaded entry after going forward again."
     81    );
     82 
     83    // And using pushState
     84    await SpecialPowers.spawn(browser, [], async () => {
     85      content.history.pushState({}, "", "nothing-1.html");
     86      content.history.pushState({}, "", "nothing-2.html");
     87    });
     88 
     89    Assert.equal(
     90      sh.count,
     91      4,
     92      "Got the right SessionHistory entry count after using pushState."
     93    );
     94    Assert.ok(
     95      sh.getEntryAtIndex(0).wireframe,
     96      "A wireframe was captured for the first entry after using pushState."
     97    );
     98    Assert.ok(
     99      sh.getEntryAtIndex(1).wireframe,
    100      "A wireframe was captured for the second entry after using pushState."
    101    );
    102    Assert.ok(
    103      sh.getEntryAtIndex(2).wireframe,
    104      "A wireframe was captured for the third entry after using pushState."
    105    );
    106    Assert.ok(
    107      !sh.getEntryAtIndex(3).wireframe,
    108      "No wireframe for the loaded entry after using pushState."
    109    );
    110 
    111    // Now check that wireframes can be written to in case we're restoring
    112    // an nsISHEntry from serialization.
    113    let wireframe = sh.getEntryAtIndex(2).wireframe;
    114    sh.getEntryAtIndex(2).wireframe = null;
    115    Assert.equal(
    116      sh.getEntryAtIndex(2).wireframe,
    117      null,
    118      "Successfully cleared wireframe."
    119    );
    120 
    121    sh.getEntryAtIndex(3).wireframe = wireframe;
    122    Assert.deepEqual(
    123      sh.getEntryAtIndex(3).wireframe,
    124      wireframe,
    125      "Successfully wrote a wireframe to an nsISHEntry."
    126    );
    127  });
    128 });