Bug 1324135 - Wait 300ms after the first IntersectionObserver notification to prevent intermittent test failure. r=jet, a=test-only
authorTobias Schneider <schneider@jancona.com>
Thu, 04 May 2017 13:14:34 -0700
changeset 393833 b0a7956aa594859ce4eb1311c4319d8aa4a5b6dd
parent 393832 c097727dc38532dfac5370dc7a1023ca1ba1ef40
child 393834 9f86465621ed869b49a6c2d925186fa9b6424407
push id7272
push userryanvm@gmail.com
push dateThu, 04 May 2017 22:37:00 +0000
treeherdermozilla-beta@6022f5353130 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjet, test-only
bugs1324135
milestone54.0
Bug 1324135 - Wait 300ms after the first IntersectionObserver notification to prevent intermittent test failure. r=jet, a=test-only
dom/base/test/test_intersectionobservers.html
--- a/dom/base/test/test_intersectionobservers.html
+++ b/dom/base/test/test_intersectionobservers.html
@@ -364,57 +364,57 @@ limitations under the License.
           function(done) {
             io.observe(targetEl1);
             spy.waitForNotification(function() {
               expect(spy.callCount).to.be(1);
               var records = sortRecords(spy.lastCall.args[0]);
               expect(records.length).to.be(1);
               expect(records[0].intersectionRatio).to.be(1);
               done();
-            }, ASYNC_TIMEOUT);
+            });
           },
           function(done) {
             targetEl1.style.display = 'none';
             spy.waitForNotification(function() {
               expect(spy.callCount).to.be(2);
               var records = sortRecords(spy.lastCall.args[0]);
               expect(records.length).to.be(1);
               expect(records[0].intersectionRatio).to.be(0);
               done();
-            }, ASYNC_TIMEOUT);
+            });
           },
           function(done) {
             targetEl1.style.display = 'block';
             spy.waitForNotification(function() {
               expect(spy.callCount).to.be(3);
               var records = sortRecords(spy.lastCall.args[0]);
               expect(records.length).to.be(1);
               expect(records[0].intersectionRatio).to.be(1);
               done();
-            }, ASYNC_TIMEOUT);
+            });
           },
           function(done) {
             rootEl.style.display = 'none';
             spy.waitForNotification(function() {
               expect(spy.callCount).to.be(4);
               var records = sortRecords(spy.lastCall.args[0]);
               expect(records.length).to.be(1);
               expect(records[0].intersectionRatio).to.be(0);
               done();
-            }, ASYNC_TIMEOUT);
+            });
           },
           function(done) {
             rootEl.style.display = 'block';
             spy.waitForNotification(function() {
               expect(spy.callCount).to.be(5);
               var records = sortRecords(spy.lastCall.args[0]);
               expect(records.length).to.be(1);
               expect(records[0].intersectionRatio).to.be(1);
               done();
-            }, ASYNC_TIMEOUT);
+            });
           },
         ], done);
       });
 
 
       it('handles container elements with non-visible overflow',
           function(done) {
 
@@ -425,37 +425,37 @@ limitations under the License.
           function(done) {
             io.observe(targetEl1);
             spy.waitForNotification(function() {
               expect(spy.callCount).to.be(1);
               var records = sortRecords(spy.lastCall.args[0]);
               expect(records.length).to.be(1);
               expect(records[0].intersectionRatio).to.be(1);
               done();
-            }, ASYNC_TIMEOUT);
+            });
           },
           function(done) {
             targetEl1.style.left = '-40px';
             spy.waitForNotification(function() {
               expect(spy.callCount).to.be(2);
               var records = sortRecords(spy.lastCall.args[0]);
               expect(records.length).to.be(1);
               expect(records[0].intersectionRatio).to.be(0);
               done();
-            }, ASYNC_TIMEOUT);
+            });
           },
           function(done) {
             parentEl.style.overflow = 'visible';
             spy.waitForNotification(function() {
               expect(spy.callCount).to.be(3);
               var records = sortRecords(spy.lastCall.args[0]);
               expect(records.length).to.be(1);
               expect(records[0].intersectionRatio).to.be(1);
               done();
-            }, ASYNC_TIMEOUT);
+            });
           }
         ], done);
       });
 
 
       it('observes one target at a single threshold correctly', function(done) {
 
         var spy = sinon.spy();
@@ -466,44 +466,44 @@ limitations under the License.
             targetEl1.style.left = '-5px';
             io.observe(targetEl1);
             spy.waitForNotification(function() {
               expect(spy.callCount).to.be(1);
               var records = sortRecords(spy.lastCall.args[0]);
               expect(records.length).to.be(1);
               expect(records[0].intersectionRatio).to.be.greaterThan(0.5);
               done();
-            }, ASYNC_TIMEOUT);
+            });
           },
           function(done) {
             targetEl1.style.left = '-15px';
             spy.waitForNotification(function() {
               expect(spy.callCount).to.be(2);
               var records = sortRecords(spy.lastCall.args[0]);
               expect(records.length).to.be(1);
               expect(records[0].intersectionRatio).to.be.lessThan(0.5);
               done();
-            }, ASYNC_TIMEOUT);
+            });
           },
           function(done) {
             targetEl1.style.left = '-25px';
             callDelayed(function() {
               expect(spy.callCount).to.be(2);
               done();
             }, ASYNC_TIMEOUT);
           },
           function(done) {
             targetEl1.style.left = '-10px';
             spy.waitForNotification(function() {
               expect(spy.callCount).to.be(3);
               var records = sortRecords(spy.lastCall.args[0]);
               expect(records.length).to.be(1);
               expect(records[0].intersectionRatio).to.be(0.5);
               done();
-            }, ASYNC_TIMEOUT);
+            });
           }
         ], done);
 
       });
 
 
       it('observes multiple targets at multiple thresholds correctly',
           function(done) {
@@ -529,17 +529,17 @@ limitations under the License.
               expect(spy.callCount).to.be(1);
               var records = sortRecords(spy.lastCall.args[0]);
               expect(records.length).to.be(2);
               expect(records[0].target).to.be(targetEl1);
               expect(records[0].intersectionRatio).to.be(0.25);
               expect(records[1].target).to.be(targetEl2);
               expect(records[1].intersectionRatio).to.be(0.75);
               done();
-            }, ASYNC_TIMEOUT);
+            });
           },
           function(done) {
             targetEl1.style.top = '0px';
             targetEl1.style.left = '-5px';
             targetEl2.style.top = '-15px';
             targetEl2.style.left = '0px';
             targetEl3.style.top = '0px';
             targetEl3.style.left = '195px';
@@ -549,17 +549,17 @@ limitations under the License.
               expect(records.length).to.be(3);
               expect(records[0].target).to.be(targetEl1);
               expect(records[0].intersectionRatio).to.be(0.75);
               expect(records[1].target).to.be(targetEl2);
               expect(records[1].intersectionRatio).to.be(0.25);
               expect(records[2].target).to.be(targetEl3);
               expect(records[2].intersectionRatio).to.be(0.25);
               done();
-            }, ASYNC_TIMEOUT);
+            });
           },
           function(done) {
             targetEl1.style.top = '0px';
             targetEl1.style.left = '5px';
             targetEl2.style.top = '-25px';
             targetEl2.style.left = '0px';
             targetEl3.style.top = '0px';
             targetEl3.style.left = '185px';
@@ -569,33 +569,33 @@ limitations under the License.
               expect(records.length).to.be(3);
               expect(records[0].target).to.be(targetEl1);
               expect(records[0].intersectionRatio).to.be(1);
               expect(records[1].target).to.be(targetEl2);
               expect(records[1].intersectionRatio).to.be(0);
               expect(records[2].target).to.be(targetEl3);
               expect(records[2].intersectionRatio).to.be(0.75);
               done();
-            }, ASYNC_TIMEOUT);
+            });
           },
           function(done) {
             targetEl1.style.top = '0px';
             targetEl1.style.left = '15px';
             targetEl2.style.top = '-35px';
             targetEl2.style.left = '0px';
             targetEl3.style.top = '0px';
             targetEl3.style.left = '175px';
             spy.waitForNotification(function() {
               expect(spy.callCount).to.be(4);
               var records = sortRecords(spy.lastCall.args[0]);
               expect(records.length).to.be(1);
               expect(records[0].target).to.be(targetEl3);
               expect(records[0].intersectionRatio).to.be(1);
               done();
-            }, ASYNC_TIMEOUT);
+            });
           }
         ], done);
       });
 
 
       it('handles rootMargin properly', function(done) {
 
         parentEl.style.overflow = 'visible';
@@ -704,47 +704,47 @@ limitations under the License.
             io.observe(targetEl2);
             spy.waitForNotification(function() {
               expect(spy.callCount).to.be(1);
               var records = sortRecords(spy.lastCall.args[0]);
               expect(records.length).to.be(1);
               expect(records[0].intersectionRatio).to.be(0);
               expect(records[0].target).to.be(targetEl2);
               done();
-            }, ASYNC_TIMEOUT);
+            });
           },
           function(done) {
             targetEl1.style.top = '0px';
             targetEl1.style.left = '-20px';
             targetEl2.style.top = '-21px';
             targetEl2.style.left = '0px';
             spy.waitForNotification(function() {
               expect(spy.callCount).to.be(2);
               var records = sortRecords(spy.lastCall.args[0]);
               expect(records.length).to.be(2);
               expect(records[0].intersectionRatio).to.be(0);
               expect(records[0].target).to.be(targetEl1);
               expect(records[1].intersectionRatio).to.be(0);
               expect(records[1].target).to.be(targetEl2);
               done();
-            }, ASYNC_TIMEOUT);
+            });
           },
           function(done) {
             targetEl1.style.top = '-20px';
             targetEl1.style.left = '200px';
             targetEl2.style.top = '200px';
             targetEl2.style.left = '200px';
             spy.waitForNotification(function() {
               expect(spy.callCount).to.be(3);
               var records = sortRecords(spy.lastCall.args[0]);
               expect(records.length).to.be(1);
               expect(records[0].intersectionRatio).to.be(0);
               expect(records[0].target).to.be(targetEl2);
               done();
-            }, ASYNC_TIMEOUT);
+            });
           },
           function(done) {
             targetEl3.style.top = '20px';
             targetEl3.style.left = '-20px';
             targetEl4.style.top = '-20px';
             targetEl4.style.left = '20px';
             io.observe(targetEl3);
             io.observe(targetEl4);
@@ -752,17 +752,17 @@ limitations under the License.
               expect(spy.callCount).to.be(4);
               var records = sortRecords(spy.lastCall.args[0]);
               expect(records.length).to.be(2);
               expect(records[0].intersectionRatio).to.be(0);
               expect(records[0].target).to.be(targetEl3);
               expect(records[1].intersectionRatio).to.be(0);
               expect(records[1].target).to.be(targetEl4);
               done();
-            }, ASYNC_TIMEOUT);
+            });
           }
         ], done);
 
       });
 
 
       it('handles zero-size targets within the root coordinate space',
           function(done) {
@@ -794,61 +794,61 @@ limitations under the License.
             io.observe(targetEl1);
             callDelayed(done, 0);
           },
           function(done) {
             document.getElementById('fixtures').appendChild(rootEl);
             callDelayed(function() {
               expect(spy.callCount).to.be(0);
               done();
-            }, ASYNC_TIMEOUT);
+            });
           },
           function(done) {
             parentEl.insertBefore(targetEl1, targetEl2);
             spy.waitForNotification(function() {
               expect(spy.callCount).to.be(1);
               var records = sortRecords(spy.lastCall.args[0]);
               expect(records.length).to.be(1);
               expect(records[0].intersectionRatio).to.be(1);
               expect(records[0].target).to.be(targetEl1);
               done();
-            }, ASYNC_TIMEOUT);
+            });
           },
           function(done) {
             grandParentEl.remove();
             spy.waitForNotification(function() {
               expect(spy.callCount).to.be(2);
               var records = sortRecords(spy.lastCall.args[0]);
               expect(records.length).to.be(1);
               expect(records[0].intersectionRatio).to.be(0);
               expect(records[0].target).to.be(targetEl1);
               done();
-            }, ASYNC_TIMEOUT);
+            });
           },
           function(done) {
             rootEl.appendChild(targetEl1);
             spy.waitForNotification(function() {
               expect(spy.callCount).to.be(3);
               var records = sortRecords(spy.lastCall.args[0]);
               expect(records.length).to.be(1);
               expect(records[0].intersectionRatio).to.be(1);
               expect(records[0].target).to.be(targetEl1);
               done();
-            }, ASYNC_TIMEOUT);
+            });
           },
           function(done) {
             rootEl.remove();
             spy.waitForNotification(function() {
               expect(spy.callCount).to.be(4);
               var records = sortRecords(spy.lastCall.args[0]);
               expect(records.length).to.be(1);
               expect(records[0].intersectionRatio).to.be(0);
               expect(records[0].target).to.be(targetEl1);
               done();
-            }, ASYNC_TIMEOUT);
+            });
           }
         ], done);
       });
 
 
       it('handles sub-root element scrolling', function(done) {
         io = new IntersectionObserver(function(records) {
           expect(records.length).to.be(1);
@@ -893,20 +893,22 @@ limitations under the License.
 
       it('triggers only once if observed multiple times (and does not crash when collected)', function(done) {
         var spy = sinon.spy();
         io = new IntersectionObserver(spy, {root: rootEl});
         io.observe(targetEl1);
         io.observe(targetEl1);
         io.observe(targetEl1);
 
-        callDelayed(function () {
-          expect(spy.callCount).to.be(1);
-          done();
-        }, ASYNC_TIMEOUT * 3);
+        spy.waitForNotification(function() {
+          callDelayed(function () {
+            expect(spy.callCount).to.be(1);
+            done();
+          }, ASYNC_TIMEOUT);
+        });
       });
 
     });
 
     describe('observe subframe', function () {
       
       it('should not trigger if target and root are not in the same document',
           function(done) {
@@ -1002,30 +1004,30 @@ limitations under the License.
               expect(spy.callCount).to.be(1);
               var records = sortRecords(spy.lastCall.args[0]);
               expect(records.length).to.be(2);
               expect(records[0].target).to.be(targetEl1);
               expect(records[0].intersectionRatio).to.be(1);
               expect(records[1].target).to.be(targetEl2);
               expect(records[1].intersectionRatio).to.be(1);
               done();
-            }, ASYNC_TIMEOUT);
+            });
           },
           function(done) {
             io.unobserve(targetEl1);
             targetEl1.style.top = targetEl2.style.top = '0px';
             targetEl1.style.left = targetEl2.style.left = '-40px';
             spy.waitForNotification(function() {
               expect(spy.callCount).to.be(2);
               var records = sortRecords(spy.lastCall.args[0]);
               expect(records.length).to.be(1);
               expect(records[0].target).to.be(targetEl2);
               expect(records[0].intersectionRatio).to.be(0);
               done();
-            }, ASYNC_TIMEOUT);
+            });
           },
           function(done) {
             io.unobserve(targetEl2);
             targetEl1.style.top = targetEl2.style.top = '0px';
             targetEl1.style.left = targetEl2.style.left = '0px';
             callDelayed(function() {
               expect(spy.callCount).to.be(2);
               done();
@@ -1054,26 +1056,26 @@ limitations under the License.
               expect(spy.callCount).to.be(1);
               var records = sortRecords(spy.lastCall.args[0]);
               expect(records.length).to.be(2);
               expect(records[0].target).to.be(targetEl1);
               expect(records[0].intersectionRatio).to.be(1);
               expect(records[1].target).to.be(targetEl2);
               expect(records[1].intersectionRatio).to.be(1);
               done();
-            }, ASYNC_TIMEOUT);
+            });
           },
           function(done) {
             io.disconnect();
             targetEl1.style.top = targetEl2.style.top = '0px';
             targetEl1.style.left = targetEl2.style.left = '-40px';
             callDelayed(function() {
               expect(spy.callCount).to.be(1);
               done();
-            }, ASYNC_TIMEOUT);
+            });
           }
         ], done);
 
       });
 
     });
 
   });