summaryrefslogtreecommitdiffstats
path: root/browser/components/urlbar/tests/unit/test_local_suggest_prefs.js
blob: 2d03cc4c54540a9fc3cca9caca60d6c4efa6cf3e (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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*-
 * vim:set ts=2 sw=2 sts=2 et:
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

// Test for following preferences related to local suggest.
// * browser.urlbar.suggest.bookmark
// * browser.urlbar.suggest.history
// * browser.urlbar.suggest.openpage

testEngine_setup();

add_task(async function setup() {
  Services.prefs.setBoolPref("browser.urlbar.autoFill", false);
  Services.prefs.setBoolPref("browser.urlbar.suggest.engines", false);
  Services.prefs.setBoolPref("browser.urlbar.suggest.quickactions", false);

  const uri = Services.io.newURI("http://example.com/");

  await PlacesTestUtils.addVisits([{ uri, title: "example" }]);
  await PlacesUtils.bookmarks.insert({
    url: uri,
    parentGuid: PlacesUtils.bookmarks.toolbarGuid,
  });
  await addOpenPages(uri);

  registerCleanupFunction(async () => {
    Services.prefs.clearUserPref("browser.urlbar.autoFill");
    Services.prefs.clearUserPref("browser.urlbar.suggest.engines");
    Services.prefs.clearUserPref("browser.urlbar.suggest.quickactions");

    Services.prefs.clearUserPref("browser.urlbar.suggest.bookmark");
    Services.prefs.clearUserPref("browser.urlbar.suggest.history");
    Services.prefs.clearUserPref("browser.urlbar.suggest.openpage");
    await cleanupPlaces();
  });
});

add_task(async function test_prefs() {
  const testData = [
    {
      bookmark: true,
      history: true,
      openpage: true,
    },
    {
      bookmark: false,
      history: true,
      openpage: true,
    },
    {
      bookmark: true,
      history: false,
      openpage: true,
    },
    {
      bookmark: true,
      history: true,
      openpage: false,
    },
    {
      bookmark: false,
      history: false,
      openpage: true,
    },
    {
      bookmark: false,
      history: true,
      openpage: false,
    },
    {
      bookmark: true,
      history: false,
      openpage: false,
    },
    {
      bookmark: false,
      history: false,
      openpage: false,
    },
  ];

  for (const { bookmark, history, openpage } of testData) {
    Services.prefs.setBoolPref("browser.urlbar.suggest.bookmark", bookmark);
    Services.prefs.setBoolPref("browser.urlbar.suggest.history", history);
    Services.prefs.setBoolPref("browser.urlbar.suggest.openpage", openpage);

    info(`Test bookmark:${bookmark} history:${history} openpage:${openpage}`);

    const context = createContext("e", { isPrivate: false });
    const matches = [];

    matches.push(
      makeSearchResult(context, {
        engineName: SUGGESTIONS_ENGINE_NAME,
        heuristic: true,
      })
    );

    if (openpage) {
      matches.push(
        makeTabSwitchResult(context, {
          uri: "http://example.com/",
          title: "example",
        })
      );
    } else if (bookmark) {
      matches.push(
        makeBookmarkResult(context, {
          uri: "http://example.com/",
          title: "example",
        })
      );
    } else if (history) {
      matches.push(
        makeVisitResult(context, {
          uri: "http://example.com/",
          title: "example",
        })
      );
    }

    await check_results({ context, matches });
  }
});