diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
commit | 43a97878ce14b72f0981164f87f2e35e14151312 (patch) | |
tree | 620249daf56c0258faa40cbdcf9cfba06de2a846 /testing/web-platform/tests/html/browsers/browsing-the-web/scroll-to-fragid | |
parent | Initial commit. (diff) | |
download | firefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip |
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/html/browsers/browsing-the-web/scroll-to-fragid')
20 files changed, 730 insertions, 0 deletions
diff --git a/testing/web-platform/tests/html/browsers/browsing-the-web/scroll-to-fragid/001.html b/testing/web-platform/tests/html/browsers/browsing-the-web/scroll-to-fragid/001.html new file mode 100644 index 0000000000..32599bbc50 --- /dev/null +++ b/testing/web-platform/tests/html/browsers/browsing-the-web/scroll-to-fragid/001.html @@ -0,0 +1,16 @@ +<!doctype html> +<!-- this tests the spec as it hopefully will be once bug https://www.w3.org/Bugs/Public/show_bug.cgi?id=17155 is fixed --> +<title>Fragment Navigation: Updating document address</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id="log"></div> +<script> +test(function() { + assert_equals(location.hash, "", "Page must be loaded with no hash") + var original_location = location.href; + location.hash = "test"; + assert_equals(location.hash, "#test"); + assert_equals(location.href, original_location + "#test"); + location.hash = "" +}); +</script> diff --git a/testing/web-platform/tests/html/browsers/browsing-the-web/scroll-to-fragid/002.html b/testing/web-platform/tests/html/browsers/browsing-the-web/scroll-to-fragid/002.html new file mode 100644 index 0000000000..92bfd63415 --- /dev/null +++ b/testing/web-platform/tests/html/browsers/browsing-the-web/scroll-to-fragid/002.html @@ -0,0 +1,21 @@ +<!doctype html> +<!-- this tests the spec as it hopefully will be once bug https://www.w3.org/Bugs/Public/show_bug.cgi?id=17155 is fixed --> +<title>Fragment Navigation: Updating document address twice</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id="log"></div> +<script> +test(function() { + assert_equals(location.hash, "", "Page must be loaded with no hash") + var original_location = location.href; + location.hash = "test"; + assert_equals(location.hash, "#test"); + assert_equals(location.href, original_location + "#test"); + + location.hash = "test1"; + assert_equals(location.hash, "#test1"); + assert_equals(location.href, original_location + "#test1"); + + location.hash = ""; +}); +</script> diff --git a/testing/web-platform/tests/html/browsers/browsing-the-web/scroll-to-fragid/003.html b/testing/web-platform/tests/html/browsers/browsing-the-web/scroll-to-fragid/003.html new file mode 100644 index 0000000000..86d85b9ca6 --- /dev/null +++ b/testing/web-platform/tests/html/browsers/browsing-the-web/scroll-to-fragid/003.html @@ -0,0 +1,25 @@ +<!doctype html> +<!-- this tests the spec as it hopefully will be once bug https://www.w3.org/Bugs/Public/show_bug.cgi?id=17155 is fixed --> +<title>Fragment Navigation: Updating scroll position</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<body> +<div id="log"></div> +<div id="test">scroll 1</div> +<div style="height:10000px">Filler</div> +<div id="test1">scroll 2</div> +<script> +test(function() { + assert_equals(document.scrollingElement.scrollTop, 0); + location.hash = "test"; + + var scroll1 = document.scrollingElement.scrollTop; + assert_true(scroll1 > 0); + + location.hash = "test1"; + var scroll2 = document.scrollingElement.scrollTop; + assert_true(scroll2 > scroll1); + + location.hash = "" +}); +</script> diff --git a/testing/web-platform/tests/html/browsers/browsing-the-web/scroll-to-fragid/004.html b/testing/web-platform/tests/html/browsers/browsing-the-web/scroll-to-fragid/004.html new file mode 100644 index 0000000000..c365c6fd29 --- /dev/null +++ b/testing/web-platform/tests/html/browsers/browsing-the-web/scroll-to-fragid/004.html @@ -0,0 +1,23 @@ +<!doctype html> +<!-- this tests the spec as it hopefully will be once bug https://www.w3.org/Bugs/Public/show_bug.cgi?id=17155 is fixed --> +<title>Fragment Navigation: hashchange event</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<body> +<div id="log"></div> +<script> +var t = async_test(); +t.step(function() { + assert_equals(location.hash, "", "Page must be loaded with no hash"); + location.hash = "test"; + + addEventListener("hashchange", + t.step_func(function(e) { + assert_equals(e.target, window); + assert_equals(e.type, "hashchange"); + assert_false(e.bubbles, "bubbles"); + assert_false(e.cancelable, "cancelable"); + t.done(); + }), true) +}); +</script> diff --git a/testing/web-platform/tests/html/browsers/browsing-the-web/scroll-to-fragid/005.html b/testing/web-platform/tests/html/browsers/browsing-the-web/scroll-to-fragid/005.html new file mode 100644 index 0000000000..f0761a64f6 --- /dev/null +++ b/testing/web-platform/tests/html/browsers/browsing-the-web/scroll-to-fragid/005.html @@ -0,0 +1,23 @@ +<!doctype html> +<!-- this tests the spec as it hopefully will be once bug https://www.w3.org/Bugs/Public/show_bug.cgi?id=17155 is fixed --> +<title>Fragment Navigation: hashchange event</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<body> +<div id="log"></div> +<script> +var t = async_test(); +t.step(function() { + var original_url = location.href; + assert_equals(location.hash, "", "Page must be loaded with no hash"); + location.hash = "test"; + + addEventListener("hashchange", + t.step_func(function(e) { + assert_equals(e.oldURL, original_url, "oldURL property"); + assert_equals(e.newURL, location.href, "newURL property"); + location.hash = ""; + t.done(); + }), true); +}); +</script> diff --git a/testing/web-platform/tests/html/browsers/browsing-the-web/scroll-to-fragid/006.html b/testing/web-platform/tests/html/browsers/browsing-the-web/scroll-to-fragid/006.html new file mode 100644 index 0000000000..a65b9eb4a2 --- /dev/null +++ b/testing/web-platform/tests/html/browsers/browsing-the-web/scroll-to-fragid/006.html @@ -0,0 +1,34 @@ +<!doctype html> +<!-- this tests the spec as it hopefully will be once bug https://www.w3.org/Bugs/Public/show_bug.cgi?id=17155 is fixed --> +<title>Fragment Navigation: hashchange event multiple changes old/newURL</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<body> +<div id="log"></div> +<script> +var t = async_test(); +t.step(function() { + var original_url = location.href; + assert_equals(location.hash, "", "Page must be loaded with no hash"); + location.hash = "test"; + + var count = 0; + var mid_url = location.href; + + addEventListener("hashchange", + t.step_func(function(e) { + if (count === 0) { + assert_equals(e.oldURL, original_url, "oldURL property first update"); + assert_equals(e.newURL, mid_url, "newURL property first update"); + count = 1; + } else if (count === 1) { + assert_equals(e.oldURL, mid_url, "oldURL property second update"); + assert_equals(e.newURL, location.href, "newURL property second update"); + location.hash = ""; + t.done(); + } + }), true); + + location.hash = "test1"; +}); +</script> diff --git a/testing/web-platform/tests/html/browsers/browsing-the-web/scroll-to-fragid/007.html b/testing/web-platform/tests/html/browsers/browsing-the-web/scroll-to-fragid/007.html new file mode 100644 index 0000000000..0b6fe813ba --- /dev/null +++ b/testing/web-platform/tests/html/browsers/browsing-the-web/scroll-to-fragid/007.html @@ -0,0 +1,37 @@ +<!doctype html> +<!-- this tests the spec as it hopefully will be once bug https://www.w3.org/Bugs/Public/show_bug.cgi?id=17155 is fixed --> +<title>Fragment Navigation: hashchange event multiple changes old/newURL</title> +<meta name=timeout content=long> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<body> +<div id="log"></div> +<script> +var t = async_test(); +t.step(function() { + var original_url = location.href; + assert_equals(location.hash, "", "Page must be loaded with no hash"); + + var count = 0; + + location.hash = "test"; + + hashes = []; + + addEventListener("hashchange", + t.step_func(function(e) { + if (count < 100) { + location.hash = "test" + count++; + hashes.push(location.hash); + } else if (count === 100) { + expected = []; + for (var i=0; i<100; i++) { + expected.push("#test" + i); + } + assert_array_equals(hashes, expected); + location.hash = ""; + t.done(); + } + }), true); +}); +</script> diff --git a/testing/web-platform/tests/html/browsers/browsing-the-web/scroll-to-fragid/forward-triggers-hashchange.html b/testing/web-platform/tests/html/browsers/browsing-the-web/scroll-to-fragid/forward-triggers-hashchange.html new file mode 100644 index 0000000000..45f7e38ba3 --- /dev/null +++ b/testing/web-platform/tests/html/browsers/browsing-the-web/scroll-to-fragid/forward-triggers-hashchange.html @@ -0,0 +1,44 @@ +<!DOCTYPE html> +<meta charset="utf-8"> +<title>Navigating forward after replace() should still trigger hashchange</title> +<link rel="help" href="https://html.spec.whatwg.org/multipage/#history-traversal"> +<link rel="author" href="mailto:d@domenic.me" title="Domenic Denicola"> + +<!-- While writing ./replacement-enabled.html, a bug was discovered in Firefox where it does not +fire hashchange when using history.forward(), at least under certain conditions. So, this test +exercises that specifically. --> + +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="navigate-helpers.js"></script> + +<body> + +<script> +"use strict"; +let resolve, iframe; +promise_test(() => { + iframe = document.createElement("iframe"); + iframe.src = "/common/blank.html"; + iframe.addEventListener("load", runTest); + document.body.appendChild(iframe); + + return new Promise(r => resolve = r); +}); + +function runTest() { + iframe.removeEventListener("load", runTest); + const frameWindow = iframe.contentWindow; + + resolve((async () => { + await navigateAndWaitForChange(frameWindow, w => w.location.href = "/common/blank.html#apple"); + await navigateAndWaitForChange(frameWindow, w => w.location.href = "/common/blank.html#banana"); + await navigateAndWaitForChange(frameWindow, w => w.location.href = "/common/blank.html#cat"); + + await navigateAndWaitForChange(frameWindow, w => w.history.back()); + await navigateAndWaitForChange(frameWindow, + w => w.location.replace("/common/blank.html#zebra")); + await navigateAndWaitForChange(frameWindow, w => w.history.forward()); + })()); +} +</script> diff --git a/testing/web-platform/tests/html/browsers/browsing-the-web/scroll-to-fragid/fragment-and-encoding-2.html b/testing/web-platform/tests/html/browsers/browsing-the-web/scroll-to-fragid/fragment-and-encoding-2.html new file mode 100644 index 0000000000..cd2502ab1c --- /dev/null +++ b/testing/web-platform/tests/html/browsers/browsing-the-web/scroll-to-fragid/fragment-and-encoding-2.html @@ -0,0 +1,41 @@ +<!doctype html> +<meta charset=windows-1252> +<title>Fragment navigation: encoding</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id="log"></div> +<div style=height:10000px></div> +<div id=�></div> +<div id=�></div> +<script> +function goToTop() { + location.hash = "top"; + assert_equals(self.scrollY, 0, "#top"); +} + +test(() => { + assert_equals(location.hash, "", "Page must be loaded with no hash"); + + location.hash = "%C2"; + assert_equals(location.hash, "#%C2"); + assert_greater_than(self.scrollY, 1000, "#%C2"); +}, "Invalid percent-encoded UTF-8 byte should decode as U+FFFD"); + +test(() => { + goToTop(); + + location.hash = "%EF%BB%BF%C2"; + assert_equals(location.hash, "#%EF%BB%BF%C2"); + assert_greater_than(self.scrollY, 1000, "#%EF%BB%BF%C2"); +}, "Percent-encoded UTF-8 BOM followed by invalid UTF-8 byte should decode as U+FEFF U+FFFD"); + +test(() => { + goToTop(); + + location.hash = "%EF%BF%BD"; + assert_equals(location.hash, "#%EF%BF%BD"); + assert_greater_than(self.scrollY, 1000, "#%EF%BF%BD"); + + goToTop(); +}, "Percent-encoded UTF-8 byte sequence for U+FFFD should decode as U+FFFD"); +</script> diff --git a/testing/web-platform/tests/html/browsers/browsing-the-web/scroll-to-fragid/fragment-and-encoding.html b/testing/web-platform/tests/html/browsers/browsing-the-web/scroll-to-fragid/fragment-and-encoding.html new file mode 100644 index 0000000000..21fbd4618d --- /dev/null +++ b/testing/web-platform/tests/html/browsers/browsing-the-web/scroll-to-fragid/fragment-and-encoding.html @@ -0,0 +1,50 @@ +<!doctype html> +<meta charset=windows-1252> +<title>Fragment navigation: encoding</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id="log"></div> +<div style=height:10000px></div> +<div id=ÿ></div> +<div id=></div> +<div id=♡ÿ><div> +<script> +function goToTop() { + location.hash = "top"; + assert_equals(self.scrollY, 0, "#top"); +} + +test(() => { + assert_equals(location.hash, "", "Page must be loaded with no hash"); + + location.hash = "\u00FF"; + assert_equals(location.hash, "#%C3%BF"); + assert_greater_than(self.scrollY, 1000, "#%C3%BF"); +}, "U+00FF should find U+00FF"); + +test(() => { + goToTop(); + + location.hash = "%EF%BB%BF"; + assert_greater_than(self.scrollY, 1000, "#%EF%BB%BF"); +}, "Percent-encoded UTF-8 BOM should find U+FEFF as BOM is not stripped when decoding"); + +test(() => { + goToTop(); + + location.hash = "%FF"; + assert_equals(self.scrollY, 0, "#%FF"); +}, "%FF should not find U+00FF as decoding it gives U+FFFD"); + +test(() => { + goToTop(); + + // U+2661 in UTF-8 + %FF. + // Chrome had an issue that the following fragment was decoded as U+2661 U+00FF. + // https://github.com/whatwg/html/pull/3111 + location.hash = "%E2%99%A1%FF"; + assert_equals(self.scrollY, 0, "%E2%99%A1%FF"); + + goToTop(); +}, "Valid UTF-8 + invalid UTF-8 should not be matched to the utf8-decoded former + the isomorphic-decoded latter"); +</script> diff --git a/testing/web-platform/tests/html/browsers/browsing-the-web/scroll-to-fragid/navigate-helpers.js b/testing/web-platform/tests/html/browsers/browsing-the-web/scroll-to-fragid/navigate-helpers.js new file mode 100644 index 0000000000..7a9adeb3d2 --- /dev/null +++ b/testing/web-platform/tests/html/browsers/browsing-the-web/scroll-to-fragid/navigate-helpers.js @@ -0,0 +1,23 @@ +"use strict"; + +// Usage examples: +// navigateAndWaitForChange(frameWindow, w => w.location.href = "..."); +// navigateAndWaitForChange(frameWindow, w => w.history.back()); +// navigateAndWaitForChange(frameWindow, w => w.history.back(), { assumeSuccessAfter: 100 }); + +window.navigateAndWaitForChange = (w, navigationAction, { assumeSuccessAfter } = {}) => { + return new Promise(resolve => { + w.addEventListener("hashchange", listener); + + function listener() { + w.removeEventListener("hashchange", listener); + resolve(); + } + + if (assumeSuccessAfter !== undefined) { + step_timeout(resolve, assumeSuccessAfter); + } + + navigationAction(w); + }); +}; diff --git a/testing/web-platform/tests/html/browsers/browsing-the-web/scroll-to-fragid/replacement-enabled.html b/testing/web-platform/tests/html/browsers/browsing-the-web/scroll-to-fragid/replacement-enabled.html new file mode 100644 index 0000000000..b22fbed80f --- /dev/null +++ b/testing/web-platform/tests/html/browsers/browsing-the-web/scroll-to-fragid/replacement-enabled.html @@ -0,0 +1,69 @@ +<!DOCTYPE html> +<meta charset="utf-8"> +<title>Navigating to a fragment should not clear forward history</title> +<link rel="help" href="https://html.spec.whatwg.org/multipage/#scroll-to-fragid"> +<link rel="help" href="https://github.com/whatwg/html/issues/2796"> +<link rel="help" href="https://github.com/whatwg/html/pull/2869"> +<link rel="author" href="mailto:d@domenic.me" title="Domenic Denicola"> + +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="navigate-helpers.js"></script> + +<body> + +<script> +"use strict"; +let resolve, iframe; +promise_test(() => { + iframe = document.createElement("iframe"); + iframe.src = "/common/blank.html"; + iframe.addEventListener("load", runTest); + document.body.appendChild(iframe); + + return new Promise(r => resolve = r); +}); + +function runTest() { + iframe.removeEventListener("load", runTest); + const frameWindow = iframe.contentWindow; + + resolve((async () => { + await navigateAndWaitForChange(frameWindow, w => w.location.href = "/common/blank.html#apple"); + await navigateAndWaitForChange(frameWindow, w => w.location.href = "/common/blank.html#banana"); + await navigateAndWaitForChange(frameWindow, w => w.location.href = "/common/blank.html#cat"); + + assert_equals(frameWindow.location.hash, "#cat"); + + // Might not be 4 (= 3 for iframe + 1 initial) due to cross-browser differences or if people are + // running this test in a window that has previously been places. The important thing for this + // test is the delta from this value. + const afterThreeNavigations = frameWindow.history.length; + + await navigateAndWaitForChange(frameWindow, w => w.history.back()); + + assert_equals(frameWindow.location.hash, "#banana"); + assert_equals(frameWindow.history.length, afterThreeNavigations, + "back() must not change the history length"); + + await navigateAndWaitForChange(frameWindow, + w => w.location.replace("/common/blank.html#zebra")); + + assert_equals(frameWindow.location.hash, "#zebra"); + assert_equals(frameWindow.history.length, afterThreeNavigations, + "replace() must not change the history length"); + + // As of the time of this writing (2017-08-14), Firefox is not firing hashchange on forward, so + // we automatically assume navigation succeeded after 100 ms. A sibling test will test this + // particular Firefox bug. + await navigateAndWaitForChange(frameWindow, w => w.history.forward(), + { assumeSuccessAfter: 500 }); + + assert_equals(frameWindow.location.hash, "#cat"); + assert_equals(frameWindow.history.length, afterThreeNavigations, + "forward() must not change the history length"); + + })()); +} + +</script> diff --git a/testing/web-platform/tests/html/browsers/browsing-the-web/scroll-to-fragid/scroll-frag-non-utf8-encoded-document.html b/testing/web-platform/tests/html/browsers/browsing-the-web/scroll-to-fragid/scroll-frag-non-utf8-encoded-document.html new file mode 100644 index 0000000000..7d4e994f0a --- /dev/null +++ b/testing/web-platform/tests/html/browsers/browsing-the-web/scroll-to-fragid/scroll-frag-non-utf8-encoded-document.html @@ -0,0 +1,21 @@ +<!doctype html> +<title>Fragment Navigation: fragment id should not be found in non UTF8 document</title> +<meta name=timeout content=long> +<meta http-equiv="Content-Type" content="text/html; charset=gbk"/> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<body> +<div></div> +<div id="塯" style="position:absolute; top:100px;"></div> +<div style="height:200vh;"></div> +<script> +async_test(test => { + assert_equals(document.characterSet, "GBK", "Document should be GBK encoded"); + assert_equals(location.hash, "", "Page must be loaded with no hash"); + location.hash = '%89g'; + test.step_timeout(() => { + assert_equals( document.scrollingElement.scrollTop, 0 ); + test.done(); + }, 1); +}); +</script> diff --git a/testing/web-platform/tests/html/browsers/browsing-the-web/scroll-to-fragid/scroll-frag-percent-encoded.html b/testing/web-platform/tests/html/browsers/browsing-the-web/scroll-to-fragid/scroll-frag-percent-encoded.html new file mode 100644 index 0000000000..aa179425c5 --- /dev/null +++ b/testing/web-platform/tests/html/browsers/browsing-the-web/scroll-to-fragid/scroll-frag-percent-encoded.html @@ -0,0 +1,62 @@ +<!doctype html> +<title>Fragment Navigation: fragment id should be percent-decoded</title> +<meta name=timeout content=long> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<body> +<div></div> +<div id="has two spaces" style="position:absolute; top:100px;"></div> +<div id="escape%20collision" style="position:absolute; top:200px;"></div> +<div id="%20has%20two%20spaces" style="position:absolute; top:300px;"></div> +<div id="escape collision" style="position:absolute; top:400px;"></div> +<div id="do%20not%20go%20here" style="position:absolute; top:400px;"></div> +<div style="height:200em;"></div> +<script> +var steps = [{ + fragid:'has%20two%20spaces', + handler: function(){ + assert_equals( document.scrollingElement.scrollTop, 100 ); + } + },{ + fragid:'escape%20collision', + handler: function(){ + assert_equals( document.scrollingElement.scrollTop, 200 ); + document.getElementById("%20has%20two%20spaces").setAttribute("id", "has%20two%20spaces"); + } + },{ + fragid:'has%20two%20spaces', + handler: function(){ + assert_equals( document.scrollingElement.scrollTop, 300 ); + } + },{ + fragid:'do%20not%20go%20here', + handler: function(){ + // don't move + assert_equals( document.scrollingElement.scrollTop, 400 ); + } + }]; + +function runNextStep(){ + if( steps.length > 0 ) { + var step = steps.shift(); + var listener = t.step_func( function(){ + step.handler(); + runNextStep(); + }); + scrollToFragmentThenDo( step.fragid, listener ); + } else { + t.done(); + } +} + +function scrollToFragmentThenDo( fragid, then ){ + location.hash = fragid; + setTimeout( then, 1 ); +} + +var t = async_test(); +t.step( function(){ + assert_equals(location.hash, "", "Page must be loaded with no hash"); + runNextStep(); +}) +</script> diff --git a/testing/web-platform/tests/html/browsers/browsing-the-web/scroll-to-fragid/scroll-position-vertical-lr.html b/testing/web-platform/tests/html/browsers/browsing-the-web/scroll-to-fragid/scroll-position-vertical-lr.html new file mode 100644 index 0000000000..57d99440e1 --- /dev/null +++ b/testing/web-platform/tests/html/browsers/browsing-the-web/scroll-to-fragid/scroll-position-vertical-lr.html @@ -0,0 +1,25 @@ +<!DOCTYPE html> +<html style="writing-mode: vertical-lr;"> +<head> +<meta charset="UTF-8"> +<title>Fragment Navigation: Scroll to block start position in vertical-lr writing mode</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +</head> +<body> +<div id="test" style="position: absolute; top: 5px; left: 7px; margin: 5px 7px; border-style: solid; border-width: 5px 7px; padding: 5px 7px; height: 5px; width: 7px;"></div> +<div style="width: 200vw;"></div> +<script> +async_test(function (t) { + on_event(window, 'load', function () { + t.step(function () { + window.scrollTo(0, 0); + location.hash = 'test'; + assert_equals(window.scrollX, 14, 'Scroll to the left border edge of #test'); + }); + t.done(); + }); +}, ''); +</script> +</body> +</html> diff --git a/testing/web-platform/tests/html/browsers/browsing-the-web/scroll-to-fragid/scroll-position-vertical-rl.html b/testing/web-platform/tests/html/browsers/browsing-the-web/scroll-to-fragid/scroll-position-vertical-rl.html new file mode 100644 index 0000000000..60a902199a --- /dev/null +++ b/testing/web-platform/tests/html/browsers/browsing-the-web/scroll-to-fragid/scroll-position-vertical-rl.html @@ -0,0 +1,25 @@ +<!DOCTYPE html> +<html style="writing-mode: vertical-rl;"> +<head> +<meta charset="UTF-8"> +<title>Fragment Navigation: Scroll to block start position in vertical-rl writing mode</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +</head> +<body> +<div id="test" style="position: absolute; top: 5px; right: 7px; margin: 5px 7px; border-style: solid; border-width: 5px 7px; padding: 5px 7px; height: 5px; width: 7px;"></div> +<div style="width: 200vw;"></div> +<script> +async_test(function (t) { + on_event(window, 'load', function () { + t.step(function () { + window.scrollTo(0, 0); + location.hash = 'test'; + assert_equals(window.scrollX, -14, 'Scroll to the right border edge of #test'); + }); + t.done(); + }); +}, ''); +</script> +</body> +</html> diff --git a/testing/web-platform/tests/html/browsers/browsing-the-web/scroll-to-fragid/scroll-position.html b/testing/web-platform/tests/html/browsers/browsing-the-web/scroll-to-fragid/scroll-position.html new file mode 100644 index 0000000000..c38d2de83b --- /dev/null +++ b/testing/web-platform/tests/html/browsers/browsing-the-web/scroll-to-fragid/scroll-position.html @@ -0,0 +1,25 @@ +<!DOCTYPE html> +<html> +<head> +<meta charset="UTF-8"> +<title>Fragment Navigation: Scroll to block start position</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +</head> +<body> +<div id="test" style="position: absolute; top: 5px; left: 7px; margin: 5px 7px; border-style: solid; border-width: 5px 7px; padding: 5px 7px; height: 5px; width: 7px;"></div> +<div style="height: 200vh;"></div> +<script> +async_test(function (t) { + on_event(window, 'load', function () { + t.step(function () { + window.scrollTo(0, 0); + location.hash = 'test'; + assert_equals(window.scrollY, 10, 'Scroll to the top border edge of #test'); + }); + t.done(); + }); +}, ''); +</script> +</body> +</html> diff --git a/testing/web-platform/tests/html/browsers/browsing-the-web/scroll-to-fragid/scroll-to-anchor-name.html b/testing/web-platform/tests/html/browsers/browsing-the-web/scroll-to-fragid/scroll-to-anchor-name.html new file mode 100644 index 0000000000..060aed11e2 --- /dev/null +++ b/testing/web-platform/tests/html/browsers/browsing-the-web/scroll-to-fragid/scroll-to-anchor-name.html @@ -0,0 +1,59 @@ +<!doctype html> +<title>Fragment Navigation: scroll to anchor name is lower priority than equal id</title> +<meta name=timeout content=long> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<body> +<div></div> +<a name="anchor1" style="position:absolute; top:200px;"></a> +<div id="id-equals-anchor" style="position:absolute; top:300px;"></div> +<a name="id-equals-anchor" style="position:absolute; top:400px;"></a> +<a name="§1" style="position:absolute; top:400px;"></a> +<div style="height:200em;"></div> +<script> +var steps = [{ + fragid:'anchor1', + handler: function(){ + assert_equals( scrollPosition(), 200 ); + } + },{ + fragid:'id-equals-anchor', + handler: function(){ + // id still takes precedence over anchor name + assert_equals( scrollPosition(), 300 ); + } + },{ + fragid:'§1', + handler: function(){ + assert_equals( scrollPosition(), 400 ); + } + }]; + +function scrollPosition(){ + return document.documentElement.scrollTop || document.body.scrollTop; +} + +function runNextStep(){ + if( steps.length > 0 ) { + var step = steps.shift(); + var listener = t.step_func( function(){ + step.handler(); + runNextStep(); + }); + scrollToFragmentThenDo( step.fragid, listener ); + } else { + t.done(); + } +} + +function scrollToFragmentThenDo( fragid, then ){ + location.hash = fragid; + setTimeout( then, 1 ); +} + +var t = async_test(); +t.step( function(){ + assert_equals(location.hash, "", "Page must be loaded with no hash"); + runNextStep(); +}) +</script> diff --git a/testing/web-platform/tests/html/browsers/browsing-the-web/scroll-to-fragid/scroll-to-id-top.html b/testing/web-platform/tests/html/browsers/browsing-the-web/scroll-to-fragid/scroll-to-id-top.html new file mode 100644 index 0000000000..601d40a2a1 --- /dev/null +++ b/testing/web-platform/tests/html/browsers/browsing-the-web/scroll-to-fragid/scroll-to-id-top.html @@ -0,0 +1,51 @@ +<!doctype html> +<title>Fragment Navigation: TOP is a valid element id, which overrides navigating to top of the document</title> +<meta name=timeout content=long> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<body> +<div></div> +<div id="Top" style="position:absolute; top:200px;"></div> +<div style="height:200em; position:relative;"></div> +<script> +var steps = [{ + fragid:'Top', + handler: function(){ + assert_equals( scrollPosition(), 200 ); + } + },{ + // scroling to top should work when fragid differs from id by case. + fragid:'top', + handler: function(){ + assert_equals( scrollPosition(), 0 ); + } + }]; + +function scrollPosition(){ + return document.documentElement.scrollTop || document.body.scrollTop; +} + +function runNextStep(){ + if( steps.length > 0 ) { + var step = steps.shift(); + var listener = t.step_func( function(){ + step.handler(); + runNextStep(); + }); + scrollToFragmentThenDo( step.fragid, listener ); + } else { + t.done(); + } +} + +function scrollToFragmentThenDo( fragid, then ){ + location.hash = fragid; + setTimeout( then, 1 ); +} + +var t = async_test(); +t.step( function(){ + assert_equals(location.hash, "", "Page must be loaded with no hash"); + runNextStep(); +}) +</script> diff --git a/testing/web-platform/tests/html/browsers/browsing-the-web/scroll-to-fragid/scroll-to-top.html b/testing/web-platform/tests/html/browsers/browsing-the-web/scroll-to-fragid/scroll-to-top.html new file mode 100644 index 0000000000..bf62e4cd55 --- /dev/null +++ b/testing/web-platform/tests/html/browsers/browsing-the-web/scroll-to-fragid/scroll-to-top.html @@ -0,0 +1,56 @@ +<!doctype html> +<title>Fragment Navigation: When fragid is TOP scroll to the top of the document</title> +<meta name=timeout content=long> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<body> +<div></div> +<div id="not-the-top"></div> +<div style="height:200em"></div> +<script> +var steps = [{ + fragid:'not-the-top', + handler: function(){ + assert_not_equals( document.scrollingElement.scrollTop, 0 ); + } + },{ + fragid:'top', + handler: function(){ + assert_equals( document.scrollingElement.scrollTop, 0 ); + } + },{ + fragid:'not-the-top', + handler: function(){ + assert_not_equals( document.scrollingElement.scrollTop, 0 ); + } + },{ + fragid:'TOP', + handler: function(){ + assert_equals( document.scrollingElement.scrollTop, 0 ); + } + }]; + +function runNextStep(){ + if( steps.length > 0 ) { + var step = steps.shift(); + var listener = t.step_func( function(){ + step.handler(); + runNextStep(); + }); + scrollToFragmentThenDo( step.fragid, listener ); + } else { + t.done(); + } +} + +function scrollToFragmentThenDo( fragid, then ){ + location.hash = fragid; + setTimeout( then, 1 ); +} + +var t = async_test(); +t.step( function(){ + assert_equals(location.hash, "", "Page must be loaded with no hash"); + runNextStep(); +}) +</script> |