Upstream version 7.35.144.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / http / tests / media / media-source / webkitmediasource-duration.html
1 <!DOCTYPE html>
2 <html>  
3   <head>
4     <script src="/media-resources/video-test.js"></script>
5     <script src="/media/resources/media-source/webm/segment-info.js"></script>
6     <script src="webkitmediasource-util.js"></script>
7     <script>
8       var segmentHelper = new MediaSourceTest.SegmentHelper(WebMSegmentInfo.testWebM);
9       var seekTo = 2;
10       var newDuration = 1;
11
12       function onSourceOpen(event)
13       {
14         mediaSource.removeEventListener('webkitsourceopen', onSourceOpen);
15
16         // Add an initialization segment and multiple media segments.
17         segmentHelper.addSourceBuffer();
18         segmentHelper.appendInitSegment();
19         segmentHelper.appendAllMediaSegments();
20
21         // Appending all segments triggers a playing event;
22         // add a listener for that event.
23         video.addEventListener('playing', onPlaying);
24       }
25
26       function onPlaying(event)
27       {
28         consoleWrite("Original duration = " + mediaSource.duration.toFixed());
29         video.currentTime = seekTo;
30
31         // Changing video current-time triggers a seeked event.
32         // Add a listener to it.
33         video.addEventListener('seeked', onSeeked);
34       }
35
36       function onSeeked(event)
37       {
38         // Playtime should now be at 2 seconds.
39         // Set duration to < current playtime.
40         mediaSource.duration = newDuration;
41         testExpected("mediaSource.duration", newDuration, "==");
42
43         // Because the duration was set to be before the playback position,
44         // current playback position should now be the same as the new duration.
45         testExpected("mediaSource.duration", video.currentTime, "==");
46         consoleWrite("PASS: Media Source duration truncated and current time changed to = " + mediaSource.duration);
47         endTest();
48       }
49
50       function start()
51       {
52         findMediaElement();
53
54         waitForEventAndFail('error');
55
56         mediaSource.addEventListener('webkitsourceopen', onSourceOpen);
57
58         segmentHelper.init(video, function (success)
59         {
60           if (!success) {
61             failTest("Failed to load segment data");
62             return;
63           }
64
65           MediaSourceTest.setSrcToMediaSourceTestURL(video);
66         });
67       }
68     </script>
69   </head>
70   <body onload="start()">
71     <video autoplay controls></video>
72     <p>Tests simple operations with duration attribute of MediaSource object.</p>
73   </body>
74 </html>