summaryrefslogtreecommitdiffstats
path: root/browser/components/urlbar/tests/unit/test_download_embed_bookmarks.js
blob: 29ce5577482ac865ee020443642a7f0fdaf7345a (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
/* -*- 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/. */

/**
 * Tests bug 449406 to ensure that TRANSITION_DOWNLOAD, TRANSITION_EMBED and
 * TRANSITION_FRAMED_LINK bookmarked uri's show up in the location bar.
 */

testEngine_setup();

const TRANSITION_EMBED = PlacesUtils.history.TRANSITION_EMBED;
const TRANSITION_FRAMED_LINK = PlacesUtils.history.TRANSITION_FRAMED_LINK;
const TRANSITION_DOWNLOAD = PlacesUtils.history.TRANSITION_DOWNLOAD;

add_task(async function test_download_embed_bookmarks() {
  Services.prefs.setBoolPref("browser.urlbar.suggest.searches", false);
  registerCleanupFunction(() => {
    Services.prefs.clearUserPref("browser.urlbar.suggest.searches");
  });

  let uri1 = Services.io.newURI("http://download/bookmarked");
  let uri2 = Services.io.newURI("http://embed/bookmarked");
  let uri3 = Services.io.newURI("http://framed/bookmarked");
  let uri4 = Services.io.newURI("http://download");
  let uri5 = Services.io.newURI("http://embed");
  let uri6 = Services.io.newURI("http://framed");
  await PlacesTestUtils.addVisits([
    { uri: uri1, title: "download-bookmark", transition: TRANSITION_DOWNLOAD },
    { uri: uri2, title: "embed-bookmark", transition: TRANSITION_EMBED },
    { uri: uri3, title: "framed-bookmark", transition: TRANSITION_FRAMED_LINK },
    { uri: uri4, title: "download2", transition: TRANSITION_DOWNLOAD },
    { uri: uri5, title: "embed2", transition: TRANSITION_EMBED },
    { uri: uri6, title: "framed2", transition: TRANSITION_FRAMED_LINK },
  ]);
  await PlacesTestUtils.addBookmarkWithDetails({
    uri: uri1,
    title: "download-bookmark",
  });
  await PlacesTestUtils.addBookmarkWithDetails({
    uri: uri2,
    title: "embed-bookmark",
  });
  await PlacesTestUtils.addBookmarkWithDetails({
    uri: uri3,
    title: "framed-bookmark",
  });
  await PlacesFrecencyRecalculator.recalculateAnyOutdatedFrecencies();

  info("Searching for bookmarked download uri matches");
  let context = createContext("download-bookmark", { isPrivate: false });
  await check_results({
    context,
    matches: [
      makeSearchResult(context, {
        engineName: SUGGESTIONS_ENGINE_NAME,
        heuristic: true,
      }),
      makeBookmarkResult(context, {
        uri: uri1.spec,
        title: "download-bookmark",
      }),
    ],
  });

  info("Searching for bookmarked embed uri matches");
  context = createContext("embed-bookmark", { isPrivate: false });
  await check_results({
    context,
    matches: [
      makeSearchResult(context, {
        engineName: SUGGESTIONS_ENGINE_NAME,
        heuristic: true,
      }),
      makeBookmarkResult(context, {
        uri: uri2.spec,
        title: "embed-bookmark",
      }),
    ],
  });

  info("Searching for bookmarked framed uri matches");
  context = createContext("framed-bookmark", { isPrivate: false });
  await check_results({
    context,
    matches: [
      makeSearchResult(context, {
        engineName: SUGGESTIONS_ENGINE_NAME,
        heuristic: true,
      }),
      makeBookmarkResult(context, {
        uri: uri3.spec,
        title: "framed-bookmark",
      }),
    ],
  });

  info("Searching for download uri does not match");
  context = createContext("download2", { isPrivate: false });
  await check_results({
    context,
    matches: [
      makeSearchResult(context, {
        engineName: SUGGESTIONS_ENGINE_NAME,
        heuristic: true,
      }),
    ],
  });

  info("Searching for embed uri does not match");
  context = createContext("embed2", { isPrivate: false });
  await check_results({
    context,
    matches: [
      makeSearchResult(context, {
        engineName: SUGGESTIONS_ENGINE_NAME,
        heuristic: true,
      }),
    ],
  });

  info("Searching for framed uri does not match");
  context = createContext("framed2", { isPrivate: false });
  await check_results({
    context,
    matches: [
      makeSearchResult(context, {
        engineName: SUGGESTIONS_ENGINE_NAME,
        heuristic: true,
      }),
    ],
  });

  await cleanupPlaces();
});