Bug 1151421 Part 3: Update tests of pageYOffset/scrollY to round off when checking expected results. r=smaug

MozReview-Commit-ID: JDS5l06FAaf

--HG--
extra : rebase_source : c7fa999490b04e591f12b3fe123d6409811f9bfe
This commit is contained in:
Brad Werth 2017-03-16 12:05:56 -07:00
parent b1269f11fa
commit 983df24b1c
10 changed files with 36 additions and 36 deletions

View File

@ -26,7 +26,7 @@
}
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.
@ -45,7 +45,7 @@
}
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";
@ -53,7 +53,7 @@
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);
@ -70,7 +70,7 @@
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";
@ -79,17 +79,17 @@
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,";

View File

@ -28,7 +28,7 @@ function runTest() {
}
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();
}

View File

@ -147,21 +147,21 @@ function* testBody()
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
@ -202,13 +202,13 @@ function* testBody()
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);

View File

@ -24,10 +24,10 @@ function childLoad() {
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.
@ -37,7 +37,7 @@ function childLoad2() {
// 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();
}

View File

@ -27,12 +27,12 @@ function childLoad2() {
// 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.

View File

@ -28,10 +28,10 @@ function subtest(winProp, elemProp, win, correctElement, elemToSet, otherElem1,
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) {

View File

@ -16,8 +16,8 @@ function runTest() {
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();
});

View File

@ -31,13 +31,13 @@
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)
@ -67,8 +67,8 @@
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();

View File

@ -23,7 +23,7 @@ addLoadEvent(function() {
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");
@ -38,14 +38,14 @@ addLoadEvent(function() {
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);

View File

@ -30,12 +30,12 @@ addLoadEvent(function() {
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();