tor-browser

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

test_UrlbarUtils_addToUrlbarHistory.js (1995B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 /**
      5 * These tests unit test the functionality of the functions in UrlbarUtils.
      6 * Some functions are bigger, and split out into sepearate test_UrlbarUtils_* files.
      7 */
      8 
      9 "use strict";
     10 
     11 const { PrivateBrowsingUtils } = ChromeUtils.importESModule(
     12  "resource://gre/modules/PrivateBrowsingUtils.sys.mjs"
     13 );
     14 const { PlacesUIUtils } = ChromeUtils.importESModule(
     15  "moz-src:///browser/components/places/PlacesUIUtils.sys.mjs"
     16 );
     17 
     18 let sandbox;
     19 
     20 add_setup(function () {
     21  sandbox = sinon.createSandbox();
     22 });
     23 
     24 add_task(function test_addToUrlbarHistory() {
     25  sandbox.stub(PlacesUIUtils, "markPageAsTyped");
     26  sandbox.stub(PrivateBrowsingUtils, "isWindowPrivate").returns(false);
     27 
     28  UrlbarUtils.addToUrlbarHistory("http://example.com");
     29  Assert.ok(
     30    PlacesUIUtils.markPageAsTyped.calledOnce,
     31    "Should have marked a simple URL as typed."
     32  );
     33  PlacesUIUtils.markPageAsTyped.resetHistory();
     34 
     35  UrlbarUtils.addToUrlbarHistory();
     36  Assert.ok(
     37    PlacesUIUtils.markPageAsTyped.notCalled,
     38    "Should not have attempted to mark a null URL as typed."
     39  );
     40  PlacesUIUtils.markPageAsTyped.resetHistory();
     41 
     42  UrlbarUtils.addToUrlbarHistory("http://exam ple.com");
     43  Assert.ok(
     44    PlacesUIUtils.markPageAsTyped.notCalled,
     45    "Should not have marked a URL containing a space as typed."
     46  );
     47  PlacesUIUtils.markPageAsTyped.resetHistory();
     48 
     49  UrlbarUtils.addToUrlbarHistory("http://exam\x01ple.com");
     50  Assert.ok(
     51    PlacesUIUtils.markPageAsTyped.notCalled,
     52    "Should not have marked a URL containing a control character as typed."
     53  );
     54  PlacesUIUtils.markPageAsTyped.resetHistory();
     55 
     56  PrivateBrowsingUtils.isWindowPrivate.returns(true);
     57  UrlbarUtils.addToUrlbarHistory("http://example.com");
     58  Assert.ok(
     59    PlacesUIUtils.markPageAsTyped.notCalled,
     60    "Should not have marked a URL provided by a private browsing page as typed."
     61  );
     62  PlacesUIUtils.markPageAsTyped.resetHistory();
     63 });