summaryrefslogtreecommitdiffstats
path: root/docshell/test/historyframes.html
blob: 30fca2c0a3b51f905ea64af7dba00a6e031d279e (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=602256
-->
<head>
  <title>Test for Bug 602256</title>
</head>
<body onload="SimpleTest.executeSoon(run_test)">
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=602256">Mozilla Bug 602256</a>
<div id="content">
  <iframe id="iframe" src="data:text/html,<p%20id='text'>Start</p>"></iframe>
</div>
<pre id="test">
<script type="application/javascript">

/** Test for Bug 602256 **/

var testWin = window.opener ? window.opener : window.parent;

var SimpleTest = testWin.SimpleTest;
function is() { testWin.is.apply(testWin, arguments); }

var gFrame = null;

function gState() {
  return location.hash.replace(/^#/, "");
}

function waitForLoad(aCallback) {
  function listener() {
    gFrame.removeEventListener("load", listener, false);
    SimpleTest.executeSoon(aCallback);
  }

  gFrame.addEventListener("load", listener, false);
}

function loadContent(aURL, aCallback) {
  waitForLoad(aCallback);

  gFrame.src = aURL;
}

function getURL() {
  return gFrame.contentDocument.documentURI;
}

function getContent() {
  return gFrame.contentDocument.getElementById("text").textContent;
}

var START = "data:text/html,<p%20id='text'>Start</p>";
var URL1 = "data:text/html,<p%20id='text'>Test1</p>";
var URL2 = "data:text/html,<p%20id='text'>Test2</p>";

function run_test() {
  window.location.hash = "START";

  gFrame = document.getElementById("iframe");

  test_basic_inner_navigation();
}

function end_test() {
  testWin.done();
}

function test_basic_inner_navigation() {
  // Navigate the inner frame a few times
  loadContent(URL1, function() {
    is(getURL(), URL1, "URL should be correct");
    is(getContent(), "Test1", "Page should be correct");

    loadContent(URL2, function() {
      is(getURL(), URL2, "URL should be correct");
      is(getContent(), "Test2", "Page should be correct");

      // Test that history is working
      waitForLoad(function() {
        is(getURL(), URL1, "URL should be correct");
        is(getContent(), "Test1", "Page should be correct");

        waitForLoad(function() {
          is(getURL(), URL2, "URL should be correct");
          is(getContent(), "Test2", "Page should be correct");

          test_state_navigation();
        });
        window.history.forward();
      });
      window.history.back();
    });
  });
}

function test_state_navigation() {
  window.location.hash = "STATE1";

  is(getURL(), URL2, "URL should be correct");
  is(getContent(), "Test2", "Page should be correct");

  window.location.hash = "STATE2";

  is(getURL(), URL2, "URL should be correct");
  is(getContent(), "Test2", "Page should be correct");

  window.history.back();

  is(gState(), "STATE1", "State should be correct after going back");
  is(getURL(), URL2, "URL should be correct");
  is(getContent(), "Test2", "Page should be correct");

  window.history.forward();

  is(gState(), "STATE2", "State should be correct after going forward");
  is(getURL(), URL2, "URL should be correct");
  is(getContent(), "Test2", "Page should be correct");

  window.history.back();
  window.history.back();

  is(gState(), "START", "State should be correct");
  is(getURL(), URL2, "URL should be correct");
  is(getContent(), "Test2", "Page should be correct");

  waitForLoad(function() {
    is(getURL(), URL1, "URL should be correct");
    is(getContent(), "Test1", "Page should be correct");

    waitForLoad(function() {
      is(gState(), "START", "State should be correct");
      is(getURL(), START, "URL should be correct");
      is(getContent(), "Start", "Page should be correct");

      end_test();
    });

    window.history.back();

    is(gState(), "START", "State should be correct after going back twice");
  });

  window.history.back();
  is(gState(), "START", "State should be correct");
}
</script>
</pre>
</body>
</html>