tor-browser

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

browser_NavigationManager_failed_navigation.js (3007B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
      3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 const { NavigableManager } = ChromeUtils.importESModule(
      6  "chrome://remote/content/shared/NavigableManager.sys.mjs"
      7 );
      8 
      9 const TEST_URL = "https://example.com/document-builder.sjs?html=test1";
     10 const TEST_URL_CLOSED_PORT = "http://127.0.0.1:36325/";
     11 const TEST_URL_WRONG_URI = "https://www.wronguri.wronguri/";
     12 
     13 add_task(async function testClosedPort() {
     14  const events = [];
     15  const onEvent = (name, data) => events.push({ name, data });
     16 
     17  const navigationManager = new NavigationManager();
     18  navigationManager.on("navigation-started", onEvent);
     19  navigationManager.on("navigation-stopped", onEvent);
     20 
     21  const tab = await addTabAndWaitForNavigated(gBrowser, TEST_URL);
     22  const browser = tab.linkedBrowser;
     23 
     24  navigationManager.startMonitoring();
     25  const navigableId = NavigableManager.getIdForBrowser(browser);
     26 
     27  is(
     28    navigationManager.getNavigationForBrowsingContext(browser.browsingContext),
     29    null,
     30    "No navigation recorded yet"
     31  );
     32  is(events.length, 0, "No event recorded");
     33 
     34  await loadURL(browser, TEST_URL_CLOSED_PORT, { maybeErrorPage: true });
     35 
     36  const firstNavigation = navigationManager.getNavigationForBrowsingContext(
     37    browser.browsingContext
     38  );
     39  assertNavigation(firstNavigation, TEST_URL_CLOSED_PORT);
     40 
     41  is(events.length, 2, "Two events recorded");
     42  assertNavigationEvents(
     43    events,
     44    TEST_URL_CLOSED_PORT,
     45    firstNavigation.navigationId,
     46    navigableId
     47  );
     48 
     49  navigationManager.off("navigation-started", onEvent);
     50  navigationManager.off("navigation-stopped", onEvent);
     51  navigationManager.stopMonitoring();
     52 });
     53 
     54 add_task(async function testWrongURI() {
     55  const events = [];
     56  const onEvent = (name, data) => events.push({ name, data });
     57 
     58  const navigationManager = new NavigationManager();
     59  navigationManager.on("navigation-started", onEvent);
     60  navigationManager.on("navigation-stopped", onEvent);
     61 
     62  const tab = await addTabAndWaitForNavigated(gBrowser, TEST_URL);
     63  const browser = tab.linkedBrowser;
     64 
     65  navigationManager.startMonitoring();
     66 
     67  const navigableId = NavigableManager.getIdForBrowser(browser);
     68 
     69  is(
     70    navigationManager.getNavigationForBrowsingContext(browser.browsingContext),
     71    null,
     72    "No navigation recorded yet"
     73  );
     74  is(events.length, 0, "No event recorded");
     75 
     76  await loadURL(browser, TEST_URL_WRONG_URI, { maybeErrorPage: true });
     77 
     78  const firstNavigation = navigationManager.getNavigationForBrowsingContext(
     79    browser.browsingContext
     80  );
     81  assertNavigation(firstNavigation, TEST_URL_WRONG_URI);
     82 
     83  is(events.length, 2, "Two events recorded");
     84  assertNavigationEvents(
     85    events,
     86    TEST_URL_WRONG_URI,
     87    firstNavigation.navigationId,
     88    navigableId
     89  );
     90 
     91  navigationManager.off("navigation-started", onEvent);
     92  navigationManager.off("navigation-stopped", onEvent);
     93  navigationManager.stopMonitoring();
     94 });