Source/WebCore/ChangeLog

112012-08-06 Anna Cavender <annacc@chromium.org>
22
 3 Update HTMLMediaElement to the new OO MediaSource API.
 4 https://bugs.webkit.org/show_bug.cgi?id=91775
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 This patch rips out the old-style MediaSource API and allows a
 9 MediaSource object to be attached to HTMLMediaElement.
 10 http://dvcs.w3.org/hg/html-media/raw-file/tip/media-source/media-source.html
 11
 12 Tests: updates to http/tests/media/media-source/*
 13
 14 * html/HTMLMediaElement.cpp:
 15 (WebCore):
 16 (WebCore::HTMLMediaElement::HTMLMediaElement): Remove old style API resources.
 17 (WebCore::HTMLMediaElement::parseAttribute): Remove old style event attributes.
 18 (WebCore::HTMLMediaElement::prepareForLoad): Set source state to "closed".
 19 (WebCore::HTMLMediaElement::loadResource): Get MediaSource object from blob registry
 20 look up and, if found, set it's MediaPlayer pointer to the current MediaPlayer.
 21 (WebCore::HTMLMediaElement::noneSupported): Set source state to "closed".
 22 (WebCore::HTMLMediaElement::mediaEngineError): Set source state to "closed".
 23 (WebCore::HTMLMediaElement::mediaPlayerSourceOpened): Set source state to "open".
 24 (WebCore::HTMLMediaElement::mediaPlayerSourceURL): Change to new blob URL.
 25 (WebCore::HTMLMediaElement::seek): Check if source state is "closed".
 26 (WebCore::HTMLMediaElement::setSourceState): Helper function so that we don't have to
 27 keep checking for m_mediaSource.
 28 (WebCore::HTMLMediaElement::userCancelledLoad): Set source state to "closed".
 29 (WebCore::HTMLMediaElement::createMediaPlayer): If the current MediaPlayer is re-
 30 created, notify the MediaSource and reset its MediaPlayer.
 31
 32 * html/HTMLMediaElement.h: Remove old style API code and add a MediaSource object.
 33 (HTMLMediaElement):
 34 * html/HTMLMediaElement.idl: Remove old style API.
 35
 362012-08-06 Anna Cavender <annacc@chromium.org>
 37
338 Create a MediaSource object.
439 https://bugs.webkit.org/show_bug.cgi?id=91773
540

Source/WebCore/html/HTMLMediaElement.cpp

111111#include "DisplaySleepDisabler.h"
112112#endif
113113
 114#if ENABLE(MEDIA_SOURCE)
 115#include "MediaSource.h"
 116#include "MediaSourceRegistry.h"
 117#endif
 118
114119using namespace std;
115120
116121namespace WebCore {

@@static const char* boolString(bool val)
145150
146151#if ENABLE(MEDIA_SOURCE)
147152// URL protocol used to signal that the media source API is being used.
148 static const char* mediaSourceURLProtocol = "x-media-source";
 153static const char* mediaSourceBlobProtocol = "blob";
149154#endif
150155
151156using namespace HTMLNames;

@@HTMLMediaElement::HTMLMediaElement(const QualifiedName& tagName, Document* docum
219224 , m_preload(MediaPlayer::Auto)
220225 , m_displayMode(Unknown)
221226 , m_processingMediaPlayerCallback(0)
222 #if ENABLE(MEDIA_SOURCE)
223  , m_sourceState(SOURCE_CLOSED)
224 #endif
225227 , m_cachedTime(MediaPlayer::invalidTime())
226228 , m_cachedTimeWallClockUpdateTime(0)
227229 , m_minimumWallClockTimeToCacheMediaTime(0)

@@HTMLMediaElement::HTMLMediaElement(const QualifiedName& tagName, Document* docum
272274 }
273275
274276#if ENABLE(MEDIA_SOURCE)
275  m_mediaSourceURL.setProtocol(mediaSourceURLProtocol);
 277 m_mediaSourceURL.setProtocol(mediaSourceBlobProtocol);
276278 m_mediaSourceURL.setPath(createCanonicalUUIDString());
277279#endif
278280

@@void HTMLMediaElement::parseAttribute(const Attribute& attribute)
421423 setAttributeEventListener(eventNames().webkitbeginfullscreenEvent, createAttributeEventListener(this, attribute));
422424 else if (attribute.name() == onwebkitendfullscreenAttr)
423425 setAttributeEventListener(eventNames().webkitendfullscreenEvent, createAttributeEventListener(this, attribute));
424 #if ENABLE(MEDIA_SOURCE)
425  else if (attribute.name() == onwebkitsourcecloseAttr)
426  setAttributeEventListener(eventNames().webkitsourcecloseEvent, createAttributeEventListener(this, attribute));
427  else if (attribute.name() == onwebkitsourceendedAttr)
428  setAttributeEventListener(eventNames().webkitsourceendedEvent, createAttributeEventListener(this, attribute));
429  else if (attribute.name() == onwebkitsourceopenAttr)
430  setAttributeEventListener(eventNames().webkitsourceopenEvent, createAttributeEventListener(this, attribute));
431 #endif
432426 else
433427 HTMLElement::parseAttribute(attribute);
434428}

@@void HTMLMediaElement::prepareForLoad()
703697#endif
704698
705699#if ENABLE(MEDIA_SOURCE)
706  if (m_sourceState != SOURCE_CLOSED)
707  setSourceState(SOURCE_CLOSED);
 700 setSourceState(MediaSource::closedKeyword());
708701#endif
709702
710703 // 4 - If the media element's networkState is not set to NETWORK_EMPTY, then run these substeps

@@void HTMLMediaElement::loadResource(const KURL& initialURL, ContentType& content
927920 }
928921
929922#if ENABLE(MEDIA_SOURCE)
930  // If this is a media source URL, make sure it is the one for this media element.
931  if (url.protocolIs(mediaSourceURLProtocol) && url != m_mediaSourceURL) {
932  mediaLoadingFailed(MediaPlayer::FormatError);
933  return;
 923 if (url.protocolIs(mediaSourceBlobProtocol)) {
 924 if (m_mediaSource)
 925 m_mediaSource->setReadyState(MediaSource::closedKeyword());
 926
 927 m_mediaSource = adoptRef(MediaSourceRegistry::registry().lookupMediaSource(url.string()));
 928
 929 if (m_mediaSource) {
 930 m_mediaSource->setMediaPlayer(m_player.get());
 931 m_mediaSourceURL = url;
 932 }
934933 }
935934#endif
936935

@@void HTMLMediaElement::noneSupported()
14321431 scheduleEvent(eventNames().errorEvent);
14331432
14341433#if ENABLE(MEDIA_SOURCE)
1435  if (m_sourceState != SOURCE_CLOSED)
1436  setSourceState(SOURCE_CLOSED);
 1434 setSourceState(MediaSource::closedKeyword());
14371435#endif
14381436
14391437 // 8 - Set the element's delaying-the-load-event flag to false. This stops delaying the load event.

@@void HTMLMediaElement::mediaEngineError(PassRefPtr<MediaError> err)
14641462 scheduleEvent(eventNames().errorEvent);
14651463
14661464#if ENABLE(MEDIA_SOURCE)
1467  if (m_sourceState != SOURCE_CLOSED)
1468  setSourceState(SOURCE_CLOSED);
 1465 setSourceState(MediaSource::closedKeyword());
14691466#endif
14701467
14711468 // 4 - Set the element's networkState attribute to the NETWORK_EMPTY value and queue a

@@void HTMLMediaElement::mediaPlayerSourceOpened()
17501747{
17511748 beginProcessingMediaPlayerCallback();
17521749
1753  setSourceState(SOURCE_OPEN);
 1750 setSourceState(MediaSource::openKeyword());
17541751
17551752 endProcessingMediaPlayerCallback();
17561753}

@@String HTMLMediaElement::mediaPlayerSourceURL() const
17591756{
17601757 return m_mediaSourceURL.string();
17611758}
1762 
1763 bool HTMLMediaElement::isValidSourceId(const String& id, ExceptionCode& ec) const
1764 {
1765  if (id.isNull() || id.isEmpty()) {
1766  ec = INVALID_ACCESS_ERR;
1767  return false;
1768  }
1769 
1770  if (!m_sourceIDs.contains(id)) {
1771  ec = SYNTAX_ERR;
1772  return false;
1773  }
1774 
1775  return true;
1776 }
1777 
17781759#endif
17791760
17801761#if ENABLE(ENCRYPTED_MEDIA)

@@void HTMLMediaElement::seek(float time, ExceptionCode& ec)
19981979#if ENABLE(MEDIA_SOURCE)
19991980 // Always notify the media engine of a seek if the source is not closed. This ensures that the source is
20001981 // always in a flushed state when the 'seeking' event fires.
2001  if (m_sourceState != SOURCE_CLOSED)
2002  noSeekRequired = false;
 1982 if (m_mediaSource && m_mediaSource->readyState() != MediaSource::closedKeyword())
 1983 noSeekRequired = false;
20031984#endif
20041985
20051986 if (noSeekRequired) {

@@void HTMLMediaElement::seek(float time, ExceptionCode& ec)
20212002 m_sentEndEvent = false;
20222003
20232004#if ENABLE(MEDIA_SOURCE)
2024  if (m_sourceState == SOURCE_ENDED)
2025  setSourceState(SOURCE_OPEN);
 2005 if (m_mediaSource && m_mediaSource->readyState() == MediaSource::endedKeyword())
 2006 setSourceState(MediaSource::openKeyword());
20262007#endif
20272008
20282009 // 8 - Set the current playback position to the given new playback position

@@void HTMLMediaElement::pauseInternal()
23702351}
23712352
23722353#if ENABLE(MEDIA_SOURCE)
2373 
2374 void HTMLMediaElement::webkitSourceAddId(const String& id, const String& type, ExceptionCode& ec)
2375 {
2376  if (id.isNull() || id.isEmpty()) {
2377  ec = INVALID_ACCESS_ERR;
2378  return;
2379  }
2380 
2381  if (m_sourceIDs.contains(id)) {
2382  ec = INVALID_STATE_ERR;
2383  return;
2384  }
2385 
2386  if (type.isNull() || type.isEmpty()) {
2387  ec = INVALID_ACCESS_ERR;
2388  return;
2389  }
2390 
2391  if (!m_player || m_currentSrc != m_mediaSourceURL || m_sourceState != SOURCE_OPEN) {
2392  ec = INVALID_STATE_ERR;
2393  return;
2394  }
2395 
2396  ContentType contentType(type);
2397  Vector<String> codecs = contentType.codecs();
2398 
2399  if (!codecs.size()) {
2400  ec = NOT_SUPPORTED_ERR;
2401  return;
2402  }
2403 
2404  switch (m_player->sourceAddId(id, contentType.type(), codecs)) {
2405  case MediaPlayer::Ok:
2406  m_sourceIDs.add(id);
2407  return;
2408  case MediaPlayer::NotSupported:
2409  ec = NOT_SUPPORTED_ERR;
2410  return;
2411  case MediaPlayer::ReachedIdLimit:
2412  ec = QUOTA_EXCEEDED_ERR;
2413  return;
2414  }
2415 
2416  ASSERT_NOT_REACHED();
2417 }
2418 
2419 void HTMLMediaElement::webkitSourceRemoveId(const String& id, ExceptionCode& ec)
 2354void HTMLMediaElement::setSourceState(const String& state)
24202355{
2421  if (!isValidSourceId(id, ec))
2422  return;
2423 
2424  if (!m_player || m_currentSrc != m_mediaSourceURL || m_sourceState == SOURCE_CLOSED) {
2425  ec = INVALID_STATE_ERR;
2426  return;
2427  }
 2356 if (!m_mediaSource)
 2357 return;
24282358
2429  if (!m_player->sourceRemoveId(id))
2430  ASSERT_NOT_REACHED();
2431 
2432  m_sourceIDs.remove(id);
2433 }
2434 
2435 PassRefPtr<TimeRanges> HTMLMediaElement::webkitSourceBuffered(const String& id, ExceptionCode& ec)
2436 {
2437  if (!isValidSourceId(id, ec))
2438  return 0;
2439 
2440  if (!m_player || m_currentSrc != m_mediaSourceURL || m_sourceState == SOURCE_CLOSED) {
2441  ec = INVALID_STATE_ERR;
2442  return 0;
2443  }
2444 
2445  return m_player->sourceBuffered(id);
2446 }
2447 
2448 void HTMLMediaElement::webkitSourceAppend(const String& id, PassRefPtr<Uint8Array> data, ExceptionCode& ec)
2449 {
2450  if (!isValidSourceId(id, ec))
2451  return;
2452 
2453  if (!m_player || m_currentSrc != m_mediaSourceURL || m_sourceState != SOURCE_OPEN) {
2454  ec = INVALID_STATE_ERR;
2455  return;
2456  }
2457 
2458  if (!data.get()) {
2459  ec = INVALID_ACCESS_ERR;
2460  return;
2461  }
2462 
2463  if (!data->length())
2464  return;
2465 
2466  if (!m_player->sourceAppend(id, data->data(), data->length())) {
2467  ec = SYNTAX_ERR;
2468  return;
2469  }
2470 }
2471 
2472 void HTMLMediaElement::webkitSourceAbort(const String& id, ExceptionCode& ec)
2473 {
2474  if (!isValidSourceId(id, ec))
2475  return;
2476 
2477  if (!m_player || m_currentSrc != m_mediaSourceURL || m_sourceState != SOURCE_OPEN) {
2478  ec = INVALID_STATE_ERR;
2479  return;
2480  }
2481 
2482  if (!m_player->sourceAbort(id))
2483  ASSERT_NOT_REACHED();
2484 }
2485 
2486 void HTMLMediaElement::webkitSourceEndOfStream(unsigned short status, ExceptionCode& ec)
2487 {
2488  if (!m_player || m_currentSrc != m_mediaSourceURL || m_sourceState != SOURCE_OPEN) {
2489  ec = INVALID_STATE_ERR;
2490  return;
2491  }
2492 
2493  MediaPlayer::EndOfStreamStatus eosStatus = MediaPlayer::EosNoError;
2494 
2495  switch (status) {
2496  case EOS_NO_ERROR:
2497  eosStatus = MediaPlayer::EosNoError;
2498  break;
2499  case EOS_NETWORK_ERR:
2500  eosStatus = MediaPlayer::EosNetworkError;
2501  break;
2502  case EOS_DECODE_ERR:
2503  eosStatus = MediaPlayer::EosDecodeError;
2504  break;
2505  default:
2506  ec = SYNTAX_ERR;
2507  return;
2508  }
2509 
2510  setSourceState(SOURCE_ENDED);
2511  m_player->sourceEndOfStream(eosStatus);
2512 }
2513 
2514 HTMLMediaElement::SourceState HTMLMediaElement::webkitSourceState() const
2515 {
2516  return m_sourceState;
2517 }
2518 
2519 void HTMLMediaElement::setSourceState(SourceState state)
2520 {
2521  SourceState oldState = m_sourceState;
2522  m_sourceState = static_cast<SourceState>(state);
2523 
2524  if (m_sourceState == oldState)
2525  return;
2526 
2527  if (m_sourceState == SOURCE_CLOSED) {
2528  m_sourceIDs.clear();
2529  scheduleEvent(eventNames().webkitsourcecloseEvent);
2530  return;
2531  }
2532 
2533  if (oldState == SOURCE_OPEN && m_sourceState == SOURCE_ENDED) {
2534  scheduleEvent(eventNames().webkitsourceendedEvent);
2535  return;
2536  }
2537 
2538  if (m_sourceState == SOURCE_OPEN) {
2539  scheduleEvent(eventNames().webkitsourceopenEvent);
2540  return;
2541  }
 2359 m_mediaSource->setReadyState(state);
25422360}
25432361#endif
25442362

@@void HTMLMediaElement::userCancelledLoad()
37933611 scheduleEvent(eventNames().abortEvent);
37943612
37953613#if ENABLE(MEDIA_SOURCE)
3796  if (m_sourceState != SOURCE_CLOSED)
3797  setSourceState(SOURCE_CLOSED);
 3614 setSourceState(MediaSource::closedKeyword());
37983615#endif
37993616
38003617 // 4 - If the media element's readyState attribute has a value equal to HAVE_NOTHING, set the

@@void HTMLMediaElement::createMediaPlayer()
43074124
43084125 m_player = MediaPlayer::create(this);
43094126
 4127#if ENABLE(MEDIA_SOURCE)
 4128 if (m_mediaSource)
 4129 m_mediaSource->setMediaPlayer(m_player.get());
 4130#endif
 4131
43104132#if ENABLE(WEB_AUDIO)
43114133 if (m_audioSourceNode) {
43124134 // When creating the player, make sure its AudioSourceProvider knows about the MediaElementAudioSourceNode.

Source/WebCore/html/HTMLMediaElement.h

@@public:
175175#if ENABLE(MEDIA_SOURCE)
176176// Media Source.
177177 const KURL& webkitMediaSourceURL() const { return m_mediaSourceURL; }
178  void webkitSourceAddId(const String&, const String&, ExceptionCode&);
179  void webkitSourceRemoveId(const String&, ExceptionCode&);
180  PassRefPtr<TimeRanges> webkitSourceBuffered(const String&, ExceptionCode&);
181  void webkitSourceAppend(const String&, PassRefPtr<Uint8Array> data, ExceptionCode&);
182  void webkitSourceAbort(const String&, ExceptionCode&);
183  enum EndOfStreamStatus { EOS_NO_ERROR, EOS_NETWORK_ERR, EOS_DECODE_ERR };
184  void webkitSourceEndOfStream(unsigned short, ExceptionCode&);
185  enum SourceState { SOURCE_CLOSED, SOURCE_OPEN, SOURCE_ENDED };
186  SourceState webkitSourceState() const;
187  void setSourceState(SourceState);
188 
189  DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitsourceopen);
190  DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitsourceended);
191  DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitsourceclose);
 178 void setSourceState(const String&);
192179#endif
193180
194181#if ENABLE(ENCRYPTED_MEDIA)

@@private:
420407#if ENABLE(MEDIA_SOURCE)
421408 virtual void mediaPlayerSourceOpened();
422409 virtual String mediaPlayerSourceURL() const;
423  bool isValidSourceId(const String&, ExceptionCode&) const;
424410#endif
425411
426412#if ENABLE(ENCRYPTED_MEDIA)

@@private:
598584
599585#if ENABLE(MEDIA_SOURCE)
600586 KURL m_mediaSourceURL;
601  SourceState m_sourceState;
602  HashSet<String> m_sourceIDs;
 587 RefPtr<MediaSource> m_mediaSource;
603588#endif
604589
605590 mutable float m_cachedTime;

Source/WebCore/html/HTMLMediaElement.idl

@@module html {
9898#if defined(ENABLE_MEDIA_SOURCE) && ENABLE_MEDIA_SOURCE
9999 // URL passed to src attribute to enable the media source logic.
100100 readonly attribute [V8EnabledAtRuntime=mediaSource, URL] DOMString webkitMediaSourceURL;
101 
102  // Manages IDs for appending media to the source.
103  [V8EnabledAtRuntime=mediaSource] void webkitSourceAddId(in DOMString id, in DOMString type) raises (DOMException);
104  [V8EnabledAtRuntime=mediaSource] void webkitSourceRemoveId(in DOMString id) raises (DOMException);
105 
106  // Returns the time ranges buffered for a specific source ID.
107  [V8EnabledAtRuntime=mediaSource] TimeRanges webkitSourceBuffered(in DOMString id) raises (DOMException);
108 
109  // Appends segment data.
110  [V8EnabledAtRuntime=mediaSource] void webkitSourceAppend(in DOMString id, in Uint8Array data) raises (DOMException);
111 
112  // Aborts the current segment.
113  [V8EnabledAtRuntime=mediaSource] void webkitSourceAbort(in DOMString id) raises (DOMException);
114 
115  // Signals the end of stream.
116  [V8EnabledAtRuntime=mediaSource] const unsigned short EOS_NO_ERROR = 0; // End of stream reached w/o error.
117  [V8EnabledAtRuntime=mediaSource] const unsigned short EOS_NETWORK_ERR = 1; // A network error triggered end of stream.
118  [V8EnabledAtRuntime=mediaSource] const unsigned short EOS_DECODE_ERR = 2; // A decode error triggered end of stream.
119  [V8EnabledAtRuntime=mediaSource] void webkitSourceEndOfStream(in unsigned short status) raises (DOMException);
120 
121  // Indicates the current state of the media source.
122  [V8EnabledAtRuntime=mediaSource] const unsigned short SOURCE_CLOSED = 0;
123  [V8EnabledAtRuntime=mediaSource] const unsigned short SOURCE_OPEN = 1;
124  [V8EnabledAtRuntime=mediaSource] const unsigned short SOURCE_ENDED = 2;
125  readonly attribute [V8EnabledAtRuntime=mediaSource] unsigned short webkitSourceState;
126 
127  attribute [V8EnabledAtRuntime=mediaSource] EventListener onwebkitsourceopen;
128  attribute [V8EnabledAtRuntime=mediaSource] EventListener onwebkitsourceended;
129  attribute [V8EnabledAtRuntime=mediaSource] EventListener onwebkitsourceclose;
130101#endif
131102
132103#if defined(ENABLE_ENCRYPTED_MEDIA) && ENABLE_ENCRYPTED_MEDIA

LayoutTests/ChangeLog

 12012-08-06 Anna Cavender <annacc@chromium.org>
 2
 3 Update HTMLMediaElement to the new OO MediaSource API.
 4 https://bugs.webkit.org/show_bug.cgi?id=91775
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 This patch rips out the old-style MediaSource API and allows a
 9 MediaSource object to be attached to HTMLMediaElement.
 10 http://dvcs.w3.org/hg/html-media/raw-file/tip/media-source/media-source.html
 11
 12 * http/tests/media/media-source/media-source.js:
 13 (MediaSourceTest.SegmentHelper):
 14 (MediaSourceTest.SegmentHelper.prototype.addSourceBuffer):
 15 (MediaSourceTest.SegmentHelper.prototype.appendInitSegment):
 16 (MediaSourceTest.SegmentHelper.prototype.appendMediaSegment):
 17 (MediaSourceTest.SegmentHelper.prototype.appendUntilEndOfStream):
 18 (MediaSourceTest.setSrcToMediaSourceTestURL):
 19 (MediaSourceTest.defaultOnErrorChecks):
 20 (MediaSourceTest.runOnSourceOpen.eventHandlerFunction):
 21 (MediaSourceTest.runOnSourceOpen):
 22 (MediaSourceTest.logSourceState):
 23 (MediaSourceTest.expectSourceState):
 24 * http/tests/media/media-source/video-media-source-abort-expected.txt:
 25 * http/tests/media/media-source/video-media-source-abort.html:
 26 * http/tests/media/media-source/video-media-source-add-and-remove-buffers-expected.txt: Removed.
 27 * http/tests/media/media-source/video-media-source-add-and-remove-buffers.html: Removed.
 28
 29 * http/tests/media/media-source/video-media-source-add-and-remove-ids-expected.txt: Removed.
 30 * http/tests/media/media-source/video-media-source-add-and-remove-ids.html: Removed.
 31 * http/tests/media/media-source/video-media-source-errors-expected.txt:
 32 * http/tests/media/media-source/video-media-source-errors.html:
 33 * http/tests/media/media-source/video-media-source-event-attributes-expected.txt:
 34 * http/tests/media/media-source/video-media-source-event-attributes.html:
 35 * http/tests/media/media-source/video-media-source-play-expected.txt:
 36 * http/tests/media/media-source/video-media-source-play.html:
 37 * http/tests/media/media-source/video-media-source-seek.html:
 38 * http/tests/media/media-source/video-media-source-state-changes-expected.txt:
 39 * http/tests/media/media-source/video-media-source-state-changes.html:
 40
1412012-08-06 Andrei Poenaru <poenaru@adobe.com>
242
343 Web Inspector: Protocol: Add "namedFlowCreated" and "namedFlowRemoved" events

LayoutTests/http/tests/media/media-source/media-source.js

11var MediaSourceTest = {};
 2var mediaSource = new MediaSource();
23
34MediaSourceTest.SegmentHelper = function(segmentInfo)
45{
56 this.MediaSegmentsToLoad = 0;
6  this.SourceID = 'sourceId';
 7 this.sourceBuffer = null;
78
89 this.videoTag = null;
910 this.segmentInfo = segmentInfo;

@@MediaSourceTest.SegmentHelper.prototype.getData_ = function (url, start, length,
121122 request.send();
122123};
123124
124 MediaSourceTest.SegmentHelper.prototype.addSourceId = function()
 125MediaSourceTest.SegmentHelper.prototype.addSourceBuffer = function()
125126{
126  this.videoTag.webkitSourceAddId(this.SourceID, this.segmentInfo.type);
 127 this.sourceBuffer = mediaSource.addSourceBuffer(this.segmentInfo.type);
127128};
128129
129130MediaSourceTest.SegmentHelper.prototype.appendInitSegment = function()
130131{
131  this.videoTag.webkitSourceAppend(this.SourceID, this.initSegment);
 132 this.sourceBuffer.append(this.initSegment);
132133};
133134
134135MediaSourceTest.SegmentHelper.prototype.appendMediaSegment = function(index)
135136{
136  this.videoTag.webkitSourceAppend(this.SourceID, this.mediaSegments[index]);
 137 this.sourceBuffer.append(this.mediaSegments[index]);
137138};
138139
139140MediaSourceTest.SegmentHelper.prototype.appendUntilEndOfStream = function(startIndex)
140141{
141  if (!this.videoTag.webkitSourceAppend) {
142  failTest("webkitSourceAppend() is not available");
 142 if (!this.sourceBuffer) {
 143 failTest("MediaSource API is not available");
143144 return;
144145 }
145146
146147 for (var index = startIndex; index < this.mediaSegments.length; index++)
147148 this.appendMediaSegment(index);
148149
149  this.videoTag.webkitSourceEndOfStream(this.videoTag.EOS_NO_ERROR);
 150 mediaSource.endOfStream();
150151};
151152
152153MediaSourceTest.SegmentHelper.prototype.getTimeForMediaSegment = function(index)

@@MediaSourceTest.setSrcToMediaSourceTestURL = function(videoTag)
176177 return;
177178 }
178179
179  videoTag.src = videoTag.webkitMediaSourceURL;
 180 videoTag.src = webkitURL.createObjectURL(mediaSource);
180181};
181182
182183MediaSourceTest.mediaErrorString = function(videoTag)

@@MediaSourceTest.defaultOnErrorChecks = function(event)
206207
207208 consoleWrite("EVENT(error) : " + MediaSourceTest.mediaErrorString(videoTag));
208209
209  if (videoTag.webkitSourceState != HTMLMediaElement.SOURCE_CLOSED) {
210  consoleWrite("Unexpected source state. Expected SOURCE_CLOSED" +
211  " got " + getSourceStateName(videoTag.webkitSourceState));
 210 if (mediaSource.readyState != "closed") {
 211 consoleWrite("Unexpected source state. Expected 'closed'" +
 212 " got " + mediaSource.readyState);
212213 }
213214};
214215

@@MediaSourceTest.runOnSourceOpen = function(videoTag, onOpenFunction)
270271{
271272 var eventHandlerFunction = function (event)
272273 {
 274 if (videoTag.networkState != HTMLMediaElement.NETWORK_LOADING &&
 275 videoTag.networkState != HTMLMediaElement.NETWORK_IDLE) {
 276 failTest("Unexpected network state. Expected " +
 277 HTMLMediaElement.NETWORK_LOADING + " or " +
 278 HTMLMediaElement.NETWORK_IDLE +
 279 " got " + videoTag.readyState);
 280 }
273281 event.target.removeEventListener('webkitsourceopen', eventHandlerFunction);
274282 onOpenFunction();
275283 };
276  videoTag.addEventListener('webkitsourceopen', eventHandlerFunction);
277  MediaSourceTest.setSrcToMediaSourceTestURL(videoTag);
278 };
279284
280 MediaSourceTest.logSourceState = function(videoTag)
281 {
282  consoleWrite("webkitSourceState : " + MediaSourceTest.getSourceStateName(videoTag.webkitSourceState));
 285 mediaSource.addEventListener('webkitsourceopen', eventHandlerFunction);
 286 MediaSourceTest.setSrcToMediaSourceTestURL(videoTag);
283287};
284288
285 MediaSourceTest.expectSourceState = function(videoTag, expected)
 289MediaSourceTest.logSourceState = function(mediaSource)
286290{
287  if (videoTag.webkitSourceState != expected) {
288  failTest("Unexpected source state. Expected " +
289  MediaSourceTest.getSourceStateName(expected) +
290  " got " + MediaSourceTest.getSourceStateName(videoTag.webkitSourceState));
291  }
 291 consoleWrite("webkitSourceState : " + mediaSource.readyState);
292292};
293293
294 MediaSourceTest.getSourceStateName = function(state)
 294MediaSourceTest.expectSourceState = function(mediaSource, expected)
295295{
296  var stateName = "UNKNOWN";
297  switch (state) {
298  case HTMLMediaElement.SOURCE_CLOSED:
299  stateName = "SOURCE_CLOSED";
300  break;
301  case HTMLMediaElement.SOURCE_OPEN:
302  stateName = "SOURCE_OPEN";
303  break;
304  case HTMLMediaElement.SOURCE_ENDED:
305  stateName = "SOURCE_ENDED";
306  break;
 296 if (mediaSource.readyState != expected) {
 297 failTest("Unexpected source state. Expected " + expected +
 298 " got " + mediaSource.readyState);
307299 }
308  return stateName;
309300};
310301
311302MediaSourceTest.expectReadyState = function(videoTag, expected)

LayoutTests/http/tests/media/media-source/video-media-source-abort-expected.txt

@@Tests webkitSourceAbort() functionality
22
33
44running abortDuringInitSegment
5 EVENT(loadstart)
65EVENT(webkitsourceopen)
76Test aborting during initialization segment.
87Appending partial initialization segment.

@@EVENT(loadeddata)
1312
1413running abortDuringMediaSegment
1514EVENT(emptied)
16 EVENT(loadstart)
1715EVENT(webkitsourceopen)
1816Test aborting in the middle of a media segment.
1917Appending partial media segment.

LayoutTests/http/tests/media/media-source/video-media-source-abort.html

99
1010 function abortDuringInitSegment(runNextTestCase, videoTag)
1111 {
12  segmentHelper.addSourceId();
 12 segmentHelper.addSourceBuffer();
1313
1414 consoleWrite("Test aborting during initialization segment.");
1515 try {

1717 var partialInitSegment = initSegment.subarray(0, initSegment.length / 2);
1818
1919 consoleWrite("Appending partial initialization segment.");
20  videoTag.webkitSourceAppend(segmentHelper.SourceID, partialInitSegment);
 20 segmentHelper.sourceBuffer.append(partialInitSegment);
2121
2222 consoleWrite("Aborting append.");
23  videoTag.webkitSourceAbort(segmentHelper.SourceID);
 23 segmentHelper.sourceBuffer.abort();
2424
2525 consoleWrite("Appending full initialization segment.");
2626 segmentHelper.appendInitSegment();

4242
4343 function abortDuringMediaSegment(runNextTestCase, videoTag)
4444 {
45  segmentHelper.addSourceId();
 45 segmentHelper.addSourceBuffer();
4646
4747 consoleWrite("Test aborting in the middle of a media segment.");
4848 try {

5151 var partialMediaSegment = mediaSegment.subarray(0, mediaSegment.length / 2);
5252
5353 consoleWrite("Appending partial media segment.");
54  videoTag.webkitSourceAppend(segmentHelper.SourceID, partialMediaSegment);
 54 segmentHelper.sourceBuffer.append(partialMediaSegment);
5555
5656 consoleWrite("Aborting append.");
57  videoTag.webkitSourceAbort(segmentHelper.SourceID);
 57 segmentHelper.sourceBuffer.abort();
5858
5959 consoleWrite("Appending full media segment.");
6060 segmentHelper.appendMediaSegment(0);

7777 {
7878 findMediaElement();
7979
80  waitForEvent('loadstart');
8180 waitForEvent('loadeddata');
82  waitForEvent('webkitsourceopen');
 81 waitForEvent('webkitsourceopen', "", false, false, mediaSource);
8382 waitForEvent('playing');
84  waitForEvent('webkitsourceended');
 83 waitForEvent('webkitsourceended', "", false, false, mediaSource);
8584 waitForEvent('ended');
8685 waitForEvent('emptied');
8786

LayoutTests/http/tests/media/media-source/video-media-source-add-and-remove-buffers-expected.txt

 1Tests webkitSourceAddId() & webkitSourceRemoveId() methods
 2
 3Test adding an ID while closed.
 4Got expected exception Error: INVALID_STATE_ERR: DOM Exception 11
 5
 6running testAddBufferFailureCases
 7EVENT(webkitsourceopen)
 8Test empty type.
 9Got expected exception Error: INVALID_ACCESS_ERR: DOM Exception 15
 10Test an unsupported type.
 11Got expected exception Error: NOT_SUPPORTED_ERR: DOM Exception 9
 12Test a supported type with an unsupported codec.
 13Got expected exception Error: NOT_SUPPORTED_ERR: DOM Exception 9
 14Test reaching sourceID limit.
 15Test that SourceBuffers can't be added while in the ended state.
 16Got expected exception Error: INVALID_STATE_ERR: DOM Exception 11
 17
 18running testRemoveNullBuffer
 19EVENT(webkitsourceopen)
 20Test null buffer case
 21Got expected exception Error: INVALID_ACCESS_ERR: DOM Exception 15
 22
 23running testRemoveAgain
 24EVENT(webkitsourceopen)
 25Test removing a buffer that was already removed.
 26Got expected exception Error: INVALID_STATE_ERR: DOM Exception 11
 27
 28running testRemoveBufferAfterEnded
 29EVENT(webkitsourceopen)
 30Test that a buffer can be removed while in the ended state.
 31
 32running testAddBufferAfterRemoving
 33EVENT(webkitsourceopen)
 34Test that a buffer can be added again after it is removed.
 35Unexpected exception: Error: QUOTA_EXCEEDED_ERR: DOM Exception 22
 36
 37running testAppendFailureCases
 38EVENT(webkitsourceopen)
 39Test a successful append.
 40Test append with a null buffer.
 41Got expected exception Error: INVALID_ACCESS_ERR: DOM Exception 15
 42Test append after ended.
 43Got expected exception Error: INVALID_STATE_ERR: DOM Exception 11
 44Test append after buffer has been removed.
 45Got expected exception Error: INVALID_STATE_ERR: DOM Exception 11
 46END OF TEST
 47

LayoutTests/http/tests/media/media-source/video-media-source-add-and-remove-buffers.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="media-source.js"></script>
 7 <script>
 8 var segmentHelper = new MediaSourceTest.SegmentHelper(WebMSegmentInfo.testWebM);
 9 var defaultSourceMimetype = segmentHelper.segmentInfo.type;
 10
 11 function expectExceptionOnAddBuffer(type, error)
 12 {
 13 try {
 14 segmentHelper.sourceBuffer = mediaSource.addSourceBuffer(type);
 15 failTest("Expected an exception");
 16 } catch (e) {
 17 if (!(e.code == error)) {
 18 failTest("Unexpected exception " + e);
 19 throw e;
 20 }
 21 consoleWrite("Got expected exception " + e);
 22 }
 23 }
 24
 25 function expectExceptionOnRemoveBuffer(buffer, error)
 26 {
 27 try {
 28 mediaSource.removeSourceBuffer(buffer);
 29 failTest("Expected an exception");
 30 } catch (e) {
 31 if (!(e.code == error)) {
 32 failTest("Unexpected exception " + e);
 33 throw e;
 34 }
 35 consoleWrite("Got expected exception " + e);
 36 }
 37 }
 38
 39 function expectExceptionOnAppend(buf, error)
 40 {
 41 try {
 42 segmentHelper.sourceBuffer.append(buf);
 43 failTest("Expected an exception");
 44 } catch (e) {
 45 if (!(e.code == error)) {
 46 failTest("Unexpected exception " + e);
 47 throw e;
 48 }
 49 consoleWrite("Got expected exception " + e);
 50 }
 51 }
 52
 53 function testAddBufferWhileClosed(videoTag)
 54 {
 55 consoleWrite("Test adding an ID while closed.");
 56 expectExceptionOnAddBuffer(defaultSourceMimetype, DOMException.INVALID_STATE_ERR);
 57 }
 58
 59 function testAddBufferFailureCases(runNextTestCase, videoTag)
 60 {
 61 consoleWrite("Test empty type.");
 62 expectExceptionOnAddBuffer("", DOMException.INVALID_ACCESS_ERR);
 63
 64 consoleWrite("Test an unsupported type.");
 65 expectExceptionOnAddBuffer("audio/x-unsupported-format", DOMException.NOT_SUPPORTED_ERR);
 66
 67 consoleWrite("Test a supported type with an unsupported codec.");
 68 expectExceptionOnAddBuffer("video/webm; codecs=\"vp8, speex\"", DOMException.NOT_SUPPORTED_ERR);
 69
 70 consoleWrite("Test reaching sourceID limit.");
 71 var reachedIdLimit = false;
 72
 73 // The 20 here is an arbitrary upper limit to make sure the test terminates. This test
 74 // assumes that implementations won't support more than 20 sourceID's simultaneously.
 75 for (var i = 0; i < 20; ++i) {
 76 try {
 77 mediaSource.addSourceBuffer(defaultSourceMimetype);
 78 } catch(e) {
 79 if (e.code != DOMException.QUOTA_EXCEEDED_ERR) {
 80 failTest("Unexpected exception " + e);
 81 throw e;
 82 }
 83 reachedIdLimit = true;
 84 break;
 85 }
 86 }
 87
 88 if (!reachedIdLimit) {
 89 failTest("Failed to reach SourceID limit.");
 90 return;
 91 }
 92
 93 consoleWrite("Test that SourceBuffers can't be added while in the ended state.");
 94 mediaSource.endOfStream();
 95 expectExceptionOnAddBuffer(defaultSourceMimetype, DOMException.INVALID_STATE_ERR);
 96
 97 runNextTestCase();
 98 }
 99
 100 function testRemoveNullBuffer(runNextTestCase, videoTag)
 101 {
 102 consoleWrite("Test null buffer case");
 103 expectExceptionOnRemoveBuffer(null, DOMException.INVALID_ACCESS_ERR);
 104
 105 runNextTestCase();
 106 }
 107
 108 function testRemoveAgain(runNextTestCase, videoTag)
 109 {
 110 consoleWrite("Test removing a buffer that was already removed.");
 111 segmentHelper.sourceBuffer = mediaSource.addSourceBuffer(defaultSourceMimetype);
 112 mediaSource.removeSourceBuffer(segmentHelper.sourceBuffer);
 113 expectExceptionOnRemoveBuffer(segmentHelper.sourceBuffer, DOMException.INVALID_STATE_ERR);
 114
 115 runNextTestCase();
 116 }
 117
 118 function testRemoveBufferAfterEnded(runNextTestCase, videoTag)
 119 {
 120 consoleWrite("Test that a buffer can be removed while in the ended state.");
 121 segmentHelper.sourceBuffer = mediaSource.addSourceBuffer(defaultSourceMimetype);
 122 mediaSource.endOfStream();
 123 mediaSource.removeSourceBuffer(segmentHelper.sourceBuffer);
 124
 125 runNextTestCase();
 126 }
 127
 128 function testAddBufferAfterRemoving(runNextTestCase, videoTag)
 129 {
 130 consoleWrite("Test that a buffer can be added again after it is removed.");
 131 segmentHelper.sourceBuffer = mediaSource.addSourceBuffer(defaultSourceMimetype);
 132 mediaSource.removeSourceBuffer(segmentHelper.sourceBuffer);
 133
 134 try {
 135 segmentHelper.sourceBuffer = mediaSource.addSourceBuffer(defaultSourceMimetype);
 136 } catch (e) {
 137 consoleWrite("Unexpected exception: " + e);
 138 }
 139
 140 runNextTestCase();
 141 }
 142
 143 function testAppendFailureCases(runNextTestCase, videoTag)
 144 {
 145 var initSegment = segmentHelper.initSegment;
 146 var mediaSegment = segmentHelper.mediaSegments[0];
 147
 148 segmentHelper.sourceBuffer = mediaSource.addSourceBuffer(defaultSourceMimetype);
 149
 150 consoleWrite("Test a successful append.");
 151 segmentHelper.sourceBuffer.append(initSegment);
 152
 153 consoleWrite("Test append with a null buffer.");
 154 expectExceptionOnAppend(null, DOMException.INVALID_ACCESS_ERR);
 155
 156 consoleWrite("Test append after ended.");
 157 mediaSource.endOfStream();
 158 expectExceptionOnAppend(initSegment, DOMException.INVALID_STATE_ERR);
 159
 160 consoleWrite("Test append after buffer has been removed.");
 161 mediaSource.removeSourceBuffer(segmentHelper.sourceBuffer);
 162 expectExceptionOnAppend(initSegment, DOMException.INVALID_STATE_ERR);
 163
 164 runNextTestCase();
 165 }
 166
 167 function onLoad()
 168 {
 169 findMediaElement();
 170
 171 mediaSource = new MediaSource();
 172 waitForEvent('webkitsourceopen', "", false, false, mediaSource);
 173
 174 segmentHelper.init(video, function(success)
 175 {
 176 if (!success) {
 177 failTest("Failed to load segment data");
 178 return;
 179 }
 180
 181 testAddBufferWhileClosed(video);
 182
 183 var testCases = [
 184 testAddBufferFailureCases,
 185 testRemoveNullBuffer,
 186 testRemoveAgain,
 187 testRemoveBufferAfterEnded,
 188 testAddBufferAfterRemoving,
 189 testAppendFailureCases,
 190 ];
 191
 192 MediaSourceTest.startSourceOpenTesting(video, testCases);
 193 });
 194 }
 195 </script>
 196 </head>
 197 <body onload="onLoad()">
 198 <video> </video>
 199 <p>Tests webkitSourceAddId() &amp; webkitSourceRemoveId() methods</p>
 200 </body>
 201</html>

LayoutTests/http/tests/media/media-source/video-media-source-add-and-remove-ids-expected.txt

1 Tests webkitSourceAddId() & webkitSourceRemoveId() methods
2 
3 Test adding an ID while closed.
4 Got expected exception Error: INVALID_STATE_ERR: DOM Exception 11
5 
6 running testAddIdFailureCases
7 EVENT(loadstart)
8 EVENT(webkitsourceopen)
9 Test empty ID case
10 Got expected exception Error: INVALID_ACCESS_ERR: DOM Exception 15
11 Test adding the same ID again.
12 Got expected exception Error: INVALID_STATE_ERR: DOM Exception 11
13 Test empty type.
14 Got expected exception Error: INVALID_ACCESS_ERR: DOM Exception 15
15 Test an unsupported type.
16 Got expected exception Error: NOT_SUPPORTED_ERR: DOM Exception 9
17 Test a supported type with an unsupported codec.
18 Got expected exception Error: NOT_SUPPORTED_ERR: DOM Exception 9
19 Test reaching sourceID limit.
20 Test that SourceIDs can't be added while in the ended state.
21 Got expected exception Error: INVALID_STATE_ERR: DOM Exception 11
22 
23 running testRemoveEmptyId
24 EVENT(loadstart)
25 EVENT(webkitsourceopen)
26 Test empty ID case
27 Got expected exception Error: INVALID_ACCESS_ERR: DOM Exception 15
28 
29 running testRemoveNonexistentId
30 EVENT(loadstart)
31 EVENT(webkitsourceopen)
32 Test removing an ID that was never added.
33 Got expected exception Error: SYNTAX_ERR: DOM Exception 12
34 
35 running testRemoveAgain
36 EVENT(loadstart)
37 EVENT(webkitsourceopen)
38 Test removing an ID that was already removed.
39 Got expected exception Error: SYNTAX_ERR: DOM Exception 12
40 
41 running testRemoveIdAfterEnded
42 EVENT(loadstart)
43 EVENT(webkitsourceopen)
44 Test that an ID can be removed while in the ended state.
45 
46 running testAddIdAfterRemoving
47 EVENT(loadstart)
48 EVENT(webkitsourceopen)
49 Test that an ID can be added again after it is removed.
50 Unexpected exception: Error: QUOTA_EXCEEDED_ERR: DOM Exception 22
51 
52 running testAppendFailureCases
53 EVENT(loadstart)
54 EVENT(webkitsourceopen)
55 Test append with empty ID.
56 Got expected exception Error: INVALID_ACCESS_ERR: DOM Exception 15
57 Test append with an invalid ID
58 Got expected exception Error: SYNTAX_ERR: DOM Exception 12
59 Test append with a null buffer.
60 Got expected exception Error: INVALID_ACCESS_ERR: DOM Exception 15
61 Test a successful append.
62 Got expected exception Error: SYNTAX_ERR: DOM Exception 12
63 END OF TEST
64 

LayoutTests/http/tests/media/media-source/video-media-source-add-and-remove-ids.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="media-source.js"></script>
7  <script>
8  var segmentHelper = new MediaSourceTest.SegmentHelper(WebMSegmentInfo.testWebM);
9  var defaultSourceMimetype = segmentHelper.segmentInfo.type;
10 
11  function expectExceptionOnAddId(videoTag, id, type, error)
12  {
13  try {
14  videoTag.webkitSourceAddId(id, type);
15  failTest("Expected an exception");
16  } catch (e) {
17  if (!(e.code == error)) {
18  failTest("Unexpected exception " + e);
19  throw e;
20  }
21  consoleWrite("Got expected exception " + e);
22  }
23  }
24 
25  function expectExceptionOnRemoveId(videoTag, id, error)
26  {
27  try {
28  videoTag.webkitSourceRemoveId(id);
29  failTest("Expected an exception");
30  } catch (e) {
31  if (!(e.code == error)) {
32  failTest("Unexpected exception " + e);
33  throw e;
34  }
35  consoleWrite("Got expected exception " + e);
36  }
37  }
38 
39  function expectExceptionOnAppend(videoTag, id, buf, error)
40  {
41  try {
42  videoTag.webkitSourceAppend(id, buf);
43  failTest("Expected an exception");
44  } catch (e) {
45  if (!(e.code == error)) {
46  failTest("Unexpected exception " + e);
47  throw e;
48  }
49  consoleWrite("Got expected exception " + e);
50  }
51  }
52 
53  function testAddIdWhileClosed(videoTag)
54  {
55  consoleWrite("Test adding an ID while closed.");
56  expectExceptionOnAddId(videoTag, "123", defaultSourceMimetype, DOMException.INVALID_STATE_ERR);
57  }
58 
59  function testAddIdFailureCases(runNextTestCase, videoTag)
60  {
61  consoleWrite("Test empty ID case");
62  expectExceptionOnAddId(videoTag, "", defaultSourceMimetype, DOMException.INVALID_ACCESS_ERR);
63 
64  videoTag.webkitSourceAddId("123", defaultSourceMimetype);
65 
66  consoleWrite("Test adding the same ID again.");
67  expectExceptionOnAddId(videoTag, "123", defaultSourceMimetype, DOMException.INVALID_STATE_ERR);
68  videoTag.webkitSourceRemoveId("123");
69 
70  consoleWrite("Test empty type.");
71  expectExceptionOnAddId(videoTag, "234", "", DOMException.INVALID_ACCESS_ERR);
72 
73  consoleWrite("Test an unsupported type.");
74  expectExceptionOnAddId(videoTag, "234", "audio/x-unsupported-format", DOMException.NOT_SUPPORTED_ERR);
75 
76  consoleWrite("Test a supported type with an unsupported codec.");
77  expectExceptionOnAddId(videoTag, "234", "video/webm; codecs=\"vp8, speex\"", DOMException.NOT_SUPPORTED_ERR);
78 
79  consoleWrite("Test reaching sourceID limit.");
80  var reachedIdLimit = false;
81 
82  // The 20 here is an arbitrary upper limit to make sure the test terminates. This test
83  // assumes that implementations won't support more than 20 sourceID's simultaneously.
84  for (var i = 0; i < 20; ++i) {
85  var sourceID = "sourceID-" + i;
86  try {
87  videoTag.webkitSourceAddId(sourceID, defaultSourceMimetype);
88  } catch(e) {
89  if (e.code != DOMException.QUOTA_EXCEEDED_ERR) {
90  failTest("Unexpected exception " + e);
91  throw e;
92  }
93  reachedIdLimit = true;
94  break;
95  }
96  }
97 
98  if (!reachedIdLimit) {
99  failTest("Failed to reach SourceID limit.");
100  return;
101  }
102 
103  consoleWrite("Test that SourceIDs can't be added while in the ended state.");
104  videoTag.webkitSourceEndOfStream(videoTag.EOS_NO_ERROR);
105  expectExceptionOnAddId(videoTag, "123", defaultSourceMimetype, DOMException.INVALID_STATE_ERR);
106 
107  runNextTestCase();
108  }
109 
110  function testRemoveEmptyId(runNextTestCase, videoTag)
111  {
112  consoleWrite("Test empty ID case");
113  expectExceptionOnRemoveId(videoTag, "", DOMException.INVALID_ACCESS_ERR);
114 
115  runNextTestCase();
116  }
117 
118  function testRemoveNonexistentId(runNextTestCase, videoTag)
119  {
120  consoleWrite("Test removing an ID that was never added.");
121  expectExceptionOnRemoveId(videoTag, "345", DOMException.SYNTAX_ERR);
122 
123  runNextTestCase();
124  }
125 
126  function testRemoveAgain(runNextTestCase, videoTag)
127  {
128  consoleWrite("Test removing an ID that was already removed.");
129  videoTag.webkitSourceAddId("123", defaultSourceMimetype);
130  videoTag.webkitSourceRemoveId("123");
131  expectExceptionOnRemoveId(videoTag, "123", DOMException.SYNTAX_ERR);
132 
133  runNextTestCase();
134  }
135 
136  function testRemoveIdAfterEnded(runNextTestCase, videoTag)
137  {
138  consoleWrite("Test that an ID can be removed while in the ended state.");
139  videoTag.webkitSourceAddId("123", defaultSourceMimetype);
140  videoTag.webkitSourceEndOfStream(videoTag.EOS_NO_ERROR);
141  videoTag.webkitSourceRemoveId("123");
142 
143  runNextTestCase();
144  }
145 
146  function testAddIdAfterRemoving(runNextTestCase, videoTag)
147  {
148  consoleWrite("Test that an ID can be added again after it is removed.");
149  videoTag.webkitSourceAddId("123", defaultSourceMimetype);
150  videoTag.webkitSourceRemoveId("123");
151 
152  try {
153  videoTag.webkitSourceAddId("123", defaultSourceMimetype);
154  } catch (e) {
155  consoleWrite("Unexpected exception: " + e);
156  }
157 
158  runNextTestCase();
159  }
160 
161  function testAppendFailureCases(runNextTestCase, videoTag)
162  {
163  var initSegment = segmentHelper.initSegment;
164  var mediaSegment = segmentHelper.mediaSegments[0];
165 
166  videoTag.webkitSourceAddId("123", defaultSourceMimetype);
167 
168  consoleWrite("Test append with empty ID.");
169  expectExceptionOnAppend(videoTag, "", initSegment, DOMException.INVALID_ACCESS_ERR);
170 
171  consoleWrite("Test append with an invalid ID");
172  expectExceptionOnAppend(videoTag, "234", initSegment, DOMException.SYNTAX_ERR);
173 
174  consoleWrite("Test append with a null buffer.");
175  expectExceptionOnAppend(videoTag, "123", null, DOMException.INVALID_ACCESS_ERR);
176 
177  consoleWrite("Test a successful append.");
178  videoTag.webkitSourceAppend("123", initSegment);
179 
180  videoTag.webkitSourceRemoveId("123");
181  expectExceptionOnAppend(videoTag, "123", mediaSegment, DOMException.SYNTAX_ERR);
182 
183  runNextTestCase();
184  }
185 
186  function onLoad()
187  {
188  findMediaElement();
189 
190  waitForEvent('loadstart');
191  waitForEvent('webkitsourceopen');
192 
193  segmentHelper.init(video, function(success)
194  {
195  if (!success) {
196  failTest("Failed to load segment data");
197  return;
198  }
199 
200  testAddIdWhileClosed(video);
201 
202  var testCases = [
203  testAddIdFailureCases,
204  testRemoveEmptyId,
205  testRemoveNonexistentId,
206  testRemoveAgain,
207  testRemoveIdAfterEnded,
208  testAddIdAfterRemoving,
209  testAppendFailureCases,
210  ];
211 
212  MediaSourceTest.startSourceOpenTesting(video, testCases);
213  });
214  }
215  </script>
216  </head>
217  <body onload="onLoad()">
218  <video> </video>
219  <p>Tests webkitSourceAddId() &amp; webkitSourceRemoveId() methods</p>
220  </body>
221 </html>

LayoutTests/http/tests/media/media-source/video-media-source-errors-expected.txt

@@Tests error cases with MediaSource API
22
33
44running didNotSendInitSegmentFirst
5 EVENT(loadstart)
65EVENT(webkitsourceopen)
76Test appending a media segment before sending the initialization segment.
87EVENT(error) : MEDIA_ERR_SRC_NOT_SUPPORTED
98
109running immediateDecodeErrorViaEndOfStream
1110EVENT(emptied)
12 EVENT(loadstart)
1311EVENT(webkitsourceopen)
14 Test signalling a decode error with webkitSourceEndOfStream.
 12Test signalling a decode error with MediaSource.endOfStream.
1513EVENT(webkitsourceended)
1614EVENT(error) : MEDIA_ERR_SRC_NOT_SUPPORTED
1715
1816running immediateNetworkErrorViaEndOfStream
1917EVENT(emptied)
20 EVENT(loadstart)
2118EVENT(webkitsourceopen)
22 Test signalling a network error with webkitSourceEndOfStream.
 19Test signalling a network error with MediaSource.endOfStream.
2320EVENT(webkitsourceended)
2421EVENT(error) : MEDIA_ERR_SRC_NOT_SUPPORTED
2522
2623running decodeErrorAfterHaveMetadata
2724EVENT(emptied)
28 EVENT(loadstart)
2925EVENT(webkitsourceopen)
30 Test signalling a decode error with webkitSourceEndOfStream after we have appended enough data to get to the HAVE_METADATA state.
 26Test signalling a decode error with MediaSource.endOfStream after we have appended enough data to get to the HAVE_METADATA state.
3127EVENT(loadedmetadata)
3228EVENT(webkitsourceended)
3329EVENT(error) : MEDIA_ERR_DECODE
3430
3531running networkErrorAfterHaveMetadata
3632EVENT(emptied)
37 EVENT(loadstart)
3833EVENT(webkitsourceopen)
39 Test signalling a network error with webkitSourceEndOfStream after we have appended enough data to get to the HAVE_METADATA state.
 34Test signalling a network error with MediaSource.endOfStream after we have appended enough data to get to the HAVE_METADATA state.
4035EVENT(loadedmetadata)
4136EVENT(webkitsourceended)
4237EVENT(error) : MEDIA_ERR_NETWORK

LayoutTests/http/tests/media/media-source/video-media-source-errors.html

2323 function didNotSendInitSegmentFirst(runNextTestCase, videoTag)
2424 {
2525 consoleWrite("Test appending a media segment before sending the initialization segment.");
26  segmentHelper.addSourceId();
 26 segmentHelper.addSourceBuffer();
2727 segmentHelper.appendMediaSegment(0);
2828 }
2929
3030 function immediateDecodeErrorViaEndOfStream(runNextTestCase, videoTag)
3131 {
32  consoleWrite("Test signalling a decode error with webkitSourceEndOfStream.");
33  var videoTag = event.target;
34  videoTag.webkitSourceEndOfStream(HTMLMediaElement.EOS_DECODE_ERR);
 32 consoleWrite("Test signalling a decode error with MediaSource.endOfStream.");
 33 mediaSource = event.target;
 34 mediaSource.endOfStream("decode");
3535 }
3636
3737 function immediateNetworkErrorViaEndOfStream(runNextTestCase, videoTag)
3838 {
39  consoleWrite("Test signalling a network error with webkitSourceEndOfStream.");
40  var videoTag = event.target;
41  videoTag.webkitSourceEndOfStream(HTMLMediaElement.EOS_NETWORK_ERR);
 39 consoleWrite("Test signalling a network error with MediaSource.endOfStream.");
 40 mediaSource = event.target;
 41 mediaSource.endOfStream("network");
4242 }
4343
4444 function decodeErrorAfterHaveMetadata(runNextTestCase, videoTag)
4545 {
46  consoleWrite("Test signalling a decode error with webkitSourceEndOfStream after we have appended enough data to get to the HAVE_METADATA state.");
47  var videoTag = event.target;
48  segmentHelper.addSourceId();
 46 consoleWrite("Test signalling a decode error with MediaSource.endOfStream after we have appended enough data to get to the HAVE_METADATA state.");
 47 mediaSource = event.target;
 48 segmentHelper.addSourceBuffer();
4949 segmentHelper.appendInitSegment();
5050
5151 appendUntilMetadataLoaded(videoTag, function()
5252 {
53  videoTag.webkitSourceEndOfStream(HTMLMediaElement.EOS_DECODE_ERR);
 53 mediaSource.endOfStream("decode");
5454 });
5555 }
5656
5757 function networkErrorAfterHaveMetadata(runNextTestCase, videoTag)
5858 {
59  consoleWrite("Test signalling a network error with webkitSourceEndOfStream after we have appended enough data to get to the HAVE_METADATA state.");
60  var videoTag = event.target;
61  segmentHelper.addSourceId();
 59 consoleWrite("Test signalling a network error with MediaSource.endOfStream after we have appended enough data to get to the HAVE_METADATA state.");
 60 mediaSource = event.target;
 61 segmentHelper.addSourceBuffer();
6262 segmentHelper.appendInitSegment();
6363 appendUntilMetadataLoaded(videoTag, function()
6464 {
65  videoTag.webkitSourceEndOfStream(HTMLMediaElement.EOS_NETWORK_ERR);
 65 mediaSource.endOfStream("network");
6666 });
6767 }
6868

7070 {
7171 findMediaElement();
7272
73  waitForEvent('loadstart');
7473 waitForEvent('loadedmetadata');
75  waitForEvent('webkitsourceopen');
 74 waitForEvent('webkitsourceopen', "", false, false, mediaSource);
7675 waitForEvent('playing');
77  waitForEvent('webkitsourceended');
 76 waitForEvent('webkitsourceended', "", false, false, mediaSource);
7877 waitForEvent('ended');
7978 waitForEvent('emptied');
8079

LayoutTests/http/tests/media/media-source/video-media-source-event-attributes-expected.txt

@@Test Media Source event handler attributes
22
33onLoad()
44onSourceOpen()
5 Calling webkitSourceEndOfStream to trigger a webkitsourceended event.
 5Calling MediaSource.endOfStream to trigger a webkitsourceended event.
66onSourceEnded()
77Setting src attribute to "" to trigger a webkitsourceclosed event.
88onSourceClose()

LayoutTests/http/tests/media/media-source/video-media-source-event-attributes.html

33 <head>
44 <script src="/media-resources/video-test.js"></script>
55 <script type="text/javascript">
6  function onSourceOpen(video)
 6
 7 var video = null;
 8 var mediaSource = null;
 9
 10 function onSourceOpen()
711 {
812 consoleWrite("onSourceOpen()");
9 
10  consoleWrite("Calling webkitSourceEndOfStream to trigger a webkitsourceended event.");
11  video.webkitSourceEndOfStream(HTMLMediaElement.EOS_NO_ERROR);
 13 consoleWrite("Calling MediaSource.endOfStream to trigger a webkitsourceended event.");
 14 mediaSource.endOfStream();
1215 }
1316
14  function onSourceEnded(video)
 17 function onSourceEnded()
1518 {
1619 consoleWrite("onSourceEnded()");
1720 consoleWrite("Setting src attribute to \"\" to trigger a webkitsourceclosed event.");
1821 video.src = "";
 22 endTest();
1923 }
2024
21  function onSourceClose(video)
 25 function onSourceClose()
2226 {
2327 consoleWrite("onSourceClose()");
2428 endTest();

2731 function onLoad(e)
2832 {
2933 consoleWrite("onLoad()");
30  var video = document.getElementById('v');
31  video.src = video.webkitMediaSourceURL;
 34 video = document.getElementById('v');
 35 mediaSource = new MediaSource();
 36 mediaSource.addEventListener('webkitsourceopen', onSourceOpen);
 37 mediaSource.addEventListener('webkitsourceended', onSourceEnded);
 38 mediaSource.addEventListener('webkitsourceclose', onSourceClose);
 39 video.src = webkitURL.createObjectURL(mediaSource);
3240 }
3341 </script>
3442 </head>
3543 <body onload="onLoad()">
3644 <p>Test Media Source event handler attributes</p>
37  <video id='v' onwebkitsourceopen='onSourceOpen(this)' onwebkitsourceended='onSourceEnded(this);' onwebkitsourceclose='onSourceClose(this);'></video>
 45 <video id='v'></video>
3846 </body>
3947</html>

LayoutTests/http/tests/media/media-source/video-media-source-play-expected.txt

11Tests normal playback case with MediaSource API
22
3 EVENT(loadstart)
43EVENT(webkitsourceopen)
54EVENT(webkitsourceended)
65EVENT(playing)

LayoutTests/http/tests/media/media-source/video-media-source-play.html

99
1010 function onSourceOpen(event)
1111 {
12  segmentHelper.addSourceId();
 12 segmentHelper.addSourceBuffer();
1313 segmentHelper.appendInitSegment();
1414
1515 // Append just enough segments to include at least 1 second of media data.
1616 var endIndex = segmentHelper.getMediaSegmentIndexForTimestamp(1);
1717 for (var i = 0; i <= endIndex; i++)
1818 segmentHelper.appendMediaSegment(i);
19  event.target.webkitSourceEndOfStream(HTMLMediaElement.EOS_NO_ERROR);
 19 event.target.endOfStream();
2020 }
2121
2222 function onLoad()
2323 {
2424 findMediaElement();
2525
 26 mediaSource = new MediaSource();
 27
2628 waitForEventAndFail('error');
27  waitForEvent('loadstart');
28  waitForEvent('webkitsourceopen');
 29 waitForEvent('webkitsourceopen', "", false, false, mediaSource);
2930 waitForEvent('playing');
30  waitForEvent('webkitsourceended');
 31 waitForEvent('webkitsourceended', "", false, false, mediaSource);
3132 waitForEventAndEnd('ended');
3233
33  video.addEventListener('webkitsourceopen', onSourceOpen);
 34 mediaSource.addEventListener('webkitsourceopen', onSourceOpen);
3435
3536 segmentHelper.init(video, function(success)
3637 {

LayoutTests/http/tests/media/media-source/video-media-source-seek.html

1616 if (firstOpen) {
1717 firstOpen = false;
1818
19  segmentHelper.addSourceId();
 19 segmentHelper.addSourceBuffer();
2020 segmentHelper.appendInitSegment();
2121 segmentHelper.appendUntilEndOfStream(0);
2222 }

3838 var videoTag = event.target;
3939
4040 // Call abort to make sure the source buffer is in a state where it can accept new segments.
41  videoTag.webkitSourceAbort(segmentHelper.SourceID);
 41 mediaSource.abort();
4242
4343 var startIndex = segmentHelper.getMediaSegmentIndexForTimestamp(videoTag.currentTime);
4444 segmentHelper.appendUntilEndOfStream(startIndex);

6060 {
6161 findMediaElement();
6262
 63 mediaSource = new MediaSource();
 64
6365 waitForEventAndFail('error');
64  waitForEvent('loadstart');
65  waitForEvent('webkitsourceopen');
66  waitForEvent('webkitsourceended');
 66 waitForEvent('webkitsourceopen', "", false, false, mediaSource);
 67 waitForEvent('webkitsourceended', "", false, false, mediaSource);
6768 waitForEvent('playing');
6869 waitForEvent('seeking');
6970 waitForEventAndEnd('ended');

LayoutTests/http/tests/media/media-source/video-media-source-state-changes-expected.txt

11Tests MediaSource API state transitions.
22
3 webkitSourceState : SOURCE_CLOSED
4 EVENT(loadstart)
5 EVENT(webkitsourceopen) : SOURCE_OPEN
 3webkitSourceState : closed
 4EVENT(webkitsourceopen) : open
65onFirstSourceOpen
7 EVENT(webkitsourceended) : SOURCE_ENDED
 6EVENT(webkitsourceended) : ended
87onFirstSourceEnded
98EVENT(playing)
109triggerFirstSeek
11 EVENT(webkitsourceopen) : SOURCE_OPEN
 10EVENT(webkitsourceopen) : open
1211EVENT(seeking)
1312onFirstSeeking
1413EVENT(seeked)

@@EVENT(seeking)
1716onSecondSeeking
1817EVENT(seeked)
1918onSecondSeeked
20 EVENT(webkitsourceclose) : SOURCE_CLOSED
 19EVENT(webkitsourceclose) : closed
2120onFirstSourceClose
2221EVENT(emptied)
23 EVENT(loadstart)
24 EVENT(webkitsourceopen) : SOURCE_OPEN
 22EVENT(webkitsourceopen) : open
2523onSecondSourceOpen
26 EVENT(webkitsourceended) : SOURCE_ENDED
 24EVENT(webkitsourceended) : ended
2725onSecondSourceEnded
2826EVENT(playing)
2927triggerSecondSourceClose
30 EVENT(webkitsourceclose) : SOURCE_CLOSED
 28EVENT(webkitsourceclose) : closed
3129onSecondSourceClose
3230EVENT(emptied)
33 EVENT(loadstart)
34 EVENT(webkitsourceopen) : SOURCE_OPEN
 31EVENT(webkitsourceopen) : open
3532onThirdSourceOpen
3633END OF TEST
3734

LayoutTests/http/tests/media/media-source/video-media-source-state-changes.html

88 var segmentHelper = new MediaSourceTest.SegmentHelper(WebMSegmentInfo.testWebM);
99 var seekTime;
1010
11  function appendMediaSegmentsForSeek(videoTag, segmentSeekTime)
 11 function appendMediaSegmentsForSeek(segmentSeekTime)
1212 {
1313 var index = segmentHelper.getMediaSegmentIndexForTimestamp(segmentSeekTime);
1414 var endIndex = index + 2;

1919 }
2020
2121 if (index >= totalMediaSegments) {
22  videoTag.webkitSourceEndOfStream(HTMLMediaElement.EOS_NO_ERROR);
 22 mediaSource.endOfStream();
2323 return;
2424 }
2525 }
2626
2727 function onSourceEvent(event)
2828 {
29  consoleWrite('EVENT(' + event.type + ') : ' + MediaSourceTest.getSourceStateName(event.target.webkitSourceState));
 29 consoleWrite('EVENT(' + event.type + ') : ' + event.target.readyState);
3030 }
3131
3232 function onFirstSourceOpen(event)

3636 // This is the first time the source is opened. We just want to append
3737 // the initialization segment and all media segments until the end of stream.
3838 // This is testing the
39  // SOURCE_CLOSED -> SOURCE_OPEN -> SOURCE_ENDED transition path.
 39 // "closed" -> "open" -> "ended" transition path.
4040
41  var videoTag = event.target;
42  videoTag.removeEventListener('webkitsourceopen', onFirstSourceOpen);
43  segmentHelper.addSourceId();
 41 var mediaSource = event.target;
 42 mediaSource.removeEventListener('webkitsourceopen', onFirstSourceOpen);
 43 segmentHelper.addSourceBuffer();
4444
45  MediaSourceTest.expectSourceState(videoTag, HTMLMediaElement.SOURCE_OPEN);
 45 MediaSourceTest.expectSourceState(mediaSource, "open");
4646
4747 segmentHelper.appendInitSegment();
4848
49  videoTag.addEventListener('webkitsourceended', onFirstSourceEnded);
 49 mediaSource.addEventListener('webkitsourceended', onFirstSourceEnded);
5050
5151 // Start appending media segments.
5252 segmentHelper.appendUntilEndOfStream(0);

5555 function onFirstSourceEnded(event)
5656 {
5757 consoleWrite("onFirstSourceEnded");
58  var videoTag = event.target;
59  videoTag.removeEventListener('webkitsourceended', onFirstSourceEnded);
6058
61  MediaSourceTest.expectSourceState(videoTag, videoTag.SOURCE_ENDED);
 59 var mediaSource = event.target;
 60 mediaSource.removeEventListener('webkitsourceended', onFirstSourceEnded);
 61
 62 MediaSourceTest.expectSourceState(mediaSource, "ended");
6263
63  videoTag.addEventListener('playing', triggerFirstSeek);
 64 video.addEventListener('playing', triggerFirstSeek);
6465 }
6566
6667 function triggerFirstSeek(event)

7172 videoTag.removeEventListener('playing', triggerFirstSeek);
7273
7374 // Now that we have appended all of the media segments and ended the stream,
74  // lets do a seek to test the SOURCE_ENDED -> SOURCE_OPEN transition.
 75 // lets do a seek to test the "ended" -> "open" transition.
7576 videoTag.addEventListener('seeking', onFirstSeeking);
7677 videoTag.addEventListener('seeked', onFirstSeeked);
7778 videoTag.currentTime = seekTime;

8485 var videoTag = event.target;
8586 videoTag.removeEventListener('seeking', onFirstSeeking);
8687
87  MediaSourceTest.expectSourceState(videoTag, HTMLMediaElement.SOURCE_OPEN);
 88 MediaSourceTest.expectSourceState(mediaSource, "open");
8889
8990 // Start appending media segments.
90  appendMediaSegmentsForSeek(videoTag, videoTag.currentTime);
 91 appendMediaSegmentsForSeek(videoTag.currentTime);
9192 }
9293
9394 function onFirstSeeked(event)

9798 var videoTag = event.target;
9899 videoTag.removeEventListener('seeked', onFirstSeeked);
99100
100  MediaSourceTest.expectSourceState(videoTag, HTMLMediaElement.SOURCE_OPEN);
 101 MediaSourceTest.expectSourceState(mediaSource, "open");
101102
102  // Now it is time to test seeking while still in SOURCE_OPEN.
 103 // Now it is time to test seeking while still in "open".
103104 videoTag.addEventListener('seeking', onSecondSeeking);
104105 videoTag.addEventListener('seeked', onSecondSeeked);
105106 videoTag.currentTime = seekTime;

112113 var videoTag = event.target;
113114 videoTag.removeEventListener('seeking', onSecondSeeking);
114115
115  MediaSourceTest.expectSourceState(videoTag, HTMLMediaElement.SOURCE_OPEN);
 116 MediaSourceTest.expectSourceState(mediaSource, "open");
116117
117118 // Start appending media segments.
118  appendMediaSegmentsForSeek(videoTag, videoTag.currentTime);
 119 appendMediaSegmentsForSeek(videoTag.currentTime);
119120 }
120121
121122 function onSecondSeeked(event)
122123 {
123124 consoleWrite("onSecondSeeked");
 125
124126 var videoTag = event.target;
125127 videoTag.removeEventListener('seeked', onSecondSeeked);
126128
127  MediaSourceTest.expectSourceState(videoTag, HTMLMediaElement.SOURCE_OPEN);
 129 MediaSourceTest.expectSourceState(mediaSource, "open");
128130
129  // Test SOURCE_OPEN -> SOURCE_CLOSED -> SOURCE_OPEN transition path.
130  videoTag.addEventListener('webkitsourceclose', onFirstSourceClose);
 131 // Test "open" -> "closed" -> "open" transition path.
 132 mediaSource.addEventListener('webkitsourceclose', onFirstSourceClose);
131133 MediaSourceTest.setSrcToMediaSourceTestURL(videoTag);
132134 }
133135

135137 {
136138 consoleWrite("onFirstSourceClose");
137139
138  var videoTag = event.target;
139  videoTag.removeEventListener('webkitsourceclose', onFirstSourceClose);
 140 var mediaSource = event.target;
 141 mediaSource.removeEventListener('webkitsourceclose', onFirstSourceClose);
140142
141  MediaSourceTest.expectSourceState(videoTag, HTMLMediaElement.SOURCE_CLOSED);
 143 MediaSourceTest.expectSourceState(mediaSource, "closed");
142144
143  videoTag.addEventListener('webkitsourceopen', onSecondSourceOpen);
 145 mediaSource.addEventListener('webkitsourceopen', onSecondSourceOpen);
144146 }
145147
146148 function onSecondSourceOpen(event)
147149 {
148150 consoleWrite("onSecondSourceOpen");
149151
150  var videoTag = event.target;
151  videoTag.removeEventListener('webkitsourceopen', onSecondSourceOpen);
152  segmentHelper.addSourceId();
 152 var mediaSource = event.target;
 153 mediaSource.removeEventListener('webkitsourceopen', onSecondSourceOpen);
 154 segmentHelper.addSourceBuffer();
153155
154  MediaSourceTest.expectSourceState(videoTag, HTMLMediaElement.SOURCE_OPEN);
 156 MediaSourceTest.expectSourceState(mediaSource, "open");
155157
156158 segmentHelper.appendInitSegment();
157159
158  videoTag.addEventListener('webkitsourceended', onSecondSourceEnded);
 160 mediaSource.addEventListener('webkitsourceended', onSecondSourceEnded);
159161
160162 // Start appending media segments.
161163 segmentHelper.appendUntilEndOfStream(0);

165167 {
166168 consoleWrite("onSecondSourceEnded");
167169
168  var videoTag = event.target;
169  videoTag.removeEventListener('webkitsourceended', onSecondSourceEnded);
 170 var mediaSource = event.target;
 171 mediaSource.removeEventListener('webkitsourceended', onSecondSourceEnded);
170172
171  MediaSourceTest.expectSourceState(videoTag, HTMLMediaElement.SOURCE_ENDED);
 173 MediaSourceTest.expectSourceState(mediaSource, "ended");
172174 //MediaSourceTest.expectReadyState(videoTag, HTMLMediaElement.HAVE_NOTHING);
173175
174  videoTag.addEventListener('playing', triggerSecondSourceClose);
 176 video.addEventListener('playing', triggerSecondSourceClose);
175177 }
176178
177179 function triggerSecondSourceClose(event)

181183 var videoTag = event.target;
182184 videoTag.removeEventListener('playing', triggerSecondSourceClose);
183185
184  // Test SOURCE_ENDED -> SOURCE_CLOSED -> SOURCE_OPEN transition path.
185  videoTag.addEventListener('webkitsourceclose', onSecondSourceClose);
 186 // Test "ended" -> "closed" -> "open" transition path.
 187 mediaSource.addEventListener('webkitsourceclose', onSecondSourceClose);
186188 MediaSourceTest.setSrcToMediaSourceTestURL(videoTag);
187189 }
188190

190192 {
191193 consoleWrite("onSecondSourceClose");
192194
193  var videoTag = event.target;
194  videoTag.removeEventListener('webkitsourceclose', onSecondSourceClose);
195  MediaSourceTest.expectSourceState(videoTag, HTMLMediaElement.SOURCE_CLOSED);
 195 var mediaSource = event.target;
 196 mediaSource.removeEventListener('webkitsourceclose', onSecondSourceClose);
 197 MediaSourceTest.expectSourceState(mediaSource, "closed");
196198
197  videoTag.addEventListener('webkitsourceopen', onThirdSourceOpen);
 199 mediaSource.addEventListener('webkitsourceopen', onThirdSourceOpen);
198200 }
199201
200202 function onThirdSourceOpen(event)
201203 {
202204 consoleWrite("onThirdSourceOpen");
203205
204  var videoTag = event.target;
205  videoTag.removeEventListener('webkitsourceopen', onThirdSourceOpen);
206  segmentHelper.addSourceId();
 206 var mediaSource = event.target;
 207 mediaSource.removeEventListener('webkitsourceopen', onThirdSourceOpen);
 208 segmentHelper.addSourceBuffer();
207209
208  MediaSourceTest.expectSourceState(videoTag, HTMLMediaElement.SOURCE_OPEN);
 210 MediaSourceTest.expectSourceState(mediaSource, "open");
209211
210212 endTest();
211213 }

214216 {
215217 findMediaElement();
216218
 219 mediaSource = new MediaSource();
 220
217221 waitForEventAndFail('error');
218  waitForEvent('loadstart');
219222 waitForEvent('playing');
220223 waitForEvent('seeking');
221224 waitForEvent('seeked');
222225 waitForEvent('ended');
223226 waitForEvent('emptied');
224227
225  video.addEventListener('webkitsourceopen', onSourceEvent);
226  video.addEventListener('webkitsourceended', onSourceEvent);
227  video.addEventListener('webkitsourceclose', onSourceEvent);
 228 mediaSource.addEventListener('webkitsourceopen', onSourceEvent);
 229 mediaSource.addEventListener('webkitsourceended', onSourceEvent);
 230 mediaSource.addEventListener('webkitsourceclose', onSourceEvent);
228231
229  video.addEventListener('webkitsourceopen', onFirstSourceOpen);
 232 mediaSource.addEventListener('webkitsourceopen', onFirstSourceOpen);
230233
231  MediaSourceTest.logSourceState(video);
 234 MediaSourceTest.logSourceState(mediaSource);
232235 segmentHelper.init(video, function(success)
233236 {
234237 if (!success) {