browser_103_user_load.js (2788B)
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 "use strict"; 6 7 // simulate user initiated loads by entering the URL in the URL-bar code based on 8 // https://searchfox.org/mozilla-central/rev/5644fae86d5122519a0e34ee03117c88c6ed9b47/browser/components/urlbar/tests/browser/browser_enter.js 9 10 ChromeUtils.defineESModuleGetters(this, { 11 UrlbarTestUtils: "resource://testing-common/UrlbarTestUtils.sys.mjs", 12 }); 13 14 const { 15 request_count_checking, 16 test_hint_preload_internal, 17 test_hint_preload, 18 } = ChromeUtils.importESModule( 19 "resource://testing-common/early_hint_preload_test_helper.sys.mjs" 20 ); 21 22 const START_VALUE = 23 "https://example.com/browser/netwerk/test/browser/early_hint_asset_html.sjs?as=style&hinted=1"; 24 25 add_setup(async function () { 26 await SpecialPowers.pushPrefEnv({ 27 set: [["browser.urlbar.suggest.quickactions", false]], 28 }); 29 }); 30 31 Services.prefs.setBoolPref("network.early-hints.enabled", true); 32 33 // bug 1780822 34 add_task(async function user_initiated_load() { 35 // reset the count 36 let headers = new Headers(); 37 headers.append("X-Early-Hint-Count-Start", ""); 38 await fetch( 39 "https://example.com/browser/netwerk/test/browser/early_hint_pixel_count.sjs", 40 { headers } 41 ); 42 43 info("Simple user initiated load"); 44 let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser); 45 46 // under normal test conditions using the systemPrincipal as loadingPrincipal 47 // doesn't elicit a crash, changing the behavior for this test: 48 // https://searchfox.org/mozilla-central/rev/5644fae86d5122519a0e34ee03117c88c6ed9b47/dom/security/nsContentSecurityManager.cpp#1149-1150 49 Services.prefs.setBoolPref( 50 "security.disallow_non_local_systemprincipal_in_tests", 51 true 52 ); 53 54 gURLBar.value = START_VALUE; 55 gURLBar.focus(); 56 EventUtils.synthesizeKey("KEY_Enter"); 57 await BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser); 58 59 // reset the config option 60 Services.prefs.clearUserPref( 61 "security.disallow_non_local_systemprincipal_in_tests" 62 ); 63 64 // Check url bar and selected tab. 65 is( 66 gURLBar.value, 67 UrlbarTestUtils.trimURL(START_VALUE), 68 "Urlbar should preserve the value on return keypress" 69 ); 70 is(gBrowser.selectedTab, tab, "New URL was loaded in the current tab"); 71 72 let gotRequestCount = await fetch( 73 "https://example.com/browser/netwerk/test/browser/early_hint_pixel_count.sjs" 74 ).then(response => response.json()); 75 let expectedRequestCount = { hinted: 1, normal: 0 }; 76 77 await request_count_checking( 78 "test_preload_user_initiated", 79 gotRequestCount, 80 expectedRequestCount 81 ); 82 83 // Cleanup. 84 BrowserTestUtils.removeTab(gBrowser.selectedTab); 85 });