summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/fast/history/saves-state-after-fragment-nav.html
blob: a5be62fec7a4f5f5deb4936b21b5619f8d734848 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<html>
<script>

// Navigation steps:
// 1- loads this page
// 2- loads this page + hash (doesn't call onload)
// 3- loads a data URL that just navigates back
// 4- loads this page + hash (calls onload, triggering completion)

function navigateToHash(field) {
  location.hash = 'hash';
  field.value = 'test';
}

function navigateAwayAndBack() {
  // Assigning to location does not create a history entry, so
  // instead we simulate a link click.
  var evt = document.createEvent("MouseEvents"); 
  evt.initMouseEvent("click", true, true, window,
      0, 0, 0, 0, 0, false, false, false, false, 0, null); 
  document.getElementById('anchor').dispatchEvent(evt);
}

function runTestStep() {
  var hash = location.hash;
  var field = document.getElementById('field');

  if (hash == "") {
    if (window.testRunner) {
      testRunner.dumpAsText();
      testRunner.waitUntilDone();
    }
    // Location changes need to happen outside the onload handler to generate history entries.
    setTimeout(function() {
      navigateToHash(field);
      navigateAwayAndBack();
    }, 0);
  } else {
    document.body.innerHTML = (field.value == '') ? 'FAIL' : 'PASS';
    if (window.testRunner)
      testRunner.notifyDone();
  }
}

</script>
<body onload='runTestStep()' onunload='/*suppress page cache*/'>
  <input id='field'></input>
  <a id='anchor' href='data:text/html,<body onload="history.back()"></body>'>go away and come back</a>
</body>
</html>