test_avoid_stripping_to_empty_tokens.js (3297B)
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_protocol_trimming() { 8 for (let prot of ["http", "https"]) { 9 let visit = { 10 // Include the protocol in the query string to ensure we get matches (see bug 1059395) 11 uri: Services.io.newURI( 12 prot + 13 "://www.mozilla.org/test/?q=" + 14 prot + 15 encodeURIComponent("://") + 16 "www.foo" 17 ), 18 title: "Test title", 19 }; 20 await PlacesTestUtils.addVisits(visit); 21 22 let input = prot + "://www."; 23 info("Searching for: " + input); 24 let context = createContext(input, { isPrivate: false }); 25 await check_results({ 26 context, 27 autofilled: prot + "://www.mozilla.org/", 28 completed: prot + "://www.mozilla.org/", 29 matches: [ 30 makeVisitResult(context, { 31 uri: prot + "://www.mozilla.org/", 32 title: UrlbarTestUtils.trimURL(prot + "://www.mozilla.org"), 33 heuristic: true, 34 }), 35 makeVisitResult(context, { 36 uri: visit.uri.spec, 37 title: visit.title, 38 }), 39 ], 40 }); 41 42 input = "www."; 43 info("Searching for: " + input); 44 context = createContext(input, { isPrivate: false }); 45 await check_results({ 46 context, 47 autofilled: "www.mozilla.org/", 48 completed: prot + "://www.mozilla.org/", 49 matches: [ 50 makeVisitResult(context, { 51 uri: prot + "://www.mozilla.org/", 52 title: UrlbarTestUtils.trimURL(prot + "://www.mozilla.org"), 53 heuristic: true, 54 }), 55 makeVisitResult(context, { 56 uri: visit.uri.spec, 57 title: visit.title, 58 }), 59 ], 60 }); 61 62 input = prot + "://www. "; 63 info("Searching for: " + input); 64 context = createContext(input, { isPrivate: false }); 65 await check_results({ 66 context, 67 matches: [ 68 makeVisitResult(context, { 69 source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL, 70 uri: `${input.trim()}/`, 71 title: `${input.trim()}/`, 72 iconUri: "", 73 heuristic: true, 74 providerName: "UrlbarProviderHeuristicFallback", 75 }), 76 makeVisitResult(context, { 77 uri: visit.uri.spec, 78 title: visit.title, 79 providerName: "UrlbarProviderPlaces", 80 }), 81 ], 82 }); 83 84 let inputs = [ 85 prot + "://", 86 prot + ":// ", 87 prot + ":// mo", 88 prot + "://mo te", 89 prot + "://www. mo", 90 prot + "://www.mo te", 91 "www. ", 92 "www. mo", 93 "www.mo te", 94 ]; 95 for (input of inputs) { 96 info("Searching for: " + input); 97 context = createContext(input, { isPrivate: false }); 98 await check_results({ 99 context, 100 matches: [ 101 makeSearchResult(context, { 102 engineName: SUGGESTIONS_ENGINE_NAME, 103 query: input, 104 heuristic: true, 105 }), 106 makeVisitResult(context, { 107 uri: visit.uri.spec, 108 title: visit.title, 109 providerName: "UrlbarProviderPlaces", 110 }), 111 ], 112 }); 113 } 114 115 await cleanupPlaces(); 116 } 117 });