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

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

Issue 808773005: Move most of the component updater artifacts to update_client. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 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/bind.h" 5 #include "base/bind.h"
6 #include "base/bind_helpers.h" 6 #include "base/bind_helpers.h"
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
13 #include "base/path_service.h" 13 #include "base/path_service.h"
14 #include "base/run_loop.h" 14 #include "base/run_loop.h"
15 #include "base/version.h" 15 #include "base/version.h"
16 #include "components/component_updater/crx_update_item.h" 16 #include "components/update_client/crx_update_item.h"
17 #include "components/component_updater/test/test_configurator.h" 17 #include "components/update_client/test/test_configurator.h"
18 #include "components/component_updater/test/url_request_post_interceptor.h" 18 #include "components/update_client/test/url_request_post_interceptor.h"
19 #include "components/component_updater/update_checker.h" 19 #include "components/update_client/update_checker.h"
20 #include "net/url_request/url_request_test_util.h" 20 #include "net/url_request/url_request_test_util.h"
21 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
22 #include "url/gurl.h" 22 #include "url/gurl.h"
23 23
24 using std::string; 24 using std::string;
25 25
26 namespace component_updater { 26 namespace update_client {
27 27
28 namespace { 28 namespace {
29 29
30 base::FilePath test_file(const char* file) { 30 base::FilePath test_file(const char* file) {
31 base::FilePath path; 31 base::FilePath path;
32 PathService::Get(base::DIR_SOURCE_ROOT, &path); 32 PathService::Get(base::DIR_SOURCE_ROOT, &path);
33 return path.AppendASCII("components").AppendASCII("test").AppendASCII("data") 33 return path.AppendASCII("components")
34 .AppendASCII("component_updater").AppendASCII(file); 34 .AppendASCII("test")
35 .AppendASCII("data")
36 .AppendASCII("update_client")
37 .AppendASCII(file);
35 } 38 }
36 39
37 } // namespace 40 } // namespace
38 41
39 class UpdateCheckerTest : public testing::Test { 42 class UpdateCheckerTest : public testing::Test {
40 public: 43 public:
41 UpdateCheckerTest(); 44 UpdateCheckerTest();
42 ~UpdateCheckerTest() override; 45 ~UpdateCheckerTest() override;
43 46
44 // Overrides from testing::Test. 47 // Overrides from testing::Test.
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 EXPECT_TRUE(post_interceptor_->ExpectRequest( 166 EXPECT_TRUE(post_interceptor_->ExpectRequest(
164 new PartialMatch("updatecheck"), test_file("updatecheck_reply_1.xml"))); 167 new PartialMatch("updatecheck"), test_file("updatecheck_reply_1.xml")));
165 168
166 update_checker_ = UpdateChecker::Create(*config_).Pass(); 169 update_checker_ = UpdateChecker::Create(*config_).Pass();
167 170
168 CrxUpdateItem item(BuildCrxUpdateItem()); 171 CrxUpdateItem item(BuildCrxUpdateItem());
169 std::vector<CrxUpdateItem*> items_to_check; 172 std::vector<CrxUpdateItem*> items_to_check;
170 items_to_check.push_back(&item); 173 items_to_check.push_back(&item);
171 174
172 update_checker_->CheckForUpdates( 175 update_checker_->CheckForUpdates(
173 items_to_check, 176 items_to_check, "extra=\"params\"",
174 "extra=\"params\"",
175 base::Bind(&UpdateCheckerTest::UpdateCheckComplete, 177 base::Bind(&UpdateCheckerTest::UpdateCheckComplete,
176 base::Unretained(this))); 178 base::Unretained(this)));
177 179
178 RunThreads(); 180 RunThreads();
179 181
180 EXPECT_EQ(1, post_interceptor_->GetHitCount()) 182 EXPECT_EQ(1, post_interceptor_->GetHitCount())
181 << post_interceptor_->GetRequestsAsString(); 183 << post_interceptor_->GetRequestsAsString();
182 EXPECT_EQ(1, post_interceptor_->GetCount()) 184 EXPECT_EQ(1, post_interceptor_->GetCount())
183 << post_interceptor_->GetRequestsAsString(); 185 << post_interceptor_->GetRequestsAsString();
184 186
185 // Sanity check the request. 187 // Sanity check the request.
188 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[0].find(
189 "request protocol=\"3.0\" extra=\"params\""));
186 EXPECT_NE( 190 EXPECT_NE(
187 string::npos, 191 string::npos,
188 post_interceptor_->GetRequests()[0].find( 192 post_interceptor_->GetRequests()[0].find(
189 "request protocol=\"3.0\" extra=\"params\""));
190 EXPECT_NE(
191 string::npos,
192 post_interceptor_->GetRequests()[0].find(
193 "app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"0.9\">" 193 "app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"0.9\">"
194 "<updatecheck /><packages><package fp=\"fp1\"/></packages></app>")); 194 "<updatecheck /><packages><package fp=\"fp1\"/></packages></app>"));
195 195
196 EXPECT_NE(string::npos, 196 EXPECT_NE(string::npos,
197 post_interceptor_->GetRequests()[0].find("<hw physmemory=")); 197 post_interceptor_->GetRequests()[0].find("<hw physmemory="));
198 198
199 // Sanity check the arguments of the callback after parsing. 199 // Sanity check the arguments of the callback after parsing.
200 EXPECT_EQ(config_->UpdateUrl().front(), original_url_); 200 EXPECT_EQ(config_->UpdateUrl().front(), original_url_);
201 EXPECT_EQ(0, error_); 201 EXPECT_EQ(0, error_);
202 EXPECT_TRUE(error_message_.empty()); 202 EXPECT_TRUE(error_message_.empty());
203 EXPECT_EQ(1ul, results_.list.size()); 203 EXPECT_EQ(1ul, results_.list.size());
204 EXPECT_STREQ("jebgalgnebhfojomionfpkfelancnnkf", 204 EXPECT_STREQ("jebgalgnebhfojomionfpkfelancnnkf",
205 results_.list[0].extension_id.c_str()); 205 results_.list[0].extension_id.c_str());
206 EXPECT_STREQ("1.0", results_.list[0].manifest.version.c_str()); 206 EXPECT_STREQ("1.0", results_.list[0].manifest.version.c_str());
207 } 207 }
208 208
209 // Simulates a 403 server response error. 209 // Simulates a 403 server response error.
210 TEST_F(UpdateCheckerTest, UpdateCheckError) { 210 TEST_F(UpdateCheckerTest, UpdateCheckError) {
211 EXPECT_TRUE( 211 EXPECT_TRUE(
212 post_interceptor_->ExpectRequest(new PartialMatch("updatecheck"), 403)); 212 post_interceptor_->ExpectRequest(new PartialMatch("updatecheck"), 403));
213 213
214 update_checker_ = UpdateChecker::Create(*config_).Pass(); 214 update_checker_ = UpdateChecker::Create(*config_).Pass();
215 215
216 CrxUpdateItem item(BuildCrxUpdateItem()); 216 CrxUpdateItem item(BuildCrxUpdateItem());
217 std::vector<CrxUpdateItem*> items_to_check; 217 std::vector<CrxUpdateItem*> items_to_check;
218 items_to_check.push_back(&item); 218 items_to_check.push_back(&item);
219 219
220 update_checker_->CheckForUpdates( 220 update_checker_->CheckForUpdates(
221 items_to_check, 221 items_to_check, "", base::Bind(&UpdateCheckerTest::UpdateCheckComplete,
222 "", 222 base::Unretained(this)));
223 base::Bind(&UpdateCheckerTest::UpdateCheckComplete,
224 base::Unretained(this)));
225 223
226 RunThreads(); 224 RunThreads();
227 225
228 EXPECT_EQ(1, post_interceptor_->GetHitCount()) 226 EXPECT_EQ(1, post_interceptor_->GetHitCount())
229 << post_interceptor_->GetRequestsAsString(); 227 << post_interceptor_->GetRequestsAsString();
230 EXPECT_EQ(1, post_interceptor_->GetCount()) 228 EXPECT_EQ(1, post_interceptor_->GetCount())
231 << post_interceptor_->GetRequestsAsString(); 229 << post_interceptor_->GetRequestsAsString();
232 230
233 EXPECT_EQ(config_->UpdateUrl().front(), original_url_); 231 EXPECT_EQ(config_->UpdateUrl().front(), original_url_);
234 EXPECT_EQ(403, error_); 232 EXPECT_EQ(403, error_);
235 EXPECT_STREQ("network error", error_message_.c_str()); 233 EXPECT_STREQ("network error", error_message_.c_str());
236 EXPECT_EQ(0ul, results_.list.size()); 234 EXPECT_EQ(0ul, results_.list.size());
237 } 235 }
238 236
239 } // namespace component_updater 237 } // namespace update_client
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698