Bug 695385: Add a mochitest to validate that cross-origin svg filters are blocked. r=jwatt
authorDaniel Holbert <dholbert@cs.stanford.edu>
Fri, 21 Dec 2018 06:46:19 +0000
changeset 451681 0987791fff8daa281dcfea241e0004a37ee7ee09
parent 451680 3a328e80b02cf3c11a36e060380277396e211cd9
child 451682 a4dc9a08f321e53e14857d8eeb9d966b7a66314c
push id35251
push userccoroiu@mozilla.com
push dateFri, 21 Dec 2018 21:54:30 +0000
treeherdermozilla-central@74101900e7d4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwatt
bugs695385
milestone66.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 695385: Add a mochitest to validate that cross-origin svg filters are blocked. r=jwatt Differential Revision: https://phabricator.services.mozilla.com/D13844
layout/svg/tests/file_black_yellow.svg
layout/svg/tests/file_filter_crossorigin.svg
layout/svg/tests/file_yellow_black.svg
layout/svg/tests/filters.svg
layout/svg/tests/mochitest.ini
layout/svg/tests/test_filter_crossorigin.html
new file mode 100644
--- /dev/null
+++ b/layout/svg/tests/file_black_yellow.svg
@@ -0,0 +1,9 @@
+<!--
+     Any copyright is dedicated to the Public Domain.
+     http://creativecommons.org/publicdomain/zero/1.0/
+-->
+<svg xmlns="http://www.w3.org/2000/svg" version="1.1"
+     xmlns:xlink="http://www.w3.org/1999/xlink">
+  <rect height="100%" width="100%" fill="yellow" />
+  <rect height="50%" width="100%" fill="black" />
+</svg>
new file mode 100644
--- /dev/null
+++ b/layout/svg/tests/file_filter_crossorigin.svg
@@ -0,0 +1,25 @@
+<!--
+     Any copyright is dedicated to the Public Domain.
+     http://creativecommons.org/publicdomain/zero/1.0/
+-->
+<svg xmlns="http://www.w3.org/2000/svg" version="1.1"
+     xmlns:xlink="http://www.w3.org/1999/xlink">
+
+  <!-- We include these <use> elements simply to be sure the SVG resource URLs
+       get a chance to block 'onload', if they can be loaded. -->
+  <use xlink:href="http://mochi.test:8888/tests/layout/svg/tests/filters.svg#empty" />
+  <use xlink:href="http://example.org/tests/layout/svg/tests/filters.svg#empty" />
+
+  <!-- giant yellow rect in the background, just so you can visually tell
+       that this SVG file has loaded/rendered. -->
+  <rect height="100%" width="100%" fill="yellow" />
+
+  <!-- For both rects below: if it's black, its filter resolved successfully.
+       If it's transparent, it means we failed to load the resource
+       (e.g. because it was blocked as a cross-origin resource). -->
+  <rect height="50%" width="100%" fill="red"
+        filter="url(http://mochi.test:8888/tests/layout/svg/tests/filters.svg#NonWhiteToBlack)"/>
+  <rect y="50%"
+        height="50%" width="100%" fill="red"
+        filter="url(http://example.org/tests/layout/svg/tests/filters.svg#NonWhiteToBlack)"/>
+</svg>
new file mode 100644
--- /dev/null
+++ b/layout/svg/tests/file_yellow_black.svg
@@ -0,0 +1,9 @@
+<!--
+     Any copyright is dedicated to the Public Domain.
+     http://creativecommons.org/publicdomain/zero/1.0/
+-->
+<svg xmlns="http://www.w3.org/2000/svg" version="1.1"
+     xmlns:xlink="http://www.w3.org/1999/xlink">
+  <rect height="100%" width="100%" fill="yellow" />
+  <rect y="50%" height="50%" width="100%" fill="black" />
+</svg>
copy from layout/reftests/filters.svg
copy to layout/svg/tests/filters.svg
--- a/layout/reftests/filters.svg
+++ b/layout/svg/tests/filters.svg
@@ -1,25 +1,16 @@
 <?xml version="1.0"?>
 <svg xmlns="http://www.w3.org/2000/svg" version="1.1">
   <defs>
 
     <!-- so that other documents can svg:use this one and force it to
          load before onload -->
     <g id="empty" />
 
-    <!-- Keep all black pixels black, and change any others to white. -->
-    <!-- NOTE: alpha is preserved, so it will not adjust alpha edges -->
-    <filter id="NonBlackToWhite" x="0%" y="0%" width="100%" height="100%">
-      <feColorMatrix type="matrix" values="255 255 255 0 0
-                                           255 255 255 0 0
-                                           255 255 255 0 0
-                                           0 0 0 1 0" />
-    </filter>
-
     <!-- Keep all white pixels white, and change any others to black. -->
     <!-- NOTE: alpha is preserved, so it will not adjust alpha edges -->
     <filter id="NonWhiteToBlack" x="0%" y="0%" width="100%" height="100%">
       <feComponentTransfer>
         <feFuncR type="linear" slope="-1" intercept="1" />
         <feFuncG type="linear" slope="-1" intercept="1" />
         <feFuncB type="linear" slope="-1" intercept="1" />
       </feComponentTransfer>
@@ -28,20 +19,10 @@
                                            255 255 255 0 0
                                            0 0 0 1 0" />
       <feComponentTransfer>
         <feFuncR type="linear" slope="-1" intercept="1" />
         <feFuncG type="linear" slope="-1" intercept="1" />
         <feFuncB type="linear" slope="-1" intercept="1" />
       </feComponentTransfer>
     </filter>
-
-    <!-- Threshold colours into sixteen steps per channel. -->
-    <filter id="ThresholdRGB" x="0%" y="0%" width="100%" height="100%" color-interpolation-filters="sRGB">
-      <feComponentTransfer>
-        <feFuncR type="discrete" tableValues="0 .125 .25 .375 .5 .625 .75 .875 1" />
-        <feFuncG type="discrete" tableValues="0 .125 .25 .375 .5 .625 .75 .875 1" />
-        <feFuncB type="discrete" tableValues="0 .125 .25 .375 .5 .625 .75 .875 1" />
-      </feComponentTransfer>
-    </filter>
-
   </defs>
 </svg>
--- a/layout/svg/tests/mochitest.ini
+++ b/layout/svg/tests/mochitest.ini
@@ -1,5 +1,11 @@
 [DEFAULT]
 support-files =
   file_disabled_iframe.html
 
 [test_disabled.html]
+[test_filter_crossorigin.html]
+support-files =
+  filters.svg
+  file_filter_crossorigin.svg
+  file_black_yellow.svg
+  file_yellow_black.svg
new file mode 100644
--- /dev/null
+++ b/layout/svg/tests/test_filter_crossorigin.html
@@ -0,0 +1,46 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=695385
+-->
+<head>
+  <meta charset="utf-8">
+  <title>Test for Bug 695385</title>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="application/javascript" src="/tests/SimpleTest/WindowSnapshot.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body onload="run()">
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=695385">Mozilla Bug 695385</a>
+<br>
+<!-- These iframes' renderings are expected to match: -->
+<iframe src="http://mochi.test:8888/tests/layout/svg/tests/file_filter_crossorigin.svg"></iframe>
+<iframe src="file_black_yellow.svg"></iframe>
+<br>
+<!-- These iframes' renderings are expected to match: -->
+<iframe src="http://example.org/tests/layout/svg/tests/file_filter_crossorigin.svg"></iframe>
+<iframe src="file_yellow_black.svg"></iframe>
+
+<pre id="test">
+<script type="application/javascript">
+// Main Function
+function run() {
+  SimpleTest.waitForExplicitFinish();
+  let snapshots = new Array(4);
+  for (let i = 0; i < snapshots.length; i++) {
+    snapshots[i] = snapshotWindow(frames[i].window, false);
+  }
+
+  // Compare mochi.test iframe against its reference:
+  assertSnapshots(snapshots[0], snapshots[1], true, null,
+                  "Testcase loaded from mochi.test", "Reference: black/yellow");
+
+  // Compare example.org iframe against its reference:
+  assertSnapshots(snapshots[2], snapshots[3], true, null,
+                  "Testcase loaded from example.org", "Reference: yellow/black");
+  SimpleTest.finish();
+}
+</script>
+</pre>
+</body>
+</html>