Bug 1369395 - Change test_intersectionobservers.html to put test callbacks through the event queue twice to ensure that we get processed after any relevant intersection callbacks. r=mstange
authorMatt Woodrow <mwoodrow@mozilla.com>
Thu, 31 May 2018 12:15:10 +1200
changeset 476816 c0c1dea29b1728bc69f13dd4cf0f2eb9756f29bf
parent 476815 f7a132050e9608f3ebbb1b45123a1847084d2940
child 476817 60e4f650a3eb3626a1daaeec1004b28365086f9b
push id9374
push userjlund@mozilla.com
push dateMon, 18 Jun 2018 21:43:20 +0000
treeherdermozilla-beta@160e085dfb0b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstange
bugs1369395
milestone62.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1369395 - Change test_intersectionobservers.html to put test callbacks through the event queue twice to ensure that we get processed after any relevant intersection callbacks. r=mstange MozReview-Commit-ID: Ad5WCWQK4GU
dom/base/test/test_intersectionobservers.html
--- a/dom/base/test/test_intersectionobservers.html
+++ b/dom/base/test/test_intersectionobservers.html
@@ -51,31 +51,26 @@ limitations under the License.
   function it(msg, fn) {
     tests.push({
       msg: `${msg} [${curDescribeMsg}]`,
       fn: fn
     });
   }
 
   var callbacks = [];
-  function callDelayed(fn, delay) {
-    callbacks.push({
-      fn: fn,
-      time: +new Date() + delay
-    });
+  function callDelayed(fn) {
+    callbacks.push(fn);
   }
 
   requestAnimationFrame(function tick() {
     var i = callbacks.length;
     while (i--) {
       var cb = callbacks[i];
-      if (+new Date() >= cb.time) {
-        SimpleTest.executeSoon(cb.fn);
-        callbacks.splice(i, 1);
-      }
+      SimpleTest.executeSoon(function() { SimpleTest.executeSoon(cb) });
+      callbacks.splice(i, 1);
     }
     requestAnimationFrame(tick);
   });
 
   function expect(val) {
     return {
       to: {
         throwException: function (regexp) {
@@ -328,32 +323,32 @@ limitations under the License.
         var spy = sinon.spy();
         io = new IntersectionObserver(spy, {root: rootEl});
 
         targetEl2.style.top = '-40px';
         io.observe(targetEl2);
         callDelayed(function() {
           expect(spy.callCount).to.be(1);
           done();
-        }, ASYNC_TIMEOUT);
+        });
       });
 
 
       it('does not trigger if target is not a descendant of the intersection root in the containing block chain',
           function(done) {
 
         var spy = sinon.spy();
         io = new IntersectionObserver(spy, {root: parentEl});
 
         parentEl.style.position = 'static';
         io.observe(targetEl2);
         callDelayed(function() {
           expect(spy.callCount).to.be(0);
           done();
-        }, ASYNC_TIMEOUT);
+        });
       });
 
       it('triggers if target or root becomes invisible',
           function(done) {
 
         var spy = sinon.spy();
         io = new IntersectionObserver(spy, {root: rootEl});
 
@@ -480,17 +475,17 @@ limitations under the License.
               done();
             });
           },
           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);
@@ -804,24 +799,24 @@ limitations under the License.
         targetEl1.remove();
 
         var spy = sinon.spy();
         io = new IntersectionObserver(spy, {root: rootEl});
 
         runSequence([
           function(done) {
             io.observe(targetEl1);
-            callDelayed(done, 0);
+            callDelayed(done);
           },
           function(done) {
             document.getElementById('fixtures').appendChild(rootEl);
             callDelayed(function() {
               expect(spy.callCount).to.be(1);
               done();
-            }, ASYNC_TIMEOUT);
+            });
           },
           function(done) {
             parentEl.insertBefore(targetEl1, targetEl2);
             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(1);
@@ -871,17 +866,17 @@ limitations under the License.
           expect(records.length).to.be(1);
           expect(records[0].intersectionRatio).to.be(1);
           done();
         }, {root: rootEl});
 
         io.observe(targetEl3);
         callDelayed(function() {
           parentEl.scrollLeft = 40;
-        }, 0);
+        });
       });
 
 
       it('supports CSS transitions and transforms', function(done) {
 
         targetEl1.style.top = '220px';
         targetEl1.style.left = '220px';
 
@@ -895,17 +890,17 @@ limitations under the License.
           expect(records.length).to.be(1);
           expect(records[0].intersectionRatio).to.be(1);
           done();
         }, {root: rootEl, threshold: [1]});
 
         io.observe(targetEl1);
         callDelayed(function() {
           targetEl1.style.transform = 'translateX(-40px) translateY(-40px)';
-        }, 0);
+        });
       });
 
 
       it('uses the viewport when no root is specified', function(done) {
         window.onmessage = function (e) {
           expect(e.data).to.be.ok();
           win.close();
           done();
@@ -920,17 +915,17 @@ limitations under the License.
         io.observe(targetEl1);
         io.observe(targetEl1);
         io.observe(targetEl1);
 
         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',
@@ -940,17 +935,17 @@ limitations under the License.
         io = new IntersectionObserver(spy, {root: rootEl});
 
         targetEl4.onload = function () {
           targetEl5 = targetEl4.contentDocument.getElementById('target5');
           io.observe(targetEl5);
           callDelayed(function() {
             expect(spy.callCount).to.be(0);
             done();
-          }, ASYNC_TIMEOUT);
+          });
         }
 
         targetEl4.src = "intersectionobserver_iframe.html";
       
       });
 
       it('boundingClientRect matches target.getBoundingClientRect() for an element inside an iframe',
           function(done) {
@@ -1000,17 +995,17 @@ limitations under the License.
           if (!lastestRecords.length) {
             requestAnimationFrame(wait);
             return;
           }
           callDelayed(function() {
             expect(lastestRecords.length).to.be(1);
             expect(lastestRecords[0].intersectionRatio).to.be(1);
             done();
-          }, ASYNC_TIMEOUT);
+          });
         });
         
       });
 
     });
 
     describe('unobserve', function() {
 
@@ -1051,17 +1046,17 @@ limitations under the License.
           },
           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();
-            }, ASYNC_TIMEOUT);
+            });
           }
         ], done);
 
       });
 
     });
 
     describe('disconnect', function() {
@@ -1090,17 +1085,17 @@ limitations under the License.
           },
           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);
 
       });
 
     });
 
   });