Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / fast / loader / stateobjects / document-destroyed-navigate-back-with-fragment-scroll.html
1 <html>
2 <head>
3 <script>
4
5 if (window.testRunner) {
6     if (!sessionStorage.stage)
7         testRunner.clearBackForwardList();
8     testRunner.dumpAsText();
9     testRunner.waitUntilDone();
10 }
11
12 function lastPathComponent(url)
13 {
14     return url.split('/').pop();
15 }
16
17 function hashOf(url)
18 {
19     return url.substring(url.lastIndexOf('#'));
20 }
21
22 function runFirstStageOfTest()
23 {
24     history.replaceState("FirstEntry", null, "#FirstEntry");
25     history.pushState("SecondEntry", null, "#SecondEntry");
26     history.back();
27 }
28
29 function runTest()
30 {
31     alert("LOADED");
32     if (!sessionStorage.stage)
33         runFirstStageOfTest();
34 }
35
36 function continueTest(state)
37 {
38     // FIXME: Once the popstate and hashchange events fire asynchronously, we
39     // can eliminate this setTimeout hack.  The hashchange event currently runs
40     // synchronously following the popstate event, but the calls to
41     // replaceState cause the location to change immediately.  That confuses
42     // our hashchange handler, which expects to see the "old" value of the
43     // location.
44
45     setTimeout(function() {
46         if (state == "FirstEntry") {
47             history.replaceState("FirstEntryWillLaterBeReactivated", null, "#FirstEntryWillLaterBeReactivated");
48             history.forward();
49         } else if (state == "SecondEntry") {
50             history.replaceState("SecondEntryWillLaterBeReactivated", null, "#SecondEntryWillLaterBeReactivated");
51             window.location = "resources/navigate-back.html";
52         } else if (state == "SecondEntryWillLaterBeReactivated")
53             history.back();
54     }, 0);
55 }
56
57 window.onpopstate = function statePopped()
58 {
59     var state = event.state;
60     alert("State popped - " + state + " (type " + typeof state + ")");
61     continueTest(state);
62 }
63
64 window.onpageshow = function pageShown()
65 {
66     if (sessionStorage.stage == 2) {
67         var state = history.state;
68         alert("Page shown - " + state + " (type " + typeof state + ")");
69         continueTest(state);
70     }
71 }
72
73 window.onhashchange = function hashChanged(event)
74 {
75    alert("hashChanged - Last path component of location is " + lastPathComponent(event.newURL));
76    if (hashOf(event.newURL) == "#FirstEntryWillLaterBeReactivated") {
77         alert("Test complete");
78         sessionStorage.clear();
79         if (window.testRunner)
80             testRunner.notifyDone();
81     }
82 }
83
84 </script>
85 <body onload="runTest();" onunload="/* disable page cache */">
86 <pre>
87 This test:
88 -Builds up a list of state object entries with fragment URLs.
89 -Navigates through them to verify that the popstate and hashchanged events are fired.
90 -Navigates away to a new document, with the old document being destroyed.
91 -Navigates back to the state object entries and verifies the pageshow or popstate events are fired on the new documents.
92 </pre>
93 </body>
94 </html>