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

Side by Side Diff: chrome/browser/component_updater/test/component_updater_service_unittest.cc

Issue 74893002: Changed the update protocol for component updater from v2 to v3. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/component_updater/test/component_updater_service_unitte st.h" 5 #include "chrome/browser/component_updater/test/component_updater_service_unitte st.h"
6 #include "base/file_util.h" 6 #include "base/file_util.h"
7 #include "base/path_service.h" 7 #include "base/path_service.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
11 #include "base/values.h" 11 #include "base/values.h"
12 #include "chrome/browser/component_updater/test/test_installer.h" 12 #include "chrome/browser/component_updater/test/test_installer.h"
13 #include "chrome/common/chrome_paths.h" 13 #include "chrome/common/chrome_paths.h"
14 #include "content/public/browser/browser_thread.h" 14 #include "content/public/browser/browser_thread.h"
15 #include "content/test/net/url_request_prepackaged_interceptor.h"
16 #include "libxml/globals.h" 15 #include "libxml/globals.h"
17 #include "net/base/upload_bytes_element_reader.h" 16 #include "net/base/upload_bytes_element_reader.h"
18 #include "net/url_request/url_fetcher.h" 17 #include "net/url_request/url_fetcher.h"
19 #include "url/gurl.h" 18 #include "url/gurl.h"
20 19
21 using content::BrowserThread; 20 using content::BrowserThread;
22 21
23 using ::testing::_; 22 using ::testing::_;
24 using ::testing::InSequence; 23 using ::testing::InSequence;
25 using ::testing::Mock; 24 using ::testing::Mock;
26 25
27 namespace component_updater { 26 namespace component_updater {
28 27
28 #define POST_INTERCEPT_SCHEME "http"
29 #define POST_INTERCEPT_HOSTNAME "localhost2"
30 #define POST_INTERCEPT_PATH "/update2"
31
29 MockComponentObserver::MockComponentObserver() { 32 MockComponentObserver::MockComponentObserver() {
30 } 33 }
31 34
32 MockComponentObserver::~MockComponentObserver() { 35 MockComponentObserver::~MockComponentObserver() {
33 } 36 }
34 37
35 TestConfigurator::TestConfigurator() 38 TestConfigurator::TestConfigurator()
36 : times_(1), 39 : times_(1),
37 recheck_time_(0), 40 recheck_time_(0),
38 ondemand_time_(0), 41 ondemand_time_(0),
(...skipping 29 matching lines...) Expand all
68 71
69 int TestConfigurator::MinimumReCheckWait() { 72 int TestConfigurator::MinimumReCheckWait() {
70 return recheck_time_; 73 return recheck_time_;
71 } 74 }
72 75
73 int TestConfigurator::OnDemandDelay() { 76 int TestConfigurator::OnDemandDelay() {
74 return ondemand_time_; 77 return ondemand_time_;
75 } 78 }
76 79
77 GURL TestConfigurator::UpdateUrl() { 80 GURL TestConfigurator::UpdateUrl() {
78 return GURL("http://localhost/upd"); 81 return GURL(POST_INTERCEPT_SCHEME "://"
82 POST_INTERCEPT_HOSTNAME POST_INTERCEPT_PATH);
79 } 83 }
80 84
81 GURL TestConfigurator::PingUrl() { 85 GURL TestConfigurator::PingUrl() {
82 return GURL("http://localhost2/update2"); 86 return UpdateUrl();
83 } 87 }
84 88
85 const char* TestConfigurator::ExtraRequestParams() { return "extra=foo"; } 89 const char* TestConfigurator::ExtraRequestParams() { return "extra=foo"; }
86 90
87 size_t TestConfigurator::UrlSizeLimit() { return 256; } 91 size_t TestConfigurator::UrlSizeLimit() { return 256; }
88 92
89 net::URLRequestContextGetter* TestConfigurator::RequestContext() { 93 net::URLRequestContextGetter* TestConfigurator::RequestContext() {
90 return context_.get(); 94 return context_.get();
91 } 95 }
92 96
(...skipping 22 matching lines...) Expand all
115 void TestConfigurator::SetComponentUpdateService(ComponentUpdateService* cus) { 119 void TestConfigurator::SetComponentUpdateService(ComponentUpdateService* cus) {
116 cus_ = cus; 120 cus_ = cus;
117 } 121 }
118 122
119 void TestConfigurator::SetQuitClosure(const base::Closure& quit_closure) { 123 void TestConfigurator::SetQuitClosure(const base::Closure& quit_closure) {
120 quit_closure_ = quit_closure; 124 quit_closure_ = quit_closure;
121 } 125 }
122 126
123 127
124 InterceptorFactory::InterceptorFactory() 128 InterceptorFactory::InterceptorFactory()
125 : URLRequestPostInterceptorFactory("http", "localhost2") {} 129 : URLRequestPostInterceptorFactory(POST_INTERCEPT_SCHEME,
130 POST_INTERCEPT_HOSTNAME) {}
126 131
127 InterceptorFactory::~InterceptorFactory() {} 132 InterceptorFactory::~InterceptorFactory() {}
128 133
129 URLRequestPostInterceptor* InterceptorFactory::CreateInterceptor() { 134 URLRequestPostInterceptor* InterceptorFactory::CreateInterceptor() {
130 return URLRequestPostInterceptorFactory::CreateInterceptor("/update2"); 135 return URLRequestPostInterceptorFactory::CreateInterceptor(
136 base::FilePath::FromUTF8Unsafe(POST_INTERCEPT_PATH));
131 } 137 }
132 138
133 class PartialMatch : public URLRequestPostInterceptor::RequestMatcher { 139 class PartialMatch : public URLRequestPostInterceptor::RequestMatcher {
134 public: 140 public:
135 explicit PartialMatch(const std::string& expected) : expected_(expected) {} 141 explicit PartialMatch(const std::string& expected) : expected_(expected) {}
136 virtual bool Match(const std::string& actual) const OVERRIDE { 142 virtual bool Match(const std::string& actual) const OVERRIDE {
137 return actual.find(expected_) != std::string::npos; 143 return actual.find(expected_) != std::string::npos;
138 } 144 }
139 145
140 private: 146 private:
(...skipping 15 matching lines...) Expand all
156 test_data_dir_ = test_data_dir_.AppendASCII("components"); 162 test_data_dir_ = test_data_dir_.AppendASCII("components");
157 163
158 net::URLFetcher::SetEnableInterceptionForTests(true); 164 net::URLFetcher::SetEnableInterceptionForTests(true);
159 } 165 }
160 166
161 ComponentUpdaterTest::~ComponentUpdaterTest() { 167 ComponentUpdaterTest::~ComponentUpdaterTest() {
162 net::URLFetcher::SetEnableInterceptionForTests(false); 168 net::URLFetcher::SetEnableInterceptionForTests(false);
163 } 169 }
164 170
165 void ComponentUpdaterTest::SetUp() { 171 void ComponentUpdaterTest::SetUp() {
172 get_interceptor_.reset(new GetInterceptor);
166 interceptor_factory_.reset(new InterceptorFactory); 173 interceptor_factory_.reset(new InterceptorFactory);
174 post_interceptor_ = interceptor_factory_->CreateInterceptor();
175 EXPECT_TRUE(post_interceptor_);
167 } 176 }
168 177
169 void ComponentUpdaterTest::TearDown() { 178 void ComponentUpdaterTest::TearDown() {
170 interceptor_factory_.reset(); 179 interceptor_factory_.reset();
180 get_interceptor_.reset();
171 xmlCleanupGlobals(); 181 xmlCleanupGlobals();
172 } 182 }
173 183
174 ComponentUpdateService* ComponentUpdaterTest::component_updater() { 184 ComponentUpdateService* ComponentUpdaterTest::component_updater() {
175 return component_updater_.get(); 185 return component_updater_.get();
176 } 186 }
177 187
178 // Makes the full path to a component updater test file. 188 // Makes the full path to a component updater test file.
179 const base::FilePath ComponentUpdaterTest::test_file(const char* file) { 189 const base::FilePath ComponentUpdaterTest::test_file(const char* file) {
180 return test_data_dir_.AppendASCII(file); 190 return test_data_dir_.AppendASCII(file);
(...skipping 20 matching lines...) Expand all
201 } 211 }
202 com->version = version; 212 com->version = version;
203 com->installer = installer; 213 com->installer = installer;
204 return component_updater_->RegisterComponent(*com); 214 return component_updater_->RegisterComponent(*com);
205 } 215 }
206 216
207 void ComponentUpdaterTest::RunThreads() { 217 void ComponentUpdaterTest::RunThreads() {
208 base::RunLoop runloop; 218 base::RunLoop runloop;
209 test_configurator()->SetQuitClosure(runloop.QuitClosure()); 219 test_configurator()->SetQuitClosure(runloop.QuitClosure());
210 runloop.Run(); 220 runloop.Run();
221 RunThreadsUntilIdle();
waffles 2013/11/18 22:15:59 Are you certain that this is safe? runloop.Run()
Sorin Jianu 2013/11/19 04:25:45 I am not sure about it and I removed the call.
waffles 2013/11/19 18:33:58 Ok, looks like it was needed after all? (As mentio
211 } 222 }
212 223
213 void ComponentUpdaterTest::RunThreadsUntilIdle() { 224 void ComponentUpdaterTest::RunThreadsUntilIdle() {
214 base::RunLoop().RunUntilIdle(); 225 base::RunLoop().RunUntilIdle();
215 } 226 }
216 227
217 ComponentUpdateService::Status OnDemandTester::OnDemand( 228 ComponentUpdateService::Status OnDemandTester::OnDemand(
218 ComponentUpdateService* cus, const std::string& component_id) { 229 ComponentUpdateService* cus, const std::string& component_id) {
219 return cus->OnDemandUpdate(component_id); 230 return cus->OnDemandUpdate(component_id);
220 } 231 }
221 232
222 // Verify that our test fixture work and the component updater can 233 // Verify that our test fixture work and the component updater can
223 // be created and destroyed with no side effects. 234 // be created and destroyed with no side effects.
224 TEST_F(ComponentUpdaterTest, VerifyFixture) { 235 TEST_F(ComponentUpdaterTest, VerifyFixture) {
225 EXPECT_TRUE(component_updater() != NULL); 236 EXPECT_TRUE(component_updater() != NULL);
226 } 237 }
227 238
228 // Verify that the component updater can be caught in a quick 239 // Verify that the component updater can be caught in a quick
229 // start-shutdown situation. Failure of this test will be a crash. 240 // start-shutdown situation. Failure of this test will be a crash.
230 TEST_F(ComponentUpdaterTest, StartStop) { 241 TEST_F(ComponentUpdaterTest, StartStop) {
231 component_updater()->Start(); 242 component_updater()->Start();
232 RunThreadsUntilIdle(); 243 RunThreadsUntilIdle();
233 component_updater()->Stop(); 244 component_updater()->Stop();
234 } 245 }
235 246
236 // Verify that when the server has no updates, we go back to sleep and 247 // Verify that when the server has no updates, we go back to sleep and
237 // the COMPONENT_UPDATER_STARTED and COMPONENT_UPDATER_SLEEPING notifications 248 // the COMPONENT_UPDATER_STARTED and COMPONENT_UPDATER_SLEEPING notifications
238 // are generated. No pings are sent. 249 // are generated. No pings are sent.
239 TEST_F(ComponentUpdaterTest, CheckCrxSleep) { 250 TEST_F(ComponentUpdaterTest, CheckCrxSleep) {
240 URLRequestPostInterceptor* post_interceptor( 251 MockComponentObserver observer;
241 interceptor_factory_->CreateInterceptor());
242 EXPECT_TRUE(post_interceptor != NULL);
243 EXPECT_TRUE(post_interceptor->ExpectRequest(new PartialMatch(
244 "event eventtype")));
245 252
246 content::URLLocalHostRequestPrepackagedInterceptor interceptor; 253 EXPECT_CALL(observer,
254 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0))
255 .Times(1);
256 EXPECT_CALL(observer,
257 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0))
258 .Times(2);
259 EXPECT_CALL(observer,
260 OnEvent(ComponentObserver::COMPONENT_NOT_UPDATED, 0))
261 .Times(2);
247 262
248 MockComponentObserver observer; 263 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch(
264 "updatecheck"), test_file("updatecheck_reply_1.xml")));
265 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch(
266 "updatecheck"), test_file("updatecheck_reply_1.xml")));
249 267
250 TestInstaller installer; 268 TestInstaller installer;
251 CrxComponent com; 269 CrxComponent com;
252 com.observer = &observer; 270 com.observer = &observer;
253 EXPECT_EQ(ComponentUpdateService::kOk, 271 EXPECT_EQ(ComponentUpdateService::kOk,
254 RegisterComponent(&com, 272 RegisterComponent(&com,
255 kTestComponent_abag, 273 kTestComponent_abag,
256 Version("1.1"), 274 Version("1.1"),
257 &installer)); 275 &installer));
258 276
259 const GURL expected_update_url(
260 "http://localhost/upd?extra=foo"
261 "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D1.1%26fp%3D%26uc");
262
263 interceptor.SetResponse(expected_update_url,
264 test_file("updatecheck_reply_1.xml"));
265
266 // We loop twice, but there are no updates so we expect two sleep messages. 277 // We loop twice, but there are no updates so we expect two sleep messages.
267 test_configurator()->SetLoopCount(2); 278 test_configurator()->SetLoopCount(2);
268
269 EXPECT_CALL(observer,
270 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0))
271 .Times(1);
272 component_updater()->Start(); 279 component_updater()->Start();
273
274 EXPECT_CALL(observer,
275 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0))
276 .Times(2);
277
278 EXPECT_CALL(observer,
279 OnEvent(ComponentObserver::COMPONENT_NOT_UPDATED, 0))
280 .Times(2);
281 RunThreads(); 280 RunThreads();
282 281
283 EXPECT_EQ(2, interceptor.GetHitCount());
284
285 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); 282 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error());
286 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count()); 283 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count());
287 284
285 // Expect to see the two update check requests and no other requests,
286 // including pings.
287 EXPECT_EQ(2, post_interceptor_->GetHitCount())
288 << post_interceptor_->GetRequestsAsString();
289 EXPECT_EQ(2, post_interceptor_->GetCount())
290 << post_interceptor_->GetRequestsAsString();
291 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[0].find(
292 "<app appid=\"abagagagagagagagagagagagagagagag\" version=\"1.1\">"
293 "<updatecheck /></app>"))
294 << post_interceptor_->GetRequestsAsString();
295 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[1].find(
296 "<app appid=\"abagagagagagagagagagagagagagagag\" version=\"1.1\">"
297 "<updatecheck /></app>"))
298 << post_interceptor_->GetRequestsAsString();
299
288 component_updater()->Stop(); 300 component_updater()->Stop();
289 301
290 // Loop twice again but this case we simulate a server error by returning 302 // Loop twice again but this case we simulate a server error by returning
291 // an empty file. 303 // an empty file. Expect the behavior of the service to be the same as before.
292
293 interceptor.SetResponse(expected_update_url,
294 test_file("updatecheck_reply_empty"));
295
296 test_configurator()->SetLoopCount(2);
297
298 EXPECT_CALL(observer, 304 EXPECT_CALL(observer,
299 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) 305 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0))
300 .Times(1); 306 .Times(1);
301 component_updater()->Start();
302
303 EXPECT_CALL(observer, 307 EXPECT_CALL(observer,
304 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) 308 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0))
305 .Times(2); 309 .Times(2);
306 EXPECT_CALL(observer, 310 EXPECT_CALL(observer,
307 OnEvent(ComponentObserver::COMPONENT_NOT_UPDATED, 0)) 311 OnEvent(ComponentObserver::COMPONENT_NOT_UPDATED, 0))
308 .Times(2); 312 .Times(2);
313
314 post_interceptor_->Reset();
315 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch(
316 "updatecheck"), test_file("updatecheck_reply_empty")));
317 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch(
318 "updatecheck"), test_file("updatecheck_reply_empty")));
319
320 test_configurator()->SetLoopCount(2);
321 component_updater()->Start();
309 RunThreads(); 322 RunThreads();
310 323
311 EXPECT_EQ(0, post_interceptor->GetHitCount())
312 << post_interceptor->GetRequestsAsString();
313 EXPECT_EQ(0, post_interceptor->GetMissCount())
314 << post_interceptor->GetRequestsAsString();
315
316 EXPECT_EQ(4, interceptor.GetHitCount());
317
318 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); 324 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error());
319 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count()); 325 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count());
320 326
327 EXPECT_EQ(2, post_interceptor_->GetHitCount())
328 << post_interceptor_->GetRequestsAsString();
329 EXPECT_EQ(2, post_interceptor_->GetCount())
330 << post_interceptor_->GetRequestsAsString();
331 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[0].find(
332 "<app appid=\"abagagagagagagagagagagagagagagag\" version=\"1.1\">"
333 "<updatecheck /></app>"))
334 << post_interceptor_->GetRequestsAsString();
335 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[1].find(
336 "<app appid=\"abagagagagagagagagagagagagagagag\" version=\"1.1\">"
337 "<updatecheck /></app>"))
338 << post_interceptor_->GetRequestsAsString();
339
321 component_updater()->Stop(); 340 component_updater()->Stop();
322 } 341 }
323 342
324 // Verify that we can check for updates and install one component. Besides 343 // Verify that we can check for updates and install one component. Besides
325 // the notifications above COMPONENT_UPDATE_FOUND and COMPONENT_UPDATE_READY 344 // the notifications above COMPONENT_UPDATE_FOUND and COMPONENT_UPDATE_READY
326 // should have been fired. We do two loops so the second time around there 345 // should have been fired. We do two loops so the second time around there
327 // should be nothing left to do. 346 // should be nothing left to do.
328 // We also check that only 3 non-ping network requests are issued: 347 // We also check that the following network requests are issued:
329 // 1- manifest check 348 // 1- manifest check
330 // 2- download crx 349 // 2- download crx
331 // 3- second manifest check. 350 // 3- ping
332 // Only one ping is sent. 351 // 4- second manifest check.
333 TEST_F(ComponentUpdaterTest, InstallCrx) { 352 TEST_F(ComponentUpdaterTest, InstallCrx) {
334 URLRequestPostInterceptor* post_interceptor(
335 interceptor_factory_->CreateInterceptor());
336 EXPECT_TRUE(post_interceptor != NULL);
337 EXPECT_TRUE(post_interceptor->ExpectRequest(new PartialMatch(
338 "<o:app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"1.0\">"
339 "<o:event eventtype=\"3\" eventresult=\"1\" "
340 "previousversion=\"0.9\" nextversion=\"1.0\"/></o:app>")));
341
342 content::URLLocalHostRequestPrepackagedInterceptor interceptor;
343
344 MockComponentObserver observer1; 353 MockComponentObserver observer1;
345 { 354 {
346 InSequence seq; 355 InSequence seq;
347 EXPECT_CALL(observer1, 356 EXPECT_CALL(observer1,
348 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) 357 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0))
349 .Times(1); 358 .Times(1);
350 EXPECT_CALL(observer1, 359 EXPECT_CALL(observer1,
351 OnEvent(ComponentObserver::COMPONENT_UPDATE_FOUND, 0)) 360 OnEvent(ComponentObserver::COMPONENT_UPDATE_FOUND, 0))
352 .Times(1); 361 .Times(1);
353 EXPECT_CALL(observer1, 362 EXPECT_CALL(observer1,
(...skipping 26 matching lines...) Expand all
380 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) 389 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0))
381 .Times(1); 390 .Times(1);
382 EXPECT_CALL(observer2, 391 EXPECT_CALL(observer2,
383 OnEvent(ComponentObserver::COMPONENT_NOT_UPDATED, 0)) 392 OnEvent(ComponentObserver::COMPONENT_NOT_UPDATED, 0))
384 .Times(1); 393 .Times(1);
385 EXPECT_CALL(observer2, 394 EXPECT_CALL(observer2,
386 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) 395 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0))
387 .Times(1); 396 .Times(1);
388 } 397 }
389 398
399 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch(
400 "updatecheck"), test_file("updatecheck_reply_1.xml")));
401 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch("event")));
402 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch(
403 "updatecheck"), test_file("updatecheck_reply_1.xml")));
404
405 get_interceptor_->SetResponse(
406 GURL(expected_crx_url),
407 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx"));
408
390 TestInstaller installer1; 409 TestInstaller installer1;
391 CrxComponent com1; 410 CrxComponent com1;
392 com1.observer = &observer1; 411 com1.observer = &observer1;
393 RegisterComponent(&com1, kTestComponent_jebg, Version("0.9"), &installer1); 412 RegisterComponent(&com1, kTestComponent_jebg, Version("0.9"), &installer1);
394 TestInstaller installer2; 413 TestInstaller installer2;
395 CrxComponent com2; 414 CrxComponent com2;
396 com2.observer = &observer2; 415 com2.observer = &observer2;
397 RegisterComponent(&com2, kTestComponent_abag, Version("2.2"), &installer2); 416 RegisterComponent(&com2, kTestComponent_abag, Version("2.2"), &installer2);
398 417
399 const GURL expected_update_url_1(
400 "http://localhost/upd?extra=foo"
401 "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26fp%3D%26uc"
402 "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc");
403
404 const GURL expected_update_url_2(
405 "http://localhost/upd?extra=foo"
406 "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc"
407 "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D1.0%26fp%3D%26uc");
408
409 interceptor.SetResponse(expected_update_url_1,
410 test_file("updatecheck_reply_1.xml"));
411 interceptor.SetResponse(expected_update_url_2,
412 test_file("updatecheck_reply_1.xml"));
413 interceptor.SetResponse(GURL(expected_crx_url),
414 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx"));
415
416 test_configurator()->SetLoopCount(2); 418 test_configurator()->SetLoopCount(2);
417
418 component_updater()->Start(); 419 component_updater()->Start();
419 RunThreads(); 420 RunThreads();
420 421
421 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error()); 422 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error());
422 EXPECT_EQ(1, static_cast<TestInstaller*>(com1.installer)->install_count()); 423 EXPECT_EQ(1, static_cast<TestInstaller*>(com1.installer)->install_count());
423 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error()); 424 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error());
424 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count()); 425 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count());
425 426
426 EXPECT_EQ(3, interceptor.GetHitCount()); 427 // Expect three request in total: two update checks and one ping.
428 EXPECT_EQ(3, post_interceptor_->GetHitCount())
429 << post_interceptor_->GetRequestsAsString();
430 EXPECT_EQ(3, post_interceptor_->GetCount())
431 << post_interceptor_->GetRequestsAsString();
427 432
428 EXPECT_EQ(1, post_interceptor->GetHitCount()) 433 // Expect one component download.
429 << post_interceptor->GetRequestsAsString(); 434 EXPECT_EQ(1, get_interceptor_->GetHitCount());
430 EXPECT_EQ(0, post_interceptor->GetMissCount()) 435
431 << post_interceptor->GetRequestsAsString(); 436 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[0].find(
437 "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"0.9\">"
438 "<updatecheck /></app>"))
439 << post_interceptor_->GetRequestsAsString();
440 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[0].find(
441 "<app appid=\"abagagagagagagagagagagagagagagag\" version=\"2.2\">"
442 "<updatecheck /></app>"))
443 << post_interceptor_->GetRequestsAsString();
444
445 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[1].find(
446 "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" "
447 "version=\"0.9\" nextversion=\"1.0\">"
448 "<event eventtype=\"3\" eventresult=\"1\"/></app>"))
449 << post_interceptor_->GetRequestsAsString();
450
451 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[2].find(
452 "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"1.0\">"
453 "<updatecheck /></app>"));
454 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[2].find(
455 "<app appid=\"abagagagagagagagagagagagagagagag\" version=\"2.2\">"
456 "<updatecheck /></app>"))
457 << post_interceptor_->GetRequestsAsString();
432 458
433 component_updater()->Stop(); 459 component_updater()->Stop();
434 } 460 }
435 461
436 // This test checks that the "prodversionmin" value is handled correctly. In 462 // This test checks that the "prodversionmin" value is handled correctly. In
437 // particular there should not be an install because the minimum product 463 // particular there should not be an install because the minimum product
438 // version is much higher than of chrome. 464 // version is much higher than of chrome.
439 TEST_F(ComponentUpdaterTest, ProdVersionCheck) { 465 TEST_F(ComponentUpdaterTest, ProdVersionCheck) {
440 URLRequestPostInterceptor* post_interceptor( 466 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch(
441 interceptor_factory_->CreateInterceptor()); 467 "updatecheck"), test_file("updatecheck_reply_2.xml")));
442 EXPECT_TRUE(post_interceptor != NULL);
443 EXPECT_TRUE(post_interceptor->ExpectRequest(new PartialMatch(
444 "event eventtype")));
445 468
446 content::URLLocalHostRequestPrepackagedInterceptor interceptor; 469 get_interceptor_->SetResponse(
470 GURL(expected_crx_url),
471 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx"));
447 472
448 TestInstaller installer; 473 TestInstaller installer;
449 CrxComponent com; 474 CrxComponent com;
450 RegisterComponent(&com, kTestComponent_jebg, Version("0.9"), &installer); 475 RegisterComponent(&com, kTestComponent_jebg, Version("0.9"), &installer);
451 476
452 const GURL expected_update_url(
453 "http://localhost/upd?extra=foo&x=id%3D"
454 "jebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26fp%3D%26uc");
455
456 interceptor.SetResponse(expected_update_url,
457 test_file("updatecheck_reply_2.xml"));
458 interceptor.SetResponse(GURL(expected_crx_url),
459 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx"));
460
461 test_configurator()->SetLoopCount(1); 477 test_configurator()->SetLoopCount(1);
462 component_updater()->Start(); 478 component_updater()->Start();
463 RunThreads(); 479 RunThreads();
464 480
465 EXPECT_EQ(0, post_interceptor->GetHitCount()) 481 // Expect one update check and no ping.
466 << post_interceptor->GetRequestsAsString(); 482 EXPECT_EQ(1, post_interceptor_->GetHitCount())
467 EXPECT_EQ(1, interceptor.GetHitCount()); 483 << post_interceptor_->GetRequestsAsString();
484 EXPECT_EQ(1, post_interceptor_->GetCount())
485 << post_interceptor_->GetRequestsAsString();
486
487 // Expect no download to occur.
488 EXPECT_EQ(0, get_interceptor_->GetHitCount());
468 489
469 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); 490 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error());
470 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count()); 491 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count());
471 492
472 component_updater()->Stop(); 493 component_updater()->Stop();
473 } 494 }
474 495
475 // Test that a update check due to an on demand call can cause installs. 496 // Test that a update check due to an on demand call can cause installs.
476 // Here is the timeline: 497 // Here is the timeline:
477 // - First loop: we return a reply that indicates no update, so 498 // - First loop: we return a reply that indicates no update, so
478 // nothing happens. 499 // nothing happens.
479 // - We make an on demand call. 500 // - We make an on demand call.
480 // - This triggers a second loop, which has a reply that triggers an install. 501 // - This triggers a second loop, which has a reply that triggers an install.
481 TEST_F(ComponentUpdaterTest, OnDemandUpdate) { 502 TEST_F(ComponentUpdaterTest, OnDemandUpdate) {
482 URLRequestPostInterceptor* post_interceptor(
483 interceptor_factory_->CreateInterceptor());
484 EXPECT_TRUE(post_interceptor != NULL);
485 EXPECT_TRUE(post_interceptor->ExpectRequest(new PartialMatch(
486 "<o:app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"1.0\">"
487 "<o:event eventtype=\"3\" eventresult=\"1\" "
488 "previousversion=\"0.9\" nextversion=\"1.0\"/></o:app>")));
489
490 content::URLLocalHostRequestPrepackagedInterceptor interceptor;
491
492 MockComponentObserver observer1; 503 MockComponentObserver observer1;
493 { 504 {
494 InSequence seq; 505 InSequence seq;
495 EXPECT_CALL(observer1, 506 EXPECT_CALL(observer1,
496 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) 507 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0))
497 .Times(1); 508 .Times(1);
498 EXPECT_CALL(observer1, 509 EXPECT_CALL(observer1,
499 OnEvent(ComponentObserver::COMPONENT_NOT_UPDATED, 0)) 510 OnEvent(ComponentObserver::COMPONENT_NOT_UPDATED, 0))
500 .Times(1); 511 .Times(1);
501 EXPECT_CALL(observer1, 512 EXPECT_CALL(observer1,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 OnEvent(ComponentObserver::COMPONENT_UPDATE_READY, 0)) 545 OnEvent(ComponentObserver::COMPONENT_UPDATE_READY, 0))
535 .Times(1); 546 .Times(1);
536 EXPECT_CALL(observer2, 547 EXPECT_CALL(observer2,
537 OnEvent(ComponentObserver::COMPONENT_UPDATED, 0)) 548 OnEvent(ComponentObserver::COMPONENT_UPDATED, 0))
538 .Times(1); 549 .Times(1);
539 EXPECT_CALL(observer2, 550 EXPECT_CALL(observer2,
540 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) 551 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0))
541 .Times(1); 552 .Times(1);
542 } 553 }
543 554
555 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch(
556 "updatecheck"), test_file("updatecheck_reply_empty")));
557
558 get_interceptor_->SetResponse(
559 GURL(expected_crx_url),
560 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx"));
561
544 TestInstaller installer1; 562 TestInstaller installer1;
545 CrxComponent com1; 563 CrxComponent com1;
546 com1.observer = &observer1; 564 com1.observer = &observer1;
547 RegisterComponent(&com1, kTestComponent_abag, Version("2.2"), &installer1); 565 RegisterComponent(&com1, kTestComponent_abag, Version("2.2"), &installer1);
548 TestInstaller installer2; 566 TestInstaller installer2;
549 CrxComponent com2; 567 CrxComponent com2;
550 com2.observer = &observer2; 568 com2.observer = &observer2;
551 RegisterComponent(&com2, kTestComponent_jebg, Version("0.9"), &installer2); 569 RegisterComponent(&com2, kTestComponent_jebg, Version("0.9"), &installer2);
552 570
553 const GURL expected_update_url_1(
554 "http://localhost/upd?extra=foo"
555 "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc"
556 "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26fp%3D%26uc");
557
558 const GURL expected_update_url_2(
559 "http://localhost/upd?extra=foo"
560 "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26fp%3D%26uc"
561 "%26installsource%3Dondemand"
562 "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc");
563
564 interceptor.SetResponse(expected_update_url_1,
565 test_file("updatecheck_reply_empty"));
566 interceptor.SetResponse(expected_update_url_2,
567 test_file("updatecheck_reply_1.xml"));
568 interceptor.SetResponse(GURL(expected_crx_url),
569 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx"));
570 // No update normally. 571 // No update normally.
571 test_configurator()->SetLoopCount(1); 572 test_configurator()->SetLoopCount(1);
572 component_updater()->Start(); 573 component_updater()->Start();
573 RunThreads(); 574 RunThreads();
574 component_updater()->Stop(); 575 component_updater()->Stop();
575 576
577 EXPECT_EQ(1, post_interceptor_->GetHitCount())
578 << post_interceptor_->GetRequestsAsString();
579 EXPECT_EQ(1, post_interceptor_->GetCount())
580 << post_interceptor_->GetRequestsAsString();
581
582 EXPECT_EQ(0, get_interceptor_->GetHitCount());
583
576 // Update after an on-demand check is issued. 584 // Update after an on-demand check is issued.
585 post_interceptor_->Reset();
586 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch(
587 "updatecheck"), test_file("updatecheck_reply_1.xml")));
588 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch("event")));
589
577 EXPECT_EQ(ComponentUpdateService::kOk, 590 EXPECT_EQ(ComponentUpdateService::kOk,
578 OnDemandTester::OnDemand(component_updater(), 591 OnDemandTester::OnDemand(component_updater(),
579 GetCrxComponentID(com2))); 592 GetCrxComponentID(com2)));
580 test_configurator()->SetLoopCount(1); 593 test_configurator()->SetLoopCount(1);
581 component_updater()->Start(); 594 component_updater()->Start();
582 RunThreads(); 595 RunThreads();
583 596
584 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error()); 597 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error());
585 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->install_count()); 598 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->install_count());
586 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error()); 599 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error());
587 EXPECT_EQ(1, static_cast<TestInstaller*>(com2.installer)->install_count()); 600 EXPECT_EQ(1, static_cast<TestInstaller*>(com2.installer)->install_count());
588 601
589 EXPECT_EQ(3, interceptor.GetHitCount()); 602 EXPECT_EQ(2, post_interceptor_->GetHitCount())
603 << post_interceptor_->GetRequestsAsString();
604 EXPECT_EQ(2, post_interceptor_->GetCount())
605 << post_interceptor_->GetRequestsAsString();
606
607 EXPECT_EQ(1, get_interceptor_->GetHitCount());
608
609 // Expect the update check to contain an "ondemand" request for the
610 // second component (com2) and a normal request for the other component.
611 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[0].find(
612 "<app appid=\"abagagagagagagagagagagagagagagag\" "
613 "version=\"2.2\"><updatecheck /></app>"))
614 << post_interceptor_->GetRequestsAsString();
615 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[0].find(
616 "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" "
617 "version=\"0.9\" installsource=\"ondemand\"><updatecheck /></app>"))
618 << post_interceptor_->GetRequestsAsString();
619 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[1].find(
620 "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" "
621 "version=\"0.9\" nextversion=\"1.0\">"
622 "<event eventtype=\"3\" eventresult=\"1\"/></app>"))
623 << post_interceptor_->GetRequestsAsString();
590 624
591 // Also check what happens if previous check too soon. 625 // Also check what happens if previous check too soon.
592 test_configurator()->SetOnDemandTime(60 * 60); 626 test_configurator()->SetOnDemandTime(60 * 60);
593 EXPECT_EQ(ComponentUpdateService::kError, 627 EXPECT_EQ(ComponentUpdateService::kError,
594 OnDemandTester::OnDemand(component_updater(), 628 OnDemandTester::OnDemand(component_updater(),
595 GetCrxComponentID(com2))); 629 GetCrxComponentID(com2)));
596 // Okay, now reset to 0 for the other tests. 630 // Okay, now reset to 0 for the other tests.
597 test_configurator()->SetOnDemandTime(0); 631 test_configurator()->SetOnDemandTime(0);
598 component_updater()->Stop(); 632 component_updater()->Stop();
599 633
(...skipping 19 matching lines...) Expand all
619 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) 653 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0))
620 .Times(1); 654 .Times(1);
621 EXPECT_CALL(observer2, 655 EXPECT_CALL(observer2,
622 OnEvent(ComponentObserver::COMPONENT_NOT_UPDATED, 0)) 656 OnEvent(ComponentObserver::COMPONENT_NOT_UPDATED, 0))
623 .Times(1); 657 .Times(1);
624 EXPECT_CALL(observer2, 658 EXPECT_CALL(observer2,
625 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) 659 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0))
626 .Times(1); 660 .Times(1);
627 } 661 }
628 662
629 const GURL expected_update_url_3( 663 // No update: error from no server response
630 "http://localhost/upd?extra=foo" 664 post_interceptor_->Reset();
631 "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D1.0%26fp%3D%26uc" 665 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch(
632 "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc"); 666 "updatecheck"), test_file("updatecheck_reply_empty")));
633 667
634 // No update: error from no server response
635 interceptor.SetResponse(expected_update_url_3,
636 test_file("updatecheck_reply_empty"));
637 test_configurator()->SetLoopCount(1); 668 test_configurator()->SetLoopCount(1);
638 component_updater()->Start(); 669 component_updater()->Start();
639 EXPECT_EQ(ComponentUpdateService::kOk, 670 EXPECT_EQ(ComponentUpdateService::kOk,
640 OnDemandTester::OnDemand(component_updater(), 671 OnDemandTester::OnDemand(component_updater(),
641 GetCrxComponentID(com2))); 672 GetCrxComponentID(com2)));
673 RunThreads();
674 component_updater()->Stop();
642 675
643 RunThreads(); 676 EXPECT_EQ(1, post_interceptor_->GetHitCount())
644 677 << post_interceptor_->GetRequestsAsString();
645 component_updater()->Stop(); 678 EXPECT_EQ(1, post_interceptor_->GetCount())
679 << post_interceptor_->GetRequestsAsString();
646 680
647 // No update: already updated to 1.0 so nothing new 681 // No update: already updated to 1.0 so nothing new
648 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&observer1)); 682 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&observer1));
649 { 683 {
650 InSequence seq; 684 InSequence seq;
651 EXPECT_CALL(observer1, 685 EXPECT_CALL(observer1,
652 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) 686 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0))
653 .Times(1); 687 .Times(1);
654 EXPECT_CALL(observer1, 688 EXPECT_CALL(observer1,
655 OnEvent(ComponentObserver::COMPONENT_NOT_UPDATED, 0)) 689 OnEvent(ComponentObserver::COMPONENT_NOT_UPDATED, 0))
656 .Times(1); 690 .Times(1);
657 EXPECT_CALL(observer1, 691 EXPECT_CALL(observer1,
658 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) 692 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0))
659 .Times(1); 693 .Times(1);
660 } 694 }
661 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&observer2)); 695 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&observer2));
662 { 696 {
663 InSequence seq; 697 InSequence seq;
664 EXPECT_CALL(observer2, 698 EXPECT_CALL(observer2,
665 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) 699 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0))
666 .Times(1); 700 .Times(1);
667 EXPECT_CALL(observer2, 701 EXPECT_CALL(observer2,
668 OnEvent(ComponentObserver::COMPONENT_NOT_UPDATED, 0)) 702 OnEvent(ComponentObserver::COMPONENT_NOT_UPDATED, 0))
669 .Times(1); 703 .Times(1);
670 EXPECT_CALL(observer2, 704 EXPECT_CALL(observer2,
671 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) 705 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0))
672 .Times(1); 706 .Times(1);
673 } 707 }
674 708
675 interceptor.SetResponse(expected_update_url_3, 709 post_interceptor_->Reset();
676 test_file("updatecheck_reply_1.xml")); 710 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch(
711 "updatecheck"), test_file("updatecheck_reply_1.xml")));
712
677 test_configurator()->SetLoopCount(1); 713 test_configurator()->SetLoopCount(1);
678 component_updater()->Start(); 714 component_updater()->Start();
679 EXPECT_EQ(ComponentUpdateService::kOk, 715 EXPECT_EQ(ComponentUpdateService::kOk,
680 OnDemandTester::OnDemand(component_updater(), 716 OnDemandTester::OnDemand(component_updater(),
681 GetCrxComponentID(com2))); 717 GetCrxComponentID(com2)));
682
683 RunThreads(); 718 RunThreads();
684 719
685 EXPECT_EQ(1, post_interceptor->GetHitCount()) 720 EXPECT_EQ(1, post_interceptor_->GetHitCount())
686 << post_interceptor->GetRequestsAsString(); 721 << post_interceptor_->GetRequestsAsString();
687 EXPECT_EQ(0, post_interceptor->GetMissCount()) 722 EXPECT_EQ(1, post_interceptor_->GetCount())
688 << post_interceptor->GetRequestsAsString(); 723 << post_interceptor_->GetRequestsAsString();
689 724
690 component_updater()->Stop(); 725 component_updater()->Stop();
691 } 726 }
692 727
693 // Verify that a previously registered component can get re-registered 728 // Verify that a previously registered component can get re-registered
694 // with a different version. 729 // with a different version.
695 TEST_F(ComponentUpdaterTest, CheckReRegistration) { 730 TEST_F(ComponentUpdaterTest, CheckReRegistration) {
696 URLRequestPostInterceptor* post_interceptor(
697 interceptor_factory_->CreateInterceptor());
698 EXPECT_TRUE(post_interceptor != NULL);
699 EXPECT_TRUE(post_interceptor->ExpectRequest(new PartialMatch(
700 "<o:app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"1.0\">"
701 "<o:event eventtype=\"3\" eventresult=\"1\" "
702 "previousversion=\"0.9\" nextversion=\"1.0\"/></o:app>")));
703
704 content::URLLocalHostRequestPrepackagedInterceptor interceptor;
705
706 MockComponentObserver observer1; 731 MockComponentObserver observer1;
707 { 732 {
708 InSequence seq; 733 InSequence seq;
709 EXPECT_CALL(observer1, 734 EXPECT_CALL(observer1,
710 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) 735 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0))
711 .Times(1); 736 .Times(1);
712 EXPECT_CALL(observer1, 737 EXPECT_CALL(observer1,
713 OnEvent(ComponentObserver::COMPONENT_UPDATE_FOUND, 0)) 738 OnEvent(ComponentObserver::COMPONENT_UPDATE_FOUND, 0))
714 .Times(1); 739 .Times(1);
715 EXPECT_CALL(observer1, 740 EXPECT_CALL(observer1,
(...skipping 26 matching lines...) Expand all
742 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) 767 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0))
743 .Times(1); 768 .Times(1);
744 EXPECT_CALL(observer2, 769 EXPECT_CALL(observer2,
745 OnEvent(ComponentObserver::COMPONENT_NOT_UPDATED, 0)) 770 OnEvent(ComponentObserver::COMPONENT_NOT_UPDATED, 0))
746 .Times(1); 771 .Times(1);
747 EXPECT_CALL(observer2, 772 EXPECT_CALL(observer2,
748 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) 773 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0))
749 .Times(1); 774 .Times(1);
750 } 775 }
751 776
777 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch(
778 "updatecheck"), test_file("updatecheck_reply_1.xml")));
779 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch("event")));
780 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch(
781 "updatecheck"), test_file("updatecheck_reply_1.xml")));
782
783 get_interceptor_->SetResponse(
784 GURL(expected_crx_url),
785 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx"));
786
752 TestInstaller installer1; 787 TestInstaller installer1;
753 CrxComponent com1; 788 CrxComponent com1;
754 com1.observer = &observer1; 789 com1.observer = &observer1;
755 RegisterComponent(&com1, kTestComponent_jebg, Version("0.9"), &installer1); 790 RegisterComponent(&com1, kTestComponent_jebg, Version("0.9"), &installer1);
756 TestInstaller installer2; 791 TestInstaller installer2;
757 CrxComponent com2; 792 CrxComponent com2;
758 com2.observer = &observer2; 793 com2.observer = &observer2;
759 RegisterComponent(&com2, kTestComponent_abag, Version("2.2"), &installer2); 794 RegisterComponent(&com2, kTestComponent_abag, Version("2.2"), &installer2);
760 795
761 // Start with 0.9, and update to 1.0 796 // Loop twice to issue two checks: (1) with original 0.9 version, update to
762 const GURL expected_update_url_1( 797 // 1.0, and do the second check (2) with the updated 1.0 version.
763 "http://localhost/upd?extra=foo"
764 "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26fp%3D%26uc"
765 "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc");
766
767 const GURL expected_update_url_2(
768 "http://localhost/upd?extra=foo"
769 "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc"
770 "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D1.0%26fp%3D%26uc");
771
772 interceptor.SetResponse(expected_update_url_1,
773 test_file("updatecheck_reply_1.xml"));
774 interceptor.SetResponse(expected_update_url_2,
775 test_file("updatecheck_reply_1.xml"));
776 interceptor.SetResponse(GURL(expected_crx_url),
777 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx"));
778
779 // Loop twice to issue two checks: (1) with original 0.9 version
780 // and (2) with the updated 1.0 version.
781 test_configurator()->SetLoopCount(2); 798 test_configurator()->SetLoopCount(2);
782
783 component_updater()->Start(); 799 component_updater()->Start();
784 RunThreads(); 800 RunThreads();
785 801
786 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error()); 802 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error());
787 EXPECT_EQ(1, static_cast<TestInstaller*>(com1.installer)->install_count()); 803 EXPECT_EQ(1, static_cast<TestInstaller*>(com1.installer)->install_count());
788 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error()); 804 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error());
789 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count()); 805 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count());
790 806
791 EXPECT_EQ(1, post_interceptor->GetHitCount()) 807 EXPECT_EQ(3, post_interceptor_->GetHitCount())
792 << post_interceptor->GetRequestsAsString(); 808 << post_interceptor_->GetRequestsAsString();
793 EXPECT_EQ(0, post_interceptor->GetMissCount()) 809 EXPECT_EQ(1, get_interceptor_->GetHitCount());
794 << post_interceptor->GetRequestsAsString();
795 810
796 EXPECT_EQ(3, interceptor.GetHitCount()); 811 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[0].find(
812 "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"0.9\">"
813 "<updatecheck /></app>"))
814 << post_interceptor_->GetRequestsAsString();
815 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[1].find(
816 "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" "
817 "version=\"0.9\" nextversion=\"1.0\">"
818 "<event eventtype=\"3\" eventresult=\"1\"/></app>"))
819 << post_interceptor_->GetRequestsAsString();
820 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[2].find(
821 "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"1.0\">"
822 "<updatecheck /></app>"))
823 << post_interceptor_->GetRequestsAsString();
797 824
798 component_updater()->Stop(); 825 component_updater()->Stop();
799 826
800 // Now re-register, pretending to be an even newer version (2.2) 827 // Now re-register, pretending to be an even newer version (2.2)
801 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&observer1)); 828 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&observer1));
802 { 829 {
803 InSequence seq; 830 InSequence seq;
804 EXPECT_CALL(observer1, 831 EXPECT_CALL(observer1,
805 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) 832 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0))
806 .Times(1); 833 .Times(1);
(...skipping 12 matching lines...) Expand all
819 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) 846 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0))
820 .Times(1); 847 .Times(1);
821 EXPECT_CALL(observer2, 848 EXPECT_CALL(observer2,
822 OnEvent(ComponentObserver::COMPONENT_NOT_UPDATED, 0)) 849 OnEvent(ComponentObserver::COMPONENT_NOT_UPDATED, 0))
823 .Times(1); 850 .Times(1);
824 EXPECT_CALL(observer2, 851 EXPECT_CALL(observer2,
825 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) 852 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0))
826 .Times(1); 853 .Times(1);
827 } 854 }
828 855
856 post_interceptor_->Reset();
857 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch(
858 "updatecheck"), test_file("updatecheck_reply_1.xml")));
859
829 TestInstaller installer3; 860 TestInstaller installer3;
830 EXPECT_EQ(ComponentUpdateService::kReplaced, 861 EXPECT_EQ(ComponentUpdateService::kReplaced,
831 RegisterComponent(&com1, 862 RegisterComponent(&com1,
832 kTestComponent_jebg, 863 kTestComponent_jebg,
833 Version("2.2"), 864 Version("2.2"),
834 &installer3)); 865 &installer3));
835 866
836 // Check that we send out 2.2 as our version.
837 // Interceptor's hit count should go up by 1.
838 const GURL expected_update_url_3(
839 "http://localhost/upd?extra=foo"
840 "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D2.2%26fp%3D%26uc"
841 "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc");
842
843 interceptor.SetResponse(expected_update_url_3,
844 test_file("updatecheck_reply_1.xml"));
845
846 // Loop once just to notice the check happening with the re-register version. 867 // Loop once just to notice the check happening with the re-register version.
847 test_configurator()->SetLoopCount(1); 868 test_configurator()->SetLoopCount(1);
848 component_updater()->Start(); 869 component_updater()->Start();
849 RunThreads(); 870 RunThreads();
850 871
851 EXPECT_EQ(4, interceptor.GetHitCount());
852
853 // No additional pings are expected.
854 EXPECT_EQ(1, post_interceptor->GetHitCount())
855 << post_interceptor->GetRequestsAsString();
856 EXPECT_EQ(0, post_interceptor->GetMissCount())
857 << post_interceptor->GetRequestsAsString();
858
859 // We created a new installer, so the counts go back to 0. 872 // We created a new installer, so the counts go back to 0.
860 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error()); 873 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error());
861 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->install_count()); 874 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->install_count());
862 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error()); 875 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error());
863 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count()); 876 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count());
864 877
878 // One update check and no additional pings are expected.
879 EXPECT_EQ(1, post_interceptor_->GetHitCount())
880 << post_interceptor_->GetRequestsAsString();
881 EXPECT_EQ(1, post_interceptor_->GetCount())
882 << post_interceptor_->GetRequestsAsString();
883
884 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[0].find(
885 "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"2.2\">"
886 "<updatecheck /></app>"));
887
865 component_updater()->Stop(); 888 component_updater()->Stop();
866 } 889 }
867 890
868 // Verify that we can download and install a component and a differential 891 // Verify that we can download and install a component and a differential
869 // update to that component. We do three loops; the final loop should do 892 // update to that component. We do three loops; the final loop should do
870 // nothing. 893 // nothing.
871 // We also check that exactly 5 non-ping network requests are issued: 894 // We also check that exactly 5 non-ping network requests are issued:
872 // 1- update check (response: v1 available) 895 // 1- update check (response: v1 available)
873 // 2- download crx (v1) 896 // 2- download crx (v1)
874 // 3- update check (response: v2 available) 897 // 3- update check (response: v2 available)
875 // 4- download differential crx (v1 to v2) 898 // 4- download differential crx (v1 to v2)
876 // 5- update check (response: no further update available) 899 // 5- update check (response: no further update available)
877 // There should be two pings, one for each update. The second will bear a 900 // There should be two pings, one for each update. The second will bear a
878 // diffresult=1, while the first will not. 901 // diffresult=1, while the first will not.
879 TEST_F(ComponentUpdaterTest, DifferentialUpdate) { 902 TEST_F(ComponentUpdaterTest, DifferentialUpdate) {
880 URLRequestPostInterceptor* post_interceptor( 903 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch(
881 interceptor_factory_->CreateInterceptor()); 904 "updatecheck"), test_file("updatecheck_diff_reply_1.xml")));
882 EXPECT_TRUE(post_interceptor != NULL); 905 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch("event")));
883 EXPECT_TRUE(post_interceptor->ExpectRequest(new PartialMatch( 906 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch(
884 "<o:app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" version=\"1.0\">" 907 "updatecheck"), test_file("updatecheck_diff_reply_2.xml")));
885 "<o:event eventtype=\"3\" eventresult=\"1\" " 908 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch("event")));
886 "previousversion=\"0.0\" nextversion=\"1.0\" nextfp=\"1\"/></o:app>"))); 909 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch(
887 EXPECT_TRUE(post_interceptor->ExpectRequest(new PartialMatch( 910 "updatecheck"), test_file("updatecheck_diff_reply_3.xml")));
888 "<o:app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" version=\"2.0\">"
889 "<o:event eventtype=\"3\" eventresult=\"1\" "
890 "previousversion=\"1.0\" nextversion=\"2.0\" "
891 "diffresult=\"1\" previousfp=\"1\" nextfp=\"f22\"/></o:app>")));
892 911
893 content::URLLocalHostRequestPrepackagedInterceptor interceptor; 912 get_interceptor_->SetResponse(
913 GURL("http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_1.crx"),
914 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1.crx"));
915 get_interceptor_->SetResponse(
916 GURL("http://localhost/download/"
917 "ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx"),
918 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx"));
894 919
895 VersionedTestInstaller installer; 920 VersionedTestInstaller installer;
896 CrxComponent com; 921 CrxComponent com;
897 RegisterComponent(&com, kTestComponent_ihfo, Version("0.0"), &installer); 922 RegisterComponent(&com, kTestComponent_ihfo, Version("0.0"), &installer);
898 923
899 const GURL expected_update_url_0(
900 "http://localhost/upd?extra=foo"
901 "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D0.0%26fp%3D%26uc");
902 const GURL expected_update_url_1(
903 "http://localhost/upd?extra=foo"
904 "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D1.0%26fp%3D1%26uc");
905 const GURL expected_update_url_2(
906 "http://localhost/upd?extra=foo"
907 "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D2.0%26fp%3Df22%26uc");
908 const GURL expected_crx_url_1(
909 "http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_1.crx");
910 const GURL expected_crx_url_1_diff_2(
911 "http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx");
912
913 interceptor.SetResponse(expected_update_url_0,
914 test_file("updatecheck_diff_reply_1.xml"));
915 interceptor.SetResponse(expected_update_url_1,
916 test_file("updatecheck_diff_reply_2.xml"));
917 interceptor.SetResponse(expected_update_url_2,
918 test_file("updatecheck_diff_reply_3.xml"));
919 interceptor.SetResponse(expected_crx_url_1,
920 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1.crx"));
921 interceptor.SetResponse(
922 expected_crx_url_1_diff_2,
923 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx"));
924
925 test_configurator()->SetLoopCount(3); 924 test_configurator()->SetLoopCount(3);
926
927 component_updater()->Start(); 925 component_updater()->Start();
928 RunThreads(); 926 RunThreads();
929 927
930 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); 928 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error());
931 EXPECT_EQ(2, static_cast<TestInstaller*>(com.installer)->install_count()); 929 EXPECT_EQ(2, static_cast<TestInstaller*>(com.installer)->install_count());
932 930
933 // One ping has the diffresult=1, the other does not. 931 EXPECT_EQ(5, post_interceptor_->GetHitCount())
934 EXPECT_EQ(2, post_interceptor->GetHitCount()) 932 << post_interceptor_->GetRequestsAsString();
935 << post_interceptor->GetRequestsAsString(); 933 EXPECT_EQ(5, post_interceptor_->GetCount())
936 EXPECT_EQ(0, post_interceptor->GetMissCount()) 934 << post_interceptor_->GetRequestsAsString();
937 << post_interceptor->GetRequestsAsString(); 935 EXPECT_EQ(2, get_interceptor_->GetHitCount());
938 936
939 EXPECT_EQ(5, interceptor.GetHitCount()); 937 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[0].find(
940 938 "<app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" version=\"0.0\">"
939 "<updatecheck /></app>"))
940 << post_interceptor_->GetRequestsAsString();
941 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[1].find(
942 "<app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" "
943 "version=\"0.0\" nextversion=\"1.0\">"
944 "<event eventtype=\"3\" eventresult=\"1\" nextfp=\"1\"/></app>"))
945 << post_interceptor_->GetRequestsAsString();
946 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[2].find(
947 "<app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" version=\"1.0\">"
948 "<updatecheck /><packages><package fp=\"1\"/></packages></app>"))
949 << post_interceptor_->GetRequestsAsString();
950 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[3].find(
951 "<app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" "
952 "version=\"1.0\" nextversion=\"2.0\">"
953 "<event eventtype=\"3\" eventresult=\"1\" diffresult=\"1\" "
954 "previousfp=\"1\" nextfp=\"22\"/></app>"))
955 << post_interceptor_->GetRequestsAsString();
956 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[4].find(
957 "<app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" version=\"2.0\">"
958 "<updatecheck /><packages><package fp=\"22\"/></packages></app>"))
959 << post_interceptor_->GetRequestsAsString();
941 component_updater()->Stop(); 960 component_updater()->Stop();
942 } 961 }
943 962
944 // Verify that component installation falls back to downloading and installing 963 // Verify that component installation falls back to downloading and installing
945 // a full update if the differential update fails (in this case, because the 964 // a full update if the differential update fails (in this case, because the
946 // installer does not know about the existing files). We do two loops; the final 965 // installer does not know about the existing files). We do two loops; the final
947 // loop should do nothing. 966 // loop should do nothing.
948 // We also check that exactly 4 non-ping network requests are issued: 967 // We also check that exactly 4 non-ping network requests are issued:
949 // 1- update check (loop 1) 968 // 1- update check (loop 1)
950 // 2- download differential crx 969 // 2- download differential crx
951 // 3- download full crx 970 // 3- download full crx
952 // 4- update check (loop 2 - no update available) 971 // 4- update check (loop 2 - no update available)
953 // There should be one ping for the first attempted update. 972 // There should be one ping for the first attempted update.
954 TEST_F(ComponentUpdaterTest, DifferentialUpdateFails) { 973 TEST_F(ComponentUpdaterTest, DifferentialUpdateFails) {
955 URLRequestPostInterceptor* post_interceptor( 974 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch(
956 interceptor_factory_->CreateInterceptor()); 975 "updatecheck"), test_file("updatecheck_diff_reply_2.xml")));
957 EXPECT_TRUE(post_interceptor != NULL); 976 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch("event")));
958 EXPECT_TRUE(post_interceptor->ExpectRequest(new PartialMatch( 977 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch(
959 "<o:app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" version=\"2.0\">" 978 "updatecheck"), test_file("updatecheck_diff_reply_3.xml")));
960 "<o:event eventtype=\"3\" eventresult=\"1\" "
961 "previousversion=\"1.0\" nextversion=\"2.0\" "
962 "diffresult=\"0\" differrorcat=\"2\" differrorcode=\"16\" "
963 "nextfp=\"f22\"/></o:app>")));
964 979
965 content::URLLocalHostRequestPrepackagedInterceptor interceptor; 980 get_interceptor_->SetResponse(
981 GURL("http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_1.crx"),
982 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1.crx"));
983 get_interceptor_->SetResponse(
984 GURL("http://localhost/download/"
985 "ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx"),
986 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx"));
987 get_interceptor_->SetResponse(
988 GURL("http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_2.crx"),
989 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_2.crx"));
966 990
967 TestInstaller installer; 991 TestInstaller installer;
968 CrxComponent com; 992 CrxComponent com;
969 RegisterComponent(&com, kTestComponent_ihfo, Version("1.0"), &installer); 993 RegisterComponent(&com, kTestComponent_ihfo, Version("1.0"), &installer);
970 994
971 const GURL expected_update_url_1(
972 "http://localhost/upd?extra=foo"
973 "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D1.0%26fp%3D%26uc");
974 const GURL expected_update_url_2(
975 "http://localhost/upd?extra=foo"
976 "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D2.0%26fp%3Df22%26uc");
977 const GURL expected_crx_url_1(
978 "http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_1.crx");
979 const GURL expected_crx_url_1_diff_2(
980 "http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx");
981 const GURL expected_crx_url_2(
982 "http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_2.crx");
983
984 interceptor.SetResponse(expected_update_url_1,
985 test_file("updatecheck_diff_reply_2.xml"));
986 interceptor.SetResponse(expected_update_url_2,
987 test_file("updatecheck_diff_reply_3.xml"));
988 interceptor.SetResponse(expected_crx_url_1,
989 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1.crx"));
990 interceptor.SetResponse(
991 expected_crx_url_1_diff_2,
992 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx"));
993 interceptor.SetResponse(expected_crx_url_2,
994 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_2.crx"));
995
996 test_configurator()->SetLoopCount(2); 995 test_configurator()->SetLoopCount(2);
997
998 component_updater()->Start(); 996 component_updater()->Start();
999 RunThreads(); 997 RunThreads();
1000 998
1001 // A failed differential update does not count as a failed install. 999 // A failed differential update does not count as a failed install.
1002 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); 1000 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error());
1003 EXPECT_EQ(1, static_cast<TestInstaller*>(com.installer)->install_count()); 1001 EXPECT_EQ(1, static_cast<TestInstaller*>(com.installer)->install_count());
1004 1002
1005 EXPECT_EQ(1, post_interceptor->GetHitCount()) 1003 EXPECT_EQ(3, post_interceptor_->GetHitCount())
1006 << post_interceptor->GetRequestsAsString(); 1004 << post_interceptor_->GetRequestsAsString();
1007 EXPECT_EQ(0, post_interceptor->GetMissCount()) 1005 EXPECT_EQ(3, post_interceptor_->GetCount())
1008 << post_interceptor->GetRequestsAsString(); 1006 << post_interceptor_->GetRequestsAsString();
1007 EXPECT_EQ(2, get_interceptor_->GetHitCount());
1009 1008
1010 EXPECT_EQ(4, interceptor.GetHitCount()); 1009 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[0].find(
1010 "<app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" version=\"1.0\">"
1011 "<updatecheck /></app>"))
1012 << post_interceptor_->GetRequestsAsString();
1013 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[1].find(
1014 "<app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" "
1015 "version=\"1.0\" nextversion=\"2.0\">"
1016 "<event eventtype=\"3\" eventresult=\"1\" diffresult=\"0\" "
1017 "differrorcat=\"2\" differrorcode=\"16\" nextfp=\"22\"/></app>"))
1018 << post_interceptor_->GetRequestsAsString();
1019 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[2].find(
1020 "<app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" version=\"2.0\">"
1021 "<updatecheck /><packages><package fp=\"22\"/></packages></app>"))
1022 << post_interceptor_->GetRequestsAsString();
1011 1023
1012 component_updater()->Stop(); 1024 component_updater()->Stop();
1013 } 1025 }
1014 1026
1015 // Verify that a failed installation causes an install failure ping. 1027 // Verify that a failed installation causes an install failure ping.
1016 TEST_F(ComponentUpdaterTest, CheckFailedInstallPing) { 1028 TEST_F(ComponentUpdaterTest, CheckFailedInstallPing) {
1017 URLRequestPostInterceptor* post_interceptor(
1018 interceptor_factory_->CreateInterceptor());
1019 EXPECT_TRUE(post_interceptor != NULL);
1020 EXPECT_TRUE(post_interceptor->ExpectRequest(new PartialMatch(
1021 "<o:app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"0.9\">"
1022 "<o:event eventtype=\"3\" eventresult=\"0\" "
1023 "previousversion=\"0.9\" nextversion=\"1.0\" "
1024 "errorcat=\"3\" errorcode=\"9\"/></o:app>")));
1025 EXPECT_TRUE(post_interceptor->ExpectRequest(new PartialMatch(
1026 "<o:app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"0.9\">"
1027 "<o:event eventtype=\"3\" eventresult=\"0\" "
1028 "previousversion=\"0.9\" nextversion=\"1.0\" "
1029 "errorcat=\"3\" errorcode=\"9\"/></o:app>")));
1030
1031 content::URLLocalHostRequestPrepackagedInterceptor interceptor;
1032
1033 // This test installer reports installation failure. 1029 // This test installer reports installation failure.
1034 class : public TestInstaller { 1030 class : public TestInstaller {
1035 virtual bool Install(const base::DictionaryValue& manifest, 1031 virtual bool Install(const base::DictionaryValue& manifest,
1036 const base::FilePath& unpack_path) OVERRIDE { 1032 const base::FilePath& unpack_path) OVERRIDE {
1037 ++install_count_; 1033 ++install_count_;
1038 base::DeleteFile(unpack_path, true); 1034 base::DeleteFile(unpack_path, true);
1039 return false; 1035 return false;
1040 } 1036 }
1041 } installer; 1037 } installer;
1042 1038
1039 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch(
1040 "updatecheck"), test_file("updatecheck_reply_1.xml")));
1041 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch("event")));
1042 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch(
1043 "updatecheck"), test_file("updatecheck_reply_1.xml")));
1044 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch("event")));
1045 get_interceptor_->SetResponse(
1046 GURL(expected_crx_url),
1047 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx"));
1048
1049 // Start with 0.9, and attempt update to 1.0.
1050 // Loop twice to issue two checks: (1) with original 0.9 version
1051 // and (2), which should retry with 0.9.
1043 CrxComponent com; 1052 CrxComponent com;
1044 RegisterComponent(&com, kTestComponent_jebg, Version("0.9"), &installer); 1053 RegisterComponent(&com, kTestComponent_jebg, Version("0.9"), &installer);
1045 1054
1046 // Start with 0.9, and attempt update to 1.0
1047 const GURL expected_update_url_1(
1048 "http://localhost/upd?extra=foo"
1049 "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26fp%3D%26uc");
1050
1051 interceptor.SetResponse(expected_update_url_1,
1052 test_file("updatecheck_reply_1.xml"));
1053 interceptor.SetResponse(GURL(expected_crx_url),
1054 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx"));
1055
1056 // Loop twice to issue two checks: (1) with original 0.9 version
1057 // and (2), which should retry with 0.9.
1058 test_configurator()->SetLoopCount(2); 1055 test_configurator()->SetLoopCount(2);
1059 component_updater()->Start(); 1056 component_updater()->Start();
1060 RunThreads(); 1057 RunThreads();
1061 1058
1059 EXPECT_EQ(4, post_interceptor_->GetHitCount())
1060 << post_interceptor_->GetRequestsAsString();
1061 EXPECT_EQ(2, get_interceptor_->GetHitCount());
1062
1063 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[0].find(
1064 "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"0.9\">"
1065 "<updatecheck /></app>"))
1066 << post_interceptor_->GetRequestsAsString();
1067 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[1].find(
1068 "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" "
1069 "version=\"0.9\" nextversion=\"1.0\">"
1070 "<event eventtype=\"3\" eventresult=\"0\" "
1071 "errorcat=\"3\" errorcode=\"9\"/></app>"))
1072 << post_interceptor_->GetRequestsAsString();
1073 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[2].find(
1074 "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"0.9\">"
1075 "<updatecheck /></app>"))
1076 << post_interceptor_->GetRequestsAsString();
1077 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[3].find(
1078 "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" "
1079 "version=\"0.9\" nextversion=\"1.0\">"
1080 "<event eventtype=\"3\" eventresult=\"0\" "
1081 "errorcat=\"3\" errorcode=\"9\"/></app>"))
1082 << post_interceptor_->GetRequestsAsString();
1083
1062 // Loop once more, but expect no ping because a noupdate response is issued. 1084 // Loop once more, but expect no ping because a noupdate response is issued.
1063 // This is necessary to clear out the fire-and-forget ping from the previous 1085 // This is necessary to clear out the fire-and-forget ping from the previous
1064 // iteration. 1086 // iteration.
1065 interceptor.SetResponse(expected_update_url_1, 1087 post_interceptor_->Reset();
1066 test_file("updatecheck_reply_noupdate.xml")); 1088 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch(
1089 "updatecheck"), test_file("updatecheck_reply_noupdate.xml")));
1090
1067 test_configurator()->SetLoopCount(1); 1091 test_configurator()->SetLoopCount(1);
1068 component_updater()->Start(); 1092 component_updater()->Start();
1069 RunThreads(); 1093 RunThreads();
1070 1094
1071 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); 1095 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error());
1072 EXPECT_EQ(2, static_cast<TestInstaller*>(com.installer)->install_count()); 1096 EXPECT_EQ(2, static_cast<TestInstaller*>(com.installer)->install_count());
1073 1097
1074 EXPECT_EQ(2, post_interceptor->GetHitCount()) 1098 EXPECT_EQ(1, post_interceptor_->GetHitCount())
1075 << post_interceptor->GetRequestsAsString(); 1099 << post_interceptor_->GetRequestsAsString();
1076 EXPECT_EQ(0, post_interceptor->GetMissCount()) 1100 EXPECT_EQ(1, post_interceptor_->GetCount())
1077 << post_interceptor->GetRequestsAsString(); 1101 << post_interceptor_->GetRequestsAsString();
1078 1102
1079 EXPECT_EQ(5, interceptor.GetHitCount()); 1103 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[0].find(
1104 "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"0.9\">"
1105 "<updatecheck /></app>"))
1106 << post_interceptor_->GetRequestsAsString();
1080 1107
1081 component_updater()->Stop(); 1108 component_updater()->Stop();
1082 } 1109 }
1083 1110
1084 // Verify that we successfully propagate a patcher error. 1111 // Verify that we successfully propagate a patcher error.
1085 // ihfokbkgjpifnbbojhneepfflplebdkc_1to2_bad.crx contains an incorrect 1112 // ihfokbkgjpifnbbojhneepfflplebdkc_1to2_bad.crx contains an incorrect
1086 // patching instruction that should fail. 1113 // patching instruction that should fail.
1087 TEST_F(ComponentUpdaterTest, DifferentialUpdateFailErrorcode) { 1114 TEST_F(ComponentUpdaterTest, DifferentialUpdateFailErrorcode) {
1088 URLRequestPostInterceptor* post_interceptor( 1115 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch(
1089 interceptor_factory_->CreateInterceptor()); 1116 "updatecheck"), test_file("updatecheck_diff_reply_1.xml")));
1090 EXPECT_TRUE(post_interceptor != NULL); 1117 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch("event")));
1091 EXPECT_TRUE(post_interceptor->ExpectRequest(new PartialMatch( 1118 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch(
1092 "<o:app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" version=\"1.0\">" 1119 "updatecheck"), test_file("updatecheck_diff_reply_2.xml")));
1093 "<o:event eventtype=\"3\" eventresult=\"1\" " 1120 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch("event")));
1094 "previousversion=\"0.0\" nextversion=\"1.0\" nextfp=\"1\"/></o:app>"))); 1121 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch(
1095 EXPECT_TRUE(post_interceptor->ExpectRequest(new PartialMatch( 1122 "updatecheck"), test_file("updatecheck_diff_reply_3.xml")));
1096 "<o:app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" version=\"2.0\">"
1097 "<o:event eventtype=\"3\" eventresult=\"1\" "
1098 "previousversion=\"1.0\" nextversion=\"2.0\" "
1099 "diffresult=\"0\" differrorcat=\"2\" "
1100 "differrorcode=\"14\" diffextracode1=\"305\" "
1101 "previousfp=\"1\" nextfp=\"f22\"/></o:app>")));
1102 1123
1103 content::URLLocalHostRequestPrepackagedInterceptor interceptor; 1124 get_interceptor_->SetResponse(
1125 GURL("http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_1.crx"),
1126 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1.crx"));
1127 // This intercept returns a different file than what is specified in the
1128 // update check response and requested in the download. The file that is
1129 // actually dowloaded contains a patching error, an therefore, an error
1130 // is injected at the time of patching.
1131 get_interceptor_->SetResponse(
1132 GURL("http://localhost/download/"
1133 "ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx"),
1134 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1to2_bad.crx"));
1135 get_interceptor_->SetResponse(
1136 GURL("http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_2.crx"),
1137 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_2.crx"));
1104 1138
1105 VersionedTestInstaller installer; 1139 VersionedTestInstaller installer;
1106 CrxComponent com; 1140 CrxComponent com;
1107 RegisterComponent(&com, kTestComponent_ihfo, Version("0.0"), &installer); 1141 RegisterComponent(&com, kTestComponent_ihfo, Version("0.0"), &installer);
1108 1142
1109 const GURL expected_update_url_0( 1143 test_configurator()->SetLoopCount(3);
1110 "http://localhost/upd?extra=foo"
1111 "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D0.0%26fp%3D%26uc");
1112 const GURL expected_update_url_1(
1113 "http://localhost/upd?extra=foo"
1114 "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D1.0%26fp%3D1%26uc");
1115 const GURL expected_update_url_2(
1116 "http://localhost/upd?extra=foo"
1117 "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D2.0%26fp%3Df22%26uc");
1118 const GURL expected_crx_url_1(
1119 "http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_1.crx");
1120 const GURL expected_crx_url_1_diff_2(
1121 "http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx");
1122 const GURL expected_crx_url_2(
1123 "http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_2.crx");
1124
1125 interceptor.SetResponse(expected_update_url_0,
1126 test_file("updatecheck_diff_reply_1.xml"));
1127 interceptor.SetResponse(expected_update_url_1,
1128 test_file("updatecheck_diff_reply_2.xml"));
1129 interceptor.SetResponse(expected_update_url_2,
1130 test_file("updatecheck_diff_reply_3.xml"));
1131 interceptor.SetResponse(expected_crx_url_1,
1132 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1.crx"));
1133 interceptor.SetResponse(
1134 expected_crx_url_1_diff_2,
1135 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1to2_bad.crx"));
1136 interceptor.SetResponse(expected_crx_url_2,
1137 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_2.crx"));
1138
1139 test_configurator()->SetLoopCount(2);
1140
1141 component_updater()->Start(); 1144 component_updater()->Start();
1142 RunThreads(); 1145 RunThreads();
1143 component_updater()->Stop(); 1146 component_updater()->Stop();
1144 // There may still be pings in the queue.
1145 RunThreadsUntilIdle();
1146 1147
1147 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); 1148 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error());
1148 EXPECT_EQ(2, static_cast<TestInstaller*>(com.installer)->install_count()); 1149 EXPECT_EQ(2, static_cast<TestInstaller*>(com.installer)->install_count());
1149 1150
1150 EXPECT_EQ(2, post_interceptor->GetHitCount()) 1151 EXPECT_EQ(5, post_interceptor_->GetHitCount())
1151 << post_interceptor->GetRequestsAsString(); 1152 << post_interceptor_->GetRequestsAsString();
1152 EXPECT_EQ(0, post_interceptor->GetMissCount()) 1153 EXPECT_EQ(5, post_interceptor_->GetCount())
1153 << post_interceptor->GetRequestsAsString(); 1154 << post_interceptor_->GetRequestsAsString();
1155 EXPECT_EQ(3, get_interceptor_->GetHitCount());
1154 1156
1155 EXPECT_EQ(5, interceptor.GetHitCount()); 1157 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[0].find(
1158 "<app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" version=\"0.0\">"
1159 "<updatecheck /></app>"))
1160 << post_interceptor_->GetRequestsAsString();
1161 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[1].find(
1162 "<app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" "
1163 "version=\"0.0\" nextversion=\"1.0\">"
1164 "<event eventtype=\"3\" eventresult=\"1\" nextfp=\"1\"/></app>"))
1165 << post_interceptor_->GetRequestsAsString();
1166 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[2].find(
1167 "<app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" version=\"1.0\">"
1168 "<updatecheck /><packages><package fp=\"1\"/></packages></app>"))
1169 << post_interceptor_->GetRequestsAsString();
1170 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[3].find(
1171 "<app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" "
1172 "version=\"1.0\" nextversion=\"2.0\">"
1173 "<event eventtype=\"3\" eventresult=\"1\" "
1174 "diffresult=\"0\" differrorcat=\"2\" "
1175 "differrorcode=\"14\" diffextracode1=\"305\" "
1176 "previousfp=\"1\" nextfp=\"22\"/></app>"))
1177 << post_interceptor_->GetRequestsAsString();
1178 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[4].find(
1179 "<app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" version=\"2.0\">"
1180 "<updatecheck /><packages><package fp=\"22\"/></packages></app>"))
1181 << post_interceptor_->GetRequestsAsString();
1156 } 1182 }
1157 1183
1158 } // namespace component_updater 1184 } // namespace component_updater
1159 1185
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698