tor-browser

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

browser_ignore_same_page_navigation.js (1805B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
      3 /* Any copyright is dedicated to the Public Domain.
      4 * http://creativecommons.org/publicdomain/zero/1.0/ */
      5 
      6 // Test that the nsISecureBrowserUI implementation doesn't send extraneous OnSecurityChange events
      7 // when it receives OnLocationChange events with the LOCATION_CHANGE_SAME_DOCUMENT flag set.
      8 
      9 add_task(async function () {
     10  await BrowserTestUtils.withNewTab("about:blank", async browser => {
     11    let onLocationChangeCount = 0;
     12    let onSecurityChangeCount = 0;
     13    let progressListener = {
     14      onStateChange() {},
     15      onLocationChange() {
     16        onLocationChangeCount++;
     17      },
     18      onSecurityChange() {
     19        onSecurityChangeCount++;
     20      },
     21      onProgressChange() {},
     22      onStatusChange() {},
     23 
     24      QueryInterface: ChromeUtils.generateQI([
     25        "nsIWebProgressListener",
     26        "nsISupportsWeakReference",
     27      ]),
     28    };
     29    browser.addProgressListener(progressListener, Ci.nsIWebProgress.NOTIFY_ALL);
     30 
     31    let uri =
     32      getRootDirectory(gTestPath).replace(
     33        "chrome://mochitests/content",
     34        "https://example.com"
     35      ) + "dummy_page.html";
     36    BrowserTestUtils.startLoadingURIString(browser, uri);
     37    await BrowserTestUtils.browserLoaded(browser, false, uri);
     38    is(onLocationChangeCount, 1, "should have 1 onLocationChange event");
     39    is(onSecurityChangeCount, 1, "should have 1 onSecurityChange event");
     40    await SpecialPowers.spawn(browser, [], async () => {
     41      content.history.pushState({}, "", "https://example.com");
     42    });
     43    is(onLocationChangeCount, 2, "should have 2 onLocationChange events");
     44    is(
     45      onSecurityChangeCount,
     46      1,
     47      "should still have only 1 onSecurityChange event"
     48    );
     49  });
     50 });