diff options
author | scherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-15 02:10:46 +0000 |
---|---|---|
committer | scherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-15 02:10:46 +0000 |
commit | e93e25629859d7d7f08428abd5bdad8a403515d4 (patch) | |
tree | 7226891aaed52aeed48922e8293ab05df72e42e1 /webkit/glue/media | |
parent | 86809eba59ca96feb557e98bbc5bdcf03c0c149b (diff) | |
download | chromium_src-e93e25629859d7d7f08428abd5bdad8a403515d4.zip chromium_src-e93e25629859d7d7f08428abd5bdad8a403515d4.tar.gz chromium_src-e93e25629859d7d7f08428abd5bdad8a403515d4.tar.bz2 |
Replace MockFilterCallback with MockCallback and simplify unit tests.
We had a ton of unnecessarily duplicated code, most of which could be solved by introducing NewExpectedCallback().
BUG=none
TEST=media_unittests
Review URL: http://codereview.chromium.org/6350001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@71537 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/glue/media')
-rw-r--r-- | webkit/glue/media/buffered_data_source_unittest.cc | 16 | ||||
-rw-r--r-- | webkit/glue/media/simple_data_source_unittest.cc | 45 |
2 files changed, 23 insertions, 38 deletions
diff --git a/webkit/glue/media/buffered_data_source_unittest.cc b/webkit/glue/media/buffered_data_source_unittest.cc index dcb11ec..df79485 100644 --- a/webkit/glue/media/buffered_data_source_unittest.cc +++ b/webkit/glue/media/buffered_data_source_unittest.cc @@ -1,10 +1,11 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include <algorithm> #include "base/test/test_timeouts.h" +#include "media/base/mock_callback.h" #include "media/base/mock_filter_host.h" #include "media/base/mock_filters.h" #include "net/base/net_errors.h" @@ -167,7 +168,6 @@ class BufferedDataSourceTest : public testing::Test { ON_CALL(*loader_, Read(_, _, _ , _)) .WillByDefault(DeleteArg<3>()); - StrictMock<media::MockFilterCallback> callback; ON_CALL(*loader_, instance_size()) .WillByDefault(Return(instance_size)); ON_CALL(*loader_, partial_response()) @@ -188,18 +188,13 @@ class BufferedDataSourceTest : public testing::Test { } else { EXPECT_CALL(host_, SetStreaming(true)); } - - EXPECT_CALL(callback, OnFilterCallback()); - EXPECT_CALL(callback, OnCallbackDestroyed()); } else { EXPECT_CALL(host_, SetError(media::PIPELINE_ERROR_NETWORK)); EXPECT_CALL(*loader_, Stop()); - EXPECT_CALL(callback, OnFilterCallback()); - EXPECT_CALL(callback, OnCallbackDestroyed()); } // Actual initialization of the data source. - data_source_->Initialize(url, callback.NewCallback()); + data_source_->Initialize(url, media::NewExpectedCallback()); message_loop_->RunAllPending(); if (initialized_ok) { @@ -220,10 +215,7 @@ class BufferedDataSourceTest : public testing::Test { EXPECT_CALL(*loader_, Stop()); } - StrictMock<media::MockFilterCallback> callback; - EXPECT_CALL(callback, OnFilterCallback()); - EXPECT_CALL(callback, OnCallbackDestroyed()); - data_source_->Stop(callback.NewCallback()); + data_source_->Stop(media::NewExpectedCallback()); message_loop_->RunAllPending(); } diff --git a/webkit/glue/media/simple_data_source_unittest.cc b/webkit/glue/media/simple_data_source_unittest.cc index 55dc913..82acaad 100644 --- a/webkit/glue/media/simple_data_source_unittest.cc +++ b/webkit/glue/media/simple_data_source_unittest.cc @@ -1,9 +1,9 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "base/callback.h" #include "media/base/filters.h" +#include "media/base/mock_callback.h" #include "media/base/mock_filter_host.h" #include "media/base/mock_filters.h" #include "net/base/net_errors.h" @@ -59,7 +59,8 @@ class SimpleDataSourceTest : public testing::Test { ignore_result(frame_.release()); } - void InitializeDataSource(const char* url) { + void InitializeDataSource(const char* url, + media::MockCallback* callback) { gurl_ = GURL(url); frame_.reset(new NiceMock<MockWebFrame>()); @@ -72,9 +73,7 @@ class SimpleDataSourceTest : public testing::Test { data_source_->set_host(&host_); data_source_->SetURLLoaderForTest(url_loader_); - InSequence s; - - data_source_->Initialize(url, callback_.NewCallback()); + data_source_->Initialize(url, callback); MessageLoop::current()->RunAllPending(); } @@ -96,8 +95,6 @@ class SimpleDataSourceTest : public testing::Test { InSequence s; EXPECT_CALL(host_, SetTotalBytes(kDataSize)); EXPECT_CALL(host_, SetBufferedBytes(kDataSize)); - EXPECT_CALL(callback_, OnFilterCallback()); - EXPECT_CALL(callback_, OnCallbackDestroyed()); data_source_->didFinishLoading(NULL, 0); @@ -108,8 +105,6 @@ class SimpleDataSourceTest : public testing::Test { void RequestFailed() { InSequence s; EXPECT_CALL(host_, SetError(media::PIPELINE_ERROR_NETWORK)); - EXPECT_CALL(callback_, OnFilterCallback()); - EXPECT_CALL(callback_, OnCallbackDestroyed()); WebURLError error; error.reason = net::ERR_FAILED; @@ -120,11 +115,7 @@ class SimpleDataSourceTest : public testing::Test { } void DestroyDataSource() { - StrictMock<media::MockFilterCallback> callback; - EXPECT_CALL(callback, OnFilterCallback()); - EXPECT_CALL(callback, OnCallbackDestroyed()); - - data_source_->Stop(callback.NewCallback()); + data_source_->Stop(media::NewExpectedCallback()); MessageLoop::current()->RunAllPending(); data_source_ = NULL; @@ -150,7 +141,6 @@ class SimpleDataSourceTest : public testing::Test { NiceMock<MockWebURLLoader>* url_loader_; scoped_refptr<SimpleDataSource> data_source_; StrictMock<media::MockFilterHost> host_; - StrictMock<media::MockFilterCallback> callback_; scoped_ptr<NiceMock<MockWebFrame> > frame_; char data_[kDataSize]; @@ -159,19 +149,19 @@ class SimpleDataSourceTest : public testing::Test { }; TEST_F(SimpleDataSourceTest, InitializeHTTP) { - InitializeDataSource(kHttpUrl); + InitializeDataSource(kHttpUrl, media::NewExpectedCallback()); RequestSucceeded(false); DestroyDataSource(); } TEST_F(SimpleDataSourceTest, InitializeHTTPS) { - InitializeDataSource(kHttpsUrl); + InitializeDataSource(kHttpsUrl, media::NewExpectedCallback()); RequestSucceeded(false); DestroyDataSource(); } TEST_F(SimpleDataSourceTest, InitializeFile) { - InitializeDataSource(kFileUrl); + InitializeDataSource(kFileUrl, media::NewExpectedCallback()); RequestSucceeded(true); DestroyDataSource(); } @@ -191,31 +181,34 @@ TEST_F(SimpleDataSourceTest, InitializeData) { EXPECT_CALL(host_, SetLoaded(true)); EXPECT_CALL(host_, SetTotalBytes(sizeof(kDataUrlDecoded))); EXPECT_CALL(host_, SetBufferedBytes(sizeof(kDataUrlDecoded))); - EXPECT_CALL(callback_, OnFilterCallback()); - EXPECT_CALL(callback_, OnCallbackDestroyed()); - data_source_->Initialize(kDataUrl, callback_.NewCallback()); + data_source_->Initialize(kDataUrl, media::NewExpectedCallback()); MessageLoop::current()->RunAllPending(); DestroyDataSource(); } TEST_F(SimpleDataSourceTest, RequestFailed) { - InitializeDataSource(kHttpUrl); + InitializeDataSource(kHttpUrl, media::NewExpectedCallback()); RequestFailed(); DestroyDataSource(); } TEST_F(SimpleDataSourceTest, StopWhenDownloading) { - InitializeDataSource(kHttpUrl); + // The callback should be deleted, but not executed. + // TODO(scherkus): should this really be the behaviour? Seems strange... + StrictMock<media::MockCallback>* callback = + new StrictMock<media::MockCallback>(); + EXPECT_CALL(*callback, Destructor()); + + InitializeDataSource(kHttpUrl, callback); EXPECT_CALL(*url_loader_, cancel()); - EXPECT_CALL(callback_, OnCallbackDestroyed()); DestroyDataSource(); } TEST_F(SimpleDataSourceTest, AsyncRead) { - InitializeDataSource(kFileUrl); + InitializeDataSource(kFileUrl, media::NewExpectedCallback()); RequestSucceeded(true); AsyncRead(); DestroyDataSource(); |