diff options
author | sorin <sorin@chromium.org> | 2015-04-28 10:15:02 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-04-28 17:15:28 +0000 |
commit | f9f4834d3690715c918eaaea589f18472e95ebd9 (patch) | |
tree | 842b7d227904e99cabfc5405b7198ca95b7d9558 /components/update_client | |
parent | 0842511c459cb46834d49766dede5c7fc4cb0187 (diff) | |
download | chromium_src-f9f4834d3690715c918eaaea589f18472e95ebd9.zip chromium_src-f9f4834d3690715c918eaaea589f18472e95ebd9.tar.gz chromium_src-f9f4834d3690715c918eaaea589f18472e95ebd9.tar.bz2 |
Eliminate component/update_client dependency on content/
BUG=479904
Review URL: https://codereview.chromium.org/1112623002
Cr-Commit-Position: refs/heads/master@{#327311}
Diffstat (limited to 'components/update_client')
-rw-r--r-- | components/update_client/DEPS | 9 | ||||
-rw-r--r-- | components/update_client/update_client_unittest.cc | 80 |
2 files changed, 42 insertions, 47 deletions
diff --git a/components/update_client/DEPS b/components/update_client/DEPS index 7fa7165..9cb7e78 100644 --- a/components/update_client/DEPS +++ b/components/update_client/DEPS @@ -9,12 +9,3 @@ include_rules = [ "+third_party/libxml", "+third_party/zlib", ] - -# Tests can use things in content. -# TODO(sorin): refactor to eliminate the dependency on content by using -# message loops directly. -specific_include_rules = { - ".*unittest\.cc": [ - "+content", - ] -}
\ No newline at end of file diff --git a/components/update_client/update_client_unittest.cc b/components/update_client/update_client_unittest.cc index 3cc3c4f..52f43fa 100644 --- a/components/update_client/update_client_unittest.cc +++ b/components/update_client/update_client_unittest.cc @@ -12,7 +12,9 @@ #include "base/message_loop/message_loop.h" #include "base/path_service.h" #include "base/run_loop.h" +#include "base/test/sequenced_worker_pool_owner.h" #include "base/thread_task_runner_handle.h" +#include "base/threading/thread.h" #include "base/values.h" #include "base/version.h" #include "components/update_client/crx_update_item.h" @@ -21,8 +23,6 @@ #include "components/update_client/test_installer.h" #include "components/update_client/update_checker.h" #include "components/update_client/update_client_internal.h" -#include "content/public/browser/browser_thread.h" -#include "content/public/test/test_browser_thread_bundle.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" #include "url/gurl.h" @@ -104,8 +104,6 @@ using ::testing::Invoke; using ::testing::Mock; using ::testing::Return; -using content::BrowserThread; - using std::string; class UpdateClientTest : public testing::Test { @@ -113,43 +111,49 @@ class UpdateClientTest : public testing::Test { UpdateClientTest(); ~UpdateClientTest() override; - void SetUp() override; - void TearDown() override; - protected: void RunThreads(); // Returns the full path to a test file. static base::FilePath TestFilePath(const char* file); - content::TestBrowserThreadBundle thread_bundle_; + scoped_refptr<update_client::Configurator> config() { return config_; } + base::Closure quit_closure() { return quit_closure_; } + + private: + static const int kNumWorkerThreads_ = 2; + + base::MessageLoopForUI message_loop_; base::RunLoop runloop_; base::Closure quit_closure_; - scoped_refptr<update_client::TestConfigurator> config_; + scoped_ptr<base::SequencedWorkerPoolOwner> worker_pool_; + scoped_ptr<base::Thread> thread_; + + scoped_refptr<update_client::Configurator> config_; - private: DISALLOW_COPY_AND_ASSIGN(UpdateClientTest); }; UpdateClientTest::UpdateClientTest() - : config_(new TestConfigurator( - BrowserThread::GetBlockingPool() - ->GetSequencedTaskRunnerWithShutdownBehavior( - BrowserThread::GetBlockingPool()->GetSequenceToken(), - base::SequencedWorkerPool::SKIP_ON_SHUTDOWN), - BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO))) { -} + : worker_pool_( + new base::SequencedWorkerPoolOwner(kNumWorkerThreads_, "test")), + thread_(new base::Thread("test")) { + quit_closure_ = runloop_.QuitClosure(); -UpdateClientTest::~UpdateClientTest() { -} + thread_->Start(); -void UpdateClientTest::SetUp() { - quit_closure_ = runloop_.QuitClosure(); + auto pool = worker_pool_->pool(); + config_ = new TestConfigurator( + pool->GetSequencedTaskRunner(pool->GetSequenceToken()), + thread_->task_runner()); } -void UpdateClientTest::TearDown() { +UpdateClientTest::~UpdateClientTest() { + config_ = nullptr; + thread_->Stop(); + worker_pool_->pool()->Shutdown(); } void UpdateClientTest::RunThreads() { @@ -232,9 +236,9 @@ TEST_F(UpdateClientTest, OneCrxNoUpdate) { ~FakePingManager() override { EXPECT_TRUE(items().empty()); } }; - scoped_ptr<PingManager> ping_manager(new FakePingManager(*config_)); + scoped_ptr<PingManager> ping_manager(new FakePingManager(*config())); scoped_ptr<UpdateClient> update_client(new UpdateClientImpl( - config_, ping_manager.Pass(), &FakeUpdateChecker::Create, + config(), ping_manager.Pass(), &FakeUpdateChecker::Create, &FakeCrxDownloader::Create)); MockObserver observer; @@ -251,7 +255,7 @@ TEST_F(UpdateClientTest, OneCrxNoUpdate) { update_client->Update( ids, base::Bind(&DataCallbackFake::Callback), - base::Bind(&CompletionCallbackFake::Callback, quit_closure_)); + base::Bind(&CompletionCallbackFake::Callback, quit_closure())); RunThreads(); @@ -398,9 +402,9 @@ TEST_F(UpdateClientTest, TwoCrxUpdateNoUpdate) { } }; - scoped_ptr<PingManager> ping_manager(new FakePingManager(*config_)); + scoped_ptr<PingManager> ping_manager(new FakePingManager(*config())); scoped_ptr<UpdateClient> update_client(new UpdateClientImpl( - config_, ping_manager.Pass(), &FakeUpdateChecker::Create, + config(), ping_manager.Pass(), &FakeUpdateChecker::Create, &FakeCrxDownloader::Create)); MockObserver observer; @@ -433,7 +437,7 @@ TEST_F(UpdateClientTest, TwoCrxUpdateNoUpdate) { update_client->Update( ids, base::Bind(&DataCallbackFake::Callback), - base::Bind(&CompletionCallbackFake::Callback, quit_closure_)); + base::Bind(&CompletionCallbackFake::Callback, quit_closure())); RunThreads(); @@ -627,9 +631,9 @@ TEST_F(UpdateClientTest, TwoCrxUpdate) { } }; - scoped_ptr<FakePingManager> ping_manager(new FakePingManager(*config_)); + scoped_ptr<FakePingManager> ping_manager(new FakePingManager(*config())); scoped_ptr<UpdateClient> update_client(new UpdateClientImpl( - config_, ping_manager.Pass(), &FakeUpdateChecker::Create, + config(), ping_manager.Pass(), &FakeUpdateChecker::Create, &FakeCrxDownloader::Create)); MockObserver observer; @@ -670,7 +674,7 @@ TEST_F(UpdateClientTest, TwoCrxUpdate) { update_client->Update( ids, base::Bind(&DataCallbackFake::Callback), - base::Bind(&CompletionCallbackFake::Callback, quit_closure_)); + base::Bind(&CompletionCallbackFake::Callback, quit_closure())); RunThreads(); @@ -888,9 +892,9 @@ TEST_F(UpdateClientTest, OneCrxDiffUpdate) { } }; - scoped_ptr<FakePingManager> ping_manager(new FakePingManager(*config_)); + scoped_ptr<FakePingManager> ping_manager(new FakePingManager(*config())); scoped_ptr<UpdateClient> update_client(new UpdateClientImpl( - config_, ping_manager.Pass(), &FakeUpdateChecker::Create, + config(), ping_manager.Pass(), &FakeUpdateChecker::Create, &FakeCrxDownloader::Create)); MockObserver observer; @@ -1101,9 +1105,9 @@ TEST_F(UpdateClientTest, OneCrxInstallError) { } }; - scoped_ptr<PingManager> ping_manager(new FakePingManager(*config_)); + scoped_ptr<PingManager> ping_manager(new FakePingManager(*config())); scoped_ptr<UpdateClient> update_client(new UpdateClientImpl( - config_, ping_manager.Pass(), &FakeUpdateChecker::Create, + config(), ping_manager.Pass(), &FakeUpdateChecker::Create, &FakeCrxDownloader::Create)); MockObserver observer; @@ -1128,7 +1132,7 @@ TEST_F(UpdateClientTest, OneCrxInstallError) { update_client->Update( ids, base::Bind(&DataCallbackFake::Callback), - base::Bind(&CompletionCallbackFake::Callback, quit_closure_)); + base::Bind(&CompletionCallbackFake::Callback, quit_closure())); RunThreads(); @@ -1362,9 +1366,9 @@ TEST_F(UpdateClientTest, OneCrxDiffUpdateFailsFullUpdateSucceeds) { } }; - scoped_ptr<FakePingManager> ping_manager(new FakePingManager(*config_)); + scoped_ptr<FakePingManager> ping_manager(new FakePingManager(*config())); scoped_ptr<UpdateClient> update_client(new UpdateClientImpl( - config_, ping_manager.Pass(), &FakeUpdateChecker::Create, + config(), ping_manager.Pass(), &FakeUpdateChecker::Create, &FakeCrxDownloader::Create)); MockObserver observer; |