diff options
author | ajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-21 22:45:40 +0000 |
---|---|---|
committer | ajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-21 22:45:40 +0000 |
commit | 0acebfa1194d1b1b7155137ef6ccdf48b3b58258 (patch) | |
tree | c4a2fae47763fe06a1f46138715e1fb8e9840245 /webkit/glue/media | |
parent | 083a8ceb8ab236e0710c40357409b5dda18f580b (diff) | |
download | chromium_src-0acebfa1194d1b1b7155137ef6ccdf48b3b58258.zip chromium_src-0acebfa1194d1b1b7155137ef6ccdf48b3b58258.tar.gz chromium_src-0acebfa1194d1b1b7155137ef6ccdf48b3b58258.tar.bz2 |
Correct network state and ready state reporting.
For network state, make it return "loading" for everything that's not a file source since our cache does not yet reliably support caching the full media w/o need for a network.
For ready state, correctly handle seeks to drop from HaveEnoughData down to HaveMetaData until the seek completes. Also implement the seeking() function.
BUG=18975
TEST=none
Review URL: http://codereview.chromium.org/165432
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@24036 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/glue/media')
-rw-r--r-- | webkit/glue/media/buffered_data_source.cc | 3 | ||||
-rw-r--r-- | webkit/glue/media/buffered_data_source_unittest.cc | 44 | ||||
-rw-r--r-- | webkit/glue/media/simple_data_source.cc | 2 | ||||
-rw-r--r-- | webkit/glue/media/simple_data_source_unittest.cc | 24 |
4 files changed, 49 insertions, 24 deletions
diff --git a/webkit/glue/media/buffered_data_source.cc b/webkit/glue/media/buffered_data_source.cc index 5b6ef7e..f081f04 100644 --- a/webkit/glue/media/buffered_data_source.cc +++ b/webkit/glue/media/buffered_data_source.cc @@ -764,6 +764,9 @@ void BufferedDataSource::InitialStartCallback(int error) { host()->SetStreaming(true); } + // Currently, only files can be used reliably w/o a network. + host()->SetLoaded(url_.SchemeIsFile()); + initial_response_received_ = true; if (probe_response_received_) DoneInitialization(); diff --git a/webkit/glue/media/buffered_data_source_unittest.cc b/webkit/glue/media/buffered_data_source_unittest.cc index 4d9efe8..003313c 100644 --- a/webkit/glue/media/buffered_data_source_unittest.cc +++ b/webkit/glue/media/buffered_data_source_unittest.cc @@ -30,8 +30,15 @@ using ::testing::WithArgs; namespace { const char* kHttpUrl = "http://test"; +const char* kFileUrl = "file://test"; const int kDataSize = 1024; +enum NetworkState { + NONE, + LOADED, + LOADING +}; + } // namespace namespace webkit_glue { @@ -400,7 +407,7 @@ class BufferedDataSourceTest : public testing::Test { } } - ~BufferedDataSourceTest() { + virtual ~BufferedDataSourceTest() { if (data_source_) { // Release the bridge factory because we don't own it. // Expects bridge factory to be destroyed along with data source. @@ -414,7 +421,7 @@ class BufferedDataSourceTest : public testing::Test { } void InitializeDataSource(const char* url, int error, int probe_error, - int64 instance_size) { + int64 instance_size, NetworkState networkState) { // Saves the url first. gurl_ = GURL(url); @@ -432,6 +439,14 @@ class BufferedDataSourceTest : public testing::Test { loader_ = new StrictMock<MockBufferedResourceLoader>(); probe_loader_ = new StrictMock<MockBufferedResourceLoader>(); + if (networkState == LOADED) { + EXPECT_CALL(host_, SetLoaded(true)); + } else if (networkState == LOADING) { + EXPECT_CALL(host_, SetLoaded(false)); + } + + // TODO(ajwong): This mock is too strict. We do not need to guarantee a + // full sequencing each of these expectations. InSequence s; StrictMock<media::MockFilterCallback> callback; @@ -448,6 +463,7 @@ class BufferedDataSourceTest : public testing::Test { .WillOnce(DoAll(Assign(&error_, error), Invoke(this, &BufferedDataSourceTest::InvokeStartCallback))); + if (error == net::OK) { EXPECT_CALL(*loader_, instance_size()) .WillOnce(Return(instance_size)); @@ -689,36 +705,36 @@ class BufferedDataSourceTest : public testing::Test { }; TEST_F(BufferedDataSourceTest, InitializationSuccess) { - InitializeDataSource(kHttpUrl, net::OK, net::OK, 1024); + InitializeDataSource(kHttpUrl, net::OK, net::OK, 1024, LOADING); StopDataSource(); } TEST_F(BufferedDataSourceTest, InitiailizationFailed) { InitializeDataSource(kHttpUrl, net::ERR_FILE_NOT_FOUND, - net::ERR_FILE_NOT_FOUND, 0); + net::ERR_FILE_NOT_FOUND, 0, NONE); StopDataSource(); } TEST_F(BufferedDataSourceTest, MissingContentLength) { - InitializeDataSource(kHttpUrl, net::OK, net::OK, -1); + InitializeDataSource(kHttpUrl, net::OK, net::OK, -1, LOADING); StopDataSource(); } TEST_F(BufferedDataSourceTest, RangeRequestNotSupported) { InitializeDataSource(kHttpUrl, net::OK, - net::ERR_REQUEST_RANGE_NOT_SATISFIABLE, 1024); + net::ERR_REQUEST_RANGE_NOT_SATISFIABLE, 1024, LOADING); StopDataSource(); } TEST_F(BufferedDataSourceTest, MissingContentLengthAndRangeRequestNotSupported) { InitializeDataSource(kHttpUrl, net::OK, - net::ERR_REQUEST_RANGE_NOT_SATISFIABLE, -1); + net::ERR_REQUEST_RANGE_NOT_SATISFIABLE, -1, LOADING); StopDataSource(); } TEST_F(BufferedDataSourceTest, ReadCacheHit) { - InitializeDataSource(kHttpUrl, net::OK, net::OK, 25); + InitializeDataSource(kHttpUrl, net::OK, net::OK, 25, LOADING); // Performs read with cache hit. ReadDataSourceHit(10, 10, 10); @@ -730,21 +746,27 @@ TEST_F(BufferedDataSourceTest, ReadCacheHit) { } TEST_F(BufferedDataSourceTest, ReadCacheMiss) { - InitializeDataSource(kHttpUrl, net::OK, net::OK, 1024); + InitializeDataSource(kHttpUrl, net::OK, net::OK, 1024, LOADING); ReadDataSourceMiss(1000, 10); ReadDataSourceMiss(20, 10); StopDataSource(); } TEST_F(BufferedDataSourceTest, ReadFailed) { - InitializeDataSource(kHttpUrl, net::OK, net::OK, 1024); + InitializeDataSource(kHttpUrl, net::OK, net::OK, 1024, LOADING); ReadDataSourceHit(10, 10, 10); ReadDataSourceFailed(10, 10, net::ERR_CONNECTION_RESET); StopDataSource(); } TEST_F(BufferedDataSourceTest, ReadTimesOut) { - InitializeDataSource(kHttpUrl, net::OK, net::OK, 1024); + InitializeDataSource(kHttpUrl, net::OK, net::OK, 1024, LOADING); + ReadDataSourceTimesOut(20, 10); + StopDataSource(); +} + +TEST_F(BufferedDataSourceTest, FileHasLoadedState) { + InitializeDataSource(kFileUrl, net::OK, net::OK, 1024, LOADED); ReadDataSourceTimesOut(20, 10); StopDataSource(); } diff --git a/webkit/glue/media/simple_data_source.cc b/webkit/glue/media/simple_data_source.cc index fd3be2f..bcbec57 100644 --- a/webkit/glue/media/simple_data_source.cc +++ b/webkit/glue/media/simple_data_source.cc @@ -70,6 +70,8 @@ void SimpleDataSource::Initialize(const std::string& url, return; } + host()->SetLoaded(url_.SchemeIsFile()); + // Post a task to the render thread to start loading the resource. render_loop_->PostTask(FROM_HERE, NewRunnableMethod(this, &SimpleDataSource::StartTask)); diff --git a/webkit/glue/media/simple_data_source_unittest.cc b/webkit/glue/media/simple_data_source_unittest.cc index 9d367aa..eb5cd78 100644 --- a/webkit/glue/media/simple_data_source_unittest.cc +++ b/webkit/glue/media/simple_data_source_unittest.cc @@ -52,10 +52,7 @@ class SimpleDataSourceTest : public testing::Test { } } - void InitializeDataSource(const char* url) { - // Saves the url first. - gurl_ = GURL(url); - + void InitializeDataSource(const char* url, bool is_loaded) { media::MediaFormat url_format; url_format.SetAsString(media::MediaFormat::kMimeType, media::mime_type::kURL); @@ -66,9 +63,11 @@ class SimpleDataSourceTest : public testing::Test { // There is no need to provide a message loop to data source. data_source_->set_host(&host_); + EXPECT_CALL(host_, SetLoaded(is_loaded)); + // First a bridge is created. InSequence s; - EXPECT_CALL(*bridge_factory_, CreateBridge(gurl_, _, -1, -1)) + EXPECT_CALL(*bridge_factory_, CreateBridge(GURL(url), _, -1, -1)) .WillOnce(Return(bridge_.get())); EXPECT_CALL(*bridge_, Start(data_source_.get())) .WillOnce(Return(true)); @@ -165,32 +164,31 @@ class SimpleDataSourceTest : public testing::Test { scoped_refptr<SimpleDataSource> data_source_; StrictMock<media::MockFilterHost> host_; StrictMock<media::MockFilterCallback> callback_; - GURL gurl_; char data_[kDataSize]; DISALLOW_COPY_AND_ASSIGN(SimpleDataSourceTest); }; TEST_F(SimpleDataSourceTest, InitializeHTTP) { - InitializeDataSource(kHttpUrl); + InitializeDataSource(kHttpUrl, false); RequestSucceeded(); DestroyDataSource(); } TEST_F(SimpleDataSourceTest, InitializeHTTPS) { - InitializeDataSource(kHttpsUrl); + InitializeDataSource(kHttpsUrl, false); RequestSucceeded(); DestroyDataSource(); } TEST_F(SimpleDataSourceTest, InitializeFTP) { - InitializeDataSource(kFtpUrl); + InitializeDataSource(kFtpUrl, false); RequestSucceeded(); DestroyDataSource(); } TEST_F(SimpleDataSourceTest, InitializeFile) { - InitializeDataSource(kFileUrl); + InitializeDataSource(kFileUrl, true); RequestSucceeded(); DestroyDataSource(); } @@ -221,13 +219,13 @@ TEST_F(SimpleDataSourceTest, InitializeInvalid) { } TEST_F(SimpleDataSourceTest, RequestFailed) { - InitializeDataSource(kHttpUrl); + InitializeDataSource(kHttpUrl, false); RequestFailed(); DestroyDataSource(); } TEST_F(SimpleDataSourceTest, StopWhenDownloading) { - InitializeDataSource(kHttpUrl); + InitializeDataSource(kHttpUrl, false); EXPECT_CALL(*bridge_, Cancel()); EXPECT_CALL(*bridge_, OnDestroy()) @@ -237,7 +235,7 @@ TEST_F(SimpleDataSourceTest, StopWhenDownloading) { } TEST_F(SimpleDataSourceTest, AsyncRead) { - InitializeDataSource(kFileUrl); + InitializeDataSource(kFileUrl, true); RequestSucceeded(); AsyncRead(); DestroyDataSource(); |