Upstream version 7.35.144.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / http / tests / media / media-source / webkitmediasource-seek-to-end-after-duration-change.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, true);
9
10             function onSourceOpen()
11             {
12                 segmentHelper.addSourceBuffer();
13                 waitForEventOnce('loadeddata', onLoadedData, false);
14                 segmentHelper.appendInitSegment();
15                 segmentHelper.appendAllMediaSegments();
16             }
17
18             function onLoadedData()
19             {
20                 waitForEventOnce('seeked', onExplicitSeek, false);
21                 video.currentTime = 3;
22             }
23
24             function onExplicitSeek()
25             {
26                 var currentTime = video.currentTime;
27                 if (currentTime != 3) {
28                     failTest("Seeked to " + currentTime + " instead of 3");
29                     return;
30                 }
31
32                 waitForEventOnce('durationchange', onDurationChange, false);
33                 mediaSource.duration = 2;
34             }
35
36             function onDurationChange()
37             {
38                 MediaSourceTest.expectDuration(video, mediaSource, 2);
39                 waitForEventOnce('seeking', function() {
40                     waitForEventOnce('seeked', onSeekToEnd, false);
41                     mediaSource.endOfStream();
42                 }, false);
43             }
44
45             function onSeekToEnd()
46             {
47                 var currentTime = video.currentTime;
48                 var duration = video.duration;
49                 if (currentTime != duration) {
50                     failTest("Seeked to " + currentTime + " instead of " + duration);
51                     return;
52                 }
53                 endTest();
54             }
55
56             function onLoad()
57             {
58                 findMediaElement();
59
60                 mediaSource = new WebKitMediaSource();
61                 waitForEvent('webkitsourceopen', onSourceOpen, false, false, mediaSource);
62
63                 segmentHelper.init(video, function(success) {
64                     if (!success) {
65                         failTest("Failed to load segment data");
66                         return;
67                     }
68                     MediaSourceTest.setSrcToMediaSourceTestURL(video);
69                 });
70             }
71         </script>
72     </head>
73     <body onload="onLoad()">
74         <video> </video>
75         <p>Test that the video tag seeks to the end of the file if duration is truncated before the current playback position.</p>
76     </body>
77 </html>