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

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

Issue 56023005: First changelist of a series to migrate the component updater protocol (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed broken build due to DISALLOW_COPY_AND_ASSIGN. 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"
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 } 111 }
112 112
113 void TestConfigurator::SetComponentUpdateService(ComponentUpdateService* cus) { 113 void TestConfigurator::SetComponentUpdateService(ComponentUpdateService* cus) {
114 cus_ = cus; 114 cus_ = cus;
115 } 115 }
116 116
117 void TestConfigurator::SetQuitClosure(const base::Closure& quit_closure) { 117 void TestConfigurator::SetQuitClosure(const base::Closure& quit_closure) {
118 quit_closure_ = quit_closure; 118 quit_closure_ = quit_closure;
119 } 119 }
120 120
121 // Intercepts ping requests sent over http POST to localhost2.
122 class PingInterceptor : public URLRequestPostInterceptor {
123 public:
124 PingInterceptor() : URLRequestPostInterceptor("http", "localhost2") {}
125
126 private:
127 DISALLOW_COPY_AND_ASSIGN(PingInterceptor);
128 };
129
121 ComponentUpdaterTest::ComponentUpdaterTest() 130 ComponentUpdaterTest::ComponentUpdaterTest()
122 : test_config_(NULL), 131 : test_config_(NULL),
123 thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) { 132 thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) {
124 // The component updater instance under test. 133 // The component updater instance under test.
125 test_config_ = new TestConfigurator; 134 test_config_ = new TestConfigurator;
126 component_updater_.reset(ComponentUpdateServiceFactory(test_config_)); 135 component_updater_.reset(ComponentUpdateServiceFactory(test_config_));
127 test_config_->SetComponentUpdateService(component_updater_.get()); 136 test_config_->SetComponentUpdateService(component_updater_.get());
128 137
129 // The test directory is chrome/test/data/components. 138 // The test directory is chrome/test/data/components.
130 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_); 139 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 void ComponentUpdaterTest::RunThreads() { 186 void ComponentUpdaterTest::RunThreads() {
178 base::RunLoop runloop; 187 base::RunLoop runloop;
179 test_configurator()->SetQuitClosure(runloop.QuitClosure()); 188 test_configurator()->SetQuitClosure(runloop.QuitClosure());
180 runloop.Run(); 189 runloop.Run();
181 } 190 }
182 191
183 void ComponentUpdaterTest::RunThreadsUntilIdle() { 192 void ComponentUpdaterTest::RunThreadsUntilIdle() {
184 base::RunLoop().RunUntilIdle(); 193 base::RunLoop().RunUntilIdle();
185 } 194 }
186 195
187 PingChecker::PingChecker(const std::map<std::string, std::string>& attributes)
188 : num_hits_(0), num_misses_(0), attributes_(attributes) {
189 }
190
191 PingChecker::~PingChecker() {}
192
193 void PingChecker::Trial(net::URLRequest* request) {
194 if (Test(request))
195 ++num_hits_;
196 else
197 ++num_misses_;
198 }
199
200 bool PingChecker::Test(net::URLRequest* request) {
201 if (request->has_upload()) {
202 const net::UploadDataStream* stream = request->get_upload();
203 const net::UploadBytesElementReader* reader =
204 stream->element_readers()[0]->AsBytesReader();
205 int size = reader->length();
206 scoped_refptr <net::IOBuffer> buffer = new net::IOBuffer(size);
207 std::string data(reader->bytes());
208 pings_.push_back(data);
209 // For now, we assume that there is only one ping per POST.
210 std::string::size_type start = data.find("<o:event");
211 if (start != std::string::npos) {
212 std::string::size_type end = data.find(">", start);
213 if (end != std::string::npos) {
214 std::string ping = data.substr(start, end - start);
215 std::map<std::string, std::string>::const_iterator iter;
216 for (iter = attributes_.begin(); iter != attributes_.end(); ++iter) {
217 // does the ping contain the specified attribute/value?
218 if (ping.find(std::string(" ") + (iter->first) +
219 std::string("=") + (iter->second)) == string::npos) {
220 return false;
221 }
222 }
223 return true;
224 }
225 }
226 }
227 return false;
228 }
229
230 std::string PingChecker::GetPings() const {
231 std::string pings_str = "Pings are:";
232 int i = 0;
233 for (std::vector<std::string>::const_iterator it = pings_.begin();
234 it != pings_.end(); ++it) {
235 pings_str.append(base::StringPrintf("\n (%d): %s", ++i, it->c_str()));
236 }
237 return pings_str;
238 }
239
240 ComponentUpdateService::Status OnDemandTester::OnDemand( 196 ComponentUpdateService::Status OnDemandTester::OnDemand(
241 ComponentUpdateService* cus, const std::string& component_id) { 197 ComponentUpdateService* cus, const std::string& component_id) {
242 return cus->OnDemandUpdate(component_id); 198 return cus->OnDemandUpdate(component_id);
243 } 199 }
244 200
245 // Verify that our test fixture work and the component updater can 201 // Verify that our test fixture work and the component updater can
246 // be created and destroyed with no side effects. 202 // be created and destroyed with no side effects.
247 TEST_F(ComponentUpdaterTest, VerifyFixture) { 203 TEST_F(ComponentUpdaterTest, VerifyFixture) {
248 EXPECT_TRUE(component_updater() != NULL); 204 EXPECT_TRUE(component_updater() != NULL);
249 } 205 }
250 206
251 // Verify that the component updater can be caught in a quick 207 // Verify that the component updater can be caught in a quick
252 // start-shutdown situation. Failure of this test will be a crash. 208 // start-shutdown situation. Failure of this test will be a crash.
253 TEST_F(ComponentUpdaterTest, StartStop) { 209 TEST_F(ComponentUpdaterTest, StartStop) {
254 component_updater()->Start(); 210 component_updater()->Start();
255 RunThreadsUntilIdle(); 211 RunThreadsUntilIdle();
256 component_updater()->Stop(); 212 component_updater()->Stop();
257 } 213 }
258 214
259 // Verify that when the server has no updates, we go back to sleep and 215 // Verify that when the server has no updates, we go back to sleep and
260 // the COMPONENT_UPDATER_STARTED and COMPONENT_UPDATER_SLEEPING notifications 216 // the COMPONENT_UPDATER_STARTED and COMPONENT_UPDATER_SLEEPING notifications
261 // are generated. 217 // are generated. No pings are sent.
262 TEST_F(ComponentUpdaterTest, CheckCrxSleep) { 218 TEST_F(ComponentUpdaterTest, CheckCrxSleep) {
219 PingInterceptor ping_interceptor;
263 content::URLLocalHostRequestPrepackagedInterceptor interceptor; 220 content::URLLocalHostRequestPrepackagedInterceptor interceptor;
264 221
265 MockComponentObserver observer; 222 MockComponentObserver observer;
266 223
267 TestInstaller installer; 224 TestInstaller installer;
268 CrxComponent com; 225 CrxComponent com;
269 com.observer = &observer; 226 com.observer = &observer;
270 EXPECT_EQ(ComponentUpdateService::kOk, 227 EXPECT_EQ(ComponentUpdateService::kOk,
271 RegisterComponent(&com, 228 RegisterComponent(&com,
272 kTestComponent_abag, 229 kTestComponent_abag,
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 276
320 EXPECT_CALL(observer, 277 EXPECT_CALL(observer,
321 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) 278 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0))
322 .Times(2); 279 .Times(2);
323 EXPECT_CALL(observer, 280 EXPECT_CALL(observer,
324 OnEvent(ComponentObserver::COMPONENT_NOT_UPDATED, 0)) 281 OnEvent(ComponentObserver::COMPONENT_NOT_UPDATED, 0))
325 .Times(2); 282 .Times(2);
326 RunThreads(); 283 RunThreads();
327 284
328 EXPECT_EQ(4, interceptor.GetHitCount()); 285 EXPECT_EQ(4, interceptor.GetHitCount());
286 EXPECT_EQ(0, ping_interceptor.GetHitCount());
329 287
330 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); 288 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error());
331 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count()); 289 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count());
332 290
333 component_updater()->Stop(); 291 component_updater()->Stop();
334 } 292 }
335 293
336 // Verify that we can check for updates and install one component. Besides 294 // Verify that we can check for updates and install one component. Besides
337 // the notifications above COMPONENT_UPDATE_FOUND and COMPONENT_UPDATE_READY 295 // the notifications above COMPONENT_UPDATE_FOUND and COMPONENT_UPDATE_READY
338 // should have been fired. We do two loops so the second time around there 296 // should have been fired. We do two loops so the second time around there
339 // should be nothing left to do. 297 // should be nothing left to do.
340 // We also check that only 3 non-ping network requests are issued: 298 // We also check that only 3 non-ping network requests are issued:
341 // 1- manifest check 299 // 1- manifest check
342 // 2- download crx 300 // 2- download crx
343 // 3- second manifest check. 301 // 3- second manifest check.
344 TEST_F(ComponentUpdaterTest, InstallCrx) { 302 TEST_F(ComponentUpdaterTest, InstallCrx) {
345 std::map<std::string, std::string> map; 303 PingInterceptor ping_interceptor;
346 map.insert(std::pair<std::string, std::string>("eventtype", "\"3\""));
347 map.insert(std::pair<std::string, std::string>("eventresult", "\"1\""));
348 map.insert(std::pair<std::string, std::string>("previousversion",
349 "\"0.9\""));
350 map.insert(std::pair<std::string, std::string>("nextversion", "\"1.0\""));
351 PingChecker ping_checker(map);
352 URLRequestPostInterceptor post_interceptor(&ping_checker);
353 content::URLLocalHostRequestPrepackagedInterceptor interceptor; 304 content::URLLocalHostRequestPrepackagedInterceptor interceptor;
354 305
355 MockComponentObserver observer1; 306 MockComponentObserver observer1;
356 { 307 {
357 InSequence seq; 308 InSequence seq;
358 EXPECT_CALL(observer1, 309 EXPECT_CALL(observer1,
359 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) 310 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0))
360 .Times(1); 311 .Times(1);
361 EXPECT_CALL(observer1, 312 EXPECT_CALL(observer1,
362 OnEvent(ComponentObserver::COMPONENT_UPDATE_FOUND, 0)) 313 OnEvent(ComponentObserver::COMPONENT_UPDATE_FOUND, 0))
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 379
429 component_updater()->Start(); 380 component_updater()->Start();
430 RunThreads(); 381 RunThreads();
431 382
432 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error()); 383 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error());
433 EXPECT_EQ(1, static_cast<TestInstaller*>(com1.installer)->install_count()); 384 EXPECT_EQ(1, static_cast<TestInstaller*>(com1.installer)->install_count());
434 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error()); 385 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error());
435 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count()); 386 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count());
436 387
437 EXPECT_EQ(3, interceptor.GetHitCount()); 388 EXPECT_EQ(3, interceptor.GetHitCount());
438 EXPECT_EQ(1, ping_checker.NumHits()) << ping_checker.GetPings(); 389
439 EXPECT_EQ(0, ping_checker.NumMisses()) << ping_checker.GetPings(); 390 EXPECT_EQ(1, ping_interceptor.GetHitCount())
391 << ping_interceptor.GetRequestsAsString();
392 EXPECT_NE(string::npos, ping_interceptor.GetRequests()[0].find(
393 "<o:app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"1.0\">"
394 "<o:event eventtype=\"3\" eventresult=\"1\" "
395 "previousversion=\"0.9\" nextversion=\"1.0\"/></o:app>"));
waffles 2013/11/04 18:32:45 I notice you're not printing the pings if we fail
440 396
441 component_updater()->Stop(); 397 component_updater()->Stop();
442 } 398 }
443 399
444 // This test checks that the "prodversionmin" value is handled correctly. In 400 // This test checks that the "prodversionmin" value is handled correctly. In
445 // particular there should not be an install because the minimum product 401 // particular there should not be an install because the minimum product
446 // version is much higher than of chrome. 402 // version is much higher than of chrome.
447 TEST_F(ComponentUpdaterTest, ProdVersionCheck) { 403 TEST_F(ComponentUpdaterTest, ProdVersionCheck) {
448 std::map<std::string, std::string> map; 404 PingInterceptor ping_interceptor;
449 PingChecker ping_checker(map);
450 URLRequestPostInterceptor post_interceptor(&ping_checker);
451 content::URLLocalHostRequestPrepackagedInterceptor interceptor; 405 content::URLLocalHostRequestPrepackagedInterceptor interceptor;
452 406
453 TestInstaller installer; 407 TestInstaller installer;
454 CrxComponent com; 408 CrxComponent com;
455 RegisterComponent(&com, kTestComponent_jebg, Version("0.9"), &installer); 409 RegisterComponent(&com, kTestComponent_jebg, Version("0.9"), &installer);
456 410
457 const GURL expected_update_url( 411 const GURL expected_update_url(
458 "http://localhost/upd?extra=foo&x=id%3D" 412 "http://localhost/upd?extra=foo&x=id%3D"
459 "jebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26fp%3D%26uc"); 413 "jebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26fp%3D%26uc");
460 414
461 interceptor.SetResponse(expected_update_url, 415 interceptor.SetResponse(expected_update_url,
462 test_file("updatecheck_reply_2.xml")); 416 test_file("updatecheck_reply_2.xml"));
463 interceptor.SetResponse(GURL(expected_crx_url), 417 interceptor.SetResponse(GURL(expected_crx_url),
464 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx")); 418 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx"));
465 419
466 test_configurator()->SetLoopCount(1); 420 test_configurator()->SetLoopCount(1);
467 component_updater()->Start(); 421 component_updater()->Start();
468 RunThreads(); 422 RunThreads();
469 423
470 EXPECT_EQ(0, ping_checker.NumHits()) << ping_checker.GetPings(); 424 EXPECT_EQ(0, ping_interceptor.GetHitCount())
471 EXPECT_EQ(0, ping_checker.NumMisses()) << ping_checker.GetPings(); 425 << ping_interceptor.GetRequestsAsString();
472 EXPECT_EQ(1, interceptor.GetHitCount()); 426 EXPECT_EQ(1, interceptor.GetHitCount());
427
473 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); 428 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error());
474 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count()); 429 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count());
475 430
476 component_updater()->Stop(); 431 component_updater()->Stop();
477 } 432 }
478 433
479 // Test that a ping for an update check can cause installs. 434 // Test that a ping for an update check can cause installs.
480 // Here is the timeline: 435 // Here is the timeline:
481 // - First loop: we return a reply that indicates no update, so 436 // - First loop: we return a reply that indicates no update, so
482 // nothing happens. 437 // nothing happens.
483 // - We ping. 438 // - We ping.
484 // - This triggers a second loop, which has a reply that triggers an install. 439 // - This triggers a second loop, which has a reply that triggers an install.
485 TEST_F(ComponentUpdaterTest, OnDemandUpdate) { 440 TEST_F(ComponentUpdaterTest, OnDemandUpdate) {
486 std::map<std::string, std::string> map; 441 PingInterceptor ping_interceptor;
487 map.insert(std::pair<std::string, std::string>("eventtype", "\"3\""));
488 map.insert(std::pair<std::string, std::string>("eventresult", "\"1\""));
489 map.insert(std::pair<std::string, std::string>("previousversion",
490 "\"0.9\""));
491 map.insert(std::pair<std::string, std::string>("nextversion", "\"1.0\""));
492 PingChecker ping_checker(map);
493 URLRequestPostInterceptor post_interceptor(&ping_checker);
494 content::URLLocalHostRequestPrepackagedInterceptor interceptor; 442 content::URLLocalHostRequestPrepackagedInterceptor interceptor;
495 443
496 MockComponentObserver observer1; 444 MockComponentObserver observer1;
497 { 445 {
498 InSequence seq; 446 InSequence seq;
499 EXPECT_CALL(observer1, 447 EXPECT_CALL(observer1,
500 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) 448 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0))
501 .Times(1); 449 .Times(1);
502 EXPECT_CALL(observer1, 450 EXPECT_CALL(observer1,
503 OnEvent(ComponentObserver::COMPONENT_NOT_UPDATED, 0)) 451 OnEvent(ComponentObserver::COMPONENT_NOT_UPDATED, 0))
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
679 interceptor.SetResponse(expected_update_url_3, 627 interceptor.SetResponse(expected_update_url_3,
680 test_file("updatecheck_reply_1.xml")); 628 test_file("updatecheck_reply_1.xml"));
681 test_configurator()->SetLoopCount(1); 629 test_configurator()->SetLoopCount(1);
682 component_updater()->Start(); 630 component_updater()->Start();
683 EXPECT_EQ(ComponentUpdateService::kOk, 631 EXPECT_EQ(ComponentUpdateService::kOk,
684 OnDemandTester::OnDemand(component_updater(), 632 OnDemandTester::OnDemand(component_updater(),
685 GetCrxComponentID(com2))); 633 GetCrxComponentID(com2)));
686 634
687 RunThreads(); 635 RunThreads();
688 636
689 EXPECT_EQ(1, ping_checker.NumHits()) << ping_checker.GetPings(); 637 EXPECT_EQ(1, ping_interceptor.GetHitCount())
690 EXPECT_EQ(0, ping_checker.NumMisses()) << ping_checker.GetPings(); 638 << ping_interceptor.GetRequestsAsString();
639 EXPECT_NE(string::npos, ping_interceptor.GetRequests()[0].find(
640 "<o:app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"1.0\">"
641 "<o:event eventtype=\"3\" eventresult=\"1\" "
642 "previousversion=\"0.9\" nextversion=\"1.0\"/></o:app>"));
691 643
692 component_updater()->Stop(); 644 component_updater()->Stop();
693 } 645 }
694 646
695 // Verify that a previously registered component can get re-registered 647 // Verify that a previously registered component can get re-registered
696 // with a different version. 648 // with a different version.
697 TEST_F(ComponentUpdaterTest, CheckReRegistration) { 649 TEST_F(ComponentUpdaterTest, CheckReRegistration) {
698 std::map<std::string, std::string> map; 650 PingInterceptor ping_interceptor;
699 map.insert(std::pair<std::string, std::string>("eventtype", "\"3\""));
700 map.insert(std::pair<std::string, std::string>("eventresult", "\"1\""));
701 map.insert(std::pair<std::string, std::string>("previousversion",
702 "\"0.9\""));
703 map.insert(std::pair<std::string, std::string>("nextversion", "\"1.0\""));
704 PingChecker ping_checker(map);
705 URLRequestPostInterceptor post_interceptor(&ping_checker);
706 content::URLLocalHostRequestPrepackagedInterceptor interceptor; 651 content::URLLocalHostRequestPrepackagedInterceptor interceptor;
707 652
708 MockComponentObserver observer1; 653 MockComponentObserver observer1;
709 { 654 {
710 InSequence seq; 655 InSequence seq;
711 EXPECT_CALL(observer1, 656 EXPECT_CALL(observer1,
712 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) 657 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0))
713 .Times(1); 658 .Times(1);
714 EXPECT_CALL(observer1, 659 EXPECT_CALL(observer1,
715 OnEvent(ComponentObserver::COMPONENT_UPDATE_FOUND, 0)) 660 OnEvent(ComponentObserver::COMPONENT_UPDATE_FOUND, 0))
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 test_configurator()->SetLoopCount(2); 728 test_configurator()->SetLoopCount(2);
784 729
785 component_updater()->Start(); 730 component_updater()->Start();
786 RunThreads(); 731 RunThreads();
787 732
788 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error()); 733 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error());
789 EXPECT_EQ(1, static_cast<TestInstaller*>(com1.installer)->install_count()); 734 EXPECT_EQ(1, static_cast<TestInstaller*>(com1.installer)->install_count());
790 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error()); 735 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error());
791 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count()); 736 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count());
792 737
793 EXPECT_EQ(1, ping_checker.NumHits()) << ping_checker.GetPings(); 738 EXPECT_EQ(1, ping_interceptor.GetHitCount())
794 EXPECT_EQ(0, ping_checker.NumMisses()) << ping_checker.GetPings(); 739 << ping_interceptor.GetRequestsAsString();
740 EXPECT_NE(string::npos, ping_interceptor.GetRequests()[0].find(
741 "<o:app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"1.0\">"
742 "<o:event eventtype=\"3\" eventresult=\"1\" "
743 "previousversion=\"0.9\" nextversion=\"1.0\"/></o:app>"));
744
795 EXPECT_EQ(3, interceptor.GetHitCount()); 745 EXPECT_EQ(3, interceptor.GetHitCount());
796 746
797 component_updater()->Stop(); 747 component_updater()->Stop();
798 748
799 // Now re-register, pretending to be an even newer version (2.2) 749 // Now re-register, pretending to be an even newer version (2.2)
800 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&observer1)); 750 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&observer1));
801 { 751 {
802 InSequence seq; 752 InSequence seq;
803 EXPECT_CALL(observer1, 753 EXPECT_CALL(observer1,
804 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) 754 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0))
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
863 // nothing. 813 // nothing.
864 // We also check that exactly 5 non-ping network requests are issued: 814 // We also check that exactly 5 non-ping network requests are issued:
865 // 1- update check (response: v1 available) 815 // 1- update check (response: v1 available)
866 // 2- download crx (v1) 816 // 2- download crx (v1)
867 // 3- update check (response: v2 available) 817 // 3- update check (response: v2 available)
868 // 4- download differential crx (v1 to v2) 818 // 4- download differential crx (v1 to v2)
869 // 5- update check (response: no further update available) 819 // 5- update check (response: no further update available)
870 // There should be two pings, one for each update. The second will bear a 820 // There should be two pings, one for each update. The second will bear a
871 // diffresult=1, while the first will not. 821 // diffresult=1, while the first will not.
872 TEST_F(ComponentUpdaterTest, DifferentialUpdate) { 822 TEST_F(ComponentUpdaterTest, DifferentialUpdate) {
873 std::map<std::string, std::string> map; 823 PingInterceptor ping_interceptor;
874 map.insert(std::pair<std::string, std::string>("eventtype", "\"3\""));
875 map.insert(std::pair<std::string, std::string>("eventresult", "\"1\""));
876 map.insert(std::pair<std::string, std::string>("diffresult", "\"1\""));
877 PingChecker ping_checker(map);
878 URLRequestPostInterceptor post_interceptor(&ping_checker);
879 content::URLLocalHostRequestPrepackagedInterceptor interceptor; 824 content::URLLocalHostRequestPrepackagedInterceptor interceptor;
880 825
881 VersionedTestInstaller installer; 826 VersionedTestInstaller installer;
882 CrxComponent com; 827 CrxComponent com;
883 RegisterComponent(&com, kTestComponent_ihfo, Version("0.0"), &installer); 828 RegisterComponent(&com, kTestComponent_ihfo, Version("0.0"), &installer);
884 829
885 const GURL expected_update_url_0( 830 const GURL expected_update_url_0(
886 "http://localhost/upd?extra=foo" 831 "http://localhost/upd?extra=foo"
887 "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D0.0%26fp%3D%26uc"); 832 "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D0.0%26fp%3D%26uc");
888 const GURL expected_update_url_1( 833 const GURL expected_update_url_1(
(...skipping 21 matching lines...) Expand all
910 855
911 test_configurator()->SetLoopCount(3); 856 test_configurator()->SetLoopCount(3);
912 857
913 component_updater()->Start(); 858 component_updater()->Start();
914 RunThreads(); 859 RunThreads();
915 860
916 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); 861 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error());
917 EXPECT_EQ(2, static_cast<TestInstaller*>(com.installer)->install_count()); 862 EXPECT_EQ(2, static_cast<TestInstaller*>(com.installer)->install_count());
918 863
919 // One ping has the diffresult=1, the other does not. 864 // One ping has the diffresult=1, the other does not.
920 EXPECT_EQ(1, ping_checker.NumHits()) << ping_checker.GetPings(); 865 EXPECT_EQ(2, ping_interceptor.GetHitCount())
921 EXPECT_EQ(1, ping_checker.NumMisses()) << ping_checker.GetPings(); 866 << ping_interceptor.GetRequestsAsString();
867 EXPECT_NE(string::npos, ping_interceptor.GetRequests()[0].find(
868 "<o:app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" version=\"1.0\">"
869 "<o:event eventtype=\"3\" eventresult=\"1\" "
870 "previousversion=\"0.0\" nextversion=\"1.0\" nextfp=\"1\"/></o:app>"));
871 EXPECT_NE(string::npos, ping_interceptor.GetRequests()[1].find(
872 "<o:app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" version=\"2.0\">"
873 "<o:event eventtype=\"3\" eventresult=\"1\" "
874 "previousversion=\"1.0\" nextversion=\"2.0\" "
875 "diffresult=\"1\" previousfp=\"1\" nextfp=\"f22\"/></o:app>"));
922 876
923 EXPECT_EQ(5, interceptor.GetHitCount()); 877 EXPECT_EQ(5, interceptor.GetHitCount());
924 878
925 component_updater()->Stop(); 879 component_updater()->Stop();
926 } 880 }
927 881
928 // Verify that component installation falls back to downloading and installing 882 // Verify that component installation falls back to downloading and installing
929 // a full update if the differential update fails (in this case, because the 883 // a full update if the differential update fails (in this case, because the
930 // installer does not know about the existing files). We do two loops; the final 884 // installer does not know about the existing files). We do two loops; the final
931 // loop should do nothing. 885 // loop should do nothing.
932 // We also check that exactly 4 non-ping network requests are issued: 886 // We also check that exactly 4 non-ping network requests are issued:
933 // 1- update check (loop 1) 887 // 1- update check (loop 1)
934 // 2- download differential crx 888 // 2- download differential crx
935 // 3- download full crx 889 // 3- download full crx
936 // 4- update check (loop 2 - no update available) 890 // 4- update check (loop 2 - no update available)
937 // There should be one ping for the first attempted update. 891 // There should be one ping for the first attempted update.
938
939 TEST_F(ComponentUpdaterTest, DifferentialUpdateFails) { 892 TEST_F(ComponentUpdaterTest, DifferentialUpdateFails) {
940 std::map<std::string, std::string> map; 893 PingInterceptor ping_interceptor;
941 map.insert(std::pair<std::string, std::string>("eventtype", "\"3\""));
942 map.insert(std::pair<std::string, std::string>("eventresult", "\"1\""));
943 map.insert(std::pair<std::string, std::string>("diffresult", "\"0\""));
944 map.insert(std::pair<std::string, std::string>("differrorcode", "\"16\""));
945 PingChecker ping_checker(map);
946 URLRequestPostInterceptor post_interceptor(&ping_checker);
947 content::URLLocalHostRequestPrepackagedInterceptor interceptor; 894 content::URLLocalHostRequestPrepackagedInterceptor interceptor;
948 895
949 TestInstaller installer; 896 TestInstaller installer;
950 CrxComponent com; 897 CrxComponent com;
951 RegisterComponent(&com, kTestComponent_ihfo, Version("1.0"), &installer); 898 RegisterComponent(&com, kTestComponent_ihfo, Version("1.0"), &installer);
952 899
953 const GURL expected_update_url_1( 900 const GURL expected_update_url_1(
954 "http://localhost/upd?extra=foo" 901 "http://localhost/upd?extra=foo"
955 "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D1.0%26fp%3D%26uc"); 902 "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D1.0%26fp%3D%26uc");
956 const GURL expected_update_url_2( 903 const GURL expected_update_url_2(
(...skipping 20 matching lines...) Expand all
977 924
978 test_configurator()->SetLoopCount(2); 925 test_configurator()->SetLoopCount(2);
979 926
980 component_updater()->Start(); 927 component_updater()->Start();
981 RunThreads(); 928 RunThreads();
982 929
983 // A failed differential update does not count as a failed install. 930 // A failed differential update does not count as a failed install.
984 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); 931 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error());
985 EXPECT_EQ(1, static_cast<TestInstaller*>(com.installer)->install_count()); 932 EXPECT_EQ(1, static_cast<TestInstaller*>(com.installer)->install_count());
986 933
987 EXPECT_EQ(1, ping_checker.NumHits()) << ping_checker.GetPings(); 934 EXPECT_EQ(1, ping_interceptor.GetHitCount())
988 EXPECT_EQ(0, ping_checker.NumMisses()) << ping_checker.GetPings(); 935 << ping_interceptor.GetRequestsAsString();
936 EXPECT_NE(string::npos, ping_interceptor.GetRequests()[0].find(
937 "<o:app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" version=\"2.0\">"
938 "<o:event eventtype=\"3\" eventresult=\"1\" "
939 "previousversion=\"1.0\" nextversion=\"2.0\" "
940 "diffresult=\"0\" differrorcat=\"2\" differrorcode=\"16\" "
941 "nextfp=\"f22\"/></o:app>"));
942
989 EXPECT_EQ(4, interceptor.GetHitCount()); 943 EXPECT_EQ(4, interceptor.GetHitCount());
990 944
991 component_updater()->Stop(); 945 component_updater()->Stop();
992 } 946 }
993 947
994 // Verify that a failed installation causes an install failure ping. 948 // Verify that a failed installation causes an install failure ping.
995 TEST_F(ComponentUpdaterTest, CheckFailedInstallPing) { 949 TEST_F(ComponentUpdaterTest, CheckFailedInstallPing) {
996 std::map<std::string, std::string> map; 950 PingInterceptor ping_interceptor;
997 map.insert(std::pair<std::string, std::string>("eventtype", "\"3\""));
998 map.insert(std::pair<std::string, std::string>("eventresult", "\"0\""));
999 map.insert(std::pair<std::string, std::string>("errorcode", "\"9\""));
1000 map.insert(std::pair<std::string, std::string>("previousversion",
1001 "\"0.9\""));
1002 map.insert(std::pair<std::string, std::string>("nextversion", "\"1.0\""));
1003 PingChecker ping_checker(map);
1004 URLRequestPostInterceptor post_interceptor(&ping_checker);
1005 content::URLLocalHostRequestPrepackagedInterceptor interceptor; 951 content::URLLocalHostRequestPrepackagedInterceptor interceptor;
1006 952
1007 // This test installer reports installation failure. 953 // This test installer reports installation failure.
1008 class : public TestInstaller { 954 class : public TestInstaller {
1009 virtual bool Install(const base::DictionaryValue& manifest, 955 virtual bool Install(const base::DictionaryValue& manifest,
1010 const base::FilePath& unpack_path) OVERRIDE { 956 const base::FilePath& unpack_path) OVERRIDE {
1011 ++install_count_; 957 ++install_count_;
1012 base::DeleteFile(unpack_path, true); 958 base::DeleteFile(unpack_path, true);
1013 return false; 959 return false;
1014 } 960 }
(...skipping 23 matching lines...) Expand all
1038 // iteration. 984 // iteration.
1039 interceptor.SetResponse(expected_update_url_1, 985 interceptor.SetResponse(expected_update_url_1,
1040 test_file("updatecheck_reply_noupdate.xml")); 986 test_file("updatecheck_reply_noupdate.xml"));
1041 test_configurator()->SetLoopCount(1); 987 test_configurator()->SetLoopCount(1);
1042 component_updater()->Start(); 988 component_updater()->Start();
1043 RunThreads(); 989 RunThreads();
1044 990
1045 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); 991 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error());
1046 EXPECT_EQ(2, static_cast<TestInstaller*>(com.installer)->install_count()); 992 EXPECT_EQ(2, static_cast<TestInstaller*>(com.installer)->install_count());
1047 993
1048 EXPECT_EQ(2, ping_checker.NumHits()) << ping_checker.GetPings(); 994 EXPECT_EQ(2, ping_interceptor.GetHitCount())
1049 EXPECT_EQ(0, ping_checker.NumMisses()) << ping_checker.GetPings(); 995 << ping_interceptor.GetRequestsAsString();
996 EXPECT_NE(string::npos, ping_interceptor.GetRequests()[0].find(
997 "<o:app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"0.9\">"
998 "<o:event eventtype=\"3\" eventresult=\"0\" "
999 "previousversion=\"0.9\" nextversion=\"1.0\" "
1000 "errorcat=\"3\" errorcode=\"9\"/></o:app>"));
1001 EXPECT_NE(string::npos, ping_interceptor.GetRequests()[1].find(
1002 "<o:app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"0.9\">"
1003 "<o:event eventtype=\"3\" eventresult=\"0\" "
1004 "previousversion=\"0.9\" nextversion=\"1.0\" "
1005 "errorcat=\"3\" errorcode=\"9\"/></o:app>"));
1006
1050 EXPECT_EQ(5, interceptor.GetHitCount()); 1007 EXPECT_EQ(5, interceptor.GetHitCount());
1051 1008
1052 component_updater()->Stop(); 1009 component_updater()->Stop();
1053 } 1010 }
1054 1011
1055 // Verify that we successfully propagate a patcher error. 1012 // Verify that we successfully propagate a patcher error.
1056 // ihfokbkgjpifnbbojhneepfflplebdkc_1to2_bad.crx contains an incorrect 1013 // ihfokbkgjpifnbbojhneepfflplebdkc_1to2_bad.crx contains an incorrect
1057 // patching instruction that should fail. 1014 // patching instruction that should fail.
1058 TEST_F(ComponentUpdaterTest, DifferentialUpdateFailErrorcode) { 1015 TEST_F(ComponentUpdaterTest, DifferentialUpdateFailErrorcode) {
1059 std::map<std::string, std::string> map; 1016 PingInterceptor ping_interceptor;
1060 map.insert(std::pair<std::string, std::string>("eventtype", "\"3\""));
1061 map.insert(std::pair<std::string, std::string>("eventresult", "\"1\""));
1062 map.insert(std::pair<std::string, std::string>("diffresult", "\"0\""));
1063 map.insert(std::pair<std::string, std::string>("differrorcode", "\"14\""));
1064 map.insert(std::pair<std::string, std::string>("diffextracode1", "\"305\""));
1065 PingChecker ping_checker(map);
1066 URLRequestPostInterceptor post_interceptor(&ping_checker);
1067 content::URLLocalHostRequestPrepackagedInterceptor interceptor; 1017 content::URLLocalHostRequestPrepackagedInterceptor interceptor;
1068 1018
1069 VersionedTestInstaller installer; 1019 VersionedTestInstaller installer;
1070 CrxComponent com; 1020 CrxComponent com;
1071 RegisterComponent(&com, kTestComponent_ihfo, Version("0.0"), &installer); 1021 RegisterComponent(&com, kTestComponent_ihfo, Version("0.0"), &installer);
1072 1022
1073 const GURL expected_update_url_0( 1023 const GURL expected_update_url_0(
1074 "http://localhost/upd?extra=foo" 1024 "http://localhost/upd?extra=foo"
1075 "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D0.0%26fp%3D%26uc"); 1025 "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D0.0%26fp%3D%26uc");
1076 const GURL expected_update_url_1( 1026 const GURL expected_update_url_1(
(...skipping 27 matching lines...) Expand all
1104 1054
1105 component_updater()->Start(); 1055 component_updater()->Start();
1106 RunThreads(); 1056 RunThreads();
1107 component_updater()->Stop(); 1057 component_updater()->Stop();
1108 // There may still be pings in the queue. 1058 // There may still be pings in the queue.
1109 RunThreadsUntilIdle(); 1059 RunThreadsUntilIdle();
1110 1060
1111 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); 1061 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error());
1112 EXPECT_EQ(2, static_cast<TestInstaller*>(com.installer)->install_count()); 1062 EXPECT_EQ(2, static_cast<TestInstaller*>(com.installer)->install_count());
1113 1063
1114 EXPECT_EQ(1, ping_checker.NumHits()) << ping_checker.GetPings(); 1064 EXPECT_EQ(2, ping_interceptor.GetHitCount())
1115 EXPECT_EQ(1, ping_checker.NumMisses()) << ping_checker.GetPings(); 1065 << ping_interceptor.GetRequestsAsString();
1066 EXPECT_NE(string::npos, ping_interceptor.GetRequests()[0].find(
1067 "<o:app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" version=\"1.0\">"
1068 "<o:event eventtype=\"3\" eventresult=\"1\" "
1069 "previousversion=\"0.0\" nextversion=\"1.0\" nextfp=\"1\"/></o:app>"));
1070 EXPECT_NE(string::npos, ping_interceptor.GetRequests()[1].find(
1071 "<o:app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" version=\"2.0\">"
1072 "<o:event eventtype=\"3\" eventresult=\"1\" "
1073 "previousversion=\"1.0\" nextversion=\"2.0\" "
1074 "diffresult=\"0\" differrorcat=\"2\" "
1075 "differrorcode=\"14\" diffextracode1=\"305\" "
1076 "previousfp=\"1\" nextfp=\"f22\"/></o:app>"));
1077
1116 EXPECT_EQ(5, interceptor.GetHitCount()); 1078 EXPECT_EQ(5, interceptor.GetHitCount());
1117 } 1079 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698