[Modern Media Controls] Turn media/modern-media-controls/ios-inline-media-controls...
[WebKit-https.git] / LayoutTests / media / restore-from-page-cache.html
1 <html>
2     <head>
3         <script src=media-file.js></script>
4         <script src=video-test.js></script>
5         <script>
6             var mediaFile = findMediaFile("video", "content/test");
7             var loadCount = 0;
8
9             if (window.testRunner) {
10                 testRunner.dumpAsText();
11                 testRunner.waitUntilDone();
12                 testRunner.overridePreference("WebKitUsesPageCachePreferenceKey", 1);
13             }
14
15             function pageshow(evt) 
16             {
17                 if (!evt.persisted) {
18                     // this is the first time the page has been loaded, setup the video element
19                     setup();
20                 } else {
21                     consoleWrite("*** Page returned from cache");
22
23                     testExpected("loadCount", 1);
24
25                     // Dump the height of the video so we can verify that the player was restored.
26                     video = document.getElementsByTagName('video')[0];
27                     videoComputedStyle = getComputedStyle(video);
28                     testExpected("videoComputedStyle.width", "320px");
29                     testExpected("videoComputedStyle.height", "240px");
30
31                     // schedule the test to end shortly, but wait long enough for the element to fire loading events
32                     //  if that is going to happen
33                     setTimeout(function() { if (window.testRunner) testRunner.notifyDone(); }, 200);
34                 }
35             }
36
37             function pagehide()
38             {
39                 // Have the video element generate some events that need to be suspended.
40                 // We use multiple events to verify that they fire in the correct order.
41                 consoleWrite("*** Changing playbackRate just before going into cache, to schedule a ratechange event.");
42                 document.getElementsByTagName("video")[0].playbackRate = 2; 
43                 consoleWrite("*** Changing volume just before going into cache, to schedule a volumechange event.");
44                 document.getElementsByTagName("video")[0].volume = 0.5; 
45             }
46
47             function canplaythrough() 
48             {
49                 testExpected("loadCount", 0);
50                 if (!loadCount) {
51                     video = document.getElementsByTagName('video')[0];
52                     consoleWrite("*** Page going into cache");
53                     setTimeout('window.location = "data:text/html,<script>history.back()<" + "/script>"', 0);
54                 }
55                 ++loadCount;
56             }
57
58             function propertyChangeCallback(evt)
59             {
60                 consoleWrite("*** " + evt.type +  " event fired. This should happen AFTER returning from cache.");
61             }
62
63             function setup()
64             {
65                 video = mediaElement = document.getElementsByTagName('video')[0];
66
67                 waitForEvent('loadstart');
68                 waitForEvent('canplaythrough', canplaythrough);
69                 
70                 video.src = mediaFile;
71
72                 video.onratechange = propertyChangeCallback;
73                 video.onvolumechange = propertyChangeCallback;
74             }
75
76             window.onpageshow = pageshow;
77             window.onpagehide = pagehide;
78         </script>
79     </head>
80     <body>
81
82         <video controls > </video>
83         <p>Make sure we don't reload a &lt;video&gt; element when navigating back to an uncached page.</p>
84     </body>
85 </html>
86