Bug 1337674 part 1 - Adjust test_load_events_on_stylesheets to not double finish even with error. r?heycam
MozReview-Commit-ID: 9lodQzZkIBG
--- 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');
};