test_exposure.js (7675B)
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 // Tests that registering an exposureResults pref and triggering a match causes 6 // the exposure event to be recorded on the UrlbarResults. 7 8 ChromeUtils.defineESModuleGetters(this, { 9 UrlbarProviderQuickSuggest: 10 "moz-src:///browser/components/urlbar/UrlbarProviderQuickSuggest.sys.mjs", 11 }); 12 13 add_setup(async function setup() { 14 await QuickSuggestTestUtils.ensureQuickSuggestInit({ 15 remoteSettingsRecords: [ 16 { 17 collection: QuickSuggestTestUtils.RS_COLLECTION.AMP, 18 type: QuickSuggestTestUtils.RS_TYPE.AMP, 19 attachment: [ 20 QuickSuggestTestUtils.ampRemoteSettings({ 21 keywords: ["amp", "amp and wikipedia"], 22 }), 23 ], 24 }, 25 { 26 collection: QuickSuggestTestUtils.RS_COLLECTION.OTHER, 27 type: QuickSuggestTestUtils.RS_TYPE.WIKIPEDIA, 28 attachment: [ 29 QuickSuggestTestUtils.wikipediaRemoteSettings({ 30 keywords: ["wikipedia", "amp and wikipedia"], 31 }), 32 ], 33 }, 34 ], 35 prefs: [ 36 ["suggest.quicksuggest.all", true], 37 ["suggest.quicksuggest.sponsored", true], 38 ["quicksuggest.ampTopPickCharThreshold", 0], 39 ], 40 }); 41 }); 42 43 add_task(async function oneExposureResult_shown_matched() { 44 UrlbarPrefs.set("exposureResults", suggestResultType("adm_sponsored")); 45 UrlbarPrefs.set("showExposureResults", true); 46 47 let context = createContext("amp", { 48 providers: [UrlbarProviderQuickSuggest.name], 49 isPrivate: false, 50 }); 51 52 await check_results({ 53 context, 54 matches: [ 55 { 56 ...QuickSuggestTestUtils.ampResult({ suggestedIndex: -1 }), 57 exposureTelemetry: UrlbarUtils.EXPOSURE_TELEMETRY.SHOWN, 58 }, 59 ], 60 }); 61 }); 62 63 add_task(async function oneExposureResult_shown_notMatched() { 64 UrlbarPrefs.set("exposureResults", suggestResultType("adm_sponsored")); 65 UrlbarPrefs.set("showExposureResults", true); 66 67 let context = createContext("wikipedia", { 68 providers: [UrlbarProviderQuickSuggest.name], 69 isPrivate: false, 70 }); 71 72 await check_results({ 73 context, 74 matches: [ 75 { 76 ...QuickSuggestTestUtils.wikipediaResult(), 77 exposureTelemetry: UrlbarUtils.EXPOSURE_TELEMETRY.NONE, 78 }, 79 ], 80 }); 81 }); 82 83 add_task(async function oneExposureResult_hidden_matched() { 84 UrlbarPrefs.set("exposureResults", suggestResultType("adm_sponsored")); 85 UrlbarPrefs.set("showExposureResults", false); 86 87 let context = createContext("amp", { 88 providers: [UrlbarProviderQuickSuggest.name], 89 isPrivate: false, 90 }); 91 92 await check_results({ 93 context, 94 matches: [ 95 { 96 ...QuickSuggestTestUtils.ampResult({ suggestedIndex: -1 }), 97 exposureTelemetry: UrlbarUtils.EXPOSURE_TELEMETRY.HIDDEN, 98 }, 99 ], 100 }); 101 }); 102 103 add_task(async function oneExposureResult_hidden_notMatched() { 104 UrlbarPrefs.set("exposureResults", suggestResultType("adm_sponsored")); 105 UrlbarPrefs.set("showExposureResults", false); 106 107 let context = createContext("wikipedia", { 108 providers: [UrlbarProviderQuickSuggest.name], 109 isPrivate: false, 110 }); 111 112 await check_results({ 113 context, 114 matches: [ 115 { 116 ...QuickSuggestTestUtils.wikipediaResult(), 117 exposureTelemetry: UrlbarUtils.EXPOSURE_TELEMETRY.NONE, 118 }, 119 ], 120 }); 121 }); 122 123 add_task(async function manyExposureResults_shown_oneMatched_1() { 124 UrlbarPrefs.set( 125 "exposureResults", 126 [ 127 suggestResultType("adm_sponsored"), 128 suggestResultType("adm_nonsponsored"), 129 ].join(",") 130 ); 131 UrlbarPrefs.set("showExposureResults", true); 132 133 let context = createContext("amp", { 134 providers: [UrlbarProviderQuickSuggest.name], 135 isPrivate: false, 136 }); 137 await check_results({ 138 context, 139 matches: [ 140 { 141 ...QuickSuggestTestUtils.ampResult({ suggestedIndex: -1 }), 142 exposureTelemetry: UrlbarUtils.EXPOSURE_TELEMETRY.SHOWN, 143 }, 144 ], 145 }); 146 }); 147 148 add_task(async function manyExposureResults_shown_oneMatched_2() { 149 UrlbarPrefs.set( 150 "exposureResults", 151 [ 152 suggestResultType("adm_sponsored"), 153 suggestResultType("adm_nonsponsored"), 154 ].join(",") 155 ); 156 UrlbarPrefs.set("showExposureResults", true); 157 158 let context = createContext("wikipedia", { 159 providers: [UrlbarProviderQuickSuggest.name], 160 isPrivate: false, 161 }); 162 await check_results({ 163 context, 164 matches: [ 165 { 166 ...QuickSuggestTestUtils.wikipediaResult(), 167 exposureTelemetry: UrlbarUtils.EXPOSURE_TELEMETRY.SHOWN, 168 }, 169 ], 170 }); 171 }); 172 173 add_task(async function manyExposureResults_shown_manyMatched() { 174 UrlbarPrefs.set( 175 "exposureResults", 176 [ 177 suggestResultType("adm_sponsored"), 178 suggestResultType("adm_nonsponsored"), 179 ].join(",") 180 ); 181 UrlbarPrefs.set("showExposureResults", true); 182 183 let keyword = "amp and wikipedia"; 184 let context = createContext(keyword, { 185 providers: [UrlbarProviderQuickSuggest.name], 186 isPrivate: false, 187 }); 188 189 // Only one result should be added since exposures are shown and at most one 190 // Suggest result should be shown. 191 await check_results({ 192 context, 193 matches: [ 194 { 195 ...QuickSuggestTestUtils.ampResult({ keyword, suggestedIndex: -1 }), 196 exposureTelemetry: UrlbarUtils.EXPOSURE_TELEMETRY.SHOWN, 197 }, 198 ], 199 }); 200 }); 201 202 add_task(async function manyExposureResults_hidden_oneMatched_1() { 203 UrlbarPrefs.set( 204 "exposureResults", 205 [ 206 suggestResultType("adm_sponsored"), 207 suggestResultType("adm_nonsponsored"), 208 ].join(",") 209 ); 210 UrlbarPrefs.set("showExposureResults", false); 211 212 let context = createContext("amp", { 213 providers: [UrlbarProviderQuickSuggest.name], 214 isPrivate: false, 215 }); 216 await check_results({ 217 context, 218 matches: [ 219 { 220 ...QuickSuggestTestUtils.ampResult({ suggestedIndex: -1 }), 221 exposureTelemetry: UrlbarUtils.EXPOSURE_TELEMETRY.HIDDEN, 222 }, 223 ], 224 }); 225 }); 226 227 add_task(async function manyExposureResults_hidden_oneMatched_2() { 228 UrlbarPrefs.set( 229 "exposureResults", 230 [ 231 suggestResultType("adm_sponsored"), 232 suggestResultType("adm_nonsponsored"), 233 ].join(",") 234 ); 235 UrlbarPrefs.set("showExposureResults", false); 236 237 let context = createContext("wikipedia", { 238 providers: [UrlbarProviderQuickSuggest.name], 239 isPrivate: false, 240 }); 241 await check_results({ 242 context, 243 matches: [ 244 { 245 ...QuickSuggestTestUtils.wikipediaResult(), 246 exposureTelemetry: UrlbarUtils.EXPOSURE_TELEMETRY.HIDDEN, 247 }, 248 ], 249 }); 250 }); 251 252 add_task(async function manyExposureResults_hidden_manyMatched() { 253 UrlbarPrefs.set( 254 "exposureResults", 255 [ 256 suggestResultType("adm_sponsored"), 257 suggestResultType("adm_nonsponsored"), 258 ].join(",") 259 ); 260 UrlbarPrefs.set("showExposureResults", false); 261 262 let keyword = "amp and wikipedia"; 263 let context = createContext(keyword, { 264 providers: [UrlbarProviderQuickSuggest.name], 265 isPrivate: false, 266 }); 267 268 // Both results should be added since exposures are hidden and there's no 269 // limit on the number of hidden-exposure Suggest results. 270 await check_results({ 271 context, 272 matches: [ 273 { 274 ...QuickSuggestTestUtils.wikipediaResult({ keyword }), 275 exposureTelemetry: UrlbarUtils.EXPOSURE_TELEMETRY.HIDDEN, 276 }, 277 { 278 ...QuickSuggestTestUtils.ampResult({ keyword, suggestedIndex: -1 }), 279 exposureTelemetry: UrlbarUtils.EXPOSURE_TELEMETRY.HIDDEN, 280 }, 281 ], 282 }); 283 }); 284 285 function suggestResultType(typeWithoutSource) { 286 return `rust_${typeWithoutSource}`; 287 }