Bug 1686820 [wpt PR 27193] - Origin-keyed agent clusters: make COI imply origin-keyin...
[gecko.git] / docshell / test / browser / browser_history_triggeringprincipal_viewsource.js
blob1bed399b3b8d1c7b4df7a2d5e53ddb2bf11d0282
1 "use strict";
3 const TEST_PATH = getRootDirectory(gTestPath).replace(
4   "chrome://mochitests/content",
5   "http://example.com"
6 );
7 const HTML_URI = TEST_PATH + "dummy_page.html";
8 const VIEW_SRC_URI = "view-source:" + HTML_URI;
10 add_task(async function() {
11   await SpecialPowers.pushPrefEnv({
12     set: [["browser.navigation.requireUserInteraction", false]],
13   });
15   info("load baseline html in new tab");
16   await BrowserTestUtils.withNewTab(HTML_URI, async function(aBrowser) {
17     is(
18       gBrowser.selectedBrowser.currentURI.spec,
19       HTML_URI,
20       "sanity check to make sure html loaded"
21     );
23     info("right-click -> view-source of html");
24     let vSrcCtxtMenu = document.getElementById("contentAreaContextMenu");
25     let popupPromise = BrowserTestUtils.waitForEvent(
26       vSrcCtxtMenu,
27       "popupshown"
28     );
29     BrowserTestUtils.synthesizeMouseAtCenter(
30       "body",
31       { type: "contextmenu", button: 2 },
32       aBrowser
33     );
34     await popupPromise;
35     let tabPromise = BrowserTestUtils.waitForNewTab(gBrowser, VIEW_SRC_URI);
36     let vSrcItem = vSrcCtxtMenu.getElementsByAttribute(
37       "id",
38       "context-viewsource"
39     )[0];
40     vSrcItem.click();
41     vSrcCtxtMenu.hidePopup();
42     let tab = await tabPromise;
43     is(
44       gBrowser.selectedBrowser.currentURI.spec,
45       VIEW_SRC_URI,
46       "loading view-source of html succeeded"
47     );
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     );
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.getElementsByAttribute("id", "context-back")[0];
81     backItem.click();
82     backCtxtMenu.hidePopup();
83     await loadPromise;
84     is(
85       gBrowser.selectedBrowser.currentURI.spec,
86       VIEW_SRC_URI,
87       "clicking .back() to view-source of html succeeded"
88     );
90     BrowserTestUtils.removeTab(tab);
91   });
92 });