summaryrefslogtreecommitdiffstats
path: root/browser/components/urlbar/tests/unit/test_UrlbarQueryContext.js
blob: e30e2fa0eb9678ddac4e779cf5319870b17fb142 (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
64
65
66
67
68
69
70
71
72
73
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

add_task(function test_constructor() {
  Assert.throws(
    () => new UrlbarQueryContext(),
    /Missing or empty allowAutofill provided to UrlbarQueryContext/,
    "Should throw with no arguments"
  );

  Assert.throws(
    () =>
      new UrlbarQueryContext({
        allowAutofill: true,
        isPrivate: false,
        searchString: "foo",
      }),
    /Missing or empty maxResults provided to UrlbarQueryContext/,
    "Should throw with a missing maxResults parameter"
  );

  Assert.throws(
    () =>
      new UrlbarQueryContext({
        allowAutofill: true,
        maxResults: 1,
        searchString: "foo",
      }),
    /Missing or empty isPrivate provided to UrlbarQueryContext/,
    "Should throw with a missing isPrivate parameter"
  );

  Assert.throws(
    () =>
      new UrlbarQueryContext({
        isPrivate: false,
        maxResults: 1,
        searchString: "foo",
      }),
    /Missing or empty allowAutofill provided to UrlbarQueryContext/,
    "Should throw with a missing allowAutofill parameter"
  );

  let qc = new UrlbarQueryContext({
    allowAutofill: false,
    isPrivate: true,
    maxResults: 1,
    searchString: "foo",
  });

  Assert.strictEqual(
    qc.allowAutofill,
    false,
    "Should have saved the correct value for allowAutofill"
  );
  Assert.strictEqual(
    qc.isPrivate,
    true,
    "Should have saved the correct value for isPrivate"
  );
  Assert.equal(
    qc.maxResults,
    1,
    "Should have saved the correct value for maxResults"
  );
  Assert.equal(
    qc.searchString,
    "foo",
    "Should have saved the correct value for searchString"
  );
});