Commit 549492fd authored by Olli Pettay's avatar Olli Pettay
Browse files

Bug 1787315, starting a new load after reload() should take precedence, r=peterv,ochameau

The devtools test reloads a page twice in a row and depending on timing it isn't guaranteed that it leads to two requests anymore.
That test seems to fail on debug builds every now and then. The test itself expects 1 or more requests, but then assumes later that there
are at least 2.

Differential Revision: https://phabricator.services.mozilla.com/D160573
parent 6454294d
Loading
Loading
Loading
Loading
+11 −9
Original line number Diff line number Diff line
@@ -91,6 +91,7 @@ async function testManyReloads({ tab, monitor, toolbox }) {
  );
  // Requests may come out of order, so try to find the bogus cancelled request
  let entry = har.log.entries.find(e => e.response.status == 0);
  if (entry) {
    ok(entry, "Found the cancelled request");
    is(entry.request.method, "GET", "Method is set");
    is(entry.request.url, SIMPLE_URL, "URL is set");
@@ -100,6 +101,7 @@ async function testManyReloads({ tab, monitor, toolbox }) {
    // "Upgrade-Insecure-Requests", "Pragma", "Cache-Control"
    is(entry.request.headers.length, 6, "But headers are partialy populated");
    is(entry.response.status, 0, "And status is set to 0");
  }

  entry = har.log.entries.find(e => e.response.status != 0);
  assertNavigationRequestEntry(entry);
+18 −1
Original line number Diff line number Diff line
@@ -4122,12 +4122,29 @@ nsDocShell::Reload(uint32_t aReloadFlags) {
      RefPtr<BrowsingContext> browsingContext(mBrowsingContext);
      nsCOMPtr<nsIURI> currentURI(mCurrentURI);
      nsCOMPtr<nsIReferrerInfo> referrerInfo(mReferrerInfo);
      RefPtr<StopDetector> stopDetector = new StopDetector();
      nsCOMPtr<nsILoadGroup> loadGroup;
      GetLoadGroup(getter_AddRefs(loadGroup));
      if (loadGroup) {
        // loadGroup may be null in theory. In that case stopDetector just
        // doesn't do anything.
        loadGroup->AddRequest(stopDetector, nullptr);
      }

      ContentChild::GetSingleton()->SendNotifyOnHistoryReload(
          mBrowsingContext, forceReload,
          [docShell, doc, loadType, browsingContext, currentURI, referrerInfo](
          [docShell, doc, loadType, browsingContext, currentURI, referrerInfo,
           loadGroup, stopDetector](
              Tuple<bool, Maybe<RefPtr<nsDocShellLoadState>>, Maybe<bool>>&&
                  aResult) {
            auto scopeExit = MakeScopeExit([loadGroup, stopDetector]() {
              if (loadGroup) {
                loadGroup->RemoveRequest(stopDetector, nullptr, NS_OK);
              }
            });
            if (stopDetector->Canceled()) {
              return;
            }
            bool canReload;
            Maybe<RefPtr<nsDocShellLoadState>> loadState;
            Maybe<bool> reloadingActiveEntry;
+12 −0
Original line number Diff line number Diff line
<!DOCTYPE HTML>
<html>
  <head>
    <script>
     function notifyOpener() {
       opener.postMessage("loaded", "*");
     }
    </script>
  </head>
  <body onload="notifyOpener()">
  </body>
</html>
+2 −0
Original line number Diff line number Diff line
@@ -155,6 +155,8 @@ support-files =
[test_forceinheritprincipal_overrule_owner.html]
[test_framedhistoryframes.html]
support-files = file_framedhistoryframes.html
[test_load_during_reload.html]
support-files = file_load_during_reload.html
[test_pushState_after_document_open.html]
[test_navigate_after_pagehide.html]
[test_redirect_history.html]
+35 −0
Original line number Diff line number Diff line
<!DOCTYPE HTML>
<html>
<head>
  <meta charset="utf-8">
  <title>Test loading a new page after calling reload()</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
  <script>

    function promiseForLoad() {
      return new Promise(resolve => {
        addEventListener("message", resolve, { once: true });
      });
    }

    add_task(async function runTest() {
      let win = window.open("file_load_during_reload.html");
      await promiseForLoad();

      win.location.reload();
      win.location.href = "file_load_during_reload.html?nextpage";
      await promiseForLoad();

      ok(win.location.href.includes("nextpage"), "Should have loaded the next page.");
      win.close();
    });

  </script>
</head>
<body>
<p id="display"></p>
<div id="content" style="display: none"></div>
<pre id="test"></pre>
</body>
</html>