browser_user_gesture.js (1944B)
1 // Bug 1725026 - HTTPS Only Mode - Test if a load triggered by a user gesture 2 // gesture can be upgraded to HTTPS successfully. 3 4 "use strict"; 5 6 const testPathUpgradeable = getRootDirectory(gTestPath).replace( 7 "chrome://mochitests/content", 8 "http://example.com" 9 ); 10 11 const kTestURI = testPathUpgradeable + "file_user_gesture.sjs"; 12 13 add_task(async function () { 14 // Enable HTTPS-Only Mode and register console-listener 15 await SpecialPowers.pushPrefEnv({ 16 set: [["dom.security.https_only_mode", true]], 17 }); 18 19 for (const buttonId of ["directButton", "redirectButton"]) { 20 info( 21 { 22 directButton: "Testing direct upgrade after user gesture", 23 redirectButton: "Testing upgrade after user gesture and redirect", 24 }[buttonId] 25 ); 26 27 await BrowserTestUtils.withNewTab("about:blank", async function (browser) { 28 let loaded = BrowserTestUtils.browserLoaded(browser, false, null, true); 29 // 1. Upgrade a page to https:// 30 BrowserTestUtils.startLoadingURIString(browser, kTestURI); 31 await loaded; 32 await ContentTask.spawn(browser, [buttonId], async buttonId => { 33 ok( 34 content.document.location.href.startsWith("https://"), 35 "Should be https" 36 ); 37 38 // 2. Trigger a load by clicking button. 39 // The scheme of the link url is `http` and the load should be able to 40 // upgraded to `https` because of HTTPS-only mode. 41 let button = content.document.getElementById(buttonId); 42 await EventUtils.synthesizeMouseAtCenter( 43 button, 44 { type: "mousedown" }, 45 content 46 ); 47 await EventUtils.synthesizeMouseAtCenter( 48 button, 49 { type: "mouseup" }, 50 content 51 ); 52 }); 53 await BrowserTestUtils.browserLoaded(browser, false, null, true); 54 info(browser.currentURI.spec); 55 is(browser.currentURI.scheme, "https", "Should be https"); 56 }); 57 } 58 });