Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / fast / loader / stateobjects / state-attribute-only-one-deserialization.html
1 <!DOCTYPE html>
2 <html>
3 <head>
4     <script src="../../../resources/js-test.js"></script>
5 </head/>
6 <body>
7 <script>
8     description("Make sure the same deserialization of the state object is used every time (both in the history object and popstate events).");
9
10     window.jsTestIsAsync = true;
11     if (window.testRunner) {
12         testRunner.clearBackForwardList();
13         testRunner.waitUntilDone();
14     }
15
16     shouldBeDefined("history.state");
17
18     // Create a new object.
19     var stateObject = ["a"];
20
21     // Use it as the state object in a replaceState.  This clones the object.
22     history.replaceState(stateObject, null, null);
23
24     shouldBeTrue("history.state === history.state");
25
26     // Since the actual history.state is a structured clone, it should not match our original object.
27     shouldBeTrue("history.state !== stateObject");
28
29     // Now let's refetch a copy of history.state to store;
30     stateObject = history.state;
31
32     // Our reference and the history.state itself should be the same.  This is now Adam's original assertion.
33     shouldBeTrue("history.state === stateObject");
34
35     // Now let's do a pushstate to add a history entry.
36     history.pushState(null, null, null);
37
38     // Now add a handler for the popstate event.
39     var popStateEvent;
40     window.onpopstate = function(e) {
41         debug("\nInside popstate event\n");
42         popStateEvent = e;
43         // Our stored reference to stateObject will not match the current state object, as it is a structured clone of the history item's state object.
44         shouldBeTrue("history.state !== stateObject");
45         // Our stored reference to stateObject will not match the state object in this pop state event, as it is the same as history.state which is a structured clone of the history item's state object.
46         shouldBeTrue("popStateEvent.state !== stateObject");
47         // The event's state object and the current state object should match.
48         shouldBeTrue("popStateEvent.state === history.state");
49
50         setTimeout(finishJSTest, 0);
51     }
52
53     // Now let's go back to our original history entry which has a state object that we've stored a reference to already.
54     // This will fire our popstate event handler above.
55     window.onload = function() {
56         history.back();
57     };
58 </script>
59 </body>
60 </html>