From 147f1b5141eec45509efe3f7366d5e7813a87201 Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Fri, 4 Oct 2019 21:50:34 +0000 Subject: [PATCH] Bug 1586119: Part 2 - Fix some more tests to almost work under Fission. r=mccr8 These still fail or timeout because of missing platform features, but at least the tests will pass once those platform features are fixed after this. Differential Revision: https://phabricator.services.mozilla.com/D48221 --HG-- extra : moz-landing-system : lando --- docshell/base/BrowsingContext.cpp | 7 +++ docshell/base/BrowsingContext.h | 2 + docshell/test/navigation/NavigationUtils.js | 55 +++++++++++++++++++ docshell/test/navigation/mochitest.ini | 2 +- docshell/test/navigation/test_bug270414.html | 18 +++--- .../test_sibling-matching-parent.html | 18 +++--- .../navigation/test_sibling-off-domain.html | 18 +++--- dom/chrome-webidl/BrowsingContext.webidl | 2 + .../content/SpecialPowersChild.jsm | 11 ++++ 9 files changed, 105 insertions(+), 28 deletions(-) diff --git a/docshell/base/BrowsingContext.cpp b/docshell/base/BrowsingContext.cpp index d88a3a3c09ad..620d3afac8c1 100644 --- a/docshell/base/BrowsingContext.cpp +++ b/docshell/base/BrowsingContext.cpp @@ -864,6 +864,13 @@ void BrowsingContext::Blur(ErrorResult& aError) { } } +Nullable BrowsingContext::GetWindow() { + if (XRE_IsParentProcess() && !IsInProcess()) { + return nullptr; + } + return WindowProxyHolder(this); +} + Nullable BrowsingContext::GetTop(ErrorResult& aError) { if (mIsDiscarded) { return nullptr; diff --git a/docshell/base/BrowsingContext.h b/docshell/base/BrowsingContext.h index fba98f3b702a..f1516708943c 100644 --- a/docshell/base/BrowsingContext.h +++ b/docshell/base/BrowsingContext.h @@ -305,6 +305,8 @@ class BrowsingContext : public nsWrapperCache, public BrowsingContextBase { mWindowProxy = aWindowProxy; } + Nullable GetWindow(); + MOZ_DECLARE_WEAKREFERENCE_TYPENAME(BrowsingContext) NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(BrowsingContext) NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(BrowsingContext) diff --git a/docshell/test/navigation/NavigationUtils.js b/docshell/test/navigation/NavigationUtils.js index bc0c5617a1fb..8094909aab90 100644 --- a/docshell/test/navigation/NavigationUtils.js +++ b/docshell/test/navigation/NavigationUtils.js @@ -224,3 +224,58 @@ function xpcWaitForFinishedFrames(callback, numFrames) { var frameWaitInterval = setInterval(poll, 500); } + +function delay(msec) { + return new Promise(resolve => setTimeout(resolve, msec)); +} + +async function waitForFinishedFrames(numFrames) { + SimpleTest.requestFlakyTimeout("Polling"); + + var finishedWindows = new Set(); + + async function searchForFinishedFrames(win) { + try { + let { href, bodyText, readyState } = await SpecialPowers.spawn( + win, + [], + () => { + return { + href: this.content.location.href, + bodyText: + this.content.document.body && + this.content.document.body.textContent.trim(), + readyState: this.content.document.readyState, + }; + } + ); + + if ( + (href.endsWith(target_url) || href.endsWith(target_popup_url)) && + (bodyText == body || bodyText == popup_body) && + readyState == "complete" + ) { + finishedWindows.add(SpecialPowers.getBrowsingContextID(win)); + } + } catch (e) { + // This may throw if a frame is not fully initialized, in which + // case we'll handle it in a later iteration. + } + + for (let i = 0; i < win.frames.length; i++) { + await searchForFinishedFrames(win.frames[i]); + } + } + + while (finishedWindows.size < numFrames) { + await delay(500); + + for (let win of SpecialPowers.getGroupTopLevelWindows(window)) { + await searchForFinishedFrames(win); + } + } + + if (finishedWindows.size > numFrames) { + throw new Error("Too many frames loaded."); + } +} diff --git a/docshell/test/navigation/mochitest.ini b/docshell/test/navigation/mochitest.ini index 546ccfc5e2a8..acf59adf693e 100644 --- a/docshell/test/navigation/mochitest.ini +++ b/docshell/test/navigation/mochitest.ini @@ -94,7 +94,7 @@ support-files = file_bug1379762-1.html [test_sibling-matching-parent.html] skip-if = fission # Times out. [test_sibling-off-domain.html] -skip-if = fission # Times out. +fail-if = fission [test_triggeringprincipal_frame_nav.html] [test_triggeringprincipal_window_open.html] [test_triggeringprincipal_parent_iframe_window_open.html] diff --git a/docshell/test/navigation/test_bug270414.html b/docshell/test/navigation/test_bug270414.html index 948125386b6d..81234eab8a72 100644 --- a/docshell/test/navigation/test_bug270414.html +++ b/docshell/test/navigation/test_bug270414.html @@ -12,8 +12,8 @@ /* eslint-disable no-useless-concat */ /* global window0:true, window1:true, window2:true, window3:true */ var headerHTML = "" + - " @@ -88,7 +89,6 @@ xpcWaitForFinishedFrames(async function() {
 
 
diff --git a/docshell/test/navigation/test_sibling-matching-parent.html b/docshell/test/navigation/test_sibling-matching-parent.html index 9c2003f3eb0b..34a7e3a1cf68 100644 --- a/docshell/test/navigation/test_sibling-matching-parent.html +++ b/docshell/test/navigation/test_sibling-matching-parent.html @@ -9,22 +9,22 @@ iframe { width: 90%; height: 50px; } diff --git a/docshell/test/navigation/test_sibling-off-domain.html b/docshell/test/navigation/test_sibling-off-domain.html index fce8d3006176..e13b21488d4a 100644 --- a/docshell/test/navigation/test_sibling-off-domain.html +++ b/docshell/test/navigation/test_sibling-off-domain.html @@ -9,22 +9,22 @@ iframe { width: 90%; height: 50px; } diff --git a/dom/chrome-webidl/BrowsingContext.webidl b/dom/chrome-webidl/BrowsingContext.webidl index ce9fe6890bd7..273978a7bbb4 100644 --- a/dom/chrome-webidl/BrowsingContext.webidl +++ b/dom/chrome-webidl/BrowsingContext.webidl @@ -31,6 +31,8 @@ interface BrowsingContext { readonly attribute BrowsingContext? opener; readonly attribute BrowsingContextGroup group; + + readonly attribute WindowProxy? window; }; [Exposed=Window, ChromeOnly] diff --git a/testing/specialpowers/content/SpecialPowersChild.jsm b/testing/specialpowers/content/SpecialPowersChild.jsm index 8156fded2f19..68fc9f2e3010 100644 --- a/testing/specialpowers/content/SpecialPowersChild.jsm +++ b/testing/specialpowers/content/SpecialPowersChild.jsm @@ -1613,6 +1613,17 @@ class SpecialPowersChild extends JSWindowActorChild { return BrowsingContext.getFromWindow(target); } + getBrowsingContextID(target) { + return this._browsingContextForTarget(target).id; + } + + *getGroupTopLevelWindows(target) { + let { group } = this._browsingContextForTarget(target); + for (let bc of group.getToplevels()) { + yield bc.window; + } + } + /** * Runs a task in the context of the given frame, and returns a * promise which resolves to the return value of that task.