summaryrefslogtreecommitdiffstats
path: root/browser/components/urlbar/tests/unit/test_autofill_functional.js
blob: ad8d567a30957bff029e609d1b0fc72788a3de08 (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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/* 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/. */

// Functional tests for inline autocomplete

add_setup(async function () {
  registerCleanupFunction(async () => {
    Services.prefs.clearUserPref("browser.urlbar.suggest.searches");
    Services.prefs.clearUserPref("browser.urlbar.suggest.quickactions");
  });

  Services.prefs.setBoolPref("browser.urlbar.suggest.searches", false);
  Services.prefs.setBoolPref("browser.urlbar.suggest.quickactions", false);
});

add_task(async function test_urls_order() {
  info("Add urls, check for correct order");
  let places = [
    { uri: Services.io.newURI("http://visit1.mozilla.org") },
    { uri: Services.io.newURI("http://visit2.mozilla.org") },
  ];
  await PlacesTestUtils.addVisits(places);
  let context = createContext("vis", { isPrivate: false });
  await check_results({
    context,
    autofilled: "visit2.mozilla.org/",
    completed: "http://visit2.mozilla.org/",
    matches: [
      makeVisitResult(context, {
        uri: "http://visit2.mozilla.org/",
        title: "test visit for http://visit2.mozilla.org/",
        heuristic: true,
      }),
      makeVisitResult(context, {
        uri: "http://visit1.mozilla.org/",
        title: "test visit for http://visit1.mozilla.org/",
      }),
    ],
  });
  await cleanupPlaces();
});

add_task(async function test_bookmark_first() {
  info("With a bookmark and history, the query result should be the bookmark");
  await PlacesTestUtils.addBookmarkWithDetails({
    uri: Services.io.newURI("http://bookmark1.mozilla.org/"),
  });
  await PlacesTestUtils.addVisits(
    Services.io.newURI("http://bookmark1.mozilla.org/foo")
  );
  let context = createContext("bookmark", { isPrivate: false });
  await check_results({
    context,
    autofilled: "bookmark1.mozilla.org/",
    completed: "http://bookmark1.mozilla.org/",
    matches: [
      makeVisitResult(context, {
        uri: "http://bookmark1.mozilla.org/",
        title: "A bookmark",
        heuristic: true,
      }),
      makeVisitResult(context, {
        uri: "http://bookmark1.mozilla.org/foo",
        title: "test visit for http://bookmark1.mozilla.org/foo",
      }),
    ],
  });
  await cleanupPlaces();
});

add_task(async function test_complete_querystring() {
  info("Check to make sure we autocomplete after ?");
  await PlacesTestUtils.addVisits(
    Services.io.newURI("http://smokey.mozilla.org/foo?bacon=delicious")
  );
  let context = createContext("smokey.mozilla.org/foo?", { isPrivate: false });
  await check_results({
    context,
    autofilled: "smokey.mozilla.org/foo?bacon=delicious",
    completed: "http://smokey.mozilla.org/foo?bacon=delicious",
    matches: [
      makeVisitResult(context, {
        uri: "http://smokey.mozilla.org/foo?bacon=delicious",
        title: "test visit for http://smokey.mozilla.org/foo?bacon=delicious",
        heuristic: true,
      }),
    ],
  });
  await cleanupPlaces();
});

add_task(async function test_complete_fragment() {
  info("Check to make sure we autocomplete after #");
  await PlacesTestUtils.addVisits(
    Services.io.newURI("http://smokey.mozilla.org/foo?bacon=delicious#bar")
  );
  let context = createContext("smokey.mozilla.org/foo?bacon=delicious#bar", {
    isPrivate: false,
  });
  await check_results({
    context,
    autofilled: "smokey.mozilla.org/foo?bacon=delicious#bar",
    completed: "http://smokey.mozilla.org/foo?bacon=delicious#bar",
    matches: [
      makeVisitResult(context, {
        uri: "http://smokey.mozilla.org/foo?bacon=delicious#bar",
        title:
          "test visit for http://smokey.mozilla.org/foo?bacon=delicious#bar",
        heuristic: true,
      }),
    ],
  });
  await cleanupPlaces();
});

add_task(async function test_prefix_autofill() {
  await PlacesTestUtils.addVisits({
    uri: Services.io.newURI("http://mozilla.org/test/"),
  });
  await PlacesTestUtils.addVisits({
    uri: Services.io.newURI("http://moz.org/test/"),
  });

  info("Should still autofill after a search is cancelled immediately");
  let context = createContext("mozi", { isPrivate: false });
  await check_results({
    context,
    incompleteSearch: "moz",
    autofilled: "mozilla.org/",
    completed: "http://mozilla.org/",
    matches: [
      makeVisitResult(context, {
        uri: "http://mozilla.org/",
        fallbackTitle: UrlbarTestUtils.trimURL("http://mozilla.org"),
        heuristic: true,
      }),
      makeVisitResult(context, {
        uri: "http://mozilla.org/test/",
        title: "test visit for http://mozilla.org/test/",
        providerName: "Places",
      }),
    ],
  });

  await cleanupPlaces();
});