Bug 1151421 Part 2: Add test of fractional scroll position properties. draft
authorBrad Werth <bwerth@mozilla.com>
Tue, 14 Mar 2017 17:31:22 -0700
changeset 500158 138b2f7c1c1b98c1b5074557d4e8214f9d81bb96
parent 500157 885caae45f2ae565a70ccc931188eb5b1cbdcb95
child 500159 42394595c8870fa695d04ca36415458bcf7a0fa5
push id49635
push userbwerth@mozilla.com
push dateThu, 16 Mar 2017 19:06:48 +0000
bugs1151421
milestone55.0a1
Bug 1151421 Part 2: Add test of fractional scroll position properties. MozReview-Commit-ID: 4a8eQeJz7fV
docshell/test/file_bug1151421.html
docshell/test/mochitest.ini
docshell/test/test_bug1151421.html
new file mode 100644
--- /dev/null
+++ b/docshell/test/file_bug1151421.html
@@ -0,0 +1,19 @@
+<html>
+<head>
+<style>
+body, html {
+    height: 100%;
+}
+.spacer {
+    height: 80%;
+}
+</style>
+</head>
+<body onload='(parent || opener).childLoad()'>
+
+<div class="spacer"></div>
+<div id="content">content</div>
+<div class="spacer"></div>
+
+</body>
+</html>
--- a/docshell/test/mochitest.ini
+++ b/docshell/test/mochitest.ini
@@ -28,16 +28,17 @@ support-files =
   file_bug653741.html
   file_bug660404
   file_bug660404^headers^
   file_bug662170.html
   file_bug669671.sjs
   file_bug680257.html
   file_bug703855.html
   file_bug728939.html
+  file_bug1151421.html
   file_pushState_after_document_open.html
   historyframes.html
 
 [test_anchor_scroll_after_document_open.html]
 [test_bfcache_plus_hash.html]
 [test_bug123696.html]
 [test_bug369814.html]
 [test_bug384014.html]
@@ -81,16 +82,17 @@ support-files = file_bug668513.html
 [test_bug691547.html]
 [test_bug694612.html]
 [test_bug703855.html]
 [test_bug713825.html]
 [test_bug728939.html]
 [test_bug797909.html]
 [test_bug1045096.html]
 [test_bug1121701.html]
+[test_bug1151421.html]
 [test_bug1186774.html]
 [test_forceinheritprincipal_overrule_owner.html]
 [test_framedhistoryframes.html]
 skip-if = toolkit == 'android' # bug 784321
 support-files = file_framedhistoryframes.html
 [test_pushState_after_document_open.html]
 [test_windowedhistoryframes.html]
 [test_triggeringprincipal_location_seturi.html]
new file mode 100644
--- /dev/null
+++ b/docshell/test/test_bug1151421.html
@@ -0,0 +1,61 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1151421
+-->
+<head>
+  <title>Test for Bug 1151421</title>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1151421">Mozilla Bug 1151421</a>
+
+<script type="application/javascript">
+
+/** Test for Bug 1151421 **/
+SimpleTest.waitForExplicitFinish();
+
+function childLoad() {
+  // Spin the event loop so we leave the onload handler.
+  SimpleTest.executeSoon(childLoad2);
+}
+
+function childLoad2() {
+  let cw = iframe.contentWindow;
+  let content = cw.document.getElementById("content");
+
+  // Create a function to calculate an invariant.
+  let topPlusOffset = function()
+  {
+    return Math.round(content.getBoundingClientRect().top + cw.pageYOffset);
+  }
+
+  let initialTPO = topPlusOffset();
+
+  // Scroll the iframe to various positions, and check the TPO.
+  // Scrolling down to the bottom will adjust the page offset by a fractional amount.
+  let positions = [-100, 0.17, 0, 1.5, 10.41, 1e6, 12.1];
+
+  // Run some tests with scrollTo() and ensure we have the same invariant after scrolling.
+  positions.forEach(function(pos) {
+    cw.scrollTo(0, pos);
+    is(topPlusOffset(), initialTPO, "Top plus offset should remain invariant across scrolling.");
+  });
+
+  positions.reverse().forEach(function(pos) {
+    cw.scrollTo(0, pos);
+    is(topPlusOffset(), initialTPO, "(reverse) Top plus offset should remain invariant across scrolling.");
+  });
+
+  SimpleTest.finish();
+}
+
+</script>
+
+<!-- When the iframe loads, it calls childLoad(). -->
+<br>
+<iframe height='100px' id='iframe' src='file_bug1151421.html'></iframe>
+
+</body>
+</html>