test_trimming.js (5490B)
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 add_setup(async function () { 6 registerCleanupFunction(async () => { 7 Services.prefs.clearUserPref("browser.urlbar.suggest.searches"); 8 Services.prefs.clearUserPref("browser.urlbar.suggest.quickactions"); 9 }); 10 Services.prefs.setBoolPref("browser.urlbar.suggest.searches", false); 11 Services.prefs.setBoolPref("browser.urlbar.suggest.quickactions", false); 12 }); 13 14 add_task(async function test_untrimmed_secure_www() { 15 info("Searching for untrimmed https://www entry"); 16 await PlacesTestUtils.addVisits({ 17 uri: Services.io.newURI("https://www.mozilla.org/test/"), 18 }); 19 let context = createContext("mo", { isPrivate: false }); 20 await check_results({ 21 context, 22 autofilled: "mozilla.org/", 23 completed: "https://www.mozilla.org/", 24 matches: [ 25 makeVisitResult(context, { 26 uri: "https://www.mozilla.org/", 27 title: UrlbarTestUtils.trimURL("https://www.mozilla.org"), 28 heuristic: true, 29 }), 30 makeVisitResult(context, { 31 uri: "https://www.mozilla.org/test/", 32 title: "test visit for https://www.mozilla.org/test/", 33 }), 34 ], 35 }); 36 await cleanupPlaces(); 37 }); 38 39 add_task(async function test_untrimmed_secure_www_path() { 40 info("Searching for untrimmed https://www entry with path"); 41 await PlacesTestUtils.addVisits({ 42 uri: Services.io.newURI("https://www.mozilla.org/test/"), 43 }); 44 let context = createContext("mozilla.org/t", { isPrivate: false }); 45 await check_results({ 46 context, 47 autofilled: "mozilla.org/test/", 48 completed: "https://www.mozilla.org/test/", 49 matches: [ 50 makeVisitResult(context, { 51 uri: "https://www.mozilla.org/test/", 52 title: "test visit for https://www.mozilla.org/test/", 53 heuristic: true, 54 }), 55 ], 56 }); 57 await cleanupPlaces(); 58 }); 59 60 add_task(async function test_untrimmed_secure() { 61 info("Searching for untrimmed https:// entry"); 62 await PlacesTestUtils.addVisits({ 63 uri: Services.io.newURI("https://mozilla.org/test/"), 64 }); 65 let context = createContext("mo", { isPrivate: false }); 66 await check_results({ 67 context, 68 autofilled: "mozilla.org/", 69 completed: "https://mozilla.org/", 70 matches: [ 71 makeVisitResult(context, { 72 uri: "https://mozilla.org/", 73 title: UrlbarTestUtils.trimURL("https://mozilla.org"), 74 heuristic: true, 75 }), 76 makeVisitResult(context, { 77 uri: "https://mozilla.org/test/", 78 title: "test visit for https://mozilla.org/test/", 79 }), 80 ], 81 }); 82 await cleanupPlaces(); 83 }); 84 85 add_task(async function test_untrimmed_secure_path() { 86 info("Searching for untrimmed https:// entry with path"); 87 await PlacesTestUtils.addVisits({ 88 uri: Services.io.newURI("https://mozilla.org/test/"), 89 }); 90 let context = createContext("mozilla.org/t", { isPrivate: false }); 91 await check_results({ 92 context, 93 autofilled: "mozilla.org/test/", 94 completed: "https://mozilla.org/test/", 95 matches: [ 96 makeVisitResult(context, { 97 uri: "https://mozilla.org/test/", 98 title: "test visit for https://mozilla.org/test/", 99 heuristic: true, 100 }), 101 ], 102 }); 103 await cleanupPlaces(); 104 }); 105 106 add_task(async function test_untrimmed_www() { 107 info("Searching for untrimmed http://www entry"); 108 await PlacesTestUtils.addVisits({ 109 uri: Services.io.newURI("http://www.mozilla.org/test/"), 110 }); 111 let context = createContext("mo", { isPrivate: false }); 112 await check_results({ 113 context, 114 autofilled: "mozilla.org/", 115 completed: "http://www.mozilla.org/", 116 matches: [ 117 makeVisitResult(context, { 118 uri: "http://www.mozilla.org/", 119 title: UrlbarTestUtils.trimURL("http://www.mozilla.org"), 120 heuristic: true, 121 }), 122 makeVisitResult(context, { 123 uri: "http://www.mozilla.org/test/", 124 title: "test visit for http://www.mozilla.org/test/", 125 }), 126 ], 127 }); 128 await cleanupPlaces(); 129 }); 130 131 add_task(async function test_untrimmed_www_path() { 132 info("Searching for untrimmed http://www entry with path"); 133 await PlacesTestUtils.addVisits({ 134 uri: Services.io.newURI("http://www.mozilla.org/test/"), 135 }); 136 let context = createContext("mozilla.org/t", { isPrivate: false }); 137 await check_results({ 138 context, 139 autofilled: "mozilla.org/test/", 140 completed: "http://www.mozilla.org/test/", 141 matches: [ 142 makeVisitResult(context, { 143 uri: "http://www.mozilla.org/test/", 144 title: "test visit for http://www.mozilla.org/test/", 145 heuristic: true, 146 }), 147 ], 148 }); 149 await cleanupPlaces(); 150 }); 151 152 add_task(async function test_escaped_chars() { 153 info("Searching for URL with characters that are normally escaped"); 154 await PlacesTestUtils.addVisits({ 155 uri: Services.io.newURI("https://www.mozilla.org/啊-test"), 156 }); 157 let context = createContext("https://www.mozilla.org/啊-test", { 158 isPrivate: false, 159 }); 160 await check_results({ 161 context, 162 matches: [ 163 makeVisitResult(context, { 164 source: UrlbarUtils.RESULT_SOURCE.HISTORY, 165 uri: "https://www.mozilla.org/%E5%95%8A-test", 166 title: "test visit for https://www.mozilla.org/%E5%95%8A-test", 167 iconUri: "page-icon:https://www.mozilla.org/%E5%95%8A-test", 168 heuristic: true, 169 }), 170 ], 171 }); 172 await cleanupPlaces(); 173 });