Bug 1496271 [wpt PR 2103] - Add test to verify scroll restoration order in history traversal, a=testonly
authorsmaug---- <smaug----@users.noreply.github.com>
Tue, 09 Oct 2018 04:13:36 +0000
changeset 495942 45d93015bb0295ea2e8f2c2ec719e26ed2253c24
parent 495941 bb93c91a609e4bb76483ae56dd105d9b01cf7ec3
child 495943 50a6846cd5cc91d5e61ed9c802723704e22f64c8
push id9984
push userffxbld-merge
push dateMon, 15 Oct 2018 21:07:35 +0000
treeherdermozilla-beta@183d27ea8570 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1496271
milestone64.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 1496271 [wpt PR 2103] - Add test to verify scroll restoration order in history traversal, a=testonly Automatic update from web-platform-testsMerge pull request #2103 from majido/scroll-restoration-order Add test to verify scroll restoration order in history traversal -- wpt-commits: 656382714083382c32a5e8df57a3fe07cb06b4b2 wpt-pr: 2103
testing/web-platform/tests/html/browsers/browsing-the-web/history-traversal/scroll-restoration-order.html
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/html/browsers/browsing-the-web/history-traversal/scroll-restoration-order.html
@@ -0,0 +1,74 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>History restoration order test</title>
+<meta name="assert" content="https://html.spec.whatwg.org/multipage/browsing-the-web.html#history-traversal">
+<meta name="assert" content="Traversing history should restore scroll position after dispatching popstate and before dispatching hashchange">
+
+<style>
+  body {
+    height: 200vh;
+    width: 200vw;
+  }
+</style>
+
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script>
+  'use strict';
+  async_test(function(t) {
+    window.addEventListener('load', t.step_func(function() {
+      // Allow 1px epsilon for fractional scrolling.
+      assert_array_approx_equals(scrollPosition(), [0, 0], 1);
+
+      history.pushState('#1', '', '#1');
+      window.scrollTo(50, 100);
+      assert_array_approx_equals(scrollPosition(), [50, 100], 1);
+
+      history.pushState('#2', '', '#2');
+      window.scrollTo(100, 200);
+      assert_array_approx_equals(scrollPosition(), [100, 200], 1);
+
+      setTimeout(t.step_func(function(){
+        history.pushState(null, null, '#done');
+        window.scrollTo(555, 555);
+        assert_array_approx_equals(scrollPosition(), [555, 555], 1);
+        // Kick off the verification.
+        window.history.back();
+      }), 0);
+    }));
+
+    window.addEventListener('popstate', t.step_func(function() {
+      // Verify that scroll position is *not* restored before popstate.
+      const key = location.hash;
+      const expected_scroll_position = expectedScrollPositionForKey(key);
+      assert_not_equals(scrollPosition()[0], expected_scroll_position[0], `scroll is restored before popstate for ${key}`);
+      assert_not_equals(scrollPosition()[1], expected_scroll_position[1], `scroll is restored before popstate for ${key}`);
+
+      if (key == '')
+        t.done();
+      else
+        setTimeout(t.step_func(function(){ window.history.back(); }), 0);
+    }));
+
+    window.addEventListener('hashchange', t.step_func(function() {
+      // Verify that scroll position is restored before hashchange.
+      var key = location.hash;
+      const expected_scroll_position = expectedScrollPositionForKey(key);
+      assert_array_approx_equals(scrollPosition(), expected_scroll_position, 1, `scroll is restored before hashchange for ${key}`);
+    }));
+
+    function scrollPosition() {
+      return [window.pageXOffset, window.pageYOffset];
+    }
+
+    function expectedScrollPositionForKey(key) {
+      switch (key) {
+        case '#2': return  [100, 200];
+        case '#1': return  [50, 100];
+        case ''  : return  [0, 0];
+        default: assert_unreached();
+      }
+    }
+
+  }, 'Traversing history should restore scroll position after dispatching popstate and before dispatching hashchange');
+</script>
\ No newline at end of file