Commit f78596c9 authored by Peter Van der Beken's avatar Peter Van der Beken
Browse files

Bug 1706347 - Check mOOPChildrenLoading when deciding to put page in BFCache...

Bug 1706347 - Check mOOPChildrenLoading when deciding to put page in BFCache with Fission enabled. r=smaug

Differential Revision: https://phabricator.services.mozilla.com/D117199
parent e72d4167
Loading
Loading
Loading
Loading
+16 −2
Original line number Original line Diff line number Diff line
@@ -2549,11 +2549,25 @@ void CanonicalBrowsingContext::CloneDocumentTreeInto(
              [source = MaybeDiscardedBrowsingContext{aSource},
              [source = MaybeDiscardedBrowsingContext{aSource},
               data = std::move(aPrintData)](
               data = std::move(aPrintData)](
                  BrowserParent* aBp) -> RefPtr<GenericNonExclusivePromise> {
                  BrowserParent* aBp) -> RefPtr<GenericNonExclusivePromise> {
                RefPtr<BrowserBridgeParent> bridge =
                    aBp->GetBrowserBridgeParent();
                return aBp->SendCloneDocumentTreeIntoSelf(source, data)
                return aBp->SendCloneDocumentTreeIntoSelf(source, data)
                    ->Then(
                    ->Then(
                        GetMainThreadSerialEventTarget(), __func__,
                        GetMainThreadSerialEventTarget(), __func__,
                        [](BrowserParent::CloneDocumentTreeIntoSelfPromise::
                        [bridge](
                            BrowserParent::CloneDocumentTreeIntoSelfPromise::
                                ResolveOrRejectValue&& aValue) {
                                ResolveOrRejectValue&& aValue) {
                          // We're cloning a remote iframe, so we created a
                          // BrowserBridge which makes us register an OOP load
                          // (see Document::OOPChildLoadStarted), even though
                          // this isn't a real load. We call
                          // SendMaybeFireEmbedderLoadEvents here so that we do
                          // register the end of the load (see
                          // Document::OOPChildLoadDone).
                          if (bridge) {
                            Unused << bridge->SendMaybeFireEmbedderLoadEvents(
                                EmbedderElementEventType::NoEvent);
                          }
                          if (aValue.IsResolve() && aValue.ResolveValue()) {
                          if (aValue.IsResolve() && aValue.ResolveValue()) {
                            return GenericNonExclusivePromise::CreateAndResolve(
                            return GenericNonExclusivePromise::CreateAndResolve(
                                true, __func__);
                                true, __func__);
+5 −0
Original line number Original line Diff line number Diff line
<html>
  <body>
    <iframe id="inner" src="iframe_slow_onload_inner.html">
  </body>
</html>
+19 −0
Original line number Original line Diff line number Diff line
<html>
  <head>
    <script>
      function load() {
        // Let the test page know that it can try to navigate.
        top.postMessage("onload", "*");
        // We're starting an infinite loop, but we need to time out after a
        // while, or the loop will keep running until shutdown.
        let t0 = performance.now();
        while (performance.now() - t0 < 5000) {
            document.getElementById("output").innerText = Math.random();
        }
      }
    </script>
  </head>
  <body onload="load()">
    <p id="output"></p>
  </body>
</html>
+2 −0
Original line number Original line Diff line number Diff line
@@ -106,6 +106,8 @@ support-files = file_bug1536471.html
support-files =
support-files =
  file_blockBFCache.html
  file_blockBFCache.html
  slow.sjs
  slow.sjs
  iframe_slow_onload.html
  iframe_slow_onload_inner.html
[test_child.html]
[test_child.html]
[test_docshell_gotoindex.html]
[test_docshell_gotoindex.html]
support-files = file_docshell_gotoindex.html
support-files = file_docshell_gotoindex.html
+34 −1
Original line number Original line Diff line number Diff line
@@ -98,6 +98,30 @@ const blockBFCacheTests = [
  },
  },
];
];


if (SpecialPowers.Services.appinfo.sessionHistoryInParent) {
  blockBFCacheTests.push({
    name: "Loading OOP iframe",
    test: () => {
      return new Promise((resolve) => {
        const el = document.body.appendChild(document.createElement("iframe"));
        el.id = "frame";
        addEventListener("message", ({ data }) => {
          if (data == "onload") {
            resolve();
          }
        });
        el.src = "https://example.com/tests/docshell/test/navigation/iframe_slow_onload.html";
      });
    },
    waitForDone: () => {
      SimpleTest.requestFlakyTimeout("Test has a loop in an onload handler that runs for 5000ms, we need to make sure the loop is done before moving to the next test.");
      return new Promise(resolve => {
        setTimeout(resolve, 5000);
      });
    },
  });
}

const dontBlockBFCacheTests = [
const dontBlockBFCacheTests = [
  {
  {
    name: "getUserMedia",
    name: "getUserMedia",
@@ -158,7 +182,7 @@ function promisePageShowNotFromBFCache(e) {
}
}


function runTests(testArray, shouldBlockBFCache) {
function runTests(testArray, shouldBlockBFCache) {
  for (const { name, prefs = {}, test } of testArray) {
  for (const { name, prefs = {}, test, waitForDone } of testArray) {
    add_task(async function() {
    add_task(async function() {
      await SpecialPowers.pushPrefEnv(prefs, async function() {
      await SpecialPowers.pushPrefEnv(prefs, async function() {
        // Load a mostly blank page that we can communicate with over
        // Load a mostly blank page that we can communicate with over
@@ -189,6 +213,15 @@ function runTests(testArray, shouldBlockBFCache) {
        let result = await goneForward;
        let result = await goneForward;
        ok(result, `Page ${shouldBlockBFCache ? "should" : "should not"} have been blocked from going into the BFCache (${name})`);
        ok(result, `Page ${shouldBlockBFCache ? "should" : "should not"} have been blocked from going into the BFCache (${name})`);


        // If the test will keep running after navigation, then we need to make
        // sure it's completely done before moving to the next test, to avoid
        // interfering with any following tests. If waitForDone is defined then
        // it'll return a Promise that we can use to wait for the end of the
        // test.
        if (waitForDone) {
          await waitForDone();
        }

        bc.postMessage({ message: "close" });
        bc.postMessage({ message: "close" });


        SpecialPowers.popPrefEnv();
        SpecialPowers.popPrefEnv();
Loading