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

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

Issue 508473002: Componentize component_updater: Move URLRequestPrepackagedInterceptor from content/ to net/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: run git cl format 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/path_service.h" 10 #include "base/path_service.h"
11 #include "base/run_loop.h" 11 #include "base/run_loop.h"
12 #include "base/version.h" 12 #include "base/version.h"
13 #include "chrome/browser/component_updater/test/component_updater_service_unitte st.h"
14 #include "chrome/browser/component_updater/test/url_request_post_interceptor.h"
15 #include "chrome/common/chrome_paths.h"
16 #include "components/component_updater/crx_update_item.h" 13 #include "components/component_updater/crx_update_item.h"
14 #include "components/component_updater/test/test_configurator.h"
15 #include "components/component_updater/test/url_request_post_interceptor.h"
17 #include "components/component_updater/update_checker.h" 16 #include "components/component_updater/update_checker.h"
18 #include "content/public/browser/browser_thread.h" 17 #include "content/public/browser/browser_thread.h"
19 #include "content/public/test/test_browser_thread_bundle.h" 18 #include "content/public/test/test_browser_thread_bundle.h"
20 #include "net/url_request/url_fetcher.h" 19 #include "net/url_request/url_fetcher.h"
21 #include "net/url_request/url_request_test_util.h" 20 #include "net/url_request/url_request_test_util.h"
22 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
23 22
24 using content::BrowserThread; 23 using content::BrowserThread;
25 24
26 namespace component_updater { 25 namespace component_updater {
27 26
28 namespace { 27 namespace {
29 28
30 base::FilePath test_file(const char* file) { 29 base::FilePath test_file(const char* file) {
31 base::FilePath path; 30 base::FilePath path;
32 PathService::Get(chrome::DIR_TEST_DATA, &path); 31 PathService::Get(base::DIR_SOURCE_ROOT, &path);
33 return path.AppendASCII("components").AppendASCII(file); 32 return path.AppendASCII("components")
33 .AppendASCII("test")
34 .AppendASCII("data")
35 .AppendASCII("component_updater")
36 .AppendASCII(file);
34 } 37 }
35 38
36 } // namespace 39 } // namespace
37 40
38 class UpdateCheckerTest : public testing::Test { 41 class UpdateCheckerTest : public testing::Test {
39 public: 42 public:
40 UpdateCheckerTest(); 43 UpdateCheckerTest();
41 virtual ~UpdateCheckerTest(); 44 virtual ~UpdateCheckerTest();
42 45
43 // Overrides from testing::Test. 46 // Overrides from testing::Test.
(...skipping 17 matching lines...) Expand all
61 64
62 scoped_ptr<InterceptorFactory> interceptor_factory_; 65 scoped_ptr<InterceptorFactory> interceptor_factory_;
63 URLRequestPostInterceptor* post_interceptor_; // Owned by the factory. 66 URLRequestPostInterceptor* post_interceptor_; // Owned by the factory.
64 67
65 int error_; 68 int error_;
66 std::string error_message_; 69 std::string error_message_;
67 UpdateResponse::Results results_; 70 UpdateResponse::Results results_;
68 71
69 private: 72 private:
70 content::TestBrowserThreadBundle thread_bundle_; 73 content::TestBrowserThreadBundle thread_bundle_;
71 base::FilePath test_data_dir_;
72 base::Closure quit_closure_; 74 base::Closure quit_closure_;
73 75
74 DISALLOW_COPY_AND_ASSIGN(UpdateCheckerTest); 76 DISALLOW_COPY_AND_ASSIGN(UpdateCheckerTest);
75 }; 77 };
76 78
77 UpdateCheckerTest::UpdateCheckerTest() 79 UpdateCheckerTest::UpdateCheckerTest()
78 : config_(new TestConfigurator), 80 : config_(new TestConfigurator),
79 error_(0), 81 error_(0),
80 thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) { 82 thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) {
81 // The test directory is chrome/test/data/components.
82 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_);
83 test_data_dir_ = test_data_dir_.AppendASCII("components");
84
85 net::URLFetcher::SetEnableInterceptionForTests(true); 83 net::URLFetcher::SetEnableInterceptionForTests(true);
86 } 84 }
87 85
88 UpdateCheckerTest::~UpdateCheckerTest() { 86 UpdateCheckerTest::~UpdateCheckerTest() {
89 net::URLFetcher::SetEnableInterceptionForTests(false); 87 net::URLFetcher::SetEnableInterceptionForTests(false);
90 } 88 }
91 89
92 void UpdateCheckerTest::SetUp() { 90 void UpdateCheckerTest::SetUp() {
93 interceptor_factory_.reset(new InterceptorFactory); 91 interceptor_factory_.reset(new InterceptorFactory);
94 post_interceptor_ = interceptor_factory_->CreateInterceptor(); 92 post_interceptor_ = interceptor_factory_->CreateInterceptor();
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 update_checker_->CheckForUpdates(items_to_check, "extra=\"params\""); 171 update_checker_->CheckForUpdates(items_to_check, "extra=\"params\"");
174 172
175 RunThreads(); 173 RunThreads();
176 174
177 EXPECT_EQ(1, post_interceptor_->GetHitCount()) 175 EXPECT_EQ(1, post_interceptor_->GetHitCount())
178 << post_interceptor_->GetRequestsAsString(); 176 << post_interceptor_->GetRequestsAsString();
179 EXPECT_EQ(1, post_interceptor_->GetCount()) 177 EXPECT_EQ(1, post_interceptor_->GetCount())
180 << post_interceptor_->GetRequestsAsString(); 178 << post_interceptor_->GetRequestsAsString();
181 179
182 // Sanity check the request. 180 // Sanity check the request.
181 EXPECT_NE(string::npos,
182 post_interceptor_->GetRequests()[0].find(
183 "request protocol=\"3.0\" extra=\"params\""));
183 EXPECT_NE( 184 EXPECT_NE(
184 string::npos, 185 string::npos,
185 post_interceptor_->GetRequests()[0].find( 186 post_interceptor_->GetRequests()[0].find(
186 "request protocol=\"3.0\" extra=\"params\""));
187 EXPECT_NE(
188 string::npos,
189 post_interceptor_->GetRequests()[0].find(
190 "app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"0.9\">" 187 "app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"0.9\">"
191 "<updatecheck /><packages><package fp=\"fp1\"/></packages></app>")); 188 "<updatecheck /><packages><package fp=\"fp1\"/></packages></app>"));
192 189
193 EXPECT_NE(string::npos, 190 EXPECT_NE(string::npos,
194 post_interceptor_->GetRequests()[0].find("<hw physmemory=")); 191 post_interceptor_->GetRequests()[0].find("<hw physmemory="));
195 192
196 // Sanity check the arguments of the callback after parsing. 193 // Sanity check the arguments of the callback after parsing.
197 EXPECT_EQ(0, error_); 194 EXPECT_EQ(0, error_);
198 EXPECT_TRUE(error_message_.empty()); 195 EXPECT_TRUE(error_message_.empty());
199 EXPECT_EQ(1ul, results_.list.size()); 196 EXPECT_EQ(1ul, results_.list.size());
(...skipping 27 matching lines...) Expand all
227 << post_interceptor_->GetRequestsAsString(); 224 << post_interceptor_->GetRequestsAsString();
228 EXPECT_EQ(1, post_interceptor_->GetCount()) 225 EXPECT_EQ(1, post_interceptor_->GetCount())
229 << post_interceptor_->GetRequestsAsString(); 226 << post_interceptor_->GetRequestsAsString();
230 227
231 EXPECT_NE(0, error_); 228 EXPECT_NE(0, error_);
232 EXPECT_STREQ("network error", error_message_.c_str()); 229 EXPECT_STREQ("network error", error_message_.c_str());
233 EXPECT_EQ(0ul, results_.list.size()); 230 EXPECT_EQ(0ul, results_.list.size());
234 } 231 }
235 232
236 } // namespace component_updater 233 } // namespace component_updater
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698