summaryrefslogtreecommitdiffstats
path: root/browser/components/urlbar/tests/unit/test_UrlbarUtils_addToUrlbarHistory.js
blob: 6eabc3bb52b0ea4c71dc60022513135c02ab7e7d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

/**
 * These tests unit test the functionality of the functions in UrlbarUtils.
 * Some functions are bigger, and split out into sepearate test_UrlbarUtils_* files.
 */

"use strict";

const { PrivateBrowsingUtils } = ChromeUtils.importESModule(
  "resource://gre/modules/PrivateBrowsingUtils.sys.mjs"
);
const { PlacesUIUtils } = ChromeUtils.importESModule(
  "resource:///modules/PlacesUIUtils.sys.mjs"
);

let sandbox;

add_task(function setup() {
  sandbox = sinon.createSandbox();
});

add_task(function test_addToUrlbarHistory() {
  sandbox.stub(PlacesUIUtils, "markPageAsTyped");
  sandbox.stub(PrivateBrowsingUtils, "isWindowPrivate").returns(false);

  UrlbarUtils.addToUrlbarHistory("http://example.com");
  Assert.ok(
    PlacesUIUtils.markPageAsTyped.calledOnce,
    "Should have marked a simple URL as typed."
  );
  PlacesUIUtils.markPageAsTyped.resetHistory();

  UrlbarUtils.addToUrlbarHistory();
  Assert.ok(
    PlacesUIUtils.markPageAsTyped.notCalled,
    "Should not have attempted to mark a null URL as typed."
  );
  PlacesUIUtils.markPageAsTyped.resetHistory();

  UrlbarUtils.addToUrlbarHistory("http://exam ple.com");
  Assert.ok(
    PlacesUIUtils.markPageAsTyped.notCalled,
    "Should not have marked a URL containing a space as typed."
  );
  PlacesUIUtils.markPageAsTyped.resetHistory();

  UrlbarUtils.addToUrlbarHistory("http://exam\x01ple.com");
  Assert.ok(
    PlacesUIUtils.markPageAsTyped.notCalled,
    "Should not have marked a URL containing a control character as typed."
  );
  PlacesUIUtils.markPageAsTyped.resetHistory();

  PrivateBrowsingUtils.isWindowPrivate.returns(true);
  UrlbarUtils.addToUrlbarHistory("http://example.com");
  Assert.ok(
    PlacesUIUtils.markPageAsTyped.notCalled,
    "Should not have marked a URL provided by a private browsing page as typed."
  );
  PlacesUIUtils.markPageAsTyped.resetHistory();
});