Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / media / media-source / mediasource-multiple-attach.html
blob6cc7bdc69152409879fb1b8949e00413d587865c
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 twoMediaElementTest(testFunction, description)
14 media_test(function(test)
16 var firstMediaTag = document.createElement('video');
17 var secondMediaTag = document.createElement('video');
18 document.body.appendChild(firstMediaTag);
19 document.body.appendChild(secondMediaTag);
21 // Overload done() so that elements added to the document can be
22 // removed.
23 var removeMediaElements = true;
24 var oldTestDone = test.done.bind(test);
25 test.done = function()
27 if (removeMediaElements) {
28 document.body.removeChild(secondMediaTag);
29 document.body.removeChild(firstMediaTag);
30 removeMediaElements = false;
32 oldTestDone();
35 testFunction(test, firstMediaTag, secondMediaTag);
36 }, description);
39 twoMediaElementTest(function(test, firstMediaTag, secondMediaTag)
41 // When attachment of mediaSource to two MediaElements is done
42 // without an intervening stable state, exactly one of the two
43 // MediaElements should successfully attach, and the other one
44 // should get error event due to mediaSource already in 'open'
45 // readyState.
46 var mediaSource = new MediaSource();
47 var mediaSourceURL = URL.createObjectURL(mediaSource);
48 var gotSourceOpen = false;
49 var gotError = false;
50 var doneIfFinished = test.step_func(function()
52 if (gotSourceOpen && gotError)
53 test.done();
54 });
55 var errorHandler = test.step_func(function(e)
57 firstMediaTag.removeEventListener('error', errorHandler);
58 secondMediaTag.removeEventListener('error', errorHandler);
60 var eventTarget = e.target;
61 var otherTarget;
62 if (eventTarget == firstMediaTag) {
63 otherTarget = secondMediaTag;
64 } else {
65 assert_equals(eventTarget, secondMediaTag, 'Error target check');
66 otherTarget = firstMediaTag;
69 assert_true(eventTarget.error != null, 'Error state on one tag');
70 assert_equals(eventTarget.error.code, MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED, 'Expected error code');
71 assert_equals(otherTarget.error, null, 'No error on other tag');
73 assert_equals(eventTarget.networkState, HTMLMediaElement.NETWORK_NO_SOURCE,
74 'Tag with error state networkState');
75 assert_equals(otherTarget.networkState, HTMLMediaElement.NETWORK_LOADING,
76 'Tag without error state networkState');
78 gotError = true;
79 doneIfFinished();
80 });
82 test.expectEvent(mediaSource, 'sourceopen', 'An attachment succeeded');
83 firstMediaTag.addEventListener('error', errorHandler);
84 secondMediaTag.addEventListener('error', errorHandler);
86 firstMediaTag.src = mediaSourceURL;
87 secondMediaTag.src = mediaSourceURL;
89 test.waitForExpectedEvents(function()
91 assert_equals(mediaSource.readyState, 'open', 'Source is opened');
92 gotSourceOpen = true;
93 doneIfFinished();
94 });
95 }, 'Test exactly one succeeds when two MediaElements attach to same MediaSource');
97 mediasource_test(function(test, mediaElement, mediaSource) {
98 assert_equals(mediaSource.readyState, 'open', 'Source open');
99 // Set the tag's src attribute. This should close mediaSource,
100 // reattach it to the tag, and initiate source reopening.
101 test.expectEvent(mediaSource, 'sourceopen', 'Source attached again');
102 mediaElement.src = URL.createObjectURL(mediaSource);
103 assert_equals(mediaSource.readyState, 'closed', 'Source closed');
105 test.waitForExpectedEvents(function()
107 assert_equals(mediaSource.readyState, 'open', 'Source reopened');
108 test.done();
110 }, 'Test that MediaSource can reattach if closed first');
111 </script>
112 </body>
113 </html>