test_keywords.js (6256B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this file, 3 * You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 testEngine_setup(); 6 7 add_task(async function test_non_keyword() { 8 info("Searching for non-keyworded entry should autoFill it"); 9 await PlacesTestUtils.addVisits({ 10 uri: Services.io.newURI("http://mozilla.org/test/"), 11 }); 12 await PlacesTestUtils.addBookmarkWithDetails({ 13 uri: Services.io.newURI("http://mozilla.org/test/"), 14 }); 15 let context = createContext("moz", { isPrivate: false }); 16 await check_results({ 17 context, 18 autofilled: "mozilla.org/", 19 completed: "http://mozilla.org/", 20 matches: [ 21 makeVisitResult(context, { 22 uri: "http://mozilla.org/", 23 title: UrlbarTestUtils.trimURL("http://mozilla.org"), 24 heuristic: true, 25 }), 26 makeBookmarkResult(context, { 27 uri: "http://mozilla.org/test/", 28 title: "A bookmark", 29 }), 30 ], 31 }); 32 await cleanupPlaces(); 33 }); 34 35 add_task(async function test_keyword() { 36 info("Searching for keyworded entry should not autoFill it"); 37 await PlacesTestUtils.addVisits({ 38 uri: Services.io.newURI("http://mozilla.org/test/"), 39 }); 40 await PlacesTestUtils.addBookmarkWithDetails({ 41 uri: Services.io.newURI("http://mozilla.org/test/"), 42 keyword: "moz", 43 }); 44 let context = createContext("moz", { isPrivate: false }); 45 await check_results({ 46 context, 47 matches: [ 48 makeKeywordSearchResult(context, { 49 uri: "http://mozilla.org/test/", 50 title: "http://mozilla.org/test/", 51 keyword: "moz", 52 heuristic: true, 53 }), 54 ], 55 }); 56 await cleanupPlaces(); 57 }); 58 59 add_task(async function test_more_than_keyword() { 60 info("Searching for more than keyworded entry should autoFill it"); 61 await PlacesTestUtils.addVisits({ 62 uri: Services.io.newURI("http://mozilla.org/test/"), 63 }); 64 await PlacesTestUtils.addBookmarkWithDetails({ 65 uri: Services.io.newURI("http://mozilla.org/test/"), 66 keyword: "moz", 67 }); 68 let context = createContext("mozi", { isPrivate: false }); 69 await check_results({ 70 context, 71 autofilled: "mozilla.org/", 72 completed: "http://mozilla.org/", 73 matches: [ 74 makeVisitResult(context, { 75 uri: "http://mozilla.org/", 76 title: UrlbarTestUtils.trimURL("http://mozilla.org"), 77 heuristic: true, 78 }), 79 makeBookmarkResult(context, { 80 uri: "http://mozilla.org/test/", 81 title: "A bookmark", 82 }), 83 ], 84 }); 85 await cleanupPlaces(); 86 }); 87 88 add_task(async function test_less_than_keyword() { 89 info("Searching for less than keyworded entry should autoFill it"); 90 await PlacesTestUtils.addVisits({ 91 uri: Services.io.newURI("http://mozilla.org/test/"), 92 }); 93 await PlacesTestUtils.addBookmarkWithDetails({ 94 uri: Services.io.newURI("http://mozilla.org/test/"), 95 keyword: "moz", 96 }); 97 let context = createContext("mo", { isPrivate: false }); 98 await check_results({ 99 context, 100 search: "mo", 101 autofilled: "mozilla.org/", 102 completed: "http://mozilla.org/", 103 matches: [ 104 makeVisitResult(context, { 105 uri: "http://mozilla.org/", 106 title: UrlbarTestUtils.trimURL("http://mozilla.org"), 107 heuristic: true, 108 }), 109 makeBookmarkResult(context, { 110 uri: "http://mozilla.org/test/", 111 title: "A bookmark", 112 }), 113 ], 114 }); 115 await cleanupPlaces(); 116 }); 117 118 add_task(async function test_keyword_casing() { 119 info("Searching for keyworded entry is case-insensitive"); 120 await PlacesTestUtils.addVisits({ 121 uri: Services.io.newURI("http://mozilla.org/test/"), 122 }); 123 await PlacesTestUtils.addBookmarkWithDetails({ 124 uri: Services.io.newURI("http://mozilla.org/test/"), 125 keyword: "moz", 126 }); 127 let context = createContext("MoZ", { isPrivate: false }); 128 await check_results({ 129 context, 130 matches: [ 131 makeKeywordSearchResult(context, { 132 uri: "http://mozilla.org/test/", 133 title: "http://mozilla.org/test/", 134 keyword: "MoZ", 135 heuristic: true, 136 }), 137 ], 138 }); 139 await cleanupPlaces(); 140 }); 141 142 add_task(async function test_less_then_equal_than_keyword_bug_1124238() { 143 info("Searching for less than keyworded entry should autoFill it"); 144 await PlacesTestUtils.addVisits({ 145 uri: Services.io.newURI("http://mozilla.org/test/"), 146 }); 147 await PlacesTestUtils.addVisits("http://mozilla.com/"); 148 await PlacesTestUtils.addBookmarkWithDetails({ 149 uri: Services.io.newURI("http://mozilla.com/"), 150 keyword: "moz", 151 }); 152 153 let context = createContext("mo", { isPrivate: false }); 154 await check_results({ 155 context, 156 search: "mo", 157 autofilled: "mozilla.com/", 158 completed: "http://mozilla.com/", 159 matches: [ 160 makeVisitResult(context, { 161 uri: "http://mozilla.com/", 162 title: "A bookmark", 163 heuristic: true, 164 }), 165 makeVisitResult(context, { 166 uri: "http://mozilla.org/test/", 167 title: "test visit for http://mozilla.org/test/", 168 }), 169 ], 170 }); 171 172 // Search with an additional character. As the input matches a keyword, the 173 // completion should equal the keyword and not the URI as before. 174 context = createContext("moz", { isPrivate: false }); 175 await check_results({ 176 context, 177 matches: [ 178 makeKeywordSearchResult(context, { 179 uri: "http://mozilla.com/", 180 title: "http://mozilla.com", 181 keyword: "moz", 182 heuristic: true, 183 }), 184 makeVisitResult(context, { 185 uri: "http://mozilla.org/test/", 186 title: "test visit for http://mozilla.org/test/", 187 }), 188 ], 189 }); 190 191 // Search with an additional character. The input doesn't match a keyword 192 // anymore, it should be autofilled. 193 context = createContext("mozi", { isPrivate: false }); 194 await check_results({ 195 context, 196 autofilled: "mozilla.com/", 197 completed: "http://mozilla.com/", 198 matches: [ 199 makeVisitResult(context, { 200 uri: "http://mozilla.com/", 201 title: "A bookmark", 202 heuristic: true, 203 }), 204 makeVisitResult(context, { 205 uri: "http://mozilla.org/test/", 206 title: "test visit for http://mozilla.org/test/", 207 }), 208 ], 209 }); 210 211 await cleanupPlaces(); 212 });