Bug 1381233 - Add test for this bug. r?heycam draft
authorXidorn Quan <me@upsuper.org>
Wed, 19 Jul 2017 19:19:07 +1000
changeset 612677 03ccb6d8bbafcd585b55fc9da6ff71dc7612cadd
parent 612676 4f7dfff7003c7ce3e6b3c5d9c6835b7cefaf1b2b
child 638470 4b41cc22e848a8a745fc9f5872c562dd76624c9d
push id69565
push userxquan@mozilla.com
push dateThu, 20 Jul 2017 23:25:47 +0000
reviewersheycam
bugs1381233
milestone56.0a1
Bug 1381233 - Add test for this bug. r?heycam MozReview-Commit-ID: 6A99LrHU2Li
layout/style/crashtests/1382710.html
layout/style/crashtests/crashtests.list
layout/style/test/file_bug1381233.html
layout/style/test/mochitest.ini
layout/style/test/test_crash_with_content_policy.html
new file mode 100644
--- /dev/null
+++ b/layout/style/crashtests/1382710.html
@@ -0,0 +1,8 @@
+<html>
+<head>
+<script>
+document.documentElement.appendChild(document.createElement("table"))
+</script>
+</head>
+<body></body>
+</html>
--- a/layout/style/crashtests/crashtests.list
+++ b/layout/style/crashtests/crashtests.list
@@ -178,8 +178,9 @@ load content-only-on-visited-before.html
 load 1375812-1.html
 load 1377053-1.html
 load 1377256-1.html
 load 1378064-1.html
 load 1378814.html
 load 1380800.html
 load link-transition-before.html
 load 1381682.html
+load 1382710.html
new file mode 100644
--- /dev/null
+++ b/layout/style/test/file_bug1381233.html
@@ -0,0 +1,4 @@
+<link rel="stylesheet" href="somestylesheet">
+<table><td>
+<embed src="whatever" type="application/x-shockwave-flash"></embed>
+</td></table>
--- a/layout/style/test/mochitest.ini
+++ b/layout/style/test/mochitest.ini
@@ -171,16 +171,18 @@ skip-if = toolkit == 'android'
 [test_computed_style_min_size_auto.html]
 [test_computed_style_no_pseudo.html]
 [test_computed_style_prefs.html]
 [test_condition_text.html]
 [test_condition_text_assignment.html]
 [test_contain_formatting_context.html]
 [test_counter_descriptor_storage.html]
 [test_counter_style.html]
+[test_crash_with_content_policy.html]
+support-files = file_bug1381233.html
 [test_css_cross_domain.html]
 skip-if = toolkit == 'android' #bug 536603
 [test_css_eof_handling.html]
 [test_css_escape_api.html]
 [test_css_function_mismatched_parenthesis.html]
 [test_css_loader_crossorigin_data_url.html]
 [test_css_supports.html]
 [test_css_supports_variables.html]
new file mode 100644
--- /dev/null
+++ b/layout/style/test/test_crash_with_content_policy.html
@@ -0,0 +1,73 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>Crashtests for style system with content policy</title>
+  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css">
+</head>
+<body>
+<iframe id="iframe"></iframe>
+<script>
+const TESTS = [
+  "file_bug1381233.html",
+];
+
+const Cc = SpecialPowers.Cc;
+const Ci = SpecialPowers.Ci;
+
+var policyID = SpecialPowers.wrap(SpecialPowers.Components).ID("{b80e19d0-878f-d41b-2654-194714a4115c}");
+var policyName = "@mozilla.org/testpolicy;1";
+var policy = {
+  // nsISupports implementation
+  QueryInterface: function(iid) {
+
+    iid = SpecialPowers.wrap(iid);
+    if (iid.equals(Ci.nsISupports) ||
+        iid.equals(Ci.nsIFactory) ||
+        iid.equals(Ci.nsIContentPolicy))
+      return this;
+
+    throw SpecialPowers.Cr.NS_ERROR_NO_INTERFACE;
+  },
+
+  // nsIFactory implementation
+  createInstance: function(outer, iid) {
+    return this.QueryInterface(iid);
+  },
+
+  // nsIContentPolicy implementation
+  shouldLoad: function(contentType, contentLocation, requestOrigin, context, mimeTypeGuess, extra) {
+    info(`shouldLoad is invoked for ${SpecialPowers.wrap(contentLocation).spec}`);
+    return Ci.nsIContentPolicy.ACCEPT;
+  },
+  shouldProcess: function(contentType, contentLocation, requestOrigin, context, mimeTypeGuess, extra) {
+    return Ci.nsIContentPolicy.ACCEPT;
+  }
+}
+policy = SpecialPowers.wrapCallbackObject(policy);
+
+// Register content policy
+var componentManager = SpecialPowers.wrap(SpecialPowers.Components).manager
+                                    .QueryInterface(Ci.nsIComponentRegistrar);
+componentManager.registerFactory(policyID, "Test content policy", policyName, policy);
+var categoryManager = Cc["@mozilla.org/categorymanager;1"].getService(Ci.nsICategoryManager);
+categoryManager.addCategoryEntry("content-policy", policyName, policyName, false, true);
+
+
+SimpleTest.waitForExplicitFinish();
+
+async function runTests() {
+  let iframe = document.getElementById("iframe");
+  for (let test of TESTS) {
+    iframe.src = test;
+    await new Promise(resolve => {
+      iframe.onload = resolve;
+    });
+    ok(true, `${test} doesn't crash`);
+  }
+  SimpleTest.finish();
+}
+runTests();
+</script>
+</body>
+</html>