test_protocol_swap.js (9451B)
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 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 /** 6 * Test bug 424717 to make sure searching with an existing location like 7 * http://site/ also matches https://site/ or ftp://site/. Same thing for 8 * ftp://site/ and https://site/. 9 * 10 * Test bug 461483 to make sure a search for "w" doesn't match the "www." from 11 * site subdomains. 12 */ 13 14 testEngine_setup(); 15 16 add_task(async function test_swap_protocol() { 17 let uri1 = Services.io.newURI("http://www.site/"); 18 let uri2 = Services.io.newURI("http://site/"); 19 let uri3 = Services.io.newURI("ftp://ftp.site/"); 20 let uri4 = Services.io.newURI("ftp://site/"); 21 let uri5 = Services.io.newURI("https://www.site/"); 22 let uri6 = Services.io.newURI("https://site/"); 23 let uri7 = Services.io.newURI("http://woohoo/"); 24 let uri8 = Services.io.newURI("http://wwwwwwacko/"); 25 await PlacesTestUtils.addVisits([ 26 { uri: uri8, title: "title" }, 27 { uri: uri7, title: "title" }, 28 { uri: uri6, title: "title" }, 29 { uri: uri5, title: "title" }, 30 { uri: uri4, title: "title" }, 31 { uri: uri3, title: "title" }, 32 { uri: uri2, title: "title" }, 33 { uri: uri1, title: "title" }, 34 ]); 35 36 // Disable autoFill to avoid handling the first result. 37 Services.prefs.setBoolPref("browser.urlbar.autoFill", false); 38 Services.prefs.setBoolPref("browser.urlbar.suggest.searches", false); 39 registerCleanupFunction(() => { 40 Services.prefs.clearUserPref("browser.urlbar.suggest.searches"); 41 }); 42 43 info("http://www.site matches 'www.site' pages"); 44 let searchString = "http://www.site"; 45 let context = createContext(searchString, { isPrivate: false }); 46 await check_results({ 47 context, 48 matches: [ 49 makeVisitResult(context, { 50 uri: `${searchString}/`, 51 title: "title", 52 source: UrlbarUtils.RESULT_SOURCE.HISTORY, 53 heuristic: true, 54 }), 55 makeVisitResult(context, { uri: uri5.spec, title: "title" }), 56 ], 57 }); 58 59 info("http://site matches all sites"); 60 searchString = "http://site"; 61 context = createContext(searchString, { isPrivate: false }); 62 await check_results({ 63 context, 64 matches: [ 65 makeVisitResult(context, { 66 uri: `${searchString}/`, 67 title: "title", 68 source: UrlbarUtils.RESULT_SOURCE.HISTORY, 69 heuristic: true, 70 }), 71 makeVisitResult(context, { uri: uri3.spec, title: "title" }), 72 makeVisitResult(context, { uri: uri4.spec, title: "title" }), 73 makeVisitResult(context, { uri: uri6.spec, title: "title" }), 74 ], 75 }); 76 77 info("ftp://ftp.site matches itself"); 78 searchString = "ftp://ftp.site"; 79 context = createContext(searchString, { isPrivate: false }); 80 await check_results({ 81 context, 82 matches: [ 83 makeVisitResult(context, { 84 uri: `${searchString}/`, 85 title: `${searchString}/`, 86 source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL, 87 heuristic: true, 88 }), 89 makeVisitResult(context, { uri: uri3.spec, title: "title" }), 90 ], 91 }); 92 93 info("ftp://site matches all sites"); 94 searchString = "ftp://site"; 95 context = createContext(searchString, { isPrivate: false }); 96 await check_results({ 97 context, 98 matches: [ 99 makeVisitResult(context, { 100 uri: `${searchString}/`, 101 title: `${searchString}/`, 102 source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL, 103 heuristic: true, 104 }), 105 makeVisitResult(context, { uri: uri3.spec, title: "title" }), 106 makeVisitResult(context, { uri: uri4.spec, title: "title" }), 107 makeVisitResult(context, { uri: uri6.spec, title: "title" }), 108 ], 109 }); 110 111 info("https://www.site matches all sites"); 112 searchString = "https://www.sit"; 113 context = createContext(searchString, { isPrivate: false }); 114 await check_results({ 115 context, 116 matches: [ 117 makeVisitResult(context, { 118 uri: `${searchString}/`, 119 title: `${searchString}/`, 120 source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL, 121 heuristic: true, 122 }), 123 makeVisitResult(context, { uri: uri5.spec, title: "title" }), 124 ], 125 }); 126 127 info("https://site matches all sites"); 128 searchString = "https://sit"; 129 context = createContext(searchString, { isPrivate: false }); 130 await check_results({ 131 context, 132 matches: [ 133 makeVisitResult(context, { 134 uri: `${searchString}/`, 135 title: `${searchString}/`, 136 source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL, 137 heuristic: true, 138 }), 139 makeVisitResult(context, { uri: uri3.spec, title: "title" }), 140 makeVisitResult(context, { uri: uri4.spec, title: "title" }), 141 makeVisitResult(context, { uri: uri6.spec, title: "title" }), 142 ], 143 }); 144 145 info("www.site matches 'www.site' pages"); 146 searchString = "www.site"; 147 context = createContext(searchString, { isPrivate: false }); 148 await check_results({ 149 context, 150 matches: [ 151 makeVisitResult(context, { 152 uri: `http://${searchString}/`, 153 title: "title", 154 source: UrlbarUtils.RESULT_SOURCE.HISTORY, 155 heuristic: true, 156 }), 157 makeVisitResult(context, { uri: uri5.spec, title: "title" }), 158 ], 159 }); 160 161 info("w matches 'w' pages, including 'www'"); 162 context = createContext("w", { isPrivate: false }); 163 await check_results({ 164 context, 165 matches: [ 166 makeSearchResult(context, { 167 engineName: SUGGESTIONS_ENGINE_NAME, 168 heuristic: true, 169 }), 170 makeVisitResult(context, { uri: uri5.spec, title: "title" }), 171 makeVisitResult(context, { uri: uri7.spec, title: "title" }), 172 makeVisitResult(context, { uri: uri8.spec, title: "title" }), 173 ], 174 }); 175 176 info("http://w matches 'w' pages, including 'www'"); 177 searchString = "http://w"; 178 context = createContext(searchString, { isPrivate: false }); 179 await check_results({ 180 context, 181 matches: [ 182 makeVisitResult(context, { 183 uri: `${searchString}/`, 184 title: `${searchString}/`, 185 source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL, 186 heuristic: true, 187 }), 188 makeVisitResult(context, { uri: uri5.spec, title: "title" }), 189 makeVisitResult(context, { uri: uri7.spec, title: "title" }), 190 makeVisitResult(context, { uri: uri8.spec, title: "title" }), 191 ], 192 }); 193 194 info("http://www.w matches nothing"); 195 searchString = "http://www.w"; 196 context = createContext(searchString, { isPrivate: false }); 197 await check_results({ 198 context, 199 matches: [ 200 makeVisitResult(context, { 201 uri: `${searchString}/`, 202 title: `${searchString}/`, 203 source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL, 204 heuristic: true, 205 }), 206 ], 207 }); 208 209 info("ww matches no 'ww' pages, including 'www'"); 210 context = createContext("ww", { isPrivate: false }); 211 await check_results({ 212 context, 213 matches: [ 214 makeSearchResult(context, { 215 engineName: SUGGESTIONS_ENGINE_NAME, 216 heuristic: true, 217 }), 218 makeVisitResult(context, { uri: uri5.spec, title: "title" }), 219 makeVisitResult(context, { uri: uri8.spec, title: "title" }), 220 ], 221 }); 222 223 info("http://ww matches no 'ww' pages, including 'www'"); 224 searchString = "http://ww"; 225 context = createContext(searchString, { isPrivate: false }); 226 await check_results({ 227 context, 228 matches: [ 229 makeVisitResult(context, { 230 uri: `${searchString}/`, 231 title: `${searchString}/`, 232 source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL, 233 heuristic: true, 234 }), 235 makeVisitResult(context, { uri: uri5.spec, title: "title" }), 236 makeVisitResult(context, { uri: uri8.spec, title: "title" }), 237 ], 238 }); 239 240 info("http://www.ww matches nothing"); 241 searchString = "http://www.ww"; 242 context = createContext(searchString, { isPrivate: false }); 243 await check_results({ 244 context, 245 matches: [ 246 makeVisitResult(context, { 247 uri: `${searchString}/`, 248 title: `${searchString}/`, 249 source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL, 250 heuristic: true, 251 }), 252 ], 253 }); 254 255 info("www matches 'www' pages"); 256 context = createContext("www", { isPrivate: false }); 257 await check_results({ 258 context, 259 matches: [ 260 makeSearchResult(context, { 261 engineName: SUGGESTIONS_ENGINE_NAME, 262 heuristic: true, 263 }), 264 makeVisitResult(context, { uri: uri5.spec, title: "title" }), 265 makeVisitResult(context, { uri: uri8.spec, title: "title" }), 266 ], 267 }); 268 269 info("http://www matches 'www' pages"); 270 searchString = "http://www"; 271 context = createContext(searchString, { isPrivate: false }); 272 await check_results({ 273 context, 274 matches: [ 275 makeVisitResult(context, { 276 uri: `${searchString}/`, 277 title: `${searchString}/`, 278 source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL, 279 heuristic: true, 280 }), 281 makeVisitResult(context, { uri: uri5.spec, title: "title" }), 282 makeVisitResult(context, { uri: uri8.spec, title: "title" }), 283 ], 284 }); 285 286 info("http://www.www matches nothing"); 287 searchString = "http://www.www"; 288 context = createContext(searchString, { isPrivate: false }); 289 await check_results({ 290 context, 291 matches: [ 292 makeVisitResult(context, { 293 uri: `${searchString}/`, 294 title: `${searchString}/`, 295 source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL, 296 heuristic: true, 297 }), 298 ], 299 }); 300 301 await cleanupPlaces(); 302 });