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

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

Issue 897873002: Make ComponentInstaller refcounted. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@2015_01_19_component_installer
Patch Set: fix Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 } 109 }
110 110
111 TestConfigurator* ComponentUpdaterTest::test_configurator() { 111 TestConfigurator* ComponentUpdaterTest::test_configurator() {
112 return test_config_; 112 return test_config_;
113 } 113 }
114 114
115 ComponentUpdateService::Status ComponentUpdaterTest::RegisterComponent( 115 ComponentUpdateService::Status ComponentUpdaterTest::RegisterComponent(
116 CrxComponent* com, 116 CrxComponent* com,
117 TestComponents component, 117 TestComponents component,
118 const Version& version, 118 const Version& version,
119 TestInstaller* installer) { 119 const scoped_refptr<TestInstaller>& installer) {
120 if (component == kTestComponent_abag) { 120 switch (component) {
121 com->name = "test_abag"; 121 case kTestComponent_abag: {
122 com->pk_hash.assign(abag_hash, abag_hash + arraysize(abag_hash)); 122 com->name = "test_abag";
123 } else if (component == kTestComponent_jebg) { 123 com->pk_hash.assign(abag_hash, abag_hash + arraysize(abag_hash));
124 com->name = "test_jebg"; 124 break;
125 com->pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash)); 125 }
126 } else { 126 case kTestComponent_jebg: {
127 com->name = "test_ihfo"; 127 com->name = "test_jebg";
128 com->pk_hash.assign(ihfo_hash, ihfo_hash + arraysize(ihfo_hash)); 128 com->pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash));
129 break;
130 }
131 case kTestComponent_ihfo: {
132 com->name = "test_ihfo";
133 com->pk_hash.assign(ihfo_hash, ihfo_hash + arraysize(ihfo_hash));
134 break;
135 }
129 } 136 }
130 com->version = version; 137 com->version = version;
131 com->installer = installer; 138 com->installer = installer;
132 return component_updater_->RegisterComponent(*com); 139 return component_updater_->RegisterComponent(*com);
133 } 140 }
134 141
135 void ComponentUpdaterTest::RunThreads() { 142 void ComponentUpdaterTest::RunThreads() {
136 base::RunLoop runloop; 143 base::RunLoop runloop;
137 test_configurator()->SetQuitClosure(runloop.QuitClosure()); 144 test_configurator()->SetQuitClosure(runloop.QuitClosure());
138 runloop.Run(); 145 runloop.Run();
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 EXPECT_CALL(observer, 190 EXPECT_CALL(observer,
184 OnEvent(ServiceObserver::COMPONENT_NOT_UPDATED, 191 OnEvent(ServiceObserver::COMPONENT_NOT_UPDATED,
185 "abagagagagagagagagagagagagagagag")) 192 "abagagagagagagagagagagagagagagag"))
186 .Times(2); 193 .Times(2);
187 194
188 EXPECT_TRUE(post_interceptor_->ExpectRequest( 195 EXPECT_TRUE(post_interceptor_->ExpectRequest(
189 new PartialMatch("updatecheck"), test_file("updatecheck_reply_1.xml"))); 196 new PartialMatch("updatecheck"), test_file("updatecheck_reply_1.xml")));
190 EXPECT_TRUE(post_interceptor_->ExpectRequest( 197 EXPECT_TRUE(post_interceptor_->ExpectRequest(
191 new PartialMatch("updatecheck"), test_file("updatecheck_reply_1.xml"))); 198 new PartialMatch("updatecheck"), test_file("updatecheck_reply_1.xml")));
192 199
193 TestInstaller installer; 200 scoped_refptr<TestInstaller> installer(new TestInstaller);
194 CrxComponent com; 201 CrxComponent com;
195 component_updater()->AddObserver(&observer); 202 component_updater()->AddObserver(&observer);
196 EXPECT_EQ( 203 EXPECT_EQ(
197 ComponentUpdateService::kOk, 204 ComponentUpdateService::kOk,
198 RegisterComponent(&com, kTestComponent_abag, Version("1.1"), &installer)); 205 RegisterComponent(&com, kTestComponent_abag, Version("1.1"), installer));
199 206
200 // We loop twice, but there are no updates so we expect two sleep messages. 207 // We loop twice, but there are no updates so we expect two sleep messages.
201 test_configurator()->SetLoopCount(2); 208 test_configurator()->SetLoopCount(2);
202 component_updater()->Start(); 209 component_updater()->Start();
203 RunThreads(); 210 RunThreads();
204 211
205 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); 212 EXPECT_EQ(0, installer->error());
206 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count()); 213 EXPECT_EQ(0, installer->install_count());
207 214
208 // Expect to see the two update check requests and no other requests, 215 // Expect to see the two update check requests and no other requests,
209 // including pings. 216 // including pings.
210 EXPECT_EQ(2, post_interceptor_->GetHitCount()) 217 EXPECT_EQ(2, post_interceptor_->GetHitCount())
211 << post_interceptor_->GetRequestsAsString(); 218 << post_interceptor_->GetRequestsAsString();
212 EXPECT_EQ(2, post_interceptor_->GetCount()) 219 EXPECT_EQ(2, post_interceptor_->GetCount())
213 << post_interceptor_->GetRequestsAsString(); 220 << post_interceptor_->GetRequestsAsString();
214 EXPECT_NE( 221 EXPECT_NE(
215 string::npos, 222 string::npos,
216 post_interceptor_->GetRequests()[0].find( 223 post_interceptor_->GetRequests()[0].find(
(...skipping 24 matching lines...) Expand all
241 post_interceptor_->Reset(); 248 post_interceptor_->Reset();
242 EXPECT_TRUE(post_interceptor_->ExpectRequest( 249 EXPECT_TRUE(post_interceptor_->ExpectRequest(
243 new PartialMatch("updatecheck"), test_file("updatecheck_reply_empty"))); 250 new PartialMatch("updatecheck"), test_file("updatecheck_reply_empty")));
244 EXPECT_TRUE(post_interceptor_->ExpectRequest( 251 EXPECT_TRUE(post_interceptor_->ExpectRequest(
245 new PartialMatch("updatecheck"), test_file("updatecheck_reply_empty"))); 252 new PartialMatch("updatecheck"), test_file("updatecheck_reply_empty")));
246 253
247 test_configurator()->SetLoopCount(2); 254 test_configurator()->SetLoopCount(2);
248 component_updater()->Start(); 255 component_updater()->Start();
249 RunThreads(); 256 RunThreads();
250 257
251 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); 258 EXPECT_EQ(0, installer->error());
252 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count()); 259 EXPECT_EQ(0, installer->install_count());
253 260
254 EXPECT_EQ(2, post_interceptor_->GetHitCount()) 261 EXPECT_EQ(2, post_interceptor_->GetHitCount())
255 << post_interceptor_->GetRequestsAsString(); 262 << post_interceptor_->GetRequestsAsString();
256 EXPECT_EQ(2, post_interceptor_->GetCount()) 263 EXPECT_EQ(2, post_interceptor_->GetCount())
257 << post_interceptor_->GetRequestsAsString(); 264 << post_interceptor_->GetRequestsAsString();
258 EXPECT_NE( 265 EXPECT_NE(
259 string::npos, 266 string::npos,
260 post_interceptor_->GetRequests()[0].find( 267 post_interceptor_->GetRequests()[0].find(
261 "<app appid=\"abagagagagagagagagagagagagagagag\" version=\"1.1\">" 268 "<app appid=\"abagagagagagagagagagagagagagagag\" version=\"1.1\">"
262 "<updatecheck /></app>")) 269 "<updatecheck /></app>"))
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch("event"))); 335 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch("event")));
329 EXPECT_TRUE(post_interceptor_->ExpectRequest( 336 EXPECT_TRUE(post_interceptor_->ExpectRequest(
330 new PartialMatch("updatecheck"), test_file("updatecheck_reply_1.xml"))); 337 new PartialMatch("updatecheck"), test_file("updatecheck_reply_1.xml")));
331 338
332 get_interceptor_->SetResponse( 339 get_interceptor_->SetResponse(
333 GURL(expected_crx_url), 340 GURL(expected_crx_url),
334 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx")); 341 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx"));
335 342
336 component_updater()->AddObserver(&observer); 343 component_updater()->AddObserver(&observer);
337 344
338 TestInstaller installer1; 345 scoped_refptr<TestInstaller> installer1(new TestInstaller);
339 CrxComponent com1; 346 CrxComponent com1;
340 RegisterComponent(&com1, kTestComponent_jebg, Version("0.9"), &installer1); 347 RegisterComponent(&com1, kTestComponent_jebg, Version("0.9"), installer1);
341 TestInstaller installer2; 348 scoped_refptr<TestInstaller> installer2(new TestInstaller);
342 CrxComponent com2; 349 CrxComponent com2;
343 RegisterComponent(&com2, kTestComponent_abag, Version("2.2"), &installer2); 350 RegisterComponent(&com2, kTestComponent_abag, Version("2.2"), installer2);
344 351
345 test_configurator()->SetLoopCount(2); 352 test_configurator()->SetLoopCount(2);
346 component_updater()->Start(); 353 component_updater()->Start();
347 RunThreads(); 354 RunThreads();
348 355
349 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error()); 356 EXPECT_EQ(0, installer1->error());
350 EXPECT_EQ(1, static_cast<TestInstaller*>(com1.installer)->install_count()); 357 EXPECT_EQ(1, installer1->install_count());
351 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error()); 358 EXPECT_EQ(0, installer2->error());
352 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count()); 359 EXPECT_EQ(0, installer2->install_count());
353 360
354 // Expect three request in total: two update checks and one ping. 361 // Expect three request in total: two update checks and one ping.
355 EXPECT_EQ(3, post_interceptor_->GetHitCount()) 362 EXPECT_EQ(3, post_interceptor_->GetHitCount())
356 << post_interceptor_->GetRequestsAsString(); 363 << post_interceptor_->GetRequestsAsString();
357 EXPECT_EQ(3, post_interceptor_->GetCount()) 364 EXPECT_EQ(3, post_interceptor_->GetCount())
358 << post_interceptor_->GetRequestsAsString(); 365 << post_interceptor_->GetRequestsAsString();
359 366
360 // Expect one component download. 367 // Expect one component download.
361 EXPECT_EQ(1, get_interceptor_->GetHitCount()); 368 EXPECT_EQ(1, get_interceptor_->GetHitCount());
362 369
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 // particular there should not be an install because the minimum product 440 // particular there should not be an install because the minimum product
434 // version is much higher than of chrome. 441 // version is much higher than of chrome.
435 TEST_F(ComponentUpdaterTest, ProdVersionCheck) { 442 TEST_F(ComponentUpdaterTest, ProdVersionCheck) {
436 EXPECT_TRUE(post_interceptor_->ExpectRequest( 443 EXPECT_TRUE(post_interceptor_->ExpectRequest(
437 new PartialMatch("updatecheck"), test_file("updatecheck_reply_2.xml"))); 444 new PartialMatch("updatecheck"), test_file("updatecheck_reply_2.xml")));
438 445
439 get_interceptor_->SetResponse( 446 get_interceptor_->SetResponse(
440 GURL(expected_crx_url), 447 GURL(expected_crx_url),
441 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx")); 448 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx"));
442 449
443 TestInstaller installer; 450 scoped_refptr<TestInstaller> installer(new TestInstaller);
444 CrxComponent com; 451 CrxComponent com;
445 RegisterComponent(&com, kTestComponent_jebg, Version("0.9"), &installer); 452 RegisterComponent(&com, kTestComponent_jebg, Version("0.9"), installer);
446 453
447 test_configurator()->SetLoopCount(1); 454 test_configurator()->SetLoopCount(1);
448 component_updater()->Start(); 455 component_updater()->Start();
449 RunThreads(); 456 RunThreads();
450 457
451 // Expect one update check and no ping. 458 // Expect one update check and no ping.
452 EXPECT_EQ(1, post_interceptor_->GetHitCount()) 459 EXPECT_EQ(1, post_interceptor_->GetHitCount())
453 << post_interceptor_->GetRequestsAsString(); 460 << post_interceptor_->GetRequestsAsString();
454 EXPECT_EQ(1, post_interceptor_->GetCount()) 461 EXPECT_EQ(1, post_interceptor_->GetCount())
455 << post_interceptor_->GetRequestsAsString(); 462 << post_interceptor_->GetRequestsAsString();
456 463
457 // Expect no download to occur. 464 // Expect no download to occur.
458 EXPECT_EQ(0, get_interceptor_->GetHitCount()); 465 EXPECT_EQ(0, get_interceptor_->GetHitCount());
459 466
460 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); 467 EXPECT_EQ(0, installer->error());
461 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count()); 468 EXPECT_EQ(0, installer->install_count());
462 469
463 component_updater()->Stop(); 470 component_updater()->Stop();
464 } 471 }
465 472
466 // Test that a update check due to an on demand call can cause installs. 473 // Test that a update check due to an on demand call can cause installs.
467 // Here is the timeline: 474 // Here is the timeline:
468 // - First loop: we return a reply that indicates no update, so 475 // - First loop: we return a reply that indicates no update, so
469 // nothing happens. 476 // nothing happens.
470 // - We make an on demand call. 477 // - We make an on demand call.
471 // - This triggers a second loop, which has a reply that triggers an install. 478 // - This triggers a second loop, which has a reply that triggers an install.
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 530
524 EXPECT_TRUE(post_interceptor_->ExpectRequest( 531 EXPECT_TRUE(post_interceptor_->ExpectRequest(
525 new PartialMatch("updatecheck"), test_file("updatecheck_reply_empty"))); 532 new PartialMatch("updatecheck"), test_file("updatecheck_reply_empty")));
526 533
527 get_interceptor_->SetResponse( 534 get_interceptor_->SetResponse(
528 GURL(expected_crx_url), 535 GURL(expected_crx_url),
529 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx")); 536 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx"));
530 537
531 component_updater()->AddObserver(&observer); 538 component_updater()->AddObserver(&observer);
532 539
533 TestInstaller installer1; 540 scoped_refptr<TestInstaller> installer1(new TestInstaller);
534 CrxComponent com1; 541 CrxComponent com1;
535 RegisterComponent(&com1, kTestComponent_abag, Version("2.2"), &installer1); 542 RegisterComponent(&com1, kTestComponent_abag, Version("2.2"), installer1);
536 TestInstaller installer2; 543 scoped_refptr<TestInstaller> installer2(new TestInstaller);
537 CrxComponent com2; 544 CrxComponent com2;
538 RegisterComponent(&com2, kTestComponent_jebg, Version("0.9"), &installer2); 545 RegisterComponent(&com2, kTestComponent_jebg, Version("0.9"), installer2);
539 546
540 // No update normally. 547 // No update normally.
541 test_configurator()->SetLoopCount(1); 548 test_configurator()->SetLoopCount(1);
542 component_updater()->Start(); 549 component_updater()->Start();
543 RunThreads(); 550 RunThreads();
544 component_updater()->Stop(); 551 component_updater()->Stop();
545 552
546 EXPECT_EQ(1, post_interceptor_->GetHitCount()) 553 EXPECT_EQ(1, post_interceptor_->GetHitCount())
547 << post_interceptor_->GetRequestsAsString(); 554 << post_interceptor_->GetRequestsAsString();
548 EXPECT_EQ(1, post_interceptor_->GetCount()) 555 EXPECT_EQ(1, post_interceptor_->GetCount())
549 << post_interceptor_->GetRequestsAsString(); 556 << post_interceptor_->GetRequestsAsString();
550 557
551 EXPECT_EQ(0, get_interceptor_->GetHitCount()); 558 EXPECT_EQ(0, get_interceptor_->GetHitCount());
552 559
553 // Update after an on-demand check is issued. 560 // Update after an on-demand check is issued.
554 post_interceptor_->Reset(); 561 post_interceptor_->Reset();
555 EXPECT_TRUE(post_interceptor_->ExpectRequest( 562 EXPECT_TRUE(post_interceptor_->ExpectRequest(
556 new PartialMatch("updatecheck"), test_file("updatecheck_reply_1.xml"))); 563 new PartialMatch("updatecheck"), test_file("updatecheck_reply_1.xml")));
557 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch("event"))); 564 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch("event")));
558 565
559 EXPECT_EQ( 566 EXPECT_EQ(
560 ComponentUpdateService::kOk, 567 ComponentUpdateService::kOk,
561 OnDemandTester::OnDemand(component_updater(), GetCrxComponentID(com2))); 568 OnDemandTester::OnDemand(component_updater(), GetCrxComponentID(com2)));
562 test_configurator()->SetLoopCount(1); 569 test_configurator()->SetLoopCount(1);
563 component_updater()->Start(); 570 component_updater()->Start();
564 RunThreads(); 571 RunThreads();
565 572
566 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error()); 573 EXPECT_EQ(0, installer1->error());
567 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->install_count()); 574 EXPECT_EQ(0, installer1->install_count());
568 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error()); 575 EXPECT_EQ(0, installer2->error());
569 EXPECT_EQ(1, static_cast<TestInstaller*>(com2.installer)->install_count()); 576 EXPECT_EQ(1, installer2->install_count());
570 577
571 EXPECT_EQ(2, post_interceptor_->GetHitCount()) 578 EXPECT_EQ(2, post_interceptor_->GetHitCount())
572 << post_interceptor_->GetRequestsAsString(); 579 << post_interceptor_->GetRequestsAsString();
573 EXPECT_EQ(2, post_interceptor_->GetCount()) 580 EXPECT_EQ(2, post_interceptor_->GetCount())
574 << post_interceptor_->GetRequestsAsString(); 581 << post_interceptor_->GetRequestsAsString();
575 582
576 EXPECT_EQ(1, get_interceptor_->GetHitCount()); 583 EXPECT_EQ(1, get_interceptor_->GetHitCount());
577 584
578 // Expect the update check to contain an "ondemand" request for the 585 // Expect the update check to contain an "ondemand" request for the
579 // second component (com2) and a normal request for the other component. 586 // second component (com2) and a normal request for the other component.
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
735 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch("event"))); 742 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch("event")));
736 EXPECT_TRUE(post_interceptor_->ExpectRequest( 743 EXPECT_TRUE(post_interceptor_->ExpectRequest(
737 new PartialMatch("updatecheck"), test_file("updatecheck_reply_1.xml"))); 744 new PartialMatch("updatecheck"), test_file("updatecheck_reply_1.xml")));
738 745
739 get_interceptor_->SetResponse( 746 get_interceptor_->SetResponse(
740 GURL(expected_crx_url), 747 GURL(expected_crx_url),
741 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx")); 748 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx"));
742 749
743 component_updater()->AddObserver(&observer); 750 component_updater()->AddObserver(&observer);
744 751
745 TestInstaller installer1; 752 scoped_refptr<TestInstaller> installer1(new TestInstaller);
746 CrxComponent com1; 753 CrxComponent com1;
747 RegisterComponent(&com1, kTestComponent_jebg, Version("0.9"), &installer1); 754 RegisterComponent(&com1, kTestComponent_jebg, Version("0.9"), installer1);
748 TestInstaller installer2; 755 scoped_refptr<TestInstaller> installer2(new TestInstaller);
749 CrxComponent com2; 756 CrxComponent com2;
750 RegisterComponent(&com2, kTestComponent_abag, Version("2.2"), &installer2); 757 RegisterComponent(&com2, kTestComponent_abag, Version("2.2"), installer2);
751 758
752 // Loop twice to issue two checks: (1) with original 0.9 version, update to 759 // Loop twice to issue two checks: (1) with original 0.9 version, update to
753 // 1.0, and do the second check (2) with the updated 1.0 version. 760 // 1.0, and do the second check (2) with the updated 1.0 version.
754 test_configurator()->SetLoopCount(2); 761 test_configurator()->SetLoopCount(2);
755 component_updater()->Start(); 762 component_updater()->Start();
756 RunThreads(); 763 RunThreads();
757 764
758 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error()); 765 EXPECT_EQ(0, installer1->error());
759 EXPECT_EQ(1, static_cast<TestInstaller*>(com1.installer)->install_count()); 766 EXPECT_EQ(1, installer1->install_count());
760 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error()); 767 EXPECT_EQ(0, installer2->error());
761 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count()); 768 EXPECT_EQ(0, installer2->install_count());
762 769
763 EXPECT_EQ(3, post_interceptor_->GetHitCount()) 770 EXPECT_EQ(3, post_interceptor_->GetHitCount())
764 << post_interceptor_->GetRequestsAsString(); 771 << post_interceptor_->GetRequestsAsString();
765 EXPECT_EQ(1, get_interceptor_->GetHitCount()); 772 EXPECT_EQ(1, get_interceptor_->GetHitCount());
766 773
767 EXPECT_NE( 774 EXPECT_NE(
768 string::npos, 775 string::npos,
769 post_interceptor_->GetRequests()[0].find( 776 post_interceptor_->GetRequests()[0].find(
770 "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"0.9\">" 777 "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"0.9\">"
771 "<updatecheck /></app>")) 778 "<updatecheck /></app>"))
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
803 .Times(1); 810 .Times(1);
804 EXPECT_CALL(observer, 811 EXPECT_CALL(observer,
805 OnEvent(ServiceObserver::COMPONENT_UPDATER_SLEEPING, "")) 812 OnEvent(ServiceObserver::COMPONENT_UPDATER_SLEEPING, ""))
806 .Times(1); 813 .Times(1);
807 } 814 }
808 815
809 post_interceptor_->Reset(); 816 post_interceptor_->Reset();
810 EXPECT_TRUE(post_interceptor_->ExpectRequest( 817 EXPECT_TRUE(post_interceptor_->ExpectRequest(
811 new PartialMatch("updatecheck"), test_file("updatecheck_reply_1.xml"))); 818 new PartialMatch("updatecheck"), test_file("updatecheck_reply_1.xml")));
812 819
813 TestInstaller installer3; 820 scoped_refptr<TestInstaller> installer3(new TestInstaller);
814 EXPECT_EQ(ComponentUpdateService::kReplaced, 821 EXPECT_EQ(ComponentUpdateService::kReplaced,
815 RegisterComponent( 822 RegisterComponent(&com1, kTestComponent_jebg, Version("2.2"),
816 &com1, kTestComponent_jebg, Version("2.2"), &installer3)); 823 installer3));
817 824
818 // Loop once just to notice the check happening with the re-register version. 825 // Loop once just to notice the check happening with the re-register version.
819 test_configurator()->SetLoopCount(1); 826 test_configurator()->SetLoopCount(1);
820 component_updater()->Start(); 827 component_updater()->Start();
821 RunThreads(); 828 RunThreads();
822 829
823 // We created a new installer, so the counts go back to 0. 830 // We created a new installer, so the counts go back to 0.
824 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error()); 831 EXPECT_EQ(0, installer3->error());
825 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->install_count()); 832 EXPECT_EQ(0, installer3->install_count());
826 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error()); 833 EXPECT_EQ(0, installer2->error());
827 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count()); 834 EXPECT_EQ(0, installer2->install_count());
828 835
829 // One update check and no additional pings are expected. 836 // One update check and no additional pings are expected.
830 EXPECT_EQ(1, post_interceptor_->GetHitCount()) 837 EXPECT_EQ(1, post_interceptor_->GetHitCount())
831 << post_interceptor_->GetRequestsAsString(); 838 << post_interceptor_->GetRequestsAsString();
832 EXPECT_EQ(1, post_interceptor_->GetCount()) 839 EXPECT_EQ(1, post_interceptor_->GetCount())
833 << post_interceptor_->GetRequestsAsString(); 840 << post_interceptor_->GetRequestsAsString();
834 841
835 EXPECT_NE( 842 EXPECT_NE(
836 string::npos, 843 string::npos,
837 post_interceptor_->GetRequests()[0].find( 844 post_interceptor_->GetRequests()[0].find(
(...skipping 28 matching lines...) Expand all
866 test_file("updatecheck_diff_reply_3.xml"))); 873 test_file("updatecheck_diff_reply_3.xml")));
867 874
868 get_interceptor_->SetResponse( 875 get_interceptor_->SetResponse(
869 GURL("http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_1.crx"), 876 GURL("http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_1.crx"),
870 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1.crx")); 877 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1.crx"));
871 get_interceptor_->SetResponse( 878 get_interceptor_->SetResponse(
872 GURL("http://localhost/download/" 879 GURL("http://localhost/download/"
873 "ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx"), 880 "ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx"),
874 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx")); 881 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx"));
875 882
876 VersionedTestInstaller installer; 883 scoped_refptr<TestInstaller> installer(new VersionedTestInstaller);
877 CrxComponent com; 884 CrxComponent com;
878 RegisterComponent(&com, kTestComponent_ihfo, Version("0.0"), &installer); 885 RegisterComponent(&com, kTestComponent_ihfo, Version("0.0"), installer);
879 886
880 test_configurator()->SetLoopCount(3); 887 test_configurator()->SetLoopCount(3);
881 component_updater()->Start(); 888 component_updater()->Start();
882 RunThreads(); 889 RunThreads();
883 890
884 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); 891 EXPECT_EQ(0, installer->error());
885 EXPECT_EQ(2, static_cast<TestInstaller*>(com.installer)->install_count()); 892 EXPECT_EQ(2, installer->install_count());
886 893
887 EXPECT_EQ(5, post_interceptor_->GetHitCount()) 894 EXPECT_EQ(5, post_interceptor_->GetHitCount())
888 << post_interceptor_->GetRequestsAsString(); 895 << post_interceptor_->GetRequestsAsString();
889 EXPECT_EQ(5, post_interceptor_->GetCount()) 896 EXPECT_EQ(5, post_interceptor_->GetCount())
890 << post_interceptor_->GetRequestsAsString(); 897 << post_interceptor_->GetRequestsAsString();
891 EXPECT_EQ(2, get_interceptor_->GetHitCount()); 898 EXPECT_EQ(2, get_interceptor_->GetHitCount());
892 899
893 EXPECT_NE( 900 EXPECT_NE(
894 string::npos, 901 string::npos,
895 post_interceptor_->GetRequests()[0].find( 902 post_interceptor_->GetRequests()[0].find(
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
955 GURL("http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_1.crx"), 962 GURL("http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_1.crx"),
956 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1.crx")); 963 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1.crx"));
957 get_interceptor_->SetResponse( 964 get_interceptor_->SetResponse(
958 GURL("http://localhost/download/" 965 GURL("http://localhost/download/"
959 "ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx"), 966 "ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx"),
960 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx")); 967 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx"));
961 get_interceptor_->SetResponse( 968 get_interceptor_->SetResponse(
962 GURL("http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_2.crx"), 969 GURL("http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_2.crx"),
963 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_2.crx")); 970 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_2.crx"));
964 971
965 TestInstaller installer; 972 scoped_refptr<TestInstaller> installer(new TestInstaller);
966 CrxComponent com; 973 CrxComponent com;
967 RegisterComponent(&com, kTestComponent_ihfo, Version("1.0"), &installer); 974 RegisterComponent(&com, kTestComponent_ihfo, Version("1.0"), installer);
968 975
969 test_configurator()->SetLoopCount(2); 976 test_configurator()->SetLoopCount(2);
970 component_updater()->Start(); 977 component_updater()->Start();
971 RunThreads(); 978 RunThreads();
972 979
973 // A failed differential update does not count as a failed install. 980 // A failed differential update does not count as a failed install.
974 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); 981 EXPECT_EQ(0, installer->error());
975 EXPECT_EQ(1, static_cast<TestInstaller*>(com.installer)->install_count()); 982 EXPECT_EQ(1, installer->install_count());
976 983
977 EXPECT_EQ(3, post_interceptor_->GetHitCount()) 984 EXPECT_EQ(3, post_interceptor_->GetHitCount())
978 << post_interceptor_->GetRequestsAsString(); 985 << post_interceptor_->GetRequestsAsString();
979 EXPECT_EQ(3, post_interceptor_->GetCount()) 986 EXPECT_EQ(3, post_interceptor_->GetCount())
980 << post_interceptor_->GetRequestsAsString(); 987 << post_interceptor_->GetRequestsAsString();
981 EXPECT_EQ(2, get_interceptor_->GetHitCount()); 988 EXPECT_EQ(2, get_interceptor_->GetHitCount());
982 989
983 EXPECT_NE( 990 EXPECT_NE(
984 string::npos, 991 string::npos,
985 post_interceptor_->GetRequests()[0].find( 992 post_interceptor_->GetRequests()[0].find(
(...skipping 20 matching lines...) Expand all
1006 1013
1007 // Test is flakey on Android bots. See crbug.com/331420. 1014 // Test is flakey on Android bots. See crbug.com/331420.
1008 #if defined(OS_ANDROID) 1015 #if defined(OS_ANDROID)
1009 #define MAYBE_CheckFailedInstallPing DISABLED_CheckFailedInstallPing 1016 #define MAYBE_CheckFailedInstallPing DISABLED_CheckFailedInstallPing
1010 #else 1017 #else
1011 #define MAYBE_CheckFailedInstallPing CheckFailedInstallPing 1018 #define MAYBE_CheckFailedInstallPing CheckFailedInstallPing
1012 #endif 1019 #endif
1013 // Verify that a failed installation causes an install failure ping. 1020 // Verify that a failed installation causes an install failure ping.
1014 TEST_F(ComponentUpdaterTest, MAYBE_CheckFailedInstallPing) { 1021 TEST_F(ComponentUpdaterTest, MAYBE_CheckFailedInstallPing) {
1015 // This test installer reports installation failure. 1022 // This test installer reports installation failure.
1016 class : public TestInstaller { 1023 class FailingTestInstaller : public TestInstaller {
1017 bool Install(const base::DictionaryValue& manifest, 1024 bool Install(const base::DictionaryValue& manifest,
1018 const base::FilePath& unpack_path) override { 1025 const base::FilePath& unpack_path) override {
1019 ++install_count_; 1026 ++install_count_;
1020 base::DeleteFile(unpack_path, true); 1027 base::DeleteFile(unpack_path, true);
1021 return false; 1028 return false;
1022 } 1029 }
1023 } installer; 1030 private:
1031 ~FailingTestInstaller() override {}
1032 };
1033 scoped_refptr<FailingTestInstaller> installer(new FailingTestInstaller);
1024 1034
1025 EXPECT_TRUE(post_interceptor_->ExpectRequest( 1035 EXPECT_TRUE(post_interceptor_->ExpectRequest(
1026 new PartialMatch("updatecheck"), test_file("updatecheck_reply_1.xml"))); 1036 new PartialMatch("updatecheck"), test_file("updatecheck_reply_1.xml")));
1027 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch("event"))); 1037 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch("event")));
1028 EXPECT_TRUE(post_interceptor_->ExpectRequest( 1038 EXPECT_TRUE(post_interceptor_->ExpectRequest(
1029 new PartialMatch("updatecheck"), test_file("updatecheck_reply_1.xml"))); 1039 new PartialMatch("updatecheck"), test_file("updatecheck_reply_1.xml")));
1030 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch("event"))); 1040 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch("event")));
1031 get_interceptor_->SetResponse( 1041 get_interceptor_->SetResponse(
1032 GURL(expected_crx_url), 1042 GURL(expected_crx_url),
1033 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx")); 1043 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx"));
1034 1044
1035 // Start with 0.9, and attempt update to 1.0. 1045 // Start with 0.9, and attempt update to 1.0.
1036 // Loop twice to issue two checks: (1) with original 0.9 version 1046 // Loop twice to issue two checks: (1) with original 0.9 version
1037 // and (2), which should retry with 0.9. 1047 // and (2), which should retry with 0.9.
1038 CrxComponent com; 1048 CrxComponent com;
1039 RegisterComponent(&com, kTestComponent_jebg, Version("0.9"), &installer); 1049 RegisterComponent(&com, kTestComponent_jebg, Version("0.9"), installer);
1040 1050
1041 test_configurator()->SetLoopCount(2); 1051 test_configurator()->SetLoopCount(2);
1042 component_updater()->Start(); 1052 component_updater()->Start();
1043 RunThreads(); 1053 RunThreads();
1044 1054
1045 EXPECT_EQ(4, post_interceptor_->GetHitCount()) 1055 EXPECT_EQ(4, post_interceptor_->GetHitCount())
1046 << post_interceptor_->GetRequestsAsString(); 1056 << post_interceptor_->GetRequestsAsString();
1047 EXPECT_EQ(2, get_interceptor_->GetHitCount()); 1057 EXPECT_EQ(2, get_interceptor_->GetHitCount());
1048 1058
1049 EXPECT_NE( 1059 EXPECT_NE(
(...skipping 30 matching lines...) Expand all
1080 // iteration. 1090 // iteration.
1081 post_interceptor_->Reset(); 1091 post_interceptor_->Reset();
1082 EXPECT_TRUE(post_interceptor_->ExpectRequest( 1092 EXPECT_TRUE(post_interceptor_->ExpectRequest(
1083 new PartialMatch("updatecheck"), 1093 new PartialMatch("updatecheck"),
1084 test_file("updatecheck_reply_noupdate.xml"))); 1094 test_file("updatecheck_reply_noupdate.xml")));
1085 1095
1086 test_configurator()->SetLoopCount(1); 1096 test_configurator()->SetLoopCount(1);
1087 component_updater()->Start(); 1097 component_updater()->Start();
1088 RunThreads(); 1098 RunThreads();
1089 1099
1090 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); 1100 EXPECT_EQ(0, installer->error());
1091 EXPECT_EQ(2, static_cast<TestInstaller*>(com.installer)->install_count()); 1101 EXPECT_EQ(2, installer->install_count());
1092 1102
1093 EXPECT_EQ(1, post_interceptor_->GetHitCount()) 1103 EXPECT_EQ(1, post_interceptor_->GetHitCount())
1094 << post_interceptor_->GetRequestsAsString(); 1104 << post_interceptor_->GetRequestsAsString();
1095 EXPECT_EQ(1, post_interceptor_->GetCount()) 1105 EXPECT_EQ(1, post_interceptor_->GetCount())
1096 << post_interceptor_->GetRequestsAsString(); 1106 << post_interceptor_->GetRequestsAsString();
1097 1107
1098 EXPECT_NE( 1108 EXPECT_NE(
1099 string::npos, 1109 string::npos,
1100 post_interceptor_->GetRequests()[0].find( 1110 post_interceptor_->GetRequests()[0].find(
1101 "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"0.9\">" 1111 "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"0.9\">"
(...skipping 27 matching lines...) Expand all
1129 // actually dowloaded contains a patching error, an therefore, an error 1139 // actually dowloaded contains a patching error, an therefore, an error
1130 // is injected at the time of patching. 1140 // is injected at the time of patching.
1131 get_interceptor_->SetResponse( 1141 get_interceptor_->SetResponse(
1132 GURL("http://localhost/download/" 1142 GURL("http://localhost/download/"
1133 "ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx"), 1143 "ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx"),
1134 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1to2_bad.crx")); 1144 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1to2_bad.crx"));
1135 get_interceptor_->SetResponse( 1145 get_interceptor_->SetResponse(
1136 GURL("http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_2.crx"), 1146 GURL("http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_2.crx"),
1137 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_2.crx")); 1147 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_2.crx"));
1138 1148
1139 VersionedTestInstaller installer; 1149 scoped_refptr<TestInstaller> installer(new VersionedTestInstaller);
1140 CrxComponent com; 1150 CrxComponent com;
1141 RegisterComponent(&com, kTestComponent_ihfo, Version("0.0"), &installer); 1151 RegisterComponent(&com, kTestComponent_ihfo, Version("0.0"), installer);
1142 1152
1143 test_configurator()->SetLoopCount(3); 1153 test_configurator()->SetLoopCount(3);
1144 component_updater()->Start(); 1154 component_updater()->Start();
1145 RunThreads(); 1155 RunThreads();
1146 component_updater()->Stop(); 1156 component_updater()->Stop();
1147 1157
1148 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); 1158 EXPECT_EQ(0, installer->error());
1149 EXPECT_EQ(2, static_cast<TestInstaller*>(com.installer)->install_count()); 1159 EXPECT_EQ(2, installer->install_count());
1150 1160
1151 EXPECT_EQ(5, post_interceptor_->GetHitCount()) 1161 EXPECT_EQ(5, post_interceptor_->GetHitCount())
1152 << post_interceptor_->GetRequestsAsString(); 1162 << post_interceptor_->GetRequestsAsString();
1153 EXPECT_EQ(5, post_interceptor_->GetCount()) 1163 EXPECT_EQ(5, post_interceptor_->GetCount())
1154 << post_interceptor_->GetRequestsAsString(); 1164 << post_interceptor_->GetRequestsAsString();
1155 EXPECT_EQ(3, get_interceptor_->GetHitCount()); 1165 EXPECT_EQ(3, get_interceptor_->GetHitCount());
1156 1166
1157 EXPECT_NE( 1167 EXPECT_NE(
1158 string::npos, 1168 string::npos,
1159 post_interceptor_->GetRequests()[0].find( 1169 post_interceptor_->GetRequests()[0].find(
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1242 "abagagagagagagagagagagagagagagag")) 1252 "abagagagagagagagagagagagagagagag"))
1243 .Times(1); 1253 .Times(1);
1244 EXPECT_CALL(observer, 1254 EXPECT_CALL(observer,
1245 OnEvent(ServiceObserver::COMPONENT_UPDATER_SLEEPING, "")) 1255 OnEvent(ServiceObserver::COMPONENT_UPDATER_SLEEPING, ""))
1246 .Times(1); 1256 .Times(1);
1247 } 1257 }
1248 1258
1249 EXPECT_TRUE(post_interceptor_->ExpectRequest( 1259 EXPECT_TRUE(post_interceptor_->ExpectRequest(
1250 new PartialMatch("updatecheck"), test_file("updatecheck_reply_1.xml"))); 1260 new PartialMatch("updatecheck"), test_file("updatecheck_reply_1.xml")));
1251 1261
1252 TestInstaller installer; 1262 scoped_refptr<TestInstaller> installer(new TestInstaller);
1253 CrxComponent com; 1263 CrxComponent com;
1254 component_updater()->AddObserver(&observer); 1264 component_updater()->AddObserver(&observer);
1255 EXPECT_EQ( 1265 EXPECT_EQ(
1256 ComponentUpdateService::kOk, 1266 ComponentUpdateService::kOk,
1257 RegisterComponent(&com, kTestComponent_abag, Version("1.1"), &installer)); 1267 RegisterComponent(&com, kTestComponent_abag, Version("1.1"), installer));
1258 // The following two calls ensure that we don't do an update check via the 1268 // The following two calls ensure that we don't do an update check via the
1259 // timer, so the only update check should be the on-demand one. 1269 // timer, so the only update check should be the on-demand one.
1260 test_configurator()->SetInitialDelay(1000000); 1270 test_configurator()->SetInitialDelay(1000000);
1261 test_configurator()->SetRecheckTime(1000000); 1271 test_configurator()->SetRecheckTime(1000000);
1262 test_configurator()->SetLoopCount(1); 1272 test_configurator()->SetLoopCount(1);
1263 component_updater()->Start(); 1273 component_updater()->Start();
1264 1274
1265 RunThreadsUntilIdle(); 1275 RunThreadsUntilIdle();
1266 1276
1267 EXPECT_EQ(0, post_interceptor_->GetHitCount()); 1277 EXPECT_EQ(0, post_interceptor_->GetHitCount());
1268 1278
1269 BrowserThread::PostTask(BrowserThread::IO, 1279 BrowserThread::PostTask(BrowserThread::IO,
1270 FROM_HERE, 1280 FROM_HERE,
1271 base::Bind(&RequestAndDeleteResourceThrottle, 1281 base::Bind(&RequestAndDeleteResourceThrottle,
1272 component_updater(), 1282 component_updater(),
1273 "abagagagagagagagagagagagagagagag")); 1283 "abagagagagagagagagagagagagagagag"));
1274 1284
1275 RunThreads(); 1285 RunThreads();
1276 1286
1277 EXPECT_EQ(1, post_interceptor_->GetHitCount()); 1287 EXPECT_EQ(1, post_interceptor_->GetHitCount());
1278 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); 1288 EXPECT_EQ(0, installer->error());
1279 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count()); 1289 EXPECT_EQ(0, installer->install_count());
1280 1290
1281 component_updater()->Stop(); 1291 component_updater()->Stop();
1282 } 1292 }
1283 1293
1284 class CancelResourceController : public TestResourceController { 1294 class CancelResourceController : public TestResourceController {
1285 public: 1295 public:
1286 CancelResourceController() : throttle_(NULL), resume_called_(0) {} 1296 CancelResourceController() : throttle_(NULL), resume_called_(0) {}
1287 ~CancelResourceController() override { 1297 ~CancelResourceController() override {
1288 // Check that the throttle has been resumed by the time we 1298 // Check that the throttle has been resumed by the time we
1289 // exit the test. 1299 // exit the test.
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1342 OnEvent(ServiceObserver::COMPONENT_UPDATER_SLEEPING, "")) 1352 OnEvent(ServiceObserver::COMPONENT_UPDATER_SLEEPING, ""))
1343 .Times(1); 1353 .Times(1);
1344 EXPECT_CALL(observer, 1354 EXPECT_CALL(observer,
1345 OnEvent(ServiceObserver::COMPONENT_UPDATER_STARTED, "")) 1355 OnEvent(ServiceObserver::COMPONENT_UPDATER_STARTED, ""))
1346 .Times(1); 1356 .Times(1);
1347 } 1357 }
1348 1358
1349 EXPECT_TRUE(post_interceptor_->ExpectRequest( 1359 EXPECT_TRUE(post_interceptor_->ExpectRequest(
1350 new PartialMatch("updatecheck"), test_file("updatecheck_reply_1.xml"))); 1360 new PartialMatch("updatecheck"), test_file("updatecheck_reply_1.xml")));
1351 1361
1352 TestInstaller installer; 1362 scoped_refptr<TestInstaller> installer(new TestInstaller);
1353 CrxComponent com; 1363 CrxComponent com;
1354 component_updater()->AddObserver(&observer); 1364 component_updater()->AddObserver(&observer);
1355 EXPECT_EQ( 1365 EXPECT_EQ(ComponentUpdateService::kOk,
1356 ComponentUpdateService::kOk, 1366 RegisterComponent(&com, kTestComponent_abag, Version("1.1"),
1357 RegisterComponent(&com, kTestComponent_abag, Version("1.1"), &installer)); 1367 installer));
1358 // The following two calls ensure that we don't do an update check via the 1368 // The following two calls ensure that we don't do an update check via the
1359 // timer, so the only update check should be the on-demand one. 1369 // timer, so the only update check should be the on-demand one.
1360 test_configurator()->SetInitialDelay(1000000); 1370 test_configurator()->SetInitialDelay(1000000);
1361 test_configurator()->SetRecheckTime(1000000); 1371 test_configurator()->SetRecheckTime(1000000);
1362 test_configurator()->SetLoopCount(1); 1372 test_configurator()->SetLoopCount(1);
1363 component_updater()->Start(); 1373 component_updater()->Start();
1364 1374
1365 RunThreadsUntilIdle(); 1375 RunThreadsUntilIdle();
1366 1376
1367 EXPECT_EQ(0, post_interceptor_->GetHitCount()); 1377 EXPECT_EQ(0, post_interceptor_->GetHitCount());
1368 1378
1369 { 1379 {
1370 // First on-demand update check is expected to succeeded. 1380 // First on-demand update check is expected to succeeded.
1371 CancelResourceController controller; 1381 CancelResourceController controller;
1372 1382
1373 BrowserThread::PostTask( 1383 BrowserThread::PostTask(
1374 BrowserThread::IO, 1384 BrowserThread::IO,
1375 FROM_HERE, 1385 FROM_HERE,
1376 base::Bind(base::IgnoreResult(&RequestTestResourceThrottle), 1386 base::Bind(base::IgnoreResult(&RequestTestResourceThrottle),
1377 component_updater(), 1387 component_updater(),
1378 &controller, 1388 &controller,
1379 "abagagagagagagagagagagagagagagag")); 1389 "abagagagagagagagagagagagagagagag"));
1380 1390
1381 RunThreads(); 1391 RunThreads();
1382 1392
1383 EXPECT_EQ(1, post_interceptor_->GetHitCount()); 1393 EXPECT_EQ(1, post_interceptor_->GetHitCount());
1384 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); 1394 EXPECT_EQ(0, installer->error());
1385 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count()); 1395 EXPECT_EQ(0, installer->install_count());
1386 1396
1387 component_updater()->Stop(); 1397 component_updater()->Stop();
1388 } 1398 }
1389 1399
1390 { 1400 {
1391 // Second on-demand update check is expected to succeed as well, since there 1401 // Second on-demand update check is expected to succeed as well, since there
1392 // is no cooldown interval between calls, due to calling SetOnDemandTime. 1402 // is no cooldown interval between calls, due to calling SetOnDemandTime.
1393 test_configurator()->SetOnDemandTime(0); 1403 test_configurator()->SetOnDemandTime(0);
1394 test_configurator()->SetLoopCount(1); 1404 test_configurator()->SetLoopCount(1);
1395 component_updater()->Start(); 1405 component_updater()->Start();
1396 1406
1397 CancelResourceController controller; 1407 CancelResourceController controller;
1398 1408
1399 BrowserThread::PostTask( 1409 BrowserThread::PostTask(
1400 BrowserThread::IO, 1410 BrowserThread::IO,
1401 FROM_HERE, 1411 FROM_HERE,
1402 base::Bind(base::IgnoreResult(&RequestTestResourceThrottle), 1412 base::Bind(base::IgnoreResult(&RequestTestResourceThrottle),
1403 component_updater(), 1413 component_updater(),
1404 &controller, 1414 &controller,
1405 "abagagagagagagagagagagagagagagag")); 1415 "abagagagagagagagagagagagagagagag"));
1406 1416
1407 RunThreads(); 1417 RunThreads();
1408 1418
1409 EXPECT_EQ(1, post_interceptor_->GetHitCount()); 1419 EXPECT_EQ(1, post_interceptor_->GetHitCount());
1410 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); 1420 EXPECT_EQ(0, installer->error());
1411 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count()); 1421 EXPECT_EQ(0, installer->install_count());
1412 1422
1413 component_updater()->Stop(); 1423 component_updater()->Stop();
1414 } 1424 }
1415 1425
1416 { 1426 {
1417 // This on-demand call is expected not to trigger a component update check. 1427 // This on-demand call is expected not to trigger a component update check.
1418 test_configurator()->SetOnDemandTime(1000000); 1428 test_configurator()->SetOnDemandTime(1000000);
1419 component_updater()->Start(); 1429 component_updater()->Start();
1420 1430
1421 CancelResourceController controller; 1431 CancelResourceController controller;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1459 OnEvent(ServiceObserver::COMPONENT_UPDATER_SLEEPING, "")) 1469 OnEvent(ServiceObserver::COMPONENT_UPDATER_SLEEPING, ""))
1460 .Times(1); 1470 .Times(1);
1461 } 1471 }
1462 1472
1463 EXPECT_TRUE(post_interceptor_->ExpectRequest( 1473 EXPECT_TRUE(post_interceptor_->ExpectRequest(
1464 new PartialMatch("updatecheck"), test_file("updatecheck_reply_1.xml"))); 1474 new PartialMatch("updatecheck"), test_file("updatecheck_reply_1.xml")));
1465 1475
1466 component_updater()->AddObserver(&observer1); 1476 component_updater()->AddObserver(&observer1);
1467 component_updater()->AddObserver(&observer2); 1477 component_updater()->AddObserver(&observer2);
1468 1478
1469 TestInstaller installer; 1479 scoped_refptr<TestInstaller> installer(new TestInstaller);
1470 CrxComponent com; 1480 CrxComponent com;
1471 EXPECT_EQ( 1481 EXPECT_EQ(
1472 ComponentUpdateService::kOk, 1482 ComponentUpdateService::kOk,
1473 RegisterComponent(&com, kTestComponent_abag, Version("1.1"), &installer)); 1483 RegisterComponent(&com, kTestComponent_abag, Version("1.1"), installer));
1474 test_configurator()->SetLoopCount(1); 1484 test_configurator()->SetLoopCount(1);
1475 component_updater()->Start(); 1485 component_updater()->Start();
1476 RunThreads(); 1486 RunThreads();
1477 1487
1478 // After removing the first observer, it's only the second observer that 1488 // After removing the first observer, it's only the second observer that
1479 // gets the events. 1489 // gets the events.
1480 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&observer1)); 1490 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&observer1));
1481 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&observer2)); 1491 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&observer2));
1482 { 1492 {
1483 InSequence seq; 1493 InSequence seq;
(...skipping 21 matching lines...) Expand all
1505 component_updater()->RemoveObserver(&observer2); 1515 component_updater()->RemoveObserver(&observer2);
1506 1516
1507 test_configurator()->SetLoopCount(1); 1517 test_configurator()->SetLoopCount(1);
1508 component_updater()->Start(); 1518 component_updater()->Start();
1509 RunThreads(); 1519 RunThreads();
1510 1520
1511 component_updater()->Stop(); 1521 component_updater()->Stop();
1512 } 1522 }
1513 1523
1514 } // namespace component_updater 1524 } // namespace component_updater
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698