browser_history_triggeringprincipal_viewsource.js (2735B)
1 "use strict"; 2 3 const TEST_PATH = getRootDirectory(gTestPath).replace( 4 "chrome://mochitests/content", 5 // eslint-disable-next-line @microsoft/sdl/no-insecure-url 6 "http://example.com" 7 ); 8 const HTML_URI = TEST_PATH + "dummy_page.html"; 9 const VIEW_SRC_URI = "view-source:" + HTML_URI; 10 11 add_task(async function () { 12 await SpecialPowers.pushPrefEnv({ 13 set: [ 14 ["test.wait300msAfterTabSwitch", true], 15 ["browser.navigation.requireUserInteraction", false], 16 ], 17 }); 18 19 info("load baseline html in new tab"); 20 await BrowserTestUtils.withNewTab(HTML_URI, async function (aBrowser) { 21 is( 22 gBrowser.selectedBrowser.currentURI.spec, 23 HTML_URI, 24 "sanity check to make sure html loaded" 25 ); 26 27 info("right-click -> view-source of html"); 28 let vSrcCtxtMenu = document.getElementById("contentAreaContextMenu"); 29 let popupPromise = BrowserTestUtils.waitForEvent( 30 vSrcCtxtMenu, 31 "popupshown" 32 ); 33 BrowserTestUtils.synthesizeMouseAtCenter( 34 "body", 35 { type: "contextmenu", button: 2 }, 36 aBrowser 37 ); 38 await popupPromise; 39 let tabPromise = BrowserTestUtils.waitForNewTab(gBrowser, VIEW_SRC_URI); 40 let vSrcItem = vSrcCtxtMenu.querySelector("#context-viewsource"); 41 vSrcCtxtMenu.activateItem(vSrcItem); 42 let tab = await tabPromise; 43 is( 44 gBrowser.selectedBrowser.currentURI.spec, 45 VIEW_SRC_URI, 46 "loading view-source of html succeeded" 47 ); 48 49 info("load html file again before going .back()"); 50 let loadPromise = BrowserTestUtils.browserLoaded( 51 tab.linkedBrowser, 52 false, 53 HTML_URI 54 ); 55 await SpecialPowers.spawn(tab.linkedBrowser, [HTML_URI], HTML_URI => { 56 content.document.location = HTML_URI; 57 }); 58 await loadPromise; 59 is( 60 gBrowser.selectedBrowser.currentURI.spec, 61 HTML_URI, 62 "loading html another time succeeded" 63 ); 64 65 info( 66 "click .back() to view-source of html again and make sure the history entry has a triggeringPrincipal" 67 ); 68 let backCtxtMenu = document.getElementById("contentAreaContextMenu"); 69 popupPromise = BrowserTestUtils.waitForEvent(backCtxtMenu, "popupshown"); 70 BrowserTestUtils.synthesizeMouseAtCenter( 71 "body", 72 { type: "contextmenu", button: 2 }, 73 aBrowser 74 ); 75 await popupPromise; 76 loadPromise = BrowserTestUtils.waitForContentEvent( 77 tab.linkedBrowser, 78 "pageshow" 79 ); 80 let backItem = backCtxtMenu.querySelector("#context-back"); 81 backCtxtMenu.activateItem(backItem); 82 await loadPromise; 83 is( 84 gBrowser.selectedBrowser.currentURI.spec, 85 VIEW_SRC_URI, 86 "clicking .back() to view-source of html succeeded" 87 ); 88 89 BrowserTestUtils.removeTab(tab); 90 }); 91 });