Verified Commit 54ba522a authored by Vincent Hilla's avatar Vincent Hilla Committed by ma1
Browse files

Bug 2048851 - Clear principalToInherit in LoadPageAsViewSource. a=pascalc

parent 8d1a814b
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -4380,6 +4380,8 @@ nsDocShell::LoadPageAsViewSource(nsIDocShell* aOtherDocShell,
  // is only exposed to system code.  The triggering principal for this load
  // should be the system principal.
  loadState->SetTriggeringPrincipal(nsContentUtils::GetSystemPrincipal());
  loadState->SetPrincipalToInherit(nullptr);
  loadState->SetPartitionedPrincipalToInherit(nullptr);
  loadState->SetOriginalURI(nullptr);
  loadState->SetResultPrincipalURI(nullptr);

+3 −0
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@
support-files = [
  "head.js",
  "file_bug464222.html",
  "file_bug2048851.html",
]

["browser_bug464222.js"]
@@ -9,6 +10,8 @@ https_first_disabled = true

["browser_bug713810.js"]

["browser_bug2048851.js"]

["browser_contextmenu.js"]
skip-if = ["os == 'mac' && !debug"] # Bug 1713913 - new Fission platform triage

+40 −0
Original line number Diff line number Diff line
"use strict";

/**
 * Crashtest for bug 2048851.
 * A cross-origin navigation has the previous page as principal to inherit.
 * When viewing as page source, the load should not reference that principal.
 */
add_task(async function test_view_source_after_cross_origin_navigation() {
  const TEST_PAGE =
    "https://example.com/browser/toolkit/components/viewsource/test/browser/file_bug2048851.html";

  await BrowserTestUtils.withNewTab(
    {
      gBrowser,
      url: TEST_PAGE,
    },
    async function (browser) {
      let loaded = BrowserTestUtils.browserLoaded(
        browser,
        false,
        "https://example.org/"
      );
      await BrowserTestUtils.synthesizeMouseAtCenter("#link", {}, browser);
      await loaded;

      let sourceTab = await openViewSourceForBrowser(browser);
      let sourceBrowser = sourceTab.linkedBrowser;

      await SpecialPowers.spawn(sourceBrowser, [], async function () {
        Assert.equal(
          content.document.body.id,
          "viewsource",
          "View source mode enabled"
        );
      });

      BrowserTestUtils.removeTab(sourceTab);
    }
  );
});
+1 −0
Original line number Diff line number Diff line
<a id="link" href="https://example.org/">click</a>