Bug 1337674 part 1 - Adjust test_load_events_on_stylesheets to not double finish even with error. r?heycam draft
authorXidorn Quan <me@upsuper.org>
Wed, 15 Feb 2017 11:19:46 +1100
changeset 485139 35c7a8e635a4d736090b5548f3b1cbc6cc6f5d0b
parent 485079 e22a2d221740303c451aac1645654d0ccc7f5f52
child 485140 865d957c70089351305a835533a198670560383f
push id45643
push userxquan@mozilla.com
push dateThu, 16 Feb 2017 06:37:46 +0000
reviewersheycam
bugs1337674
milestone54.0a1
Bug 1337674 part 1 - Adjust test_load_events_on_stylesheets to not double finish even with error. r?heycam MozReview-Commit-ID: 9lodQzZkIBG
layout/style/test/test_load_events_on_stylesheets.html
--- a/layout/style/test/test_load_events_on_stylesheets.html
+++ b/layout/style/test/test_load_events_on_stylesheets.html
@@ -48,29 +48,37 @@ is(pendingEventCounter, 0, "There should
 window.onmessage = function() {
   messagePosted = true;
   // There are 4 pending events: two from the two direct example.com loads,
   // and 2 from the two data:text/css loads that import things
   is(pendingEventCounter, 4, "Load event for sheet should have fired");
 }
 window.postMessage("", "*");
 
+function checkSheetComplete(sheet, length) {
+  try {
+    is(sheet.cssRules.length, length, `Should be loaded with ${length} rule(s)`);
+  } catch (e) {
+    ok(false, "Sheet has not been loaded completely");
+  }
+}
+
 document.write('<link rel="stylesheet" href="data:text/css,*{}"\
                 onload="--pendingEventCounter;\
                         ok(true, \'Load event firing on basic stylesheet\')"\
                 onerror="--pendingEventCounter;\
                         ok(false, \'Error event firing on basic stylesheet\')">');
 
 // Make sure we have that second stylesheet
 is(document.styleSheets.length, 3, "Should have three stylesheets");
 
 // Make sure that the second stylesheet is all loaded
 // If we ever switch away from sync loading of already-complete sheets, this
 // test will need adjusting
-is(document.styleSheets[2].cssRules.length, 1, "Should have one rule");
+checkSheetComplete(document.styleSheets[2], 1);
 
 // Make sure the load event for that stylesheet has not fired yet
 is(pendingEventCounter, 1, "There should be one pending event");
 
 ++pendingEventCounter;
 document.write('<style\
                 onload="--pendingEventCounter;\
                         ok(true, \'Load event firing on inline stylesheet\')"\
@@ -112,17 +120,17 @@ link.onerror = function() { --pendingEve
 document.body.appendChild(link);
 
 // Make sure we have that last stylesheet
 is(document.styleSheets.length, 7, "Should have seven stylesheets here");
 
 // Make sure that the sixth stylesheet is all loaded
 // If we ever switch away from sync loading of already-complete sheets, this
 // test will need adjusting
-is(document.styleSheets[6].cssRules.length, 1, "Should have one rule");
+checkSheetComplete(document.styleSheets[6], 1);
 
 ++pendingEventCounter;
 link = document.createElement("link");
 link.rel = "stylesheet";
 link.href = "data:text/css,@import url('data:text/css,*{}')";
 link.onload = function() { --pendingEventCounter;
   ok(true, 'Load event firing on external stylesheet');
 };