tor-browser

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

browser_bug1705872.js (1931B)


      1 "use strict";
      2 
      3 async function doLoadAndGoBack(browser, ext) {
      4  let loaded = BrowserTestUtils.browserLoaded(browser);
      5  BrowserTestUtils.startLoadingURIString(browser, "https://example.com/");
      6  await ext.awaitMessage("redir-handled");
      7  await loaded;
      8 
      9  let pageShownPromise = BrowserTestUtils.waitForContentEvent(
     10    browser,
     11    "pageshow",
     12    true
     13  );
     14  await SpecialPowers.spawn(browser, [], () => {
     15    content.history.back();
     16  });
     17  return pageShownPromise;
     18 }
     19 
     20 add_task(async function test_back() {
     21  let extension = ExtensionTestUtils.loadExtension({
     22    manifest: {
     23      permissions: ["webRequest", "webRequestBlocking", "https://example.com/"],
     24      web_accessible_resources: ["test.html"],
     25    },
     26    files: {
     27      "test.html":
     28        "<!DOCTYPE html><html><head><title>Test add-on</title></head><body></body></html>",
     29    },
     30    background: () => {
     31      let { browser } = this;
     32      browser.webRequest.onHeadersReceived.addListener(
     33        details => {
     34          if (details.statusCode != 200) {
     35            return undefined;
     36          }
     37          browser.test.sendMessage("redir-handled");
     38          return { redirectUrl: browser.runtime.getURL("test.html") };
     39        },
     40        {
     41          urls: ["https://example.com/"],
     42          types: ["main_frame"],
     43        },
     44        ["blocking"]
     45      );
     46    },
     47  });
     48 
     49  await extension.startup();
     50 
     51  await BrowserTestUtils.withNewTab("about:home", async function (browser) {
     52    await doLoadAndGoBack(browser, extension);
     53 
     54    await SpecialPowers.spawn(browser, [], () => {
     55      is(
     56        content.document.documentURI,
     57        "about:home",
     58        "Gone back to the right page"
     59      );
     60    });
     61 
     62    await doLoadAndGoBack(browser, extension);
     63 
     64    await SpecialPowers.spawn(browser, [], () => {
     65      is(
     66        content.document.documentURI,
     67        "about:home",
     68        "Gone back to the right page"
     69      );
     70    });
     71  });
     72 
     73  await extension.unload();
     74 });