Bug 1334944 - Make all layout/reftests/bugs/315920-* tests use MozReftestInvalidate instead of onload r?mats draft
authorWes Kocher <wkocher@mozilla.com>
Mon, 27 Feb 2017 16:01:32 -0800
changeset 490270 fa660ae2677cf4ed49b0aca7467b68f34ddccba0
parent 490265 5d1ebf7782dfd48afbac00e99f93c1726affec09
child 547212 d6e545d9eee3bb76523a4195c23ddf7b4fe992d3
push id47047
push userkwierso@gmail.com
push dateTue, 28 Feb 2017 00:02:15 +0000
reviewersmats
bugs1334944, 315920
milestone54.0a1
Bug 1334944 - Make all layout/reftests/bugs/315920-* tests use MozReftestInvalidate instead of onload r?mats MozReview-Commit-ID: CGiTe4wm054
layout/reftests/bugs/315920-10.html
layout/reftests/bugs/315920-11.html
layout/reftests/bugs/315920-12a.html
layout/reftests/bugs/315920-12b.html
layout/reftests/bugs/315920-12c.html
layout/reftests/bugs/315920-13a.html
layout/reftests/bugs/315920-13b.html
layout/reftests/bugs/315920-14.html
layout/reftests/bugs/315920-15.html
layout/reftests/bugs/315920-16.html
layout/reftests/bugs/315920-18a.html
layout/reftests/bugs/315920-18c.html
layout/reftests/bugs/315920-18d.html
layout/reftests/bugs/315920-18e.html
layout/reftests/bugs/315920-18f.html
layout/reftests/bugs/315920-18g.html
layout/reftests/bugs/315920-19.html
layout/reftests/bugs/315920-1a.html
layout/reftests/bugs/315920-1b.html
layout/reftests/bugs/315920-22.html
layout/reftests/bugs/315920-23.html
layout/reftests/bugs/315920-24.html
layout/reftests/bugs/315920-25.html
layout/reftests/bugs/315920-26.html
layout/reftests/bugs/315920-27.html
layout/reftests/bugs/315920-28a.html
layout/reftests/bugs/315920-28b.html
layout/reftests/bugs/315920-28c.html
layout/reftests/bugs/315920-29a.html
layout/reftests/bugs/315920-29b.html
layout/reftests/bugs/315920-2a.html
layout/reftests/bugs/315920-2b.html
layout/reftests/bugs/315920-2c.html
layout/reftests/bugs/315920-30.html
layout/reftests/bugs/315920-3a.html
layout/reftests/bugs/315920-3b.html
layout/reftests/bugs/315920-3c.html
layout/reftests/bugs/315920-3d.html
layout/reftests/bugs/315920-4.html
layout/reftests/bugs/315920-5.html
layout/reftests/bugs/315920-6.html
layout/reftests/bugs/315920-7a.html
layout/reftests/bugs/315920-7b.html
layout/reftests/bugs/315920-7c.html
layout/reftests/bugs/315920-8a.html
layout/reftests/bugs/315920-8b.html
layout/reftests/bugs/315920-9.html
--- a/layout/reftests/bugs/315920-10.html
+++ b/layout/reftests/bugs/315920-10.html
@@ -2,23 +2,30 @@
 <html>
   <head>
     <style>
       input ~ label {color: red}
       input[checked]:checked ~ label {color: green}
       input[checked]:checked:not(:default) + label {color: red}
     </style>
   </head>
-  <body onload='var e1 = document.getElementById("one");
-                var l1 = document.getElementById("l1");
-                e1.parentNode.removeChild(e1);
-                l1.parentNode.removeChild(l1);
-                document.getElementById("two").setAttribute("checked", "true");'>
+  <body>
     <form>
       <input type="radio" name="group1" id="one" value="1" default="true" checked/>
       <label id="l1" for="one">Should be no red</label><br>
       <input type="radio" name="group1" id="two" value="2"/>
       <label for="two">Should be no red</label>
       <input type="radio" name="group1" id="three" value="3"/>
       <label for="three">Should be no red</label>
     </form>
+    <script>
+    function doTest() {
+      var e1 = document.getElementById("one");
+      var l1 = document.getElementById("l1");
+      e1.parentNode.removeChild(e1);
+      l1.parentNode.removeChild(l1);
+      document.getElementById("two").setAttribute("checked", "true");
+      setTimeout(function () { document.documentElement.removeAttribute("class"); }, 0);
+    }
+    window.addEventListener("MozReftestInvalidate", doTest);
+    </script>
   </body>
 </html>
--- a/layout/reftests/bugs/315920-11.html
+++ b/layout/reftests/bugs/315920-11.html
@@ -2,17 +2,24 @@
 <html>
   <head>
     <style>
       input ~ label {color: red}
       input[checked]:checked:default ~ label {color: red}
       input:not(:default):not(:checked):not([checked]) ~ label {color:green}
     </style>
   </head>
-  <body onload='document.getElementById("one").removeAttribute("checked");'>
+  <body>
     <form>
       <input type="radio" name="group1" id="one" value="1" default="true" checked/>
       <label for="one">Should be no red</label><br>
       <input type="radio" name="group1" id="two" value="2"/>
       <label for="two">Should be no red</label>
     </form>
+    <script>
+    function doTest() {
+      document.getElementById("one").removeAttribute("checked");
+      setTimeout(function () { document.documentElement.removeAttribute("class"); }, 0);
+    }
+    window.addEventListener("MozReftestInvalidate", doTest);
+    </script>
   </body>
 </html>
--- a/layout/reftests/bugs/315920-12a.html
+++ b/layout/reftests/bugs/315920-12a.html
@@ -2,18 +2,25 @@
 <html>
   <head>
     <style>
       label {color: red}
       input:default + label {color: green}
       input:not(:checked):not([checked]):not(:default) + label {color:green}
     </style>
   </head>
-  <body onload='document.getElementById("one").setAttribute("checked", "true");
-                document.getElementById("two").removeAttribute("checked");'>
+  <body>
     <form>
       <input type="checkbox" name="group1" id="one" value="1"/>
       <label id="l1" for="one">Should be no red</label><br>
       <input type="checkbox" name="group1" id="two" value="2" checked="true"/>
       <label id="l2" for="two">Should be no red</label>
     </form>
+    <script>
+    function doTest() {
+      document.getElementById("one").setAttribute("checked", "true");
+      document.getElementById("two").removeAttribute("checked");
+      setTimeout(function () { document.documentElement.removeAttribute("class"); }, 0);
+    }
+    window.addEventListener("MozReftestInvalidate", doTest);
+    </script>
   </body>
 </html>
--- a/layout/reftests/bugs/315920-12b.html
+++ b/layout/reftests/bugs/315920-12b.html
@@ -2,19 +2,26 @@
 <html>
   <head>
       <style>
         label {color: red}
         input[checked]:default:checked ~ label {color: green}
 
       </style>
   </head>
-  <body onload='var e1 = document.getElementById("one");
-                e1.setAttribute("checked", "false");
-                document.getElementById("two").removeAttribute("checked");'>
+  <body>
     <form>
       <input type="checkbox" name="group1" id="one" value="1"/>
       <label for="one">Should be no red</label><br>
       <input type="checkbox" name="group1" id="two" value="2" checked/>
       <label for="two">Should be no red</label>
     </form>
+    <script>
+    function doTest() {
+      var e1 = document.getElementById("one");
+      e1.setAttribute("checked", "false");
+      document.getElementById("two").removeAttribute("checked");
+      setTimeout(function () { document.documentElement.removeAttribute("class"); }, 0);
+    }
+    window.addEventListener("MozReftestInvalidate", doTest);
+    </script>
   </body>
 </html>
--- a/layout/reftests/bugs/315920-12c.html
+++ b/layout/reftests/bugs/315920-12c.html
@@ -2,17 +2,24 @@
 <html>
   <head>
     <style>
       input ~ label {color: red}
       input:not(:default):not(:checked):not([checked]) ~ label {color:red}
       input[checked]:checked:default ~ label {color: green}
     </style>
   </head>
-  <body onload='document.getElementById("one").setAttribute("checked", "checked");'>
+  <body>
     <form>
       <input type="checkbox" name="group1" id="one" value="1"/>
       <label for="one">Should be no red</label><br>
       <input type="checkbox" name="group1" id="two" value="2"/>
       <label for="two">Should be no red</label>
     </form>
+    <script>
+    function doTest() {
+      document.getElementById("one").setAttribute("checked", "checked");
+      setTimeout(function () { document.documentElement.removeAttribute("class"); }, 0);
+    }
+    window.addEventListener("MozReftestInvalidate", doTest);
+    </script>
   </body>
 </html>
--- a/layout/reftests/bugs/315920-13a.html
+++ b/layout/reftests/bugs/315920-13a.html
@@ -2,17 +2,24 @@
 <html>
   <head>
     <style>
       input ~ label {color: red}
       input[checked]:default + label {color: green}
       input:not(:default):not([checked]) + label {color:green}
     </style>
   </head>
-  <body onload='document.getElementById("two").setAttribute("checked", "true");'>
+  <body>
     <form>
       <input type="checkbox" name="group1" id="one" value="1"/>
       <label for="one">Should be no red</label><br>
       <input type="checkbox" name="group1" id="two" value="2"/>
       <label for="two">Should be no red</label>
     </form>
+    <script>
+    function doTest() {
+      document.getElementById("two").setAttribute("checked", "true");
+      setTimeout(function () { document.documentElement.removeAttribute("class"); }, 0);
+    }
+    window.addEventListener("MozReftestInvalidate", doTest);
+    </script>
   </body>
 </html>
--- a/layout/reftests/bugs/315920-13b.html
+++ b/layout/reftests/bugs/315920-13b.html
@@ -2,17 +2,24 @@
 <html>
   <head>
     <style>
       label {color: red}
       input[checked]:checked:default + label {color: green}
       input:not(:checked) + label {color: green}
     </style>
   </head>
-  <body onload='document.getElementById("two").setAttribute("checked", "true");'>
+  <body>
     <form>
       <input type="checkbox" name="group1" id="one" value="1"/>
         <label for="one">Should be no red</label><br>
         <input type="checkbox" name="group1" id="two" value="2"/>
         <label for="two">Should be no red</label>
     </form>
+    <script>
+    function doTest() {
+      document.getElementById("two").setAttribute("checked", "true");
+      setTimeout(function () { document.documentElement.removeAttribute("class"); }, 0);
+    }
+    window.addEventListener("MozReftestInvalidate", doTest);
+    </script>
   </body>
 </html>
--- a/layout/reftests/bugs/315920-14.html
+++ b/layout/reftests/bugs/315920-14.html
@@ -1,25 +1,32 @@
 <!DOCTYPE html>
 <html>
   <head>
     <style>
       label {color: red}
       input[checked]:checked:default ~ label {color: green}
     </style>
   </head>
-  <body onload='var form = document.getElementById("form");
-                var input2 = document.createElement("input");
-                input2.setAttribute("type", "checkbox");
-                input2.setAttribute("id", "two");
-                input2.setAttribute("checked", "true");
-                form.insertBefore(input2, form.firstChild);
-                var label2 = document.createElement("label");
-                label2.setAttribute("for", "two");
-                var text2 = document.createTextNode("Should be no red");
-                label2.appendChild(text2);
-                form.insertBefore(label2, document.getElementById("one"));'>
+  <body>
     <form id="form">
       <input type="checkbox" name="group1" id="one" value="1"/>
       <label for="one">Should be no red</label>
     </form>
+    <script>
+    function doTest() {
+      var form = document.getElementById("form");
+      var input2 = document.createElement("input");
+      input2.setAttribute("type", "checkbox");
+      input2.setAttribute("id", "two");
+      input2.setAttribute("checked", "true");
+      form.insertBefore(input2, form.firstChild);
+      var label2 = document.createElement("label");
+      label2.setAttribute("for", "two");
+      var text2 = document.createTextNode("Should be no red");
+      label2.appendChild(text2);
+      form.insertBefore(label2, document.getElementById("one"));
+      setTimeout(function () { document.documentElement.removeAttribute("class"); }, 0);
+    }
+    window.addEventListener("MozReftestInvalidate", doTest);
+    </script>
   </body>
 </html>
--- a/layout/reftests/bugs/315920-15.html
+++ b/layout/reftests/bugs/315920-15.html
@@ -2,23 +2,30 @@
 <html>
   <head>
     <style>
       input ~ label {color: red}
       input[checked]:checked ~ label {color: green}
       input[checked]:checked:not(:default) + label {color: red}
     </style>
   </head>
-  <body onload='var e1 = document.getElementById("one");
-                var l1 = document.getElementById("l1");
-                e1.parentNode.removeChild(e1);
-                l1.parentNode.removeChild(l1);
-                document.getElementById("two").setAttribute("checked", "true");'>
+  <body>
     <form>
       <input type="checkbox" name="group1" id="one" value="1" default="true" checked/>
       <label id="l1" for="one">Should be no red</label><br>
       <input type="checkbox" name="group1" id="two" value="2"/>
       <label for="two">Should be no red</label>
       <input type="checkbox" name="group1" id="three" value="3"/>
       <label for="three">Should be no red</label>
     </form>
+    <script>
+    function doTest() {
+      var e1 = document.getElementById("one");
+      var l1 = document.getElementById("l1");
+      e1.parentNode.removeChild(e1);
+      l1.parentNode.removeChild(l1);
+      document.getElementById("two").setAttribute("checked", "true");
+      setTimeout(function () { document.documentElement.removeAttribute("class"); }, 0);
+    }
+    window.addEventListener("MozReftestInvalidate", doTest);
+    </script>
   </body>
 </html>
--- a/layout/reftests/bugs/315920-16.html
+++ b/layout/reftests/bugs/315920-16.html
@@ -2,17 +2,24 @@
 <html>
   <head>
     <style>
       input ~ label {color: red}
       input[checked]:checked:default ~ label {color: red}
       input:not(:default):not(:checked):not([checked]) ~ label {color:green}
     </style>
   </head>
-  <body onload='document.getElementById("one").removeAttribute("checked");'>
+  <body>
     <form>
       <input type="checkbox" name="group1" id="one" value="1" checked/>
       <label for="one">Should be no red</label><br>
       <input type="checkbox" name="group1" id="two" value="2"/>
       <label for="two">Should be no red</label>
     </form>
+    <script>
+    function doTest() {
+      document.getElementById("one").removeAttribute("checked");
+      setTimeout(function () { document.documentElement.removeAttribute("class"); }, 0);
+    }
+    window.addEventListener("MozReftestInvalidate", doTest);
+    </script>
   </body>
 </html>
--- a/layout/reftests/bugs/315920-18a.html
+++ b/layout/reftests/bugs/315920-18a.html
@@ -2,16 +2,23 @@
 <html class="reftest-wait">
   <head>
     <style>
       label {color: red}
       img:not(:-moz-broken) ~ label {color: green}
       img { display: none; }
     </style>
   </head>
-  <body onload='var i1 = document.getElementById("ffximage");
-                i1.onload =
-                  function() { document.documentElement.className = ""; };
-                i1.setAttribute("src", "solidblue.png");'>
+  <body>
     <img src="no-such-scheme:nothing" id="ffximage"/>
     <label for="ffximage">Text should be green</label>
+    <script>
+    function doTest() {
+      var i1 = document.getElementById("ffximage");
+      i1.onload =
+        function() { document.documentElement.className = ""; };
+      i1.setAttribute("src", "solidblue.png");
+      setTimeout(function () { document.documentElement.removeAttribute("class"); }, 0);
+    }
+    window.addEventListener("MozReftestInvalidate", doTest);
+    </script>
   </body>
 </html>
--- a/layout/reftests/bugs/315920-18c.html
+++ b/layout/reftests/bugs/315920-18c.html
@@ -2,16 +2,23 @@
 <html class="reftest-wait">
   <head>
     <style>
       label {color: red}
       input:not(:-moz-broken) ~ label {color: green}
       input { display: none }
     </style>
   </head>
-  <body onload='var i1 = document.getElementById("ffximage");
-                i1.onload =
-                  function() { document.documentElement.className = ""; };
-                i1.setAttribute("src", "solidblue.png");'>
+  <body>
     <input type="image" src="no-such-scheme:nothing" id="ffximage"/>
     <label for="ffximage">Text should be green</label>
+    <script>
+    function doTest() {
+      var i1 = document.getElementById("ffximage");
+      i1.onload =
+        function() { document.documentElement.className = ""; };
+      i1.setAttribute("src", "solidblue.png");
+      setTimeout(function () { document.documentElement.removeAttribute("class"); }, 0);
+    }
+    window.addEventListener("MozReftestInvalidate", doTest);
+    </script>
   </body>
 </html>
--- a/layout/reftests/bugs/315920-18d.html
+++ b/layout/reftests/bugs/315920-18d.html
@@ -2,16 +2,23 @@
 <html class="reftest-wait">
   <head>
     <style>
       label {color: red}
       object:not(:-moz-broken) ~ label {color: green}
       object { display: none }
     </style>
   </head>
-  <body onload='var i1 = document.getElementById("ffximage");
-                i1.onload =
-                  function() { document.documentElement.className = ""; };
-                i1.setAttribute("data", "solidblue.png");'>
+  <body>
     <object type="image/png" data="no-such-scheme:nothing" id="ffximage"></object>
     <label for="ffximage">Text should be green</label>
+    <script>
+    function doTest() {
+      var i1 = document.getElementById("ffximage");
+      i1.onload =
+        function() { document.documentElement.className = ""; };
+      i1.setAttribute("data", "solidblue.png");
+      setTimeout(function () { document.documentElement.removeAttribute("class"); }, 0);
+    }
+    window.addEventListener("MozReftestInvalidate", doTest);
+    </script>
   </body>
 </html>
--- a/layout/reftests/bugs/315920-18e.html
+++ b/layout/reftests/bugs/315920-18e.html
@@ -2,17 +2,24 @@
 <html class="reftest-wait">
   <head>
     <style>
       label {color: red}
       img[src*="solidblue"]:not(:-moz-broken) + label {color: green}
       img { display: none; }
     </style>
   </head>
-  <body onload='var i1 = document.getElementById("ffximage");
-                i1.onload =
-                  function() { document.documentElement.className = ""; };
-                i1.setAttribute("src", "solidblue.png");'>
+  <body>
     <img src="solidblue.png">
     <img src="no-such-scheme:nothing" id="ffximage"/>
     <label for="ffximage">Text should be green</label>
+    <script>
+    function doTest() {
+      var i1 = document.getElementById("ffximage");
+      i1.onload =
+        function() { document.documentElement.className = ""; };
+      i1.setAttribute("src", "solidblue.png");
+      setTimeout(function () { document.documentElement.removeAttribute("class"); }, 0);
+    }
+    window.addEventListener("MozReftestInvalidate", doTest);
+    </script>
   </body>
 </html>
--- a/layout/reftests/bugs/315920-18f.html
+++ b/layout/reftests/bugs/315920-18f.html
@@ -2,17 +2,24 @@
 <html class="reftest-wait">
   <head>
     <style>
       label {color: red}
       input[src*="solidblue"]:not(:-moz-broken) + label {color: green}
       input, img { display: none }
     </style>
   </head>
-  <body onload='var i1 = document.getElementById("ffximage");
-                i1.onload =
-                  function() { document.documentElement.className = ""; };
-                i1.setAttribute("src", "solidblue.png");'>
+  <body>
     <img src="solidblue.png">
     <input type="image" src="no-such-scheme:nothing" id="ffximage"/>
     <label for="ffximage">Text should be green</label>
   </body>
+    <script>
+    function doTest() {
+      var i1 = document.getElementById("ffximage");
+                i1.onload =
+                  function() { document.documentElement.className = ""; };
+                i1.setAttribute("src", "solidblue.png");
+      setTimeout(function () { document.documentElement.removeAttribute("class"); }, 0);
+    }
+    window.addEventListener("MozReftestInvalidate", doTest);
+    </script>
 </html>
--- a/layout/reftests/bugs/315920-18g.html
+++ b/layout/reftests/bugs/315920-18g.html
@@ -2,17 +2,24 @@
 <html class="reftest-wait">
   <head>
     <style>
       label {color: red}
       object[data*="solidblue"]:not(:-moz-broken) + label {color: green}
       object, img { display: none }
     </style>
   </head>
-  <body onload='var i1 = document.getElementById("ffximage");
-                i1.onload =
-                  function() { document.documentElement.className = ""; };
-                i1.setAttribute("data", "solidblue.png");'>
+  <body>
     <img src="solidblue.png">
     <object type="image/png" data="no-such-scheme:nothing" id="ffximage"></object>
     <label for="ffximage">Text should be green</label>
+    <script>
+    function doTest() {
+      var i1 = document.getElementById("ffximage");
+      i1.onload =
+        function() { document.documentElement.className = ""; };
+      i1.setAttribute("data", "solidblue.png");
+      setTimeout(function () { document.documentElement.removeAttribute("class"); }, 0);
+    }
+    window.addEventListener("MozReftestInvalidate", doTest);
+    </script>
   </body>
 </html>
--- a/layout/reftests/bugs/315920-19.html
+++ b/layout/reftests/bugs/315920-19.html
@@ -4,16 +4,23 @@
     <style>
       span {color: red}
       label {color: red}
       input[disabled]:disabled ~ span {color: green}
       input[disabled]:disabled + label {color: green}
       input { display: none; }
     </style>
   </head>
-  <body onload='var i1 = document.getElementById("ffximage");
-                i1.setAttribute("disabled", "disabled");'>
+  <body>
     <input type="image" id="ffximage"/>
     <label for="ffximage">Should be no red</label>
     <br>
     <span>Should be no red</span>
+    <script>
+    function doTest() {
+      var i1 = document.getElementById("ffximage");
+      i1.setAttribute("disabled", "disabled");
+      setTimeout(function () { document.documentElement.removeAttribute("class"); }, 0);
+    }
+    window.addEventListener("MozReftestInvalidate", doTest);
+    </script>
   </body>
 </html
--- a/layout/reftests/bugs/315920-1a.html
+++ b/layout/reftests/bugs/315920-1a.html
@@ -2,16 +2,23 @@
 <html>
   <head>
     <style>
       option {color: blue}
       option:disabled {color: green}
       option#one:not([disabled]):not(:disabled) + option#two {color: red}
     </style>
   </head>
-  <body onload='var elem = document.getElementById("one");
-                elem.setAttribute("disabled", "disabled");'>
+  <body>
     <select size="2">
       <option id="one">Should be green</option>
       <option id="two">Should be blue</option>
     </select>
+    <script>
+    function doTest() {
+      var elem = document.getElementById("one");
+      elem.setAttribute("disabled", "disabled");
+      setTimeout(function () { document.documentElement.removeAttribute("class"); }, 0);
+    }
+    window.addEventListener("MozReftestInvalidate", doTest);
+    </script>
   </body>
 </html>
--- a/layout/reftests/bugs/315920-1b.html
+++ b/layout/reftests/bugs/315920-1b.html
@@ -2,16 +2,23 @@
 <html>
   <head>
     <style>
       option {color: blue}
       option:disabled {color: green}
       option#one:not([disabled]):enabled + option#two {color: red}
     </style>
   </head>
-  <body onload='var elem = document.getElementById("one");
-                elem.setAttribute("disabled", "disabled");'>
+  <body>
     <select size="2">
       <option id="one">Should be green</option>
       <option id="two">Should be blue</option>
     </select>
+    <script>
+    function doTest() {
+      var elem = document.getElementById("one");
+      elem.setAttribute("disabled", "disabled");
+      setTimeout(function () { document.documentElement.removeAttribute("class"); }, 0);
+    }
+    window.addEventListener("MozReftestInvalidate", doTest);
+    </script>
   </body>
 </html>
--- a/layout/reftests/bugs/315920-22.html
+++ b/layout/reftests/bugs/315920-22.html
@@ -2,21 +2,28 @@
 <html>
   <head>
     <style>
       label {color: red}
       #one[disabled]:disabled + label {color: green}
       #two:not([disabled]):not(:disabled) + label {color: green}
     </style>
   </head>
-  <body onload='var elem = document.getElementById("one");
-                elem.setAttribute("disabled", "disabled");
-                document.getElementById("two").removeAttribute("disabled")'>
+  <body>
     <div>
       <input id="one"/>
       <label for="one">Should be no red</label>
     </div>
     <div>
       <input id="two" disabled="disabled"/>
       <label for="two">Should be no red</label>
     </div>
+    <script>
+    function doTest() {
+      var elem = document.getElementById("one");
+      elem.setAttribute("disabled", "disabled");
+      document.getElementById("two").removeAttribute("disabled")
+      setTimeout(function () { document.documentElement.removeAttribute("class"); }, 0);
+    }
+    window.addEventListener("MozReftestInvalidate", doTest);
+    </script>
   </body>
 </html>
--- a/layout/reftests/bugs/315920-23.html
+++ b/layout/reftests/bugs/315920-23.html
@@ -2,21 +2,28 @@
 <html>
   <head>
     <style>
       label {color: red}
       #one[disabled]:not(:enabled) + label {color: green}
       #two:not([disabled]):enabled + label {color: green}
     </style>
   </head>
-  <body onload='var elem = document.getElementById("one");
-                elem.setAttribute("disabled", "disabled");
-                document.getElementById("two").removeAttribute("disabled")'>
+  <body>
     <div>
       <input id="one"/>
       <label for="one">Should be no red</label>
     </div>
     <div>
       <input id="two" disabled="disabled"/>
       <label for="two">Should be no red</label>
     </div>
   </body>
+    <script>
+    function doTest() {
+      var elem = document.getElementById("one");
+      elem.setAttribute("disabled", "disabled");
+      document.getElementById("two").removeAttribute("disabled")
+      setTimeout(function () { document.documentElement.removeAttribute("class"); }, 0);
+    }
+    window.addEventListener("MozReftestInvalidate", doTest);
+    </script>
 </html>
--- a/layout/reftests/bugs/315920-24.html
+++ b/layout/reftests/bugs/315920-24.html
@@ -4,14 +4,21 @@
     <style>
       span {color: red}
       input[type=text][disabled]:disabled + span {color: green}
       input[type=submit]:disabled + span {color: red}
       input { display: none }
     </style>
   </head>
 
-  <body onload='document.getElementById("one").setAttribute("disabled", "disabled");
-                document.getElementById("one").setAttribute("type", "text");'>
+  <body>
     <input type="submit" id="one"/>
     <span>Should be no red </span>
+    <script>
+    function doTest() {
+      document.getElementById("one").setAttribute("disabled", "disabled");
+                document.getElementById("one").setAttribute("type", "text");
+      setTimeout(function () { document.documentElement.removeAttribute("class"); }, 0);
+    }
+    window.addEventListener("MozReftestInvalidate", doTest);
+    </script>
   </body>
 </html>
--- a/layout/reftests/bugs/315920-25.html
+++ b/layout/reftests/bugs/315920-25.html
@@ -5,19 +5,26 @@
       span {color: red}
       input[type=submit]:not([disabled]):not(:disabled) ~ span {color: green}
       input[type=submit][disabled]:disabled + span {color: blue}
       input[type=text] + span {color: red}
       input { display: none }
     </style>
   </head>
 
-  <body onload='document.getElementById("one").setAttribute("type", "submit");
-                document.getElementById("two").setAttribute("type", "submit");
-                document.getElementById("two").setAttribute("disabled", "disabled");
-                document.getElementById("one").removeAttribute("disabled");'>
+  <body>
     <input type="text" id="one" disabled="disabled"/>
     <span>Should be no red </span><br>
     <span>Should be no red </span><br>
     <input type="text" id="two"/>
     <span>Should be no red </span>
+    <script>
+    function doTest() {
+      document.getElementById("one").setAttribute("type", "submit");
+      document.getElementById("two").setAttribute("type", "submit");
+      document.getElementById("two").setAttribute("disabled", "disabled");
+      document.getElementById("one").removeAttribute("disabled");
+      setTimeout(function () { document.documentElement.removeAttribute("class"); }, 0);
+    }
+    window.addEventListener("MozReftestInvalidate", doTest);
+    </script>
   </body>
 </html>
--- a/layout/reftests/bugs/315920-26.html
+++ b/layout/reftests/bugs/315920-26.html
@@ -3,21 +3,28 @@
   <head>
     <style>
       span {color: red}
       #one:checked + span {color: green}
       #two:default + span {color: green}
     </style>
   </head>
 
-  <body onload='document.getElementById("one").setAttribute("type", "checkbox");
-                document.getElementById("two").setAttribute("type", "checkbox");
-                document.documentElement.removeAttribute("class");'>
+  <body>
     <div>
       <input type="text" id="one" checked="checked"/>
       <span>Should be no red </span>
     </div>
     <div>
       <input type="text" id="two" checked="checked"/>
       <span>Should be no red </span>
     </div>
+    <script>
+    function doTest() {
+      document.getElementById("one").setAttribute("type", "checkbox");
+      document.getElementById("two").setAttribute("type", "checkbox");
+      document.documentElement.removeAttribute("class");
+      setTimeout(function () { document.documentElement.removeAttribute("class"); }, 0);
+    }
+    window.addEventListener("MozReftestInvalidate", doTest);
+    </script>
   </body>
 </html>
--- a/layout/reftests/bugs/315920-27.html
+++ b/layout/reftests/bugs/315920-27.html
@@ -3,20 +3,27 @@
   <head>
     <style>
       span {color: green}
       #one:checked + span {color: red}
       #two:default + span {color: red}
     </style>
   </head>
 
-  <body onload='document.getElementById("one").removeAttribute("type");
-                document.getElementById("two").removeAttribute("type");'>
+  <body>
     <div>
       <input type="text" id="one" checked="checked" type="checkbox"/>
       <span>Should be no red </span>
     </div>
     <div>
       <input type="text" id="two" checked="checked" type="checkbox"/>
       <span>Should be no red </span>
     </div>
+    <script>
+    function doTest() {
+      document.getElementById("one").removeAttribute("type");
+      document.getElementById("two").removeAttribute("type");
+      setTimeout(function () { document.documentElement.removeAttribute("class"); }, 0);
+    }
+    window.addEventListener("MozReftestInvalidate", doTest);
+    </script>
   </body>
 </html>
--- a/layout/reftests/bugs/315920-28a.html
+++ b/layout/reftests/bugs/315920-28a.html
@@ -5,21 +5,28 @@
       optgroup {color: red}
       option {color: red}
       optgroup[disabled]:disabled {color: green}
       optgroup[disabled]:disabled + optgroup:not([disabled]):not(:disabled) {color: blue}
       optgroup[disabled]:disabled > option{color: green}
       optgroup:not([disabled]):not(:disabled) > option {color: blue}
     </style>
   </head>
-  <body onload='document.getElementById("ogone").setAttribute("disabled", "disabled");'>
+  <body>
     <select size="7">
       <optgroup id="ogone" label="opt group 1">
         <option id="one">Should be no red</option>
         <option id="two">Should be no red</option>
       </optgroup>
       <optgroup id="ogtwo" label="opt group 2">
         <option id=three>Should be no red</option>
         <option id=four>Should be no red</option>
       </optgroup>
     </select>
+    <script>
+    function doTest() {
+      document.getElementById("ogone").setAttribute("disabled", "disabled");
+      setTimeout(function () { document.documentElement.removeAttribute("class"); }, 0);
+    }
+    window.addEventListener("MozReftestInvalidate", doTest);
+    </script>
   </body>
 </html>
--- a/layout/reftests/bugs/315920-28b.html
+++ b/layout/reftests/bugs/315920-28b.html
@@ -5,21 +5,28 @@
       optgroup {color: red}
       option {color: red}
       optgroup[disabled]:disabled {color: green}
       optgroup[disabled]:disabled + optgroup:not([disabled]):not(:disabled) {color: blue}
       optgroup[disabled]:disabled > option{color: green}
       optgroup:not([disabled]):not(:disabled) > option {color: blue}
     </style>
   </head>
-  <body onload='document.getElementById("ogtwo").removeAttribute("disabled");'>
+  <body>
     <select size="7">
       <optgroup id="ogone" label="opt group 1" disabled="disabled">
         <option id="one">Should be no red</option>
         <option id="two">Should be no red</option>
       </optgroup>
       <optgroup id="ogtwo" label="opt group 2" disabled="disabled">
         <option id=three>Should be no red</option>
         <option id=four>Should be no red</option>
       </optgroup>
     </select>
+    <script>
+    function doTest() {
+      document.getElementById("ogtwo").removeAttribute("disabled");
+      setTimeout(function () { document.documentElement.removeAttribute("class"); }, 0);
+    }
+    window.addEventListener("MozReftestInvalidate", doTest);
+    </script>
   </body>
 </html>
--- a/layout/reftests/bugs/315920-28c.html
+++ b/layout/reftests/bugs/315920-28c.html
@@ -5,22 +5,29 @@
       optgroup {color: red}
       option {color: red}
       optgroup[disabled]:disabled {color: green}
       optgroup[disabled]:disabled + optgroup:not([disabled]):not(:disabled) {color: blue}
       optgroup[disabled]:disabled > option{color: green}
       optgroup:not([disabled]):not(:disabled) > option {color: blue}
     </style>
   </head>
-  <body onload='document.getElementById("ogtwo").removeAttribute("disabled");
-                document.getElementById("ogone").setAttribute("disabled", "disabled");'>
+  <body>
     <select size="7">
       <optgroup id="ogone" label="opt group 1">
         <option id="one">Should be no red</option>
         <option id="two">Should be no red</option>
       </optgroup>
       <optgroup id="ogtwo" label="opt group 2" disabled="disabled">
         <option id=three>Should be no red</option>
         <option id=four>Should be no red</option>
       </optgroup>
     </select>
+    <script>
+    function doTest() {
+      document.getElementById("ogtwo").removeAttribute("disabled");
+      document.getElementById("ogone").setAttribute("disabled", "disabled");
+      setTimeout(function () { document.documentElement.removeAttribute("class"); }, 0);
+    }
+    window.addEventListener("MozReftestInvalidate", doTest);
+    </script>
   </body>
 </html>
--- a/layout/reftests/bugs/315920-29a.html
+++ b/layout/reftests/bugs/315920-29a.html
@@ -3,17 +3,24 @@
   <head>
     <style>
       optgroup {color: red}
       optgroup[disabled]:disabled {color: red}
       optgroup:not([disabled]):not(:disabled) + optgroup {color: green}
       optgroup:not(:disabled) {color: green}
     </style>
   </head>
-  <body onload='document.getElementById("ogone").removeAttribute("disabled");'>
+  <body>
     <select size="2">
       <optgroup id="ogone" label="There should be no red" disabled="disabled">
       </optgroup>
       <optgroup id="ogtwo" label="There should be no red">
       </optgroup>
     </select>
+    <script>
+    function doTest() {
+      document.getElementById("ogone").removeAttribute("disabled");
+      setTimeout(function () { document.documentElement.removeAttribute("class"); }, 0);
+    }
+    window.addEventListener("MozReftestInvalidate", doTest);
+    </script>
   </body>
 </html>
--- a/layout/reftests/bugs/315920-29b.html
+++ b/layout/reftests/bugs/315920-29b.html
@@ -3,17 +3,24 @@
   <head>
     <style>
       optgroup {color: red}
       optgroup:disabled {color: green}
       optgroup[disabled]:disabled + optgroup {color: green}
       optgroup:not(:disabled) {color: red}
     </style>
   </head>
-  <body onload='document.getElementById("ogone").setAttribute("disabled", "disabled");'>
+  <body>
     <select size="2">
       <optgroup id="ogone" label="There should be no red">
       </optgroup>
       <optgroup id="ogtwo" label="There should be no red">
       </optgroup>
     </select>
+    <script>
+    function doTest() {
+      document.getElementById("ogone").setAttribute("disabled", "disabled");
+      setTimeout(function () { document.documentElement.removeAttribute("class"); }, 0);
+    }
+    window.addEventListener("MozReftestInvalidate", doTest);
+    </script>
   </body>
 </html>
--- a/layout/reftests/bugs/315920-2a.html
+++ b/layout/reftests/bugs/315920-2a.html
@@ -3,16 +3,23 @@
   <head>
     <style>
       option {color: red}
       option:disabled {color: green}
       option[disabled]:disabled + option {color: green}
       option:not([disabled]):not(:disabled) + option {color: red}
     </style>
   </head>
-  <body onload='var elem = document.getElementById("one");
-                elem.setAttribute("disabled", "disabled");'>
+  <body>
     <select size="2">
       <option id="one">Should be no red</option>
       <option id="two">Should be no red</option>
     </select>
+    <script>
+    function doTest() {
+      var elem = document.getElementById("one");
+      elem.setAttribute("disabled", "disabled");
+      setTimeout(function () { document.documentElement.removeAttribute("class"); }, 0);
+    }
+    window.addEventListener("MozReftestInvalidate", doTest);
+    </script>
   </body>
 </html>
--- a/layout/reftests/bugs/315920-2b.html
+++ b/layout/reftests/bugs/315920-2b.html
@@ -2,15 +2,22 @@
 <html>
   <head>
     <style>
       option {color: green}
       option[selected] {color: red}
       option:not([selected]):not(:default) + option {color: green}
     </style>
   </head>
-  <body onload='document.getElementById("one").removeAttribute("selected");'>
+  <body>
     <select size="2">
       <option id="one" selected="selected">Should be no red</option>
       <option id="two">Should be no red</option>
     </select>
+    <script>
+    function doTest() {
+      document.getElementById("one").removeAttribute("selected");
+      setTimeout(function () { document.documentElement.removeAttribute("class"); }, 0);
+    }
+    window.addEventListener("MozReftestInvalidate", doTest);
+    </script>
   </body>
 </html>
--- a/layout/reftests/bugs/315920-2c.html
+++ b/layout/reftests/bugs/315920-2c.html
@@ -3,16 +3,23 @@
   <head>
     <style>
       option {color: red}
       option:disabled {color: green}
       option[disabled]:not(:enabled) + option {color: green}
       option:not([disabled]):enabled + option {color: red}
     </style>
   </head>
-  <body onload='var elem = document.getElementById("one");
-                elem.setAttribute("disabled", "disabled");'>
+  <body>
     <select size="2">
       <option id="one">Should be no red</option>
       <option id="two">Should be no red</option>
     </select>
+    <script>
+    function doTest() {
+      var elem = document.getElementById("one");
+      elem.setAttribute("disabled", "disabled");
+      setTimeout(function () { document.documentElement.removeAttribute("class"); }, 0);
+    }
+    window.addEventListener("MozReftestInvalidate", doTest);
+    </script>
   </body>
 </html>
--- a/layout/reftests/bugs/315920-30.html
+++ b/layout/reftests/bugs/315920-30.html
@@ -6,22 +6,29 @@
       optgroup {color: red}
       optgroup:disabled {color: green}
       optgroup[disabled]:disabled + optgroup {color: green}
       optgroup:not(:disabled) {color: red}
       optgroup[disabled]:disabled > option:default {color:blue}
       optgroup:disabled > option:default ~ option {color:blue}
     </style>
   </head>
-  <body onload='document.getElementById("ogone").setAttribute("disabled", "disabled");
-                document.getElementById("one").setAttribute("selected", "selected");'>
+  <body>
     <select size="7">
       <optgroup id="ogone" label="There should be no red">
         <option id="one">This should be blue</option>
         <option id="two">This should be blue</option>
       </optgroup>
       <optgroup id="ogtwo" label="There should be no red">
         <option id="three">There should be no red</option>
         <option id="four">There should be no red</option>
       </optgroup>
     </select>
+    <script>
+    function doTest() {
+      document.getElementById("ogone").setAttribute("disabled", "disabled");
+      document.getElementById("one").setAttribute("selected", "selected");
+      setTimeout(function () { document.documentElement.removeAttribute("class"); }, 0);
+    }
+    window.addEventListener("MozReftestInvalidate", doTest);
+    </script>
   </body>
 </html>
--- a/layout/reftests/bugs/315920-3a.html
+++ b/layout/reftests/bugs/315920-3a.html
@@ -3,14 +3,21 @@
   <head>
     <style>
       input {color: red}
       #two { color: green }
       input[disabled]:disabled {color: green}
       input:not([disabled]):not(:disabled) + #two:enabled {color: red}
     </style>
   </head>
-  <body onload='var elem = document.getElementById("one");
-                elem.setAttribute("disabled", "disabled");'>
+  <body>
     <input type="button" id="one" value="Should be no red"/>
     <input type="button" id="two" value="Should be no red"/>
+    <script>
+    function doTest() {
+      var elem = document.getElementById("one");
+      elem.setAttribute("disabled", "disabled");
+      setTimeout(function () { document.documentElement.removeAttribute("class"); }, 0);
+    }
+    window.addEventListener("MozReftestInvalidate", doTest);
+    </script>
   </body>
 </html>
--- a/layout/reftests/bugs/315920-3b.html
+++ b/layout/reftests/bugs/315920-3b.html
@@ -3,14 +3,21 @@
   <head>
     <style>
       input {color: red }
       #two { color: green }
       input[disabled]:disabled {color: green}
       input:not([disabled]):not(:disabled) + #two:enabled {color: red}
     </style>
   </head>
-  <body onload='var elem = document.getElementById("one");
-                elem.setAttribute("disabled", "disabled");'>
+  <body>
     <input type="submit" id="one" value="Should be no red"/>
     <input type="submit" id="two" value="Should be no red"/>
+    <script>
+    function doTest() {
+      var elem = document.getElementById("one");
+      elem.setAttribute("disabled", "disabled");
+      setTimeout(function () { document.documentElement.removeAttribute("class"); }, 0);
+    }
+    window.addEventListener("MozReftestInvalidate", doTest);
+    </script>
   </body>
 </html>
--- a/layout/reftests/bugs/315920-3c.html
+++ b/layout/reftests/bugs/315920-3c.html
@@ -3,14 +3,21 @@
   <head>
     <style>
       input {color: red}
       #two { color: green }
       input[disabled]:not(:enabled) {color: green}
       input:not([disabled]):enabled + #two:enabled {color: red}
     </style>
   </head>
-  <body onload='var elem = document.getElementById("one");
-                elem.setAttribute("disabled", "disabled");'>
+  <body>
     <input type="button" id="one" value="Should be no red"/>
     <input type="button" id="two" value="Should be no red"/>
+    <script>
+    function doTest() {
+      var elem = document.getElementById("one");
+      elem.setAttribute("disabled", "disabled");
+      setTimeout(function () { document.documentElement.removeAttribute("class"); }, 0);
+    }
+    window.addEventListener("MozReftestInvalidate", doTest);
+    </script>
   </body>
 </html>
--- a/layout/reftests/bugs/315920-3d.html
+++ b/layout/reftests/bugs/315920-3d.html
@@ -3,14 +3,21 @@
   <head>
     <style>
       input {color: red }
       #two { color: green }
       input[disabled]:not(:enabled) {color: green}
       input:not([disabled]):enabled + #two:enabled {color: red}
     </style>
   </head>
-  <body onload='var elem = document.getElementById("one");
-                elem.setAttribute("disabled", "disabled");'>
+  <body>
     <input type="submit" id="one" value="Should be no red"/>
     <input type="submit" id="two" value="Should be no red"/>
+    <script>
+    function doTest() {
+      var elem = document.getElementById("one");
+      elem.setAttribute("disabled", "disabled");
+      setTimeout(function () { document.documentElement.removeAttribute("class"); }, 0);
+    }
+    window.addEventListener("MozReftestInvalidate", doTest);
+    </script>
   </body>
 </html>
--- a/layout/reftests/bugs/315920-4.html
+++ b/layout/reftests/bugs/315920-4.html
@@ -3,20 +3,27 @@
   <head>
     <style>
       option {color: red}
       option[disabled] {color: green}
       option:disabled ~ option:not([disabled]):not(:disabled) {color: green}
       option:not(:disabled):not([disabled]) + option:enabled {color: red}
     </style>
   </head>
-  <body onload='var elem0 = document.createElement("option");
-                elem0.setAttribute("disabled", "disabled");
-                var elem1 = document.getElementById("selection");
-                elem1.insertBefore(elem0, elem1.firstChild);
-                document.getElementById("two").setAttribute("disabled","disabled");'>
+  <body>
     <select size="4" id="selection">
       <option id="one">Should be no red</option>
       <option id="two">Should be no red</option>
       <option id="three">Should be no red</option>
     </select>
+    <script>
+    function doTest() {
+      var elem0 = document.createElement("option");
+      elem0.setAttribute("disabled", "disabled");
+      var elem1 = document.getElementById("selection");
+      elem1.insertBefore(elem0, elem1.firstChild);
+      document.getElementById("two").setAttribute("disabled","disabled");
+      setTimeout(function () { document.documentElement.removeAttribute("class"); }, 0);
+    }
+    window.addEventListener("MozReftestInvalidate", doTest);
+    </script>
   </body>
 </html>
--- a/layout/reftests/bugs/315920-5.html
+++ b/layout/reftests/bugs/315920-5.html
@@ -1,19 +1,26 @@
 <!DOCTYPE html>
 <html>
   <head>
     <style>
       option {color: green}
       option[selected]:disabled ~ option:not([disabled]):not(:disabled) {color: red}
     </style>
   </head>
-  <body onload='var e1 = document.getElementById("one");
-                e1.parentNode.removeChild(e1);
-                document.getElementById("zero").setAttribute("selected", "true");'>
+  <body>
     <select size="4" id="selection">
       <option id="zero">Should be no red</option>
       <option id="one" selected="true" disabled="disabled">Should be no red</option>
       <option id="two">Should be no red</option>
       <option id="three">Should be no red</option>
     </select>
+    <script>
+    function doTest() {
+      var e1 = document.getElementById("one");
+      e1.parentNode.removeChild(e1);
+      document.getElementById("zero").setAttribute("selected", "true");
+      setTimeout(function () { document.documentElement.removeAttribute("class"); }, 0);
+    }
+    window.addEventListener("MozReftestInvalidate", doTest);
+    </script>
   </body>
 </html>
--- a/layout/reftests/bugs/315920-6.html
+++ b/layout/reftests/bugs/315920-6.html
@@ -2,16 +2,23 @@
 <html>
   <head>
     <style>
       option {color: red}
       option[selected] {color: green}
       option[selected]:default + option {color: green}
     </style>
   </head>
-  <body onload='var elem = document.getElementById("one");
-                elem.setAttribute("selected", "selected");'>
+  <body>
     <select size="2">
       <option id="one">Should be no red</option>
       <option id="two">Should be no red</option>
     </select>
+    <script>
+    function doTest() {
+      var elem = document.getElementById("one");
+      elem.setAttribute("selected", "selected");
+      setTimeout(function () { document.documentElement.removeAttribute("class"); }, 0);
+    }
+    window.addEventListener("MozReftestInvalidate", doTest);
+    </script>
   </body>
 </html>
--- a/layout/reftests/bugs/315920-7a.html
+++ b/layout/reftests/bugs/315920-7a.html
@@ -2,18 +2,25 @@
 <html>
   <head>
     <style>
       label {color: red}
       input:default + label {color: green}
       input:not(:checked):not([checked]):not(:default) + label {color:green}
     </style>
   </head>
-  <body onload='document.getElementById("one").setAttribute("checked", "true");
-                document.getElementById("two").removeAttribute("checked");'>
+  <body>
     <form>
       <input type="radio" name="group1" id="one" value="1"/>
       <label id="l1" for="one">Should be no red</label><br>
       <input type="radio" name="group1" id="two" value="2" checked="true"/>
       <label id="l2" for="two">Should be no red</label>
     </form>
+    <script>
+    function doTest() {
+      document.getElementById("one").setAttribute("checked", "true");
+      document.getElementById("two").removeAttribute("checked");
+      setTimeout(function () { document.documentElement.removeAttribute("class"); }, 0);
+    }
+    window.addEventListener("MozReftestInvalidate", doTest);
+    </script>
   </body>
 </html>
--- a/layout/reftests/bugs/315920-7b.html
+++ b/layout/reftests/bugs/315920-7b.html
@@ -1,19 +1,26 @@
 <!DOCTYPE html>
 <html>
   <head>
       <style>
         label {color: red}
         input[checked]:default:checked ~ label {color: green}
       </style>
   </head>
-  <body onload='var e1 = document.getElementById("one");
-                e1.setAttribute("checked", "false");
-                document.getElementById("two").removeAttribute("checked");'>
+  <body>
     <form>
       <input type="radio" name="group1" id="one" value="1"/>
       <label for="one">Should be no red</label><br>
       <input type="radio" name="group1" id="two" value="2" checked/>
       <label for="two">Should be no red</label>
     </form>
+    <script>
+    function doTest() {
+      var e1 = document.getElementById("one");
+      e1.setAttribute("checked", "false");
+      document.getElementById("two").removeAttribute("checked");
+      setTimeout(function () { document.documentElement.removeAttribute("class"); }, 0);
+    }
+    window.addEventListener("MozReftestInvalidate", doTest);
+    </script>
   </body>
 </html>
--- a/layout/reftests/bugs/315920-7c.html
+++ b/layout/reftests/bugs/315920-7c.html
@@ -2,17 +2,24 @@
 <html>
   <head>
     <style>
       input ~ label {color: red}
       input:not(:default):not(:checked):not([checked]) ~ label {color:red}
       input[checked]:checked:default ~ label {color: green}
     </style>
   </head>
-  <body onload='document.getElementById("one").setAttribute("checked", "checked");'>
+  <body>
     <form>
       <input type="radio" name="group1" id="one" value="1"/>
       <label for="one">Should be no red</label><br>
       <input type="radio" name="group1" id="two" value="2"/>
       <label for="two">Should be no red</label>
     </form>
+    <script>
+    function doTest() {
+      document.getElementById("one").setAttribute("checked", "checked");
+      setTimeout(function () { document.documentElement.removeAttribute("class"); }, 0);
+    }
+    window.addEventListener("MozReftestInvalidate", doTest);
+    </script>
   </body>
 </html>
--- a/layout/reftests/bugs/315920-8a.html
+++ b/layout/reftests/bugs/315920-8a.html
@@ -2,17 +2,24 @@
 <html>
   <head>
     <style>
       input ~ label {color: red}
       input[checked]:default + label {color: green}
       input:not(:default):not([checked]) + label {color:green}
     </style>
   </head>
-  <body onload='document.getElementById("two").setAttribute("checked", "true");'>
+  <body>
     <form>
       <input type="radio" name="group1" id="one" value="1"/>
       <label for="one">Should be no red</label><br>
       <input type="radio" name="group1" id="two" value="2"/>
       <label for="two">Should be no red</label>
     </form>
+    <script>
+    function doTest() {
+      document.getElementById("two").setAttribute("checked", "true");
+      setTimeout(function () { document.documentElement.removeAttribute("class"); }, 0);
+    }
+    window.addEventListener("MozReftestInvalidate", doTest);
+    </script>
   </body>
 </html>
--- a/layout/reftests/bugs/315920-8b.html
+++ b/layout/reftests/bugs/315920-8b.html
@@ -2,17 +2,24 @@
 <html>
   <head>
     <style>
       label {color: red}
       input[checked]:checked:default + label {color: green}
       input:not(:checked) + label {color: green}
     </style>
   </head>
-  <body onload='document.getElementById("two").setAttribute("checked", "true");'>
+  <body>
     <form>
       <input type="radio" name="group1" id="one" value="1"/>
         <label for="one">Should be no red</label><br>
         <input type="radio" name="group1" id="two" value="2"/>
         <label for="two">Should be no red</label>
     </form>
+    <script>
+    function doTest() {
+      document.getElementById("two").setAttribute("checked", "true");
+      setTimeout(function () { document.documentElement.removeAttribute("class"); }, 0);
+    }
+    window.addEventListener("MozReftestInvalidate", doTest);
+    </script>
   </body>
 </html>
--- a/layout/reftests/bugs/315920-9.html
+++ b/layout/reftests/bugs/315920-9.html
@@ -2,25 +2,32 @@
 <html>
   <head>
     <style>
       label {color: red}
       input[checked]:checked:default ~ label {color: green}
       input:not([checked]):not(:checked) + label {color: red}
     </style>
   </head>
-  <body onload='var form = document.getElementById("form");
-                var input2 = document.createElement("input");
-                input2.setAttribute("type", "radio");
-                input2.setAttribute("id", "two");
-                input2.setAttribute("checked", "true");
-                form.insertBefore(input2, form.firstChild);
-                var label2 = document.createElement("label");
-                label2.setAttribute("for", "two");
-                var text2 = document.createTextNode("Should be no red");
-                label2.appendChild(text2);
-                form.insertBefore(label2, document.getElementById("one"));'>
+  <body>
     <form id="form">
       <input type="radio" name="group1" id="one" value="1"/>
       <label for="one">Should be no red</label>
     </form>
+    <script>
+    function doTest() {
+      var form = document.getElementById("form");
+      var input2 = document.createElement("input");
+      input2.setAttribute("type", "radio");
+      input2.setAttribute("id", "two");
+      input2.setAttribute("checked", "true");
+      form.insertBefore(input2, form.firstChild);
+      var label2 = document.createElement("label");
+      label2.setAttribute("for", "two");
+      var text2 = document.createTextNode("Should be no red");
+      label2.appendChild(text2);
+      form.insertBefore(label2, document.getElementById("one"));
+      setTimeout(function () { document.documentElement.removeAttribute("class"); }, 0);
+    }
+    window.addEventListener("MozReftestInvalidate", doTest);
+    </script>
   </body>
 </html>