| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // Adds event listeners and populates on-load-div. |
| 6 window.onload = function() { |
| 7 window.addEventListener('popstate', onPopstate); |
| 8 window.addEventListener('hashchange', onHashChange); |
| 9 updateOnLoadText('OnLoadText'); |
| 10 }; |
| 11 |
| 12 // Populates pop-state-received-div and state-object-div upon a popstate event. |
| 13 var onPopstate = function(e) { |
| 14 updatePopStateReceivedText(true); |
| 15 updateStateObjectText(e.state); |
| 16 }; |
| 17 |
| 18 // Populates hash-change-received-div upon receiving of a hashchange event. |
| 19 var onHashChange = function(e) { |
| 20 updateHashChangeReceivedText(true); |
| 21 } |
| 22 |
| 23 var updateOnLoadText = function(text) { |
| 24 document.getElementById('on-load-div').innerHTML = text; |
| 25 } |
| 26 |
| 27 var updateNoOpText = function(text) { |
| 28 document.getElementById('no-op-div').innerHTML = text; |
| 29 } |
| 30 |
| 31 var updatePopStateReceivedText = function(received) { |
| 32 var text = received ? 'PopStateReceived' : ''; |
| 33 document.getElementById('pop-state-received-div').innerHTML = text; |
| 34 } |
| 35 |
| 36 var updateStateObjectText = function(state) { |
| 37 document.getElementById('state-object-div').innerHTML = state; |
| 38 } |
| 39 |
| 40 var updateHashChangeReceivedText = function(received) { |
| 41 var text = received ? 'HashChangeReceived' : ''; |
| 42 document.getElementById('hash-change-received-div').innerHTML = text; |
| 43 } |
| 44 |
| 45 // Clears all div text an starts a timer that updates no-op-div with "NoOpText" |
| 46 // after 1s. This allows tests to verify that no nagivations occur after a |
| 47 // no-op JavaScript call. |
| 48 var onButtonTapped = function() { |
| 49 updateOnLoadText(''); |
| 50 updateNoOpText(''); |
| 51 updatePopStateReceivedText(false); |
| 52 updateStateObjectText(''); |
| 53 updateHashChangeReceivedText(false); |
| 54 setTimeout("updateNoOpText('NoOpText')", 1000); |
| 55 } |
| 56 |
| 57 var goNoParameter = function() { |
| 58 onButtonTapped(); |
| 59 window.history.go(); |
| 60 } |
| 61 |
| 62 var goZero = function() { |
| 63 onButtonTapped(); |
| 64 window.history.go(0); |
| 65 } |
| 66 |
| 67 var go2 = function() { |
| 68 onButtonTapped(); |
| 69 window.history.go(2); |
| 70 } |
| 71 |
| 72 var goBack2 = function() { |
| 73 onButtonTapped(); |
| 74 window.history.go(-2); |
| 75 } |
| OLD | NEW |