From 6088cf63bfddfc6ec5d4488d62f7afe3528aa6d2 Mon Sep 17 00:00:00 2001 From: "Abdoulaye O. Ly" Date: Thu, 15 Aug 2019 19:28:13 +0000 Subject: [PATCH] Bug 1559244 - Step 3: Add test for crashing an oop iframe. r=mconley Differential Revision: https://phabricator.services.mozilla.com/D38896 --HG-- extra : moz-landing-system : lando --- dom/ipc/tests/browser.ini | 2 + dom/ipc/tests/browser_crash_oopiframe.js | 90 ++++++++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 dom/ipc/tests/browser_crash_oopiframe.js diff --git a/dom/ipc/tests/browser.ini b/dom/ipc/tests/browser.ini index 9593d58f51d2..4fcf3db637f1 100644 --- a/dom/ipc/tests/browser.ini +++ b/dom/ipc/tests/browser.ini @@ -4,6 +4,8 @@ support-files = file_domainPolicy_base.html file_cancel_content_js.html +[browser_crash_oopiframe.js] +skip-if = true # Disabled until bug 1566196 is fixed [browser_domainPolicy.js] skip-if = fission [browser_memory_distribution_telemetry.js] diff --git a/dom/ipc/tests/browser_crash_oopiframe.js b/dom/ipc/tests/browser_crash_oopiframe.js new file mode 100644 index 000000000000..b22e7b64907a --- /dev/null +++ b/dom/ipc/tests/browser_crash_oopiframe.js @@ -0,0 +1,90 @@ +"use strict"; + +/** + * In this test, we crash an out-of-process iframe and + * verify that : + * 1. the "oop-browser-crashed" event is dispatched with + * the browsing context of the crashed oop subframe. + * 2. the crashed subframe is now pointing at "about:framecrashed" + * page. + */ +add_task(async function() { + // Open a new window with fission enabled. + let win = await BrowserTestUtils.openNewBrowserWindow({ + remote: true, + fission: true, + }); + + // Wait for the provided URL to load in our browser. + let url = "about:blank"; + let browser = win.gBrowser.selectedBrowser; + BrowserTestUtils.loadURI(browser, url); + await BrowserTestUtils.browserLoaded(browser, false, url); + + let rootBC = browser.browsingContext; + + // Create an oop iframe. + let iframeID = await SpecialPowers.spawn(browser, [], async () => { + let iframe = content.document.createElement("iframe"); + iframe.setAttribute("fission", "true"); + iframe.setAttribute("src", "http://example.com"); + + const { ContentTaskUtils } = ChromeUtils.import( + "resource://testing-common/ContentTaskUtils.jsm" + ); + + content.document.body.appendChild(iframe); + await ContentTaskUtils.waitForEvent(iframe, "load"); + + let iframeBC = iframe.frameLoader.browsingContext; + return iframeBC.id; + }); + + let iframeBC = BrowsingContext.get(iframeID); + is(iframeBC.parent, rootBC, "oop frame has root as parent"); + + BrowserTestUtils.crashFrame( + browser, + true /* shouldShowTabCrashPage */, + true /* shouldClearMinidumps */, + iframeBC + ); + + let eventFiredPromise = BrowserTestUtils.waitForEvent( + browser, + "oop-browser-crashed" + ); + + await eventFiredPromise.then(event => { + isnot( + event.browsingContextId, + rootBC, + "top frame browsing context id not expected." + ); + + is( + event.browsingContextId, + iframeBC.id, + "oop frame browsing context id expected." + ); + }); + + info("Wait for a new browsing context to get attached to our oop iframe."); + await BrowserTestUtils.waitForCondition( + () => rootBC.getChildren()[0] != iframeBC + ); + + let newIframeBC = rootBC.getChildren()[0]; + let newIframeURI = await SpecialPowers.spawn( + newIframeBC, + [], + () => content.document.documentURI + ); + + ok( + newIframeURI.startsWith("about:framecrashed"), + "The iframe is now pointing at about:framecrashed" + ); + + await BrowserTestUtils.closeWindow(win); +});