browser_hiddenExposure.js (2653B)
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 // Tests view updates in relation to hidden-exposure results. 6 7 "use strict"; 8 9 // Tests the case where a hidden-exposure result replaces another result in a 10 // row in the view. 11 add_task(async function rowCanUpdateToResult() { 12 // Create a provider that returns two non-hidden results. 13 let provider = new UrlbarTestUtils.TestProvider({ priority: Infinity }); 14 UrlbarProvidersManager.registerProvider(provider); 15 registerCleanupFunction(() => { 16 UrlbarProvidersManager.unregisterProvider(provider); 17 }); 18 19 for (let i = 0; i < 2; i++) { 20 provider.results.push( 21 new UrlbarResult({ 22 type: UrlbarUtils.RESULT_TYPE.URL, 23 source: UrlbarUtils.RESULT_SOURCE.HISTORY, 24 payload: { 25 url: "https://example.com/" + i, 26 }, 27 }) 28 ); 29 } 30 31 // Do a search to populate the view with the provider's results, and leave the 32 // view open. 33 await UrlbarTestUtils.promiseAutocompleteResultPopup({ 34 window, 35 value: "test1", 36 }); 37 38 Assert.equal( 39 UrlbarTestUtils.getResultCount(window), 40 2, 41 "The view should have the two non-hidden provider results" 42 ); 43 for (let i = 0; i < 2; i++) { 44 let details = await UrlbarTestUtils.getDetailsOfResultAt(window, i); 45 Assert.equal( 46 details.url, 47 "https://example.com/" + i, 48 "The non-hidden result should have the expected URL at index " + i 49 ); 50 } 51 52 // Now make the provider return only a hidden-exposure result. Important: The 53 // hidden-exposure result needs to pass the view's "row can update to result?" 54 // check so that it can replace the non-hidden result in the first row. So 55 // make sure the two results are the exact same type. 56 provider.results = [ 57 new UrlbarResult({ 58 type: UrlbarUtils.RESULT_TYPE.URL, 59 source: UrlbarUtils.RESULT_SOURCE.HISTORY, 60 exposureTelemetry: UrlbarUtils.EXPOSURE_TELEMETRY.HIDDEN, 61 payload: { 62 url: "https://example.com/hidden-exposure", 63 }, 64 }), 65 ]; 66 67 // Do another search without closing the view first. Since the only result is 68 // the hidden result, there should no longer be any rows in the view. 69 await UrlbarTestUtils.promiseAutocompleteResultPopup({ 70 window, 71 value: "test2", 72 }); 73 74 Assert.equal( 75 UrlbarTestUtils.getResultCount(window), 76 0, 77 "The view should be empty" 78 ); 79 80 await UrlbarTestUtils.promisePopupClose(window); 81 gURLBar.handleRevert(); 82 83 UrlbarProvidersManager.unregisterProvider(provider); 84 });