Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / media / media-source / mediasource-appendstream-quota-exceeded.html
blob644f3fdb33063f257c6d2284e476f989df8f308a
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 createMediaXHR(test, onFinished) {
13 var mediaURL = "/media/resources/media-source/webm/test-a-5min-44100Hz-1ch.webm";
14 var xhr = new XMLHttpRequest();
15 xhr.open('GET', mediaURL, true);
16 xhr.responseType = 'legacystream';
17 test.failOnEvent(xhr, 'error');
18 xhr.onreadystatechange = function() {
19 if (xhr.readyState == 4 && xhr.status == 200) {
20 onFinished();
23 return xhr;
26 mediasource_test(function(test, mediaElement, mediaSource)
28 var sourceBuffer = mediaSource.addSourceBuffer(MediaSourceUtil.AUDIO_ONLY_TYPE);
29 sourceBuffer.mode = 'sequence';
31 function onUpdateEnd() {
32 var xhr = createMediaXHR(test, function()
34 // We are appending data repeatedly in sequence mode, there should be no gaps.
35 assert_false(sourceBuffer.buffered.length > 1, "unexpected gap in buffered ranges.");
36 try {
37 sourceBuffer.appendStream(xhr.response, 551 * 1024);
38 } catch(ex) {
39 assert_equals(ex.name, 'QuotaExceededError');
40 test.done();
42 test.expectEvent(sourceBuffer, "updateend", "Append ended.");
43 test.waitForExpectedEvents(onUpdateEnd);
44 });
45 xhr.send();
47 // Start appending data
48 onUpdateEnd();
49 }, 'Calling appendStream repeatedly (with size parameter) should fill up the buffer and throw a QuotaExceededError when buffer is full.');
51 mediasource_test(function(test, mediaElement, mediaSource)
53 var sourceBuffer = mediaSource.addSourceBuffer(MediaSourceUtil.AUDIO_ONLY_TYPE);
54 sourceBuffer.mode = 'sequence';
56 sourceBuffer.addEventListener('error', function() {
57 // Ok, we got error message as expected. This error notifies us that the async
58 // appendStream has failed due to buffer being full.
59 test.done();
60 });
62 function onUpdateEnd() {
63 var xhr = createMediaXHR(test, function()
65 // We are appending data repeatedly in sequence mode, there should be no gaps.
66 assert_false(sourceBuffer.buffered.length > 1, "unexpected gap in buffered ranges.");
67 sourceBuffer.appendStream(xhr.response);
68 test.expectEvent(sourceBuffer, "updateend", "Append ended.");
69 test.waitForExpectedEvents(onUpdateEnd);
70 });
71 xhr.send();
73 // Start appending data
74 onUpdateEnd();
75 }, 'Calling appendStream repeatedly (without size parameter) should fill up the buffer and send an error event when buffer is full.');
76 </script>
77 </body>
78 </html>