Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / media / media-source / mediasource-timestamp-offset.html
blobaf8ea5074503ef285928ccc1fffb221a756ae78f
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="/w3c/resources/testharness.js"></script>
5 <script src="/w3c/resources/testharnessreport.js"></script>
6 <script src="mediasource-util.js"></script>
7 <link rel='stylesheet' href='/w3c/resources/testharness.css'>
8 </head>
9 <body>
10 <div id="log"></div>
11 <script>
12 function simpleTimestampOffsetTest(value, expected, description)
14 mediasource_test(function(test, mediaElement, mediaSource)
16 var segmentInfo = MediaSourceUtil.SEGMENT_INFO;
17 var sourceBuffer = mediaSource.addSourceBuffer(segmentInfo.type);
19 if (expected == 'TypeError') {
20 assert_throws({name: 'TypeError'},
21 function() { sourceBuffer.timestampOffset = value; },
22 'setting timestampOffset to ' + description + ' throws an exception.');
23 } else {
24 sourceBuffer.timestampOffset = value;
25 assert_equals(sourceBuffer.timestampOffset, expected);
28 test.done();
29 }, 'Test setting SourceBuffer.timestampOffset to ' + description + '.');
32 simpleTimestampOffsetTest(10.5, 10.5, 'a positive number');
33 simpleTimestampOffsetTest(-10.4, -10.4, 'a negative number');
34 simpleTimestampOffsetTest(0, 0, 'zero');
35 simpleTimestampOffsetTest(Number.POSITIVE_INFINITY, 'TypeError', 'positive infinity');
36 simpleTimestampOffsetTest(Number.NEGATIVE_INFINITY, 'TypeError', 'negative infinity');
37 simpleTimestampOffsetTest(Number.NaN, 'TypeError', 'NaN');
38 simpleTimestampOffsetTest(undefined, 'TypeError', 'undefined');
39 simpleTimestampOffsetTest(null, 0, 'null');
40 simpleTimestampOffsetTest(false, 0, 'false');
41 simpleTimestampOffsetTest(true, 1, 'true');
42 simpleTimestampOffsetTest('10.5', 10.5, 'a number string');
43 simpleTimestampOffsetTest('', 0, 'an empty string');
45 mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData)
47 var initSegment = MediaSourceUtil.extractSegmentData(mediaData, segmentInfo.init);
48 var mediaSegment = MediaSourceUtil.extractSegmentData(mediaData, segmentInfo.media[0]);
50 test.expectEvent(sourceBuffer, "updateend", "initSegment append ended.");
51 sourceBuffer.appendBuffer(initSegment);
53 test.waitForExpectedEvents(function()
55 test.expectEvent(sourceBuffer, "updateend", "mediaSegment append ended.");
56 sourceBuffer.appendBuffer(mediaSegment);
57 });
59 test.waitForExpectedEvents(function()
61 mediaSource.endOfStream();
63 assert_equals(mediaSource.readyState, "ended");
65 mediaSource.sourceBuffers[0].timestampOffset = 2;
67 assert_equals(mediaSource.readyState, "open");
69 test.expectEvent(mediaSource, "sourceopen", "mediaSource fired 'sourceopen' event.");
70 });
72 test.waitForExpectedEvents(function()
74 test.done();
75 });
76 }, "Test setting timestampOffset in 'ended' state causes a transition to 'open'.");
78 mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData)
80 var initSegment = MediaSourceUtil.extractSegmentData(mediaData, segmentInfo.init);
81 var mediaSegment = MediaSourceUtil.extractSegmentData(mediaData, segmentInfo.media[0]);
83 test.expectEvent(sourceBuffer, "updateend", "initSegment append ended.");
84 sourceBuffer.appendBuffer(initSegment);
85 assert_equals(mediaSource.sourceBuffers[0].timestampOffset, 0, "read initial value");
87 test.waitForExpectedEvents(function()
89 test.expectEvent(sourceBuffer, "updateend", "mediaSegment append ended.");
90 sourceBuffer.appendBuffer(mediaSegment);
91 assert_equals(mediaSource.sourceBuffers[0].timestampOffset, 0,
92 "No change to timestampoffset after segments mode init segment append");
93 });
95 test.waitForExpectedEvents(function()
97 assert_equals(mediaSource.sourceBuffers[0].timestampOffset, 0,
98 "No change to timestampoffset after segments mode media segment append");
99 test.done();
101 }, "Test getting the initial value of timestampOffset.");
103 mediasource_test(function(test, mediaElement, mediaSource)
105 var sourceBuffer = mediaSource.addSourceBuffer(MediaSourceUtil.AUDIO_VIDEO_TYPE);
106 assert_true(sourceBuffer != null, "New SourceBuffer returned");
108 // FIXME: verify activeSourceBuffers is empty before removeSourceBuffer as well.
110 mediaSource.removeSourceBuffer(sourceBuffer);
111 assert_true(mediaSource.sourceBuffers.length == 0, "MediaSource.sourceBuffers is empty");
112 assert_true(mediaSource.activeSourceBuffers.length == 0, "MediaSource.activesourceBuffers is empty");
114 assert_throws("InvalidStateError", function()
116 sourceBuffer.timestampOffset = 10;
119 test.done();
120 }, "Test setting timestampoffset after removing the sourcebuffer.");
121 </script>
122 </body>
123 </html>