summaryrefslogtreecommitdiffstats
path: root/toolkit/components/places/tests/unifiedcomplete/test_match_beginning.js
blob: 57a1efaeb5dfbd11f8b30cf287f78d430d3a006a (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
/* 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 bug 451760 which allows matching only at the beginning of urls or
 * titles to simulate Firefox 2 functionality.
 */

add_task(function* test_match_beginning() {
  Services.prefs.setBoolPref("browser.urlbar.autoFill.searchEngines", false);

  let uri1 = NetUtil.newURI("http://x.com/y");
  let uri2 = NetUtil.newURI("https://y.com/x");
  yield PlacesTestUtils.addVisits([
    { uri: uri1, title: "a b" },
    { uri: uri2, title: "b a" }
  ]);

  do_print("Match at the beginning of titles");
  Services.prefs.setIntPref("browser.urlbar.matchBehavior", 3);
  yield check_autocomplete({
    search: "a",
    matches: [ { uri: uri1, title: "a b" } ]
  });

  do_print("Match at the beginning of titles");
  yield check_autocomplete({
    search: "b",
    matches: [ { uri: uri2, title: "b a" } ]
  });

  do_print("Match at the beginning of urls");
  yield check_autocomplete({
    search: "x",
    matches: [ { uri: uri1, title: "a b" } ]
  });

  do_print("Match at the beginning of urls");
  yield check_autocomplete({
    search: "y",
    matches: [ { uri: uri2, title: "b a" } ]
  });

  do_print("Sanity check that matching anywhere finds more");
  Services.prefs.setIntPref("browser.urlbar.matchBehavior", 1);
  yield check_autocomplete({
    search: "a",
    matches: [ { uri: uri1, title: "a b" },
               { uri: uri2, title: "b a" } ]
  });

  yield cleanup();
});