scroll-to-top.html (1374B)
1 <!doctype html> 2 <title>Fragment Navigation: When fragid is TOP scroll to the top of the document</title> 3 <meta name=timeout content=long> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 <body> 7 <div></div> 8 <div id="not-the-top"></div> 9 <div style="height:200em"></div> 10 <script> 11 var steps = [{ 12 fragid:'not-the-top', 13 handler: function(){ 14 assert_not_equals( document.scrollingElement.scrollTop, 0 ); 15 } 16 },{ 17 fragid:'top', 18 handler: function(){ 19 assert_equals( document.scrollingElement.scrollTop, 0 ); 20 } 21 },{ 22 fragid:'not-the-top', 23 handler: function(){ 24 assert_not_equals( document.scrollingElement.scrollTop, 0 ); 25 } 26 },{ 27 fragid:'TOP', 28 handler: function(){ 29 assert_equals( document.scrollingElement.scrollTop, 0 ); 30 } 31 }]; 32 33 function runNextStep(){ 34 if( steps.length > 0 ) { 35 var step = steps.shift(); 36 var listener = t.step_func( function(){ 37 step.handler(); 38 runNextStep(); 39 }); 40 scrollToFragmentThenDo( step.fragid, listener ); 41 } else { 42 t.done(); 43 } 44 } 45 46 function scrollToFragmentThenDo( fragid, then ){ 47 location.hash = fragid; 48 setTimeout( then, 1 ); 49 } 50 51 var t = async_test(); 52 t.step( function(){ 53 assert_equals(location.hash, "", "Page must be loaded with no hash"); 54 runNextStep(); 55 }) 56 </script>