Bug 1513445: add tests r=ckerschb
authorFrederik Braun <fbraun@mozilla.com>
Wed, 10 Apr 2019 14:20:21 +0000
changeset 468792 59c870edc6771c3de626e692bd6db1501a58e0e9
parent 468791 18f074af5d93ffb94a4f905509a21a5c143f2b02
child 468793 68df166b4d9e53aaa1ff1e39ea6f3e534814f891
push id112755
push userdvarga@mozilla.com
push dateWed, 10 Apr 2019 22:06:41 +0000
treeherdermozilla-inbound@606f85641d0b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersckerschb
bugs1513445
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1513445: add tests r=ckerschb Differential Revision: https://phabricator.services.mozilla.com/D26681
dom/security/test/general/browser.ini
dom/security/test/general/browser_test_assert_systemprincipal_documents.js
dom/security/test/general/file_assert_systemprincipal_documents.html
dom/security/test/general/file_assert_systemprincipal_documents_iframe.html
--- a/dom/security/test/general/browser.ini
+++ b/dom/security/test/general/browser.ini
@@ -11,8 +11,13 @@ support-files =
 support-files =
   file_data_text_csv.html
 [browser_test_view_image_data_navigation.js]
 support-files =
   file_view_image_data_navigation.html
 [browser_test_FTP_console_warning.js]
 support-files =
   file_FTP_console_warning.html
+[browser_test_assert_systemprincipal_documents.js]
+skip-if = !debug && !fuzzing
+support-files =
+  file_assert_systemprincipal_documents.html
+  file_assert_systemprincipal_documents_iframe.html
new file mode 100644
--- /dev/null
+++ b/dom/security/test/general/browser_test_assert_systemprincipal_documents.js
@@ -0,0 +1,29 @@
+//"use strict"
+
+const kTestPath = getRootDirectory(gTestPath);
+const kTestURI = kTestPath + "file_assert_systemprincipal_documents.html";
+
+add_task(async function setup() {
+  // We expect the assertion in function
+  // AssertSystemPrincipalMustNotLoadRemoteDocuments as defined in
+  // file dom/security/nsContentSecurityManager.cpp
+  SimpleTest.expectAssertions(1);
+
+  await SpecialPowers.pushPrefEnv({
+    "set": [["security.disallow_non_local_systemprincipal_in_tests", true]],
+  });
+});
+
+add_task(async function open_test_iframe_in_tab() {
+  // This looks at the iframe (load type SUBDOCUMENT)
+  await BrowserTestUtils.withNewTab({ gBrowser, url: kTestURI}, async (browser) => {
+    await ContentTask.spawn(browser, {}, async function() {
+      let outerPrincipal = content.document.nodePrincipal;
+      ok(outerPrincipal.isSystemPrincipal, "Sanity: Using SystemPrincipal for test file on chrome://");
+
+      const iframeWin = content.document.getElementById("testframe").contentWindow;
+      const iframeChannel = iframeWin.docShell.currentDocumentChannel;
+      ok(iframeChannel.loadInfo.loadingPrincipal.isSystemPrincipal, 'LoadingPrincipal for iframe is SystemPrincipal');
+    });
+  });
+});
new file mode 100644
--- /dev/null
+++ b/dom/security/test/general/file_assert_systemprincipal_documents.html
@@ -0,0 +1,11 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>Bug 1513445: Assert not loading web documents into system land</title>
+</head>
+<body>
+<h1>This page loads documents from the SystemPrincipal (which causes the assertion)</h1>
+<iframe type="chrome" id="testframe" src="http://example.com/browser/dom/security/test/general/file_assert_systemprincipal_documents_iframe.html"></iframe>
+</body>
+</html>
+
new file mode 100644
--- /dev/null
+++ b/dom/security/test/general/file_assert_systemprincipal_documents_iframe.html
@@ -0,0 +1,9 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>Bug 1513445: Assert not loading web documents into system land</title>
+</head>
+<body>
+<h1>This is the iframe</h1>
+</body>
+</html>