Bug 1354163 - Wait until there are intersection records to observe. Prevents an intermittent test failure. r=jet, a=test-only
authorTobias Schneider <schneider@jancona.com>
Fri, 14 Apr 2017 16:08:09 -0700
changeset 396167 9f86465621ed869b49a6c2d925186fa9b6424407
parent 396166 b0a7956aa594859ce4eb1311c4319d8aa4a5b6dd
child 396168 c45159d6fe1fb87ee4411ec1043a533e2c81866b
push id1468
push userasasaki@mozilla.com
push dateMon, 05 Jun 2017 19:31:07 +0000
treeherdermozilla-release@0641fc6ee9d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjet, test-only
bugs1354163
milestone54.0
Bug 1354163 - Wait until there are intersection records to observe. Prevents an 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
@@ -959,39 +959,41 @@ limitations under the License.
         targetEl4.src = "http://example.org/tests/dom/base/test/intersectionobserver_cross_domain_iframe.html";
 
       });
     
     });
 
     describe('takeRecords', function() {
 
-      it('supports getting records before the callback is invoked',
-          function(done) {
+      it('supports getting records before the callback is invoked', function(done) {
 
         var lastestRecords = [];
         io = new IntersectionObserver(function(records) {
           lastestRecords = lastestRecords.concat(records);
         }, {root: rootEl});
         io.observe(targetEl1);
 
-        window.requestAnimationFrame && requestAnimationFrame(function() {
+        window.requestAnimationFrame && requestAnimationFrame(function wait() {
           lastestRecords = lastestRecords.concat(io.takeRecords());
+          if (!lastestRecords.length) {
+            requestAnimationFrame(wait);
+            return;
+          }
+          callDelayed(function() {
+            expect(lastestRecords.length).to.be(1);
+            expect(lastestRecords[0].intersectionRatio).to.be(1);
+            done();
+          }, ASYNC_TIMEOUT);
         });
-
-        callDelayed(function() {
-          expect(lastestRecords.length).to.be(1);
-          expect(lastestRecords[0].intersectionRatio).to.be(1);
-          done();
-        }, ASYNC_TIMEOUT);
+        
       });
 
     });
 
-
     describe('unobserve', function() {
 
       it('removes targets from the internal store', function(done) {
 
         var spy = sinon.spy();
         io = new IntersectionObserver(spy, {root: rootEl});
 
         runSequence([