Bug 1151421 Part 3: Update tests of pageYOffset/scrollY to round off when checking expected results. draft
authorBrad Werth <bwerth@mozilla.com>
Thu, 16 Mar 2017 12:05:56 -0700
changeset 500159 42394595c8870fa695d04ca36415458bcf7a0fa5
parent 500158 138b2f7c1c1b98c1b5074557d4e8214f9d81bb96
child 549556 b74816efbf38b0f71fa0641247f51d01e5026f93
push id49635
push userbwerth@mozilla.com
push dateThu, 16 Mar 2017 19:06:48 +0000
bugs1151421
milestone55.0a1
Bug 1151421 Part 3: Update tests of pageYOffset/scrollY to round off when checking expected results. MozReview-Commit-ID: JDS5l06FAaf
docshell/test/navigation/file_scrollRestoration.html
docshell/test/test_bug1186774.html
docshell/test/test_bug590573.html
docshell/test/test_bug653741.html
docshell/test/test_bug662170.html
dom/base/test/test_viewport_scroll.html
dom/browser-element/mochitest/browserElement_ScrollEvent.js
dom/tests/mochitest/general/test_domWindowUtils_scrollXY.html
layout/forms/test/test_bug562447.html
layout/forms/test/test_bug564115.html
--- a/docshell/test/navigation/file_scrollRestoration.html
+++ b/docshell/test/navigation/file_scrollRestoration.html
@@ -21,17 +21,17 @@
             history.scrollRestoration = "auto";
             opener.ok(history.scrollRestoration, "auto", "Valid enum value should change the value of an attribute.");
             document.getElementById("bottom").scrollIntoView();
             window.location.reload(false);
             break;
           }
           case 2: {
             opener.is(event.persisted, false, "Shouldn't have persisted session history entry.");
-            opener.isnot(window.scrollY, 0, "Should have restored scrolling.");
+            opener.isnot(Math.round(window.scrollY), 0, "Should have restored scrolling.");
             opener.is(history.scrollRestoration, "auto", "Should have the same scrollRestoration as before reload.");
             history.scrollRestoration = "manual";
             window.onunload = function() {} // Disable bfcache.
             window.location.reload(false);
             break;
           }
           case 3: {
             opener.is(event.persisted, false, "Shouldn't have persisted session history entry.");
@@ -40,61 +40,61 @@
             document.getElementById("bottom").scrollIntoView();
             window.onunload = null; // Should get bfcache behavior.
             opener.setTimeout("testWindow.history.back();", 250);
             window.location.href = 'data:text/html,';
             break;
           }
           case 4: {
             opener.is(event.persisted, true, "Should have persisted session history entry.");
-            opener.isnot(window.scrollY, 0, "Should have kept the old scroll position.");
+            opener.isnot(Math.round(window.scrollY), 0, "Should have kept the old scroll position.");
             opener.is(history.scrollRestoration, "manual", "Should have the same scrollRestoration as before reload.");
             window.scrollTo(0, 0);
             window.location.hash = "hash";
             requestAnimationFrame(test);
             break;
           }
           case 5: {
-            opener.isnot(window.scrollY, 0, "Should have scrolled to #hash.");
+            opener.isnot(Math.round(window.scrollY), 0, "Should have scrolled to #hash.");
             opener.is(history.scrollRestoration, "manual", "Should have the same scrollRestoration mode as before fragment navigation.");
             window.onunload = function() {} // Disable bfcache.
             opener.setTimeout("is(testWindow.history.scrollRestoration, 'auto'); testWindow.history.back();", 250);
             window.location.href = 'data:text/html,';
             break;
           }
           case 6: {
             opener.is(event.persisted, false, "Shouldn't have persisted session history entry.");
             opener.is(window.scrollY, 0, "Shouldn't have kept the old scroll position.");
             opener.is(history.scrollRestoration, "manual", "Should have the same scrollRestoration mode as before fragment navigation.");
             history.scrollRestoration = "auto";
             document.getElementById("bottom").scrollIntoView();
             history.pushState({ state: "state1" }, "state1");
             history.pushState({ state: "state2" }, "state2");
             window.scrollTo(0, 0);
             history.back();
-            opener.isnot(window.scrollY, 0, "Should have scrolled back to the state1's position");
+            opener.isnot(Math.round(window.scrollY), 0, "Should have scrolled back to the state1's position");
             opener.is(history.state.state, "state1", "Unexpected state.");
 
             history.scrollRestoration = "manual";
             document.getElementById("bottom").scrollIntoView();
             history.pushState({ state: "state3" }, "state3");
             history.pushState({ state: "state4" }, "state4");
             window.scrollTo(0, 0);
             history.back();
-            opener.is(window.scrollY, 0, "Shouldn't have scrolled back to the state3's position");
+            opener.is(Math.round(window.scrollY), 0, "Shouldn't have scrolled back to the state3's position");
             opener.is(history.state.state, "state3", "Unexpected state.");
 
             history.pushState({ state: "state5" }, "state5");
             history.scrollRestoration = "auto";
             document.getElementById("bottom").scrollIntoView();
-            opener.isnot(window.scrollY, 0, "Should have scrolled to 'bottom'.");
+            opener.isnot(Math.round(window.scrollY), 0, "Should have scrolled to 'bottom'.");
             history.back();
             window.scrollTo(0, 0);
             history.forward();
-            opener.isnot(window.scrollY, 0, "Should have scrolled back to the state5's position");
+            opener.isnot(Math.round(window.scrollY), 0, "Should have scrolled back to the state5's position");
 
             var ifr = document.createElement("iframe");
             ifr.src = "data:text/html,";
             document.body.appendChild(ifr);
             ifr.onload = test;
             break;
           }
           case 7: {
--- a/docshell/test/test_bug1186774.html
+++ b/docshell/test/test_bug1186774.html
@@ -23,17 +23,17 @@ function runTest() {
       child.scrollTo(0, 3000);
       child.history.pushState({}, "scrolled");
       child.scrollTo(0, 6000);
       child.history.back();
     });
   }
 
   child.onpopstate = function() {
-    is(child.scrollY,  6000, "Shouldn't have scrolled before popstate");
+    is(Math.round(child.scrollY),  6000, "Shouldn't have scrolled before popstate");
     child.close();
     SimpleTest.finish();
   }
 }
 
 SimpleTest.waitForExplicitFinish();
 addLoadEvent(runTest);
 
--- a/docshell/test/test_bug590573.html
+++ b/docshell/test/test_bug590573.html
@@ -142,31 +142,31 @@ function pageLoad()
 }
 
 function* testBody()
 {
   is(popup.scrollY, 0, "test 1");
   popup.scroll(0, 100);
 
   popup.history.pushState('', '', '?pushed');
-  is(popup.scrollY, 100, "test 2");
+  is(Math.round(popup.scrollY), 100, "test 2");
   popup.scroll(0, 200); // set state-2's position to 200
 
   popup.history.back();
-  is(popup.scrollY, 100, "test 3");
+  is(Math.round(popup.scrollY), 100, "test 3");
   popup.scroll(0, 150); // set original page's position to 150
 
   popup.history.forward();
-  is(popup.scrollY, 200, "test 4");
+  is(Math.round(popup.scrollY), 200, "test 4");
 
   popup.history.back();
-  is(popup.scrollY, 150, "test 5");
+  is(Math.round(popup.scrollY), 150, "test 5");
 
   popup.history.forward();
-  is(popup.scrollY, 200, "test 6");
+  is(Math.round(popup.scrollY), 200, "test 6");
 
   // At this point, the history looks like:
   //   PATH                         POSITION
   //   file_bug590573_1.html        150       <-- oldest
   //   file_bug590573_1.html?pushed 200       <-- newest, current
 
   // Now test that the scroll position is persisted when we have real
   // navigations involved.  First, we need to spin the event loop so that the
@@ -197,23 +197,23 @@ function* testBody()
 
   // Spin the event loop again so that we get the right scroll positions.
   setTimeout(pageLoad, 0);
   yield;
 
   is(popup.location.search, "?pushed");
   ok(popup.document.getElementById('div1'), 'page should have div1.');
 
-  is(popup.scrollY, 200, "test 8");
+  is(Math.round(popup.scrollY), 200, "test 8");
 
   popup.history.back();
-  is(popup.scrollY, 150, "test 9");
+  is(Math.round(popup.scrollY), 150, "test 9");
   popup.history.forward();
 
-  is(popup.scrollY, 200, "test 10");
+  is(Math.round(popup.scrollY), 200, "test 10");
 
   // Spin one last time...
   setTimeout(pageLoad, 0);
   yield;
 
   page2PageShowCallbackEnabled = true;
   popup.history.forward();
   yield;
--- a/docshell/test/test_bug653741.html
+++ b/docshell/test/test_bug653741.html
@@ -19,30 +19,30 @@ SimpleTest.waitForExplicitFinish();
 
 function childLoad() {
   // Spin the event loop so we leave the onload handler.
   SimpleTest.executeSoon(childLoad2);
 }
 
 function childLoad2() {
   let cw = $('iframe').contentWindow;
-  
+
   // Save the Y offset.  For sanity's sake, make sure it's not 0, because we
   // should be at the bottom of the page!
-  let origYOffset = cw.pageYOffset;
+  let origYOffset = Math.round(cw.pageYOffset);
   ok(origYOffset != 0, 'Original Y offset is not 0.');
 
   // Scroll the iframe to the top, then navigate to #bottom again.
   cw.scrollTo(0, 0);
 
   // Our current location is #bottom, so this should scroll us down to the
   // bottom again.
   cw.location = cw.location + '';
 
-  is(cw.pageYOffset, origYOffset, 'Correct offset after reloading page.');
+  is(Math.round(cw.pageYOffset), origYOffset, 'Correct offset after reloading page.');
   SimpleTest.finish();
 }
 
 </script>
 
 <iframe height='100px' id='iframe' src='file_bug653741.html#bottom'></iframe>
 
 </body>
--- a/docshell/test/test_bug662170.html
+++ b/docshell/test/test_bug662170.html
@@ -22,22 +22,22 @@ function childLoad() {
   SimpleTest.executeSoon(childLoad2);
 }
 
 function childLoad2() {
   let cw = $('iframe').contentWindow;
 
   // When we initially load the page, we should be at the top.
   is(cw.pageYOffset, 0, 'Initial Y offset should be 0.');
-  
+
   // Scroll the iframe to the bottom.
   cw.scrollTo(0, 300);
 
   // Did we actually scroll somewhere?
-  isnot(cw.pageYOffset, 0, 'Y offset should be non-zero after scrolling.');
+  isnot(Math.round(cw.pageYOffset), 0, 'Y offset should be non-zero after scrolling.');
 
   // Now load file_bug662170.html#, which should take us to the top of the
   // page.
   cw.location = cw.location + '#';
 
   is(cw.pageYOffset, 0, 'Correct Y offset after loading #.');
   SimpleTest.finish();
 }
--- a/dom/base/test/test_viewport_scroll.html
+++ b/dom/base/test/test_viewport_scroll.html
@@ -23,20 +23,20 @@ var xml = document.getElementById("xml")
 quirks.src = "data:text/html,<html><body style='height:2000px; width:2000px;'>";
 standards.src = "data:text/html,<!DOCTYPE HTML><html><body style='height:2000px; width:2000px;'>";
 xml.src = "data:text/xml,<?xml-stylesheet href='data:text/css,html { display:block; height:2000px; width:2000px; }'?><foo><html></html></foo>";
 
 function subtest(winProp, elemProp, win, correctElement, elemToSet, otherElem1, otherElem2) {
   win.scrollTo(50, 50);
   elemToSet[elemProp] = 100;
   if (elemToSet == correctElement) {
-    is(win[winProp], 100, "Setting " + elemToSet.name + "." + elemProp + " should scroll");
+    is(Math.round(win[winProp]), 100, "Setting " + elemToSet.name + "." + elemProp + " should scroll");
     is(elemToSet[elemProp], 100, "Reading back " + elemToSet.name + "." + elemProp + " after scrolling");
   } else {
-    is(win[winProp], 50, "Setting " + elemToSet.name + "." + elemProp + " should not scroll");
+    is(Math.round(win[winProp]), 50, "Setting " + elemToSet.name + "." + elemProp + " should not scroll");
     is(elemToSet[elemProp], 0, "Reading back " + elemToSet.name + "." + elemProp + " after not scrolling");
   }
   if (otherElem1 == correctElement) {
     is(otherElem1[elemProp], 50, "Reading back " + otherElem1.name + "." + elemProp + " (correct element) after not scrolling");
   } else {
     is(otherElem1[elemProp], 0, "Reading back " + otherElem1.name + "." + elemProp + " (irrelevant element)");
   }
   if (otherElem2 == correctElement) {
--- a/dom/browser-element/mochitest/browserElement_ScrollEvent.js
+++ b/dom/browser-element/mochitest/browserElement_ScrollEvent.js
@@ -11,17 +11,17 @@ browserElementTestHelpers.addPermission(
 function runTest() {
   var iframe = document.createElement('iframe');
   iframe.setAttribute('mozbrowser', 'true');
   document.body.appendChild(iframe);
 
   iframe.addEventListener("mozbrowserscroll", function(e) {
     ok(true, "got mozbrowserscroll event.");
     ok(e.detail, "event.detail is not null.");
-    ok(e.detail.top === 4000, "top position is correct.");
-    ok(e.detail.left === 4000, "left position is correct.");
+    ok(Math.round(e.detail.top) == 4000, "top position is correct.");
+    ok(Math.round(e.detail.left) == 4000, "left position is correct.");
     SimpleTest.finish();
   });
 
   iframe.src = "data:text/html,<html><body style='min-height: 5000px; min-width: 5000px;'></body><script>window.scrollTo(4000, 4000);</script></html>";
 }
 
 addEventListener('testready', runTest);
--- a/dom/tests/mochitest/general/test_domWindowUtils_scrollXY.html
+++ b/dom/tests/mochitest/general/test_domWindowUtils_scrollXY.html
@@ -26,23 +26,23 @@
     function testScrollXY() {
       let iframe = document.getElementById("iframe");
       let cwindow = iframe.contentWindow;
       let domWindowUtils = SpecialPowers.getDOMWindowUtils(cwindow);
 
       function checkGetScrollXYState(flush, vals, testName) {
         let scrollX = {}, scrollY = {};
         domWindowUtils.getScrollXY(flush, scrollX, scrollY);
-        is(scrollX.value, vals[0], "getScrollXY x for test: " + testName);
-        is(scrollY.value, vals[1], "getScrollXY y for test: " + testName);
+        is(Math.round(scrollX.value), vals[0], "getScrollXY x for test: " + testName);
+        is(Math.round(scrollY.value), vals[1], "getScrollXY y for test: " + testName);
       }
 
       function checkWindowScrollState(vals, testName) {
-        is(cwindow.scrollX, vals[0], "scrollX for test: " + testName);
-        is(cwindow.scrollY, vals[1], "scrollY for test: " + testName);
+        is(Math.round(cwindow.scrollX), vals[0], "scrollX for test: " + testName);
+        is(Math.round(cwindow.scrollY), vals[1], "scrollY for test: " + testName);
       }
 
       // Check initial state (0, 0)
       checkGetScrollXYState(false, [0, 0], "initial getScrollXY state");
       checkGetScrollXYState(true, [0, 0], "initial getScrollXY state+flush");
       checkWindowScrollState([0, 0], "initial window.scroll* state");
 
       // scroll
@@ -62,18 +62,18 @@
       let iframe = document.getElementById("hidden-iframe");
       let cwindow = iframe.contentWindow;
       let domWindowUtils = SpecialPowers.getDOMWindowUtils(cwindow);
 
       // make sure getScrollXY doesn't throw
       let scrollX = {}, scrollY = {};
       domWindowUtils.getScrollXY(false, scrollX, scrollY);
 
-      is(scrollX.value, 0, "scrollX is zero for display:none iframe");
-      is(scrollY.value, 0, "scrollY is zero for display:none iframe");
+      is(Math.round(scrollX.value), 0, "scrollX is zero for display:none iframe");
+      is(Math.round(scrollY.value), 0, "scrollY is zero for display:none iframe");
     }
 
     SimpleTest.waitForExplicitFinish();
   </script>
 
   <!-- can't run this in the test document, since it potentially runs in a
        scrolling="no" test harness iframe, and that causes a failure for some
        reason -->
--- a/layout/forms/test/test_bug562447.html
+++ b/layout/forms/test/test_bug562447.html
@@ -18,39 +18,39 @@ https://bugzilla.mozilla.org/show_bug.cg
 <pre id="test">
 <script>
 addLoadEvent(function() {
   // Scroll down a bit
   window.scrollTo(0, 5000);
 
   setTimeout(function() {
     // Make sure that we're scrolled by 5000px
-    is(window.pageYOffset, 5000, "Make sure we're scrolled correctly");
+    is(Math.round(window.pageYOffset), 5000, "Make sure we're scrolled correctly");
 
     // Scroll back up, and mess with the input box along the way
     var input = document.getElementById("WhyDoYouFocusMe");
     input.focus();
     input.blur();
     window.scrollTo(0, 0);
 
     setTimeout(function() {
       is(window.pageYOffset, 0, "Make sure we're scrolled back up correctly");
 
       // Scroll back up
       window.scrollTo(0, 5000);
 
       setTimeout(function() {
-        is(window.pageYOffset, 5000, "Sanity check");
+        is(Math.round(window.pageYOffset), 5000, "Sanity check");
 
         window.scrollTo(0, 0);
         input.focus();
         input.blur();
 
         setTimeout(function() {
-          isnot(window.pageYOffset, 0, "This time we shouldn't be scrolled up");
+          isnot(Math.round(window.pageYOffset), 0, "This time we shouldn't be scrolled up");
 
           SimpleTest.finish();
         }, 0);
       }, 0);
     }, 0);
   }, 0);
 });
 
--- a/layout/forms/test/test_bug564115.html
+++ b/layout/forms/test/test_bug564115.html
@@ -25,22 +25,22 @@ addLoadEvent(function() {
 
     // Focus the input box, and wait for the focus to actually happen
     input.focus();
     setTimeout(function() {
       // Scroll down a bit
       win.scrollTo(0, 5000);
 
       setTimeout(function() {
-        is(win.pageYOffset, 5000, "Page should be scrolled correctly");
+        is(Math.round(win.pageYOffset), 5000, "Page should be scrolled correctly");
 
         // Refocus the window
         SimpleTest.waitForFocus(function() {
           SimpleTest.waitForFocus(function() {
-            is(win.pageYOffset, 5000,
+            is(Math.round(win.pageYOffset), 5000,
                "The page's scroll offset should not have been changed");
 
             win.close();
             SimpleTest.finish();
           }, win);
         });
       }, 0);
     }, 0);