summaryrefslogtreecommitdiffstats
path: root/browser/components/urlbar/tests/unit/test_autofill_search_engine_aliases.js
blob: 018a2e168135f5ebf4b2fbb5699439917a6a2f30 (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
/* 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/. */

// Tests autofilling search engine token ("@") aliases.

"use strict";

const TEST_ENGINE_NAME = "test autofill aliases";
const TEST_ENGINE_ALIAS = "@autofilltest";

add_task(async function init() {
  // Add an engine with an "@" alias.
  await SearchTestUtils.installSearchExtension({
    name: TEST_ENGINE_NAME,
    keyword: TEST_ENGINE_ALIAS,
  });
});

// Searching for @autofi should autofill to @autofilltest.
add_task(async function basic() {
  // Add a history visit that should normally match but for the fact that the
  // search uses an @ alias.  When an @ alias is autofilled, there should be no
  // other matches except the autofill heuristic match.
  await PlacesTestUtils.addVisits({
    uri: "http://example.com/",
    title: TEST_ENGINE_ALIAS,
  });

  let search = TEST_ENGINE_ALIAS.substr(
    0,
    Math.round(TEST_ENGINE_ALIAS.length / 2)
  );
  let autofilledValue = TEST_ENGINE_ALIAS + " ";
  let context = createContext(search, { isPrivate: false });
  await check_results({
    context,
    autofilled: autofilledValue,
    matches: [
      makeSearchResult(context, {
        engineName: TEST_ENGINE_NAME,
        alias: TEST_ENGINE_ALIAS,
        query: "",
        providesSearchMode: true,
        heuristic: false,
      }),
    ],
  });
  await cleanupPlaces();
});

// Searching for @AUTOFI should autofill to @AUTOFIlltest, preserving the case
// in the search string.
add_task(async function preserveCase() {
  // Add a history visit that should normally match but for the fact that the
  // search uses an @ alias.  When an @ alias is autofilled, there should be no
  // other matches except the autofill heuristic match.
  await PlacesTestUtils.addVisits({
    uri: "http://example.com/",
    title: TEST_ENGINE_ALIAS,
  });

  let search = TEST_ENGINE_ALIAS.toUpperCase().substr(
    0,
    Math.round(TEST_ENGINE_ALIAS.length / 2)
  );
  let alias = search + TEST_ENGINE_ALIAS.substr(search.length);

  let autofilledValue = alias + " ";
  let context = createContext(search, { isPrivate: false });
  await check_results({
    context,
    autofilled: autofilledValue,
    matches: [
      makeSearchResult(context, {
        engineName: TEST_ENGINE_NAME,
        alias,
        query: "",
        providesSearchMode: true,
        heuristic: false,
      }),
    ],
  });
  await cleanupPlaces();
});