Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(157)

Side by Side Diff: components/component_updater/test/update_checker_unittest.cc

Issue 514473002: Componentize component_updater: Break content/ dependency for rest of component_updater tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/compiler_specific.h" 6 #include "base/compiler_specific.h"
7 #include "base/files/file_util.h" 7 #include "base/files/file_util.h"
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/message_loop/message_loop.h"
10 #include "base/path_service.h" 11 #include "base/path_service.h"
11 #include "base/run_loop.h" 12 #include "base/run_loop.h"
12 #include "base/version.h" 13 #include "base/version.h"
13 #include "components/component_updater/crx_update_item.h" 14 #include "components/component_updater/crx_update_item.h"
14 #include "components/component_updater/test/test_configurator.h" 15 #include "components/component_updater/test/test_configurator.h"
15 #include "components/component_updater/test/url_request_post_interceptor.h" 16 #include "components/component_updater/test/url_request_post_interceptor.h"
16 #include "components/component_updater/update_checker.h" 17 #include "components/component_updater/update_checker.h"
17 #include "content/public/browser/browser_thread.h"
18 #include "content/public/test/test_browser_thread_bundle.h"
19 #include "net/url_request/url_fetcher.h" 18 #include "net/url_request/url_fetcher.h"
20 #include "net/url_request/url_request_test_util.h" 19 #include "net/url_request/url_request_test_util.h"
21 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
22 21
23 using content::BrowserThread;
24
25 namespace component_updater { 22 namespace component_updater {
26 23
27 namespace { 24 namespace {
28 25
29 base::FilePath test_file(const char* file) { 26 base::FilePath test_file(const char* file) {
30 base::FilePath path; 27 base::FilePath path;
31 PathService::Get(base::DIR_SOURCE_ROOT, &path); 28 PathService::Get(base::DIR_SOURCE_ROOT, &path);
32 return path.AppendASCII("components").AppendASCII("test").AppendASCII("data") 29 return path.AppendASCII("components").AppendASCII("test").AppendASCII("data")
33 .AppendASCII("component_updater").AppendASCII(file); 30 .AppendASCII("component_updater").AppendASCII(file);
34 } 31 }
(...skipping 25 matching lines...) Expand all
60 scoped_ptr<UpdateChecker> update_checker_; 57 scoped_ptr<UpdateChecker> update_checker_;
61 58
62 scoped_ptr<InterceptorFactory> interceptor_factory_; 59 scoped_ptr<InterceptorFactory> interceptor_factory_;
63 URLRequestPostInterceptor* post_interceptor_; // Owned by the factory. 60 URLRequestPostInterceptor* post_interceptor_; // Owned by the factory.
64 61
65 int error_; 62 int error_;
66 std::string error_message_; 63 std::string error_message_;
67 UpdateResponse::Results results_; 64 UpdateResponse::Results results_;
68 65
69 private: 66 private:
70 content::TestBrowserThreadBundle thread_bundle_; 67 base::MessageLoopForIO loop_;
71 base::Closure quit_closure_; 68 base::Closure quit_closure_;
72 69
73 DISALLOW_COPY_AND_ASSIGN(UpdateCheckerTest); 70 DISALLOW_COPY_AND_ASSIGN(UpdateCheckerTest);
74 }; 71 };
75 72
76 UpdateCheckerTest::UpdateCheckerTest() 73 UpdateCheckerTest::UpdateCheckerTest()
77 : config_(new TestConfigurator), 74 : post_interceptor_(NULL),
78 error_(0), 75 error_(0) {
79 thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) {
80 net::URLFetcher::SetEnableInterceptionForTests(true); 76 net::URLFetcher::SetEnableInterceptionForTests(true);
81 } 77 }
82 78
83 UpdateCheckerTest::~UpdateCheckerTest() { 79 UpdateCheckerTest::~UpdateCheckerTest() {
84 net::URLFetcher::SetEnableInterceptionForTests(false); 80 net::URLFetcher::SetEnableInterceptionForTests(false);
85 } 81 }
86 82
87 void UpdateCheckerTest::SetUp() { 83 void UpdateCheckerTest::SetUp() {
88 interceptor_factory_.reset(new InterceptorFactory); 84 config_.reset(new TestConfigurator(base::MessageLoopProxy::current(),
85 base::MessageLoopProxy::current()));
86 interceptor_factory_.reset(
87 new InterceptorFactory(base::MessageLoopProxy::current()));
89 post_interceptor_ = interceptor_factory_->CreateInterceptor(); 88 post_interceptor_ = interceptor_factory_->CreateInterceptor();
90 EXPECT_TRUE(post_interceptor_); 89 EXPECT_TRUE(post_interceptor_);
91 90
92 update_checker_.reset(); 91 update_checker_.reset();
93 92
94 error_ = 0; 93 error_ = 0;
95 error_message_.clear(); 94 error_message_.clear();
96 results_ = UpdateResponse::Results(); 95 results_ = UpdateResponse::Results();
97 } 96 }
98 97
99 void UpdateCheckerTest::TearDown() { 98 void UpdateCheckerTest::TearDown() {
100 update_checker_.reset(); 99 update_checker_.reset();
101 100
102 post_interceptor_ = NULL; 101 post_interceptor_ = NULL;
103 interceptor_factory_.reset(); 102 interceptor_factory_.reset();
104 103
105 config_.reset(); 104 config_.reset();
105
106 // The PostInterceptor requires the message loop to run to destruct correctly.
107 // TODO: This is fragile and should be fixed.
108 RunThreadsUntilIdle();
blundell 2014/08/27 12:44:56 Why didn't this need to be done before?
tommycli 2014/08/27 15:36:30 In the destructor of content::TestBrowserThreadBun
Ryan Sleevi 2014/09/03 00:12:17 This is more of a question for Paul. content:TBTB
106 } 109 }
107 110
108 void UpdateCheckerTest::RunThreads() { 111 void UpdateCheckerTest::RunThreads() {
109 base::RunLoop runloop; 112 base::RunLoop runloop;
110 quit_closure_ = runloop.QuitClosure(); 113 quit_closure_ = runloop.QuitClosure();
111 runloop.Run(); 114 runloop.Run();
112 115
113 // Since some tests need to drain currently enqueued tasks such as network 116 // Since some tests need to drain currently enqueued tasks such as network
114 // intercepts on the IO thread, run the threads until they are 117 // intercepts on the IO thread, run the threads until they are
115 // idle. The component updater service won't loop again until the loop count 118 // idle. The component updater service won't loop again until the loop count
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 << post_interceptor_->GetRequestsAsString(); 225 << post_interceptor_->GetRequestsAsString();
223 EXPECT_EQ(1, post_interceptor_->GetCount()) 226 EXPECT_EQ(1, post_interceptor_->GetCount())
224 << post_interceptor_->GetRequestsAsString(); 227 << post_interceptor_->GetRequestsAsString();
225 228
226 EXPECT_NE(0, error_); 229 EXPECT_NE(0, error_);
227 EXPECT_STREQ("network error", error_message_.c_str()); 230 EXPECT_STREQ("network error", error_message_.c_str());
228 EXPECT_EQ(0ul, results_.list.size()); 231 EXPECT_EQ(0ul, results_.list.size());
229 } 232 }
230 233
231 } // namespace component_updater 234 } // namespace component_updater
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698