Bug 1429744 - Relax a test of StyleRuleAdded events to allow for the possibility that style rules could arrive before import rules. r=emilio, a=test-only
authorBrad Werth <bwerth@mozilla.com>
Fri, 12 Jan 2018 08:39:50 -0800
changeset 454482 0a7b0fd5bf128263b4869d896909ce0b1deb14a9
parent 454481 68f206b648afc79e87bcd01e4d341498fa1794af
child 454483 3221e647134d970526ca63fa24cb3c5b3c4b4cb2
push id1648
push usermtabara@mozilla.com
push dateThu, 01 Mar 2018 12:45:47 +0000
treeherdermozilla-release@cbb9688c2eeb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemilio, test-only
bugs1429744
milestone59.0
Bug 1429744 - Relax a test of StyleRuleAdded events to allow for the possibility that style rules could arrive before import rules. r=emilio, a=test-only MozReview-Commit-ID: COIK852QzUm The test also verifies that when an import rule event arrives, that the rule has a loaded stylesheet.
layout/inspector/tests/chrome/test_parseStyleSheetObservers.html
--- a/layout/inspector/tests/chrome/test_parseStyleSheetObservers.html
+++ b/layout/inspector/tests/chrome/test_parseStyleSheetObservers.html
@@ -51,40 +51,39 @@ function test1Result() {
 
   document.removeEventListener("StyleRuleAdded", countingAddListener, listenerOptions);
   document.removeEventListener("StyleRuleRemoved", countingRemoveListener, listenerOptions);
 
   SimpleTest.executeSoon(test2Setup);
 }
 
 // Test 2: Import rules should be deferred until sheet is actually loaded.
-// We'll test this by parsing an import rule followed by style rule, then
-// ensuring that the event for the style rule lands first.
+// When the import rule lands, the associated sheet should be loaded.
 // This test is constructed with async functions so we can await an event that
 // might take awhile to arrive (but is guaranteed to arrive, per spec).
 let foundImport = false;
 let foundStyle = false;
 let styleFirstAddProcessor = function(event) {
   info("styleFirstAddProcessor: called with event "+ event.rule.cssText);
   if (event.rule.type == CSSRule.IMPORT_RULE) {
     foundImport = true;
+    isnot(event.rule.styleSheet, null, "Test 2: import rule has stylesheet loaded.");
   } else if (event.rule.type == CSSRule.STYLE_RULE) {
     foundStyle = true;
-    is(foundImport, false, "Test 2: The style rule arrived before the import rule.");
   }
-  return foundImport;
+  return foundImport && foundStyle;
 };
 
 async function test2Setup() {
   info("test2Setup: called");
 
-  // Create a Promise to watch for two StyleRuleAdded events. The first invocation should
-  // be the style rule, and the second should be the import rule. We use the same processor
+  // Create a Promise to watch for two StyleRuleAdded events. The first invocation will
+  // likely be the style rule, though this is not guaranteed. We use the same processor
   // for both events, but the processor will only return true (completing the Promise) when
-  // the import rule has been processed.
+  // both rules have been processed.
   let gotAllStyleRuleAddedEvents = ContentTaskUtils.waitForEvent(document,
     "StyleRuleAdded", true, styleFirstAddProcessor);
 
   InspectorUtils.parseStyleSheet(sheet, "@import url('imported_no_op.css'); p {color: purple;}");
   is(sheet.cssRules.length, 2, "Test 2: Stylesheet now has 2 rules.");
 
   // Await and then process the events we expect to arrive.
   await gotAllStyleRuleAddedEvents;