OLD | NEW |
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/component_updater_service_unittest.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" |
11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
15 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
16 #include "base/values.h" | 16 #include "base/values.h" |
17 #include "chrome/browser/component_updater/component_updater_resource_throttle.h
" | 17 #include "chrome/browser/component_updater/component_updater_resource_throttle.h
" |
18 #include "chrome/common/chrome_paths.h" | 18 #include "chrome/common/chrome_paths.h" |
19 #include "components/update_client/test/test_configurator.h" | 19 #include "components/update_client/test_configurator.h" |
20 #include "components/update_client/test/test_installer.h" | 20 #include "components/update_client/test_installer.h" |
21 #include "components/update_client/test/url_request_post_interceptor.h" | 21 #include "components/update_client/url_request_post_interceptor.h" |
22 #include "components/update_client/utils.h" | 22 #include "components/update_client/utils.h" |
23 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
24 #include "content/public/browser/resource_controller.h" | 24 #include "content/public/browser/resource_controller.h" |
25 #include "content/public/browser/resource_request_info.h" | 25 #include "content/public/browser/resource_request_info.h" |
26 #include "content/public/browser/resource_throttle.h" | 26 #include "content/public/browser/resource_throttle.h" |
27 #include "libxml/globals.h" | 27 #include "libxml/globals.h" |
28 #include "net/base/upload_bytes_element_reader.h" | 28 #include "net/base/upload_bytes_element_reader.h" |
29 #include "net/url_request/test_url_request_interceptor.h" | 29 #include "net/url_request/test_url_request_interceptor.h" |
30 #include "net/url_request/url_request.h" | 30 #include "net/url_request/url_request.h" |
31 #include "net/url_request/url_request_test_util.h" | 31 #include "net/url_request/url_request_test_util.h" |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"0.9\">" | 355 "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"0.9\">" |
356 "<updatecheck /></app>")) | 356 "<updatecheck /></app>")) |
357 << post_interceptor_->GetRequestsAsString(); | 357 << post_interceptor_->GetRequestsAsString(); |
358 EXPECT_NE( | 358 EXPECT_NE( |
359 string::npos, | 359 string::npos, |
360 post_interceptor_->GetRequests()[0].find( | 360 post_interceptor_->GetRequests()[0].find( |
361 "<app appid=\"abagagagagagagagagagagagagagagag\" version=\"2.2\">" | 361 "<app appid=\"abagagagagagagagagagagagagagagag\" version=\"2.2\">" |
362 "<updatecheck /></app>")) | 362 "<updatecheck /></app>")) |
363 << post_interceptor_->GetRequestsAsString(); | 363 << post_interceptor_->GetRequestsAsString(); |
364 | 364 |
365 EXPECT_NE( | 365 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[1].find( |
366 string::npos, | 366 "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" " |
367 post_interceptor_->GetRequests()[1].find( | 367 "version=\"0.9\" nextversion=\"1.0\">" |
368 "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" " | 368 "<event eventtype=\"3\" eventresult=\"1\"/>")) |
369 "version=\"0.9\" nextversion=\"1.0\">" | |
370 "<event eventtype=\"3\" eventresult=\"1\"/>")) | |
371 << post_interceptor_->GetRequestsAsString(); | 369 << post_interceptor_->GetRequestsAsString(); |
372 | 370 |
373 EXPECT_NE( | 371 EXPECT_NE( |
374 string::npos, | 372 string::npos, |
375 post_interceptor_->GetRequests()[2].find( | 373 post_interceptor_->GetRequests()[2].find( |
376 "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"1.0\">" | 374 "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"1.0\">" |
377 "<updatecheck /></app>")); | 375 "<updatecheck /></app>")); |
378 EXPECT_NE( | 376 EXPECT_NE( |
379 string::npos, | 377 string::npos, |
380 post_interceptor_->GetRequests()[2].find( | 378 post_interceptor_->GetRequests()[2].find( |
381 "<app appid=\"abagagagagagagagagagagagagagagag\" version=\"2.2\">" | 379 "<app appid=\"abagagagagagagagagagagagagagagag\" version=\"2.2\">" |
382 "<updatecheck /></app>")) | 380 "<updatecheck /></app>")) |
383 << post_interceptor_->GetRequestsAsString(); | 381 << post_interceptor_->GetRequestsAsString(); |
384 | 382 |
385 // Test the protocol version is correct and the extra request attributes | 383 // Test the protocol version is correct and the extra request attributes |
386 // are included in the request. | 384 // are included in the request. |
387 EXPECT_NE( | 385 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[0].find( |
388 string::npos, | 386 "request protocol=\"3.0\" extra=\"foo\"")) |
389 post_interceptor_->GetRequests()[0].find( | |
390 "request protocol=\"3.0\" extra=\"foo\"")) | |
391 << post_interceptor_->GetRequestsAsString(); | 387 << post_interceptor_->GetRequestsAsString(); |
392 | 388 |
393 // Tokenize the request string to look for specific attributes, which | 389 // Tokenize the request string to look for specific attributes, which |
394 // are important for backward compatibility with the version v2 of the update | 390 // are important for backward compatibility with the version v2 of the update |
395 // protocol. In this case, inspect the <request>, which is the first element | 391 // protocol. In this case, inspect the <request>, which is the first element |
396 // after the xml declaration of the update request body. | 392 // after the xml declaration of the update request body. |
397 // Expect to find the |os|, |arch|, |prodchannel|, and |prodversion| | 393 // Expect to find the |os|, |arch|, |prodchannel|, and |prodversion| |
398 // attributes: | 394 // attributes: |
399 // <?xml version="1.0" encoding="UTF-8"?> | 395 // <?xml version="1.0" encoding="UTF-8"?> |
400 // <request... os=... arch=... prodchannel=... prodversion=...> | 396 // <request... os=... arch=... prodchannel=... prodversion=...> |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
541 | 537 |
542 EXPECT_EQ(2, post_interceptor_->GetHitCount()) | 538 EXPECT_EQ(2, post_interceptor_->GetHitCount()) |
543 << post_interceptor_->GetRequestsAsString(); | 539 << post_interceptor_->GetRequestsAsString(); |
544 EXPECT_EQ(2, post_interceptor_->GetCount()) | 540 EXPECT_EQ(2, post_interceptor_->GetCount()) |
545 << post_interceptor_->GetRequestsAsString(); | 541 << post_interceptor_->GetRequestsAsString(); |
546 | 542 |
547 EXPECT_EQ(1, get_interceptor_->GetHitCount()); | 543 EXPECT_EQ(1, get_interceptor_->GetHitCount()); |
548 | 544 |
549 // Expect the update check to contain an "ondemand" request for the | 545 // Expect the update check to contain an "ondemand" request for the |
550 // second component (com2) and a normal request for the other component. | 546 // second component (com2) and a normal request for the other component. |
551 EXPECT_NE( | 547 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[0].find( |
552 string::npos, | 548 "<app appid=\"abagagagagagagagagagagagagagagag\" " |
553 post_interceptor_->GetRequests()[0].find( | 549 "version=\"2.2\"><updatecheck /></app>")) |
554 "<app appid=\"abagagagagagagagagagagagagagagag\" " | |
555 "version=\"2.2\"><updatecheck /></app>")) | |
556 << post_interceptor_->GetRequestsAsString(); | 550 << post_interceptor_->GetRequestsAsString(); |
557 EXPECT_NE( | 551 EXPECT_NE( |
558 string::npos, | 552 string::npos, |
559 post_interceptor_->GetRequests()[0].find( | 553 post_interceptor_->GetRequests()[0].find( |
560 "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" " | 554 "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" " |
561 "version=\"0.9\" installsource=\"ondemand\"><updatecheck /></app>")) | 555 "version=\"0.9\" installsource=\"ondemand\"><updatecheck /></app>")) |
562 << post_interceptor_->GetRequestsAsString(); | 556 << post_interceptor_->GetRequestsAsString(); |
563 EXPECT_NE( | 557 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[1].find( |
564 string::npos, | 558 "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" " |
565 post_interceptor_->GetRequests()[1].find( | 559 "version=\"0.9\" nextversion=\"1.0\">" |
566 "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" " | 560 "<event eventtype=\"3\" eventresult=\"1\"/>")) |
567 "version=\"0.9\" nextversion=\"1.0\">" | |
568 "<event eventtype=\"3\" eventresult=\"1\"/>")) | |
569 << post_interceptor_->GetRequestsAsString(); | 561 << post_interceptor_->GetRequestsAsString(); |
570 | 562 |
571 // Also check what happens if previous check too soon. It works, since this | 563 // Also check what happens if previous check too soon. It works, since this |
572 // direct OnDemand call does not implement a cooldown. | 564 // direct OnDemand call does not implement a cooldown. |
573 test_configurator()->SetOnDemandTime(60 * 60); | 565 test_configurator()->SetOnDemandTime(60 * 60); |
574 EXPECT_EQ(Status::kOk, OnDemandTester::OnDemand(component_updater(), | 566 EXPECT_EQ(Status::kOk, OnDemandTester::OnDemand(component_updater(), |
575 GetCrxComponentID(com2))); | 567 GetCrxComponentID(com2))); |
576 // Okay, now reset to 0 for the other tests. | 568 // Okay, now reset to 0 for the other tests. |
577 test_configurator()->SetOnDemandTime(0); | 569 test_configurator()->SetOnDemandTime(0); |
578 component_updater()->Stop(); | 570 component_updater()->Stop(); |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
703 EXPECT_EQ(3, post_interceptor_->GetHitCount()) | 695 EXPECT_EQ(3, post_interceptor_->GetHitCount()) |
704 << post_interceptor_->GetRequestsAsString(); | 696 << post_interceptor_->GetRequestsAsString(); |
705 EXPECT_EQ(1, get_interceptor_->GetHitCount()); | 697 EXPECT_EQ(1, get_interceptor_->GetHitCount()); |
706 | 698 |
707 EXPECT_NE( | 699 EXPECT_NE( |
708 string::npos, | 700 string::npos, |
709 post_interceptor_->GetRequests()[0].find( | 701 post_interceptor_->GetRequests()[0].find( |
710 "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"0.9\">" | 702 "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"0.9\">" |
711 "<updatecheck /></app>")) | 703 "<updatecheck /></app>")) |
712 << post_interceptor_->GetRequestsAsString(); | 704 << post_interceptor_->GetRequestsAsString(); |
713 EXPECT_NE( | 705 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[1].find( |
714 string::npos, | 706 "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" " |
715 post_interceptor_->GetRequests()[1].find( | 707 "version=\"0.9\" nextversion=\"1.0\">" |
716 "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" " | 708 "<event eventtype=\"3\" eventresult=\"1\"/>")) |
717 "version=\"0.9\" nextversion=\"1.0\">" | |
718 "<event eventtype=\"3\" eventresult=\"1\"/>")) | |
719 << post_interceptor_->GetRequestsAsString(); | 709 << post_interceptor_->GetRequestsAsString(); |
720 EXPECT_NE( | 710 EXPECT_NE( |
721 string::npos, | 711 string::npos, |
722 post_interceptor_->GetRequests()[2].find( | 712 post_interceptor_->GetRequests()[2].find( |
723 "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"1.0\">" | 713 "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"1.0\">" |
724 "<updatecheck /></app>")) | 714 "<updatecheck /></app>")) |
725 << post_interceptor_->GetRequestsAsString(); | 715 << post_interceptor_->GetRequestsAsString(); |
726 | 716 |
727 component_updater()->Stop(); | 717 component_updater()->Stop(); |
728 | 718 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
795 test_file("updatecheck_diff_reply_2.xml"))); | 785 test_file("updatecheck_diff_reply_2.xml"))); |
796 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch("event"))); | 786 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch("event"))); |
797 EXPECT_TRUE(post_interceptor_->ExpectRequest( | 787 EXPECT_TRUE(post_interceptor_->ExpectRequest( |
798 new PartialMatch("updatecheck"), | 788 new PartialMatch("updatecheck"), |
799 test_file("updatecheck_diff_reply_3.xml"))); | 789 test_file("updatecheck_diff_reply_3.xml"))); |
800 | 790 |
801 get_interceptor_->SetResponse( | 791 get_interceptor_->SetResponse( |
802 GURL("http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_1.crx"), | 792 GURL("http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_1.crx"), |
803 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1.crx")); | 793 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1.crx")); |
804 get_interceptor_->SetResponse( | 794 get_interceptor_->SetResponse( |
805 GURL("http://localhost/download/" | 795 GURL( |
806 "ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx"), | 796 "http://localhost/download/" |
| 797 "ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx"), |
807 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx")); | 798 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx")); |
808 | 799 |
809 scoped_refptr<TestInstaller> installer(new VersionedTestInstaller); | 800 scoped_refptr<TestInstaller> installer(new VersionedTestInstaller); |
810 CrxComponent com; | 801 CrxComponent com; |
811 RegisterComponent(&com, kTestComponent_ihfo, Version("0.0"), installer); | 802 RegisterComponent(&com, kTestComponent_ihfo, Version("0.0"), installer); |
812 | 803 |
813 test_configurator()->SetLoopCount(3); | 804 test_configurator()->SetLoopCount(3); |
814 component_updater()->Start(); | 805 component_updater()->Start(); |
815 RunThreads(); | 806 RunThreads(); |
816 | 807 |
817 EXPECT_EQ(0, installer->error()); | 808 EXPECT_EQ(0, installer->error()); |
818 EXPECT_EQ(2, installer->install_count()); | 809 EXPECT_EQ(2, installer->install_count()); |
819 | 810 |
820 EXPECT_EQ(5, post_interceptor_->GetHitCount()) | 811 EXPECT_EQ(5, post_interceptor_->GetHitCount()) |
821 << post_interceptor_->GetRequestsAsString(); | 812 << post_interceptor_->GetRequestsAsString(); |
822 EXPECT_EQ(5, post_interceptor_->GetCount()) | 813 EXPECT_EQ(5, post_interceptor_->GetCount()) |
823 << post_interceptor_->GetRequestsAsString(); | 814 << post_interceptor_->GetRequestsAsString(); |
824 EXPECT_EQ(2, get_interceptor_->GetHitCount()); | 815 EXPECT_EQ(2, get_interceptor_->GetHitCount()); |
825 | 816 |
826 EXPECT_NE( | 817 EXPECT_NE( |
827 string::npos, | 818 string::npos, |
828 post_interceptor_->GetRequests()[0].find( | 819 post_interceptor_->GetRequests()[0].find( |
829 "<app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" version=\"0.0\">" | 820 "<app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" version=\"0.0\">" |
830 "<updatecheck /></app>")) | 821 "<updatecheck /></app>")) |
831 << post_interceptor_->GetRequestsAsString(); | 822 << post_interceptor_->GetRequestsAsString(); |
832 EXPECT_NE( | 823 EXPECT_NE(string::npos, |
833 string::npos, | 824 post_interceptor_->GetRequests()[1].find( |
834 post_interceptor_->GetRequests()[1].find( | 825 "<app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" " |
835 "<app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" " | 826 "version=\"0.0\" nextversion=\"1.0\">" |
836 "version=\"0.0\" nextversion=\"1.0\">" | 827 "<event eventtype=\"3\" eventresult=\"1\" nextfp=\"1\"/>")) |
837 "<event eventtype=\"3\" eventresult=\"1\" nextfp=\"1\"/>")) | |
838 << post_interceptor_->GetRequestsAsString(); | 828 << post_interceptor_->GetRequestsAsString(); |
839 EXPECT_NE( | 829 EXPECT_NE( |
840 string::npos, | 830 string::npos, |
841 post_interceptor_->GetRequests()[2].find( | 831 post_interceptor_->GetRequests()[2].find( |
842 "<app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" version=\"1.0\">" | 832 "<app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" version=\"1.0\">" |
843 "<updatecheck /><packages><package fp=\"1\"/></packages></app>")) | 833 "<updatecheck /><packages><package fp=\"1\"/></packages></app>")) |
844 << post_interceptor_->GetRequestsAsString(); | 834 << post_interceptor_->GetRequestsAsString(); |
845 EXPECT_NE( | 835 EXPECT_NE(string::npos, |
846 string::npos, | 836 post_interceptor_->GetRequests()[3].find( |
847 post_interceptor_->GetRequests()[3].find( | 837 "<app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" " |
848 "<app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" " | 838 "version=\"1.0\" nextversion=\"2.0\">" |
849 "version=\"1.0\" nextversion=\"2.0\">" | 839 "<event eventtype=\"3\" eventresult=\"1\" diffresult=\"1\" " |
850 "<event eventtype=\"3\" eventresult=\"1\" diffresult=\"1\" " | 840 "previousfp=\"1\" nextfp=\"22\"/>")) |
851 "previousfp=\"1\" nextfp=\"22\"/>")) | |
852 << post_interceptor_->GetRequestsAsString(); | 841 << post_interceptor_->GetRequestsAsString(); |
853 EXPECT_NE( | 842 EXPECT_NE( |
854 string::npos, | 843 string::npos, |
855 post_interceptor_->GetRequests()[4].find( | 844 post_interceptor_->GetRequests()[4].find( |
856 "<app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" version=\"2.0\">" | 845 "<app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" version=\"2.0\">" |
857 "<updatecheck /><packages><package fp=\"22\"/></packages></app>")) | 846 "<updatecheck /><packages><package fp=\"22\"/></packages></app>")) |
858 << post_interceptor_->GetRequestsAsString(); | 847 << post_interceptor_->GetRequestsAsString(); |
859 component_updater()->Stop(); | 848 component_updater()->Stop(); |
860 } | 849 } |
861 | 850 |
(...skipping 19 matching lines...) Expand all Loading... |
881 test_file("updatecheck_diff_reply_2.xml"))); | 870 test_file("updatecheck_diff_reply_2.xml"))); |
882 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch("event"))); | 871 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch("event"))); |
883 EXPECT_TRUE(post_interceptor_->ExpectRequest( | 872 EXPECT_TRUE(post_interceptor_->ExpectRequest( |
884 new PartialMatch("updatecheck"), | 873 new PartialMatch("updatecheck"), |
885 test_file("updatecheck_diff_reply_3.xml"))); | 874 test_file("updatecheck_diff_reply_3.xml"))); |
886 | 875 |
887 get_interceptor_->SetResponse( | 876 get_interceptor_->SetResponse( |
888 GURL("http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_1.crx"), | 877 GURL("http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_1.crx"), |
889 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1.crx")); | 878 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1.crx")); |
890 get_interceptor_->SetResponse( | 879 get_interceptor_->SetResponse( |
891 GURL("http://localhost/download/" | 880 GURL( |
| 881 "http://localhost/download/" |
892 "ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx"), | 882 "ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx"), |
893 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx")); | 883 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx")); |
894 get_interceptor_->SetResponse( | 884 get_interceptor_->SetResponse( |
895 GURL("http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_2.crx"), | 885 GURL("http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_2.crx"), |
896 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_2.crx")); | 886 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_2.crx")); |
897 | 887 |
898 scoped_refptr<TestInstaller> installer(new TestInstaller); | 888 scoped_refptr<TestInstaller> installer(new TestInstaller); |
899 CrxComponent com; | 889 CrxComponent com; |
900 RegisterComponent(&com, kTestComponent_ihfo, Version("1.0"), installer); | 890 RegisterComponent(&com, kTestComponent_ihfo, Version("1.0"), installer); |
901 | 891 |
(...skipping 10 matching lines...) Expand all Loading... |
912 EXPECT_EQ(3, post_interceptor_->GetCount()) | 902 EXPECT_EQ(3, post_interceptor_->GetCount()) |
913 << post_interceptor_->GetRequestsAsString(); | 903 << post_interceptor_->GetRequestsAsString(); |
914 EXPECT_EQ(2, get_interceptor_->GetHitCount()); | 904 EXPECT_EQ(2, get_interceptor_->GetHitCount()); |
915 | 905 |
916 EXPECT_NE( | 906 EXPECT_NE( |
917 string::npos, | 907 string::npos, |
918 post_interceptor_->GetRequests()[0].find( | 908 post_interceptor_->GetRequests()[0].find( |
919 "<app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" version=\"1.0\">" | 909 "<app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" version=\"1.0\">" |
920 "<updatecheck /></app>")) | 910 "<updatecheck /></app>")) |
921 << post_interceptor_->GetRequestsAsString(); | 911 << post_interceptor_->GetRequestsAsString(); |
922 EXPECT_NE( | 912 EXPECT_NE(string::npos, |
923 string::npos, | 913 post_interceptor_->GetRequests()[1].find( |
924 post_interceptor_->GetRequests()[1].find( | 914 "<app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" " |
925 "<app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" " | 915 "version=\"1.0\" nextversion=\"2.0\">" |
926 "version=\"1.0\" nextversion=\"2.0\">" | 916 "<event eventtype=\"3\" eventresult=\"1\" diffresult=\"0\" " |
927 "<event eventtype=\"3\" eventresult=\"1\" diffresult=\"0\" " | 917 "differrorcat=\"2\" differrorcode=\"16\" nextfp=\"22\"/>")) |
928 "differrorcat=\"2\" differrorcode=\"16\" nextfp=\"22\"/>")) | |
929 << post_interceptor_->GetRequestsAsString(); | 918 << post_interceptor_->GetRequestsAsString(); |
930 EXPECT_NE( | 919 EXPECT_NE( |
931 string::npos, | 920 string::npos, |
932 post_interceptor_->GetRequests()[2].find( | 921 post_interceptor_->GetRequests()[2].find( |
933 "<app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" version=\"2.0\">" | 922 "<app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" version=\"2.0\">" |
934 "<updatecheck /><packages><package fp=\"22\"/></packages></app>")) | 923 "<updatecheck /><packages><package fp=\"22\"/></packages></app>")) |
935 << post_interceptor_->GetRequestsAsString(); | 924 << post_interceptor_->GetRequestsAsString(); |
936 | 925 |
937 component_updater()->Stop(); | 926 component_updater()->Stop(); |
938 } | 927 } |
939 | 928 |
940 // Test is flakey on Android bots. See crbug.com/331420. | 929 // Test is flakey on Android bots. See crbug.com/331420. |
941 #if defined(OS_ANDROID) | 930 #if defined(OS_ANDROID) |
942 #define MAYBE_CheckFailedInstallPing DISABLED_CheckFailedInstallPing | 931 #define MAYBE_CheckFailedInstallPing DISABLED_CheckFailedInstallPing |
943 #else | 932 #else |
944 #define MAYBE_CheckFailedInstallPing CheckFailedInstallPing | 933 #define MAYBE_CheckFailedInstallPing CheckFailedInstallPing |
945 #endif | 934 #endif |
946 // Verify that a failed installation causes an install failure ping. | 935 // Verify that a failed installation causes an install failure ping. |
947 TEST_F(ComponentUpdaterTest, MAYBE_CheckFailedInstallPing) { | 936 TEST_F(ComponentUpdaterTest, MAYBE_CheckFailedInstallPing) { |
948 // This test installer reports installation failure. | 937 // This test installer reports installation failure. |
949 class FailingTestInstaller : public TestInstaller { | 938 class FailingTestInstaller : public TestInstaller { |
950 bool Install(const base::DictionaryValue& manifest, | 939 bool Install(const base::DictionaryValue& manifest, |
951 const base::FilePath& unpack_path) override { | 940 const base::FilePath& unpack_path) override { |
952 ++install_count_; | 941 ++install_count_; |
953 base::DeleteFile(unpack_path, true); | 942 base::DeleteFile(unpack_path, true); |
954 return false; | 943 return false; |
955 } | 944 } |
| 945 |
956 private: | 946 private: |
957 ~FailingTestInstaller() override {} | 947 ~FailingTestInstaller() override {} |
958 }; | 948 }; |
959 scoped_refptr<FailingTestInstaller> installer(new FailingTestInstaller); | 949 scoped_refptr<FailingTestInstaller> installer(new FailingTestInstaller); |
960 | 950 |
961 EXPECT_TRUE(post_interceptor_->ExpectRequest( | 951 EXPECT_TRUE(post_interceptor_->ExpectRequest( |
962 new PartialMatch("updatecheck"), test_file("updatecheck_reply_1.xml"))); | 952 new PartialMatch("updatecheck"), test_file("updatecheck_reply_1.xml"))); |
963 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch("event"))); | 953 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch("event"))); |
964 EXPECT_TRUE(post_interceptor_->ExpectRequest( | 954 EXPECT_TRUE(post_interceptor_->ExpectRequest( |
965 new PartialMatch("updatecheck"), test_file("updatecheck_reply_1.xml"))); | 955 new PartialMatch("updatecheck"), test_file("updatecheck_reply_1.xml"))); |
(...skipping 15 matching lines...) Expand all Loading... |
981 EXPECT_EQ(4, post_interceptor_->GetHitCount()) | 971 EXPECT_EQ(4, post_interceptor_->GetHitCount()) |
982 << post_interceptor_->GetRequestsAsString(); | 972 << post_interceptor_->GetRequestsAsString(); |
983 EXPECT_EQ(2, get_interceptor_->GetHitCount()); | 973 EXPECT_EQ(2, get_interceptor_->GetHitCount()); |
984 | 974 |
985 EXPECT_NE( | 975 EXPECT_NE( |
986 string::npos, | 976 string::npos, |
987 post_interceptor_->GetRequests()[0].find( | 977 post_interceptor_->GetRequests()[0].find( |
988 "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"0.9\">" | 978 "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"0.9\">" |
989 "<updatecheck /></app>")) | 979 "<updatecheck /></app>")) |
990 << post_interceptor_->GetRequestsAsString(); | 980 << post_interceptor_->GetRequestsAsString(); |
991 EXPECT_NE( | 981 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[1].find( |
992 string::npos, | 982 "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" " |
993 post_interceptor_->GetRequests()[1].find( | 983 "version=\"0.9\" nextversion=\"1.0\">" |
994 "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" " | 984 "<event eventtype=\"3\" eventresult=\"0\" " |
995 "version=\"0.9\" nextversion=\"1.0\">" | 985 "errorcat=\"3\" errorcode=\"9\"/>")) |
996 "<event eventtype=\"3\" eventresult=\"0\" " | |
997 "errorcat=\"3\" errorcode=\"9\"/>")) | |
998 << post_interceptor_->GetRequestsAsString(); | 986 << post_interceptor_->GetRequestsAsString(); |
999 EXPECT_NE( | 987 EXPECT_NE( |
1000 string::npos, | 988 string::npos, |
1001 post_interceptor_->GetRequests()[2].find( | 989 post_interceptor_->GetRequests()[2].find( |
1002 "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"0.9\">" | 990 "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"0.9\">" |
1003 "<updatecheck /></app>")) | 991 "<updatecheck /></app>")) |
1004 << post_interceptor_->GetRequestsAsString(); | 992 << post_interceptor_->GetRequestsAsString(); |
1005 EXPECT_NE( | 993 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[3].find( |
1006 string::npos, | 994 "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" " |
1007 post_interceptor_->GetRequests()[3].find( | 995 "version=\"0.9\" nextversion=\"1.0\">" |
1008 "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" " | 996 "<event eventtype=\"3\" eventresult=\"0\" " |
1009 "version=\"0.9\" nextversion=\"1.0\">" | 997 "errorcat=\"3\" errorcode=\"9\"/>")) |
1010 "<event eventtype=\"3\" eventresult=\"0\" " | |
1011 "errorcat=\"3\" errorcode=\"9\"/>")) | |
1012 << post_interceptor_->GetRequestsAsString(); | 998 << post_interceptor_->GetRequestsAsString(); |
1013 | 999 |
1014 // Loop once more, but expect no ping because a noupdate response is issued. | 1000 // Loop once more, but expect no ping because a noupdate response is issued. |
1015 // This is necessary to clear out the fire-and-forget ping from the previous | 1001 // This is necessary to clear out the fire-and-forget ping from the previous |
1016 // iteration. | 1002 // iteration. |
1017 post_interceptor_->Reset(); | 1003 post_interceptor_->Reset(); |
1018 EXPECT_TRUE(post_interceptor_->ExpectRequest( | 1004 EXPECT_TRUE(post_interceptor_->ExpectRequest( |
1019 new PartialMatch("updatecheck"), | 1005 new PartialMatch("updatecheck"), |
1020 test_file("updatecheck_reply_noupdate.xml"))); | 1006 test_file("updatecheck_reply_noupdate.xml"))); |
1021 | 1007 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1058 test_file("updatecheck_diff_reply_3.xml"))); | 1044 test_file("updatecheck_diff_reply_3.xml"))); |
1059 | 1045 |
1060 get_interceptor_->SetResponse( | 1046 get_interceptor_->SetResponse( |
1061 GURL("http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_1.crx"), | 1047 GURL("http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_1.crx"), |
1062 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1.crx")); | 1048 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1.crx")); |
1063 // This intercept returns a different file than what is specified in the | 1049 // This intercept returns a different file than what is specified in the |
1064 // update check response and requested in the download. The file that is | 1050 // update check response and requested in the download. The file that is |
1065 // actually dowloaded contains a patching error, an therefore, an error | 1051 // actually dowloaded contains a patching error, an therefore, an error |
1066 // is injected at the time of patching. | 1052 // is injected at the time of patching. |
1067 get_interceptor_->SetResponse( | 1053 get_interceptor_->SetResponse( |
1068 GURL("http://localhost/download/" | 1054 GURL( |
1069 "ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx"), | 1055 "http://localhost/download/" |
| 1056 "ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx"), |
1070 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1to2_bad.crx")); | 1057 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1to2_bad.crx")); |
1071 get_interceptor_->SetResponse( | 1058 get_interceptor_->SetResponse( |
1072 GURL("http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_2.crx"), | 1059 GURL("http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_2.crx"), |
1073 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_2.crx")); | 1060 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_2.crx")); |
1074 | 1061 |
1075 scoped_refptr<TestInstaller> installer(new VersionedTestInstaller); | 1062 scoped_refptr<TestInstaller> installer(new VersionedTestInstaller); |
1076 CrxComponent com; | 1063 CrxComponent com; |
1077 RegisterComponent(&com, kTestComponent_ihfo, Version("0.0"), installer); | 1064 RegisterComponent(&com, kTestComponent_ihfo, Version("0.0"), installer); |
1078 | 1065 |
1079 test_configurator()->SetLoopCount(3); | 1066 test_configurator()->SetLoopCount(3); |
1080 component_updater()->Start(); | 1067 component_updater()->Start(); |
1081 RunThreads(); | 1068 RunThreads(); |
1082 component_updater()->Stop(); | 1069 component_updater()->Stop(); |
1083 | 1070 |
1084 EXPECT_EQ(0, installer->error()); | 1071 EXPECT_EQ(0, installer->error()); |
1085 EXPECT_EQ(2, installer->install_count()); | 1072 EXPECT_EQ(2, installer->install_count()); |
1086 | 1073 |
1087 EXPECT_EQ(5, post_interceptor_->GetHitCount()) | 1074 EXPECT_EQ(5, post_interceptor_->GetHitCount()) |
1088 << post_interceptor_->GetRequestsAsString(); | 1075 << post_interceptor_->GetRequestsAsString(); |
1089 EXPECT_EQ(5, post_interceptor_->GetCount()) | 1076 EXPECT_EQ(5, post_interceptor_->GetCount()) |
1090 << post_interceptor_->GetRequestsAsString(); | 1077 << post_interceptor_->GetRequestsAsString(); |
1091 EXPECT_EQ(3, get_interceptor_->GetHitCount()); | 1078 EXPECT_EQ(3, get_interceptor_->GetHitCount()); |
1092 | 1079 |
1093 EXPECT_NE( | 1080 EXPECT_NE( |
1094 string::npos, | 1081 string::npos, |
1095 post_interceptor_->GetRequests()[0].find( | 1082 post_interceptor_->GetRequests()[0].find( |
1096 "<app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" version=\"0.0\">" | 1083 "<app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" version=\"0.0\">" |
1097 "<updatecheck /></app>")) | 1084 "<updatecheck /></app>")) |
1098 << post_interceptor_->GetRequestsAsString(); | 1085 << post_interceptor_->GetRequestsAsString(); |
1099 EXPECT_NE( | 1086 EXPECT_NE(string::npos, |
1100 string::npos, | 1087 post_interceptor_->GetRequests()[1].find( |
1101 post_interceptor_->GetRequests()[1].find( | 1088 "<app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" " |
1102 "<app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" " | 1089 "version=\"0.0\" nextversion=\"1.0\">" |
1103 "version=\"0.0\" nextversion=\"1.0\">" | 1090 "<event eventtype=\"3\" eventresult=\"1\" nextfp=\"1\"/>")) |
1104 "<event eventtype=\"3\" eventresult=\"1\" nextfp=\"1\"/>")) | |
1105 << post_interceptor_->GetRequestsAsString(); | 1091 << post_interceptor_->GetRequestsAsString(); |
1106 EXPECT_NE( | 1092 EXPECT_NE( |
1107 string::npos, | 1093 string::npos, |
1108 post_interceptor_->GetRequests()[2].find( | 1094 post_interceptor_->GetRequests()[2].find( |
1109 "<app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" version=\"1.0\">" | 1095 "<app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" version=\"1.0\">" |
1110 "<updatecheck /><packages><package fp=\"1\"/></packages></app>")) | 1096 "<updatecheck /><packages><package fp=\"1\"/></packages></app>")) |
1111 << post_interceptor_->GetRequestsAsString(); | 1097 << post_interceptor_->GetRequestsAsString(); |
1112 EXPECT_NE( | 1098 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[3].find( |
1113 string::npos, | 1099 "<app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" " |
1114 post_interceptor_->GetRequests()[3].find( | 1100 "version=\"1.0\" nextversion=\"2.0\">" |
1115 "<app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" " | 1101 "<event eventtype=\"3\" eventresult=\"1\" " |
1116 "version=\"1.0\" nextversion=\"2.0\">" | 1102 "diffresult=\"0\" differrorcat=\"2\" " |
1117 "<event eventtype=\"3\" eventresult=\"1\" " | 1103 "differrorcode=\"14\" diffextracode1=\"305\" " |
1118 "diffresult=\"0\" differrorcat=\"2\" " | 1104 "previousfp=\"1\" nextfp=\"22\"/>")) |
1119 "differrorcode=\"14\" diffextracode1=\"305\" " | |
1120 "previousfp=\"1\" nextfp=\"22\"/>")) | |
1121 << post_interceptor_->GetRequestsAsString(); | 1105 << post_interceptor_->GetRequestsAsString(); |
1122 EXPECT_NE( | 1106 EXPECT_NE( |
1123 string::npos, | 1107 string::npos, |
1124 post_interceptor_->GetRequests()[4].find( | 1108 post_interceptor_->GetRequests()[4].find( |
1125 "<app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" version=\"2.0\">" | 1109 "<app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" version=\"2.0\">" |
1126 "<updatecheck /><packages><package fp=\"22\"/></packages></app>")) | 1110 "<updatecheck /><packages><package fp=\"22\"/></packages></app>")) |
1127 << post_interceptor_->GetRequestsAsString(); | 1111 << post_interceptor_->GetRequestsAsString(); |
1128 } | 1112 } |
1129 | 1113 |
1130 class TestResourceController : public content::ResourceController { | 1114 class TestResourceController : public content::ResourceController { |
1131 public: | 1115 public: |
1132 virtual void SetThrottle(content::ResourceThrottle* throttle) {} | 1116 virtual void SetThrottle(content::ResourceThrottle* throttle) {} |
1133 }; | 1117 }; |
1134 | 1118 |
1135 content::ResourceThrottle* RequestTestResourceThrottle( | 1119 content::ResourceThrottle* RequestTestResourceThrottle( |
1136 ComponentUpdateService* cus, | 1120 ComponentUpdateService* cus, |
1137 TestResourceController* controller, | 1121 TestResourceController* controller, |
1138 const char* crx_id) { | 1122 const char* crx_id) { |
1139 net::TestURLRequestContext context; | 1123 net::TestURLRequestContext context; |
1140 scoped_ptr<net::URLRequest> url_request(context.CreateRequest( | 1124 scoped_ptr<net::URLRequest> url_request(context.CreateRequest( |
1141 GURL("http://foo.example.com/thing.bin"), | 1125 GURL("http://foo.example.com/thing.bin"), net::DEFAULT_PRIORITY, NULL)); |
1142 net::DEFAULT_PRIORITY, | |
1143 NULL)); | |
1144 | 1126 |
1145 content::ResourceThrottle* rt = GetOnDemandResourceThrottle(cus, crx_id); | 1127 content::ResourceThrottle* rt = GetOnDemandResourceThrottle(cus, crx_id); |
1146 rt->set_controller_for_testing(controller); | 1128 rt->set_controller_for_testing(controller); |
1147 controller->SetThrottle(rt); | 1129 controller->SetThrottle(rt); |
1148 return rt; | 1130 return rt; |
1149 } | 1131 } |
1150 | 1132 |
1151 void RequestAndDeleteResourceThrottle(ComponentUpdateService* cus, | 1133 void RequestAndDeleteResourceThrottle(ComponentUpdateService* cus, |
1152 const char* crx_id) { | 1134 const char* crx_id) { |
1153 // By requesting a throttle and deleting it immediately we ensure that we | 1135 // By requesting a throttle and deleting it immediately we ensure that we |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1189 // timer, so the only update check should be the on-demand one. | 1171 // timer, so the only update check should be the on-demand one. |
1190 test_configurator()->SetInitialDelay(1000000); | 1172 test_configurator()->SetInitialDelay(1000000); |
1191 test_configurator()->SetRecheckTime(1000000); | 1173 test_configurator()->SetRecheckTime(1000000); |
1192 test_configurator()->SetLoopCount(1); | 1174 test_configurator()->SetLoopCount(1); |
1193 component_updater()->Start(); | 1175 component_updater()->Start(); |
1194 | 1176 |
1195 RunThreadsUntilIdle(); | 1177 RunThreadsUntilIdle(); |
1196 | 1178 |
1197 EXPECT_EQ(0, post_interceptor_->GetHitCount()); | 1179 EXPECT_EQ(0, post_interceptor_->GetHitCount()); |
1198 | 1180 |
1199 BrowserThread::PostTask(BrowserThread::IO, | 1181 BrowserThread::PostTask( |
1200 FROM_HERE, | 1182 BrowserThread::IO, FROM_HERE, |
1201 base::Bind(&RequestAndDeleteResourceThrottle, | 1183 base::Bind(&RequestAndDeleteResourceThrottle, component_updater(), |
1202 component_updater(), | 1184 "abagagagagagagagagagagagagagagag")); |
1203 "abagagagagagagagagagagagagagagag")); | |
1204 | 1185 |
1205 RunThreads(); | 1186 RunThreads(); |
1206 | 1187 |
1207 EXPECT_EQ(1, post_interceptor_->GetHitCount()); | 1188 EXPECT_EQ(1, post_interceptor_->GetHitCount()); |
1208 EXPECT_EQ(0, installer->error()); | 1189 EXPECT_EQ(0, installer->error()); |
1209 EXPECT_EQ(0, installer->install_count()); | 1190 EXPECT_EQ(0, installer->install_count()); |
1210 | 1191 |
1211 component_updater()->Stop(); | 1192 component_updater()->Stop(); |
1212 } | 1193 } |
1213 | 1194 |
1214 class CancelResourceController : public TestResourceController { | 1195 class CancelResourceController : public TestResourceController { |
1215 public: | 1196 public: |
1216 CancelResourceController() : throttle_(NULL), resume_called_(0) {} | 1197 CancelResourceController() : throttle_(NULL), resume_called_(0) {} |
1217 ~CancelResourceController() override { | 1198 ~CancelResourceController() override { |
1218 // Check that the throttle has been resumed by the time we | 1199 // Check that the throttle has been resumed by the time we |
1219 // exit the test. | 1200 // exit the test. |
1220 CHECK_EQ(1, resume_called_); | 1201 CHECK_EQ(1, resume_called_); |
1221 delete throttle_; | 1202 delete throttle_; |
1222 } | 1203 } |
1223 void Cancel() override { CHECK(false); } | 1204 void Cancel() override { CHECK(false); } |
1224 void CancelAndIgnore() override { CHECK(false); } | 1205 void CancelAndIgnore() override { CHECK(false); } |
1225 void CancelWithError(int error_code) override { CHECK(false); } | 1206 void CancelWithError(int error_code) override { CHECK(false); } |
1226 void Resume() override { | 1207 void Resume() override { |
1227 BrowserThread::PostTask(BrowserThread::IO, | 1208 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
1228 FROM_HERE, | |
1229 base::Bind(&CancelResourceController::ResumeCalled, | 1209 base::Bind(&CancelResourceController::ResumeCalled, |
1230 base::Unretained(this))); | 1210 base::Unretained(this))); |
1231 } | 1211 } |
1232 void SetThrottle(content::ResourceThrottle* throttle) override { | 1212 void SetThrottle(content::ResourceThrottle* throttle) override { |
1233 throttle_ = throttle; | 1213 throttle_ = throttle; |
1234 bool defer = false; | 1214 bool defer = false; |
1235 // Initially the throttle is blocked. The CUS needs to run a | 1215 // Initially the throttle is blocked. The CUS needs to run a |
1236 // task on the UI thread to decide if it should unblock. | 1216 // task on the UI thread to decide if it should unblock. |
1237 throttle_->WillStartRequest(&defer); | 1217 throttle_->WillStartRequest(&defer); |
1238 CHECK(defer); | 1218 CHECK(defer); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1284 | 1264 |
1285 RunThreadsUntilIdle(); | 1265 RunThreadsUntilIdle(); |
1286 | 1266 |
1287 EXPECT_EQ(0, post_interceptor_->GetHitCount()); | 1267 EXPECT_EQ(0, post_interceptor_->GetHitCount()); |
1288 | 1268 |
1289 { | 1269 { |
1290 // First on-demand update check is expected to succeeded. | 1270 // First on-demand update check is expected to succeeded. |
1291 CancelResourceController controller; | 1271 CancelResourceController controller; |
1292 | 1272 |
1293 BrowserThread::PostTask( | 1273 BrowserThread::PostTask( |
1294 BrowserThread::IO, | 1274 BrowserThread::IO, FROM_HERE, |
1295 FROM_HERE, | |
1296 base::Bind(base::IgnoreResult(&RequestTestResourceThrottle), | 1275 base::Bind(base::IgnoreResult(&RequestTestResourceThrottle), |
1297 component_updater(), | 1276 component_updater(), &controller, |
1298 &controller, | |
1299 "abagagagagagagagagagagagagagagag")); | 1277 "abagagagagagagagagagagagagagagag")); |
1300 | 1278 |
1301 RunThreads(); | 1279 RunThreads(); |
1302 | 1280 |
1303 EXPECT_EQ(1, post_interceptor_->GetHitCount()); | 1281 EXPECT_EQ(1, post_interceptor_->GetHitCount()); |
1304 EXPECT_EQ(0, installer->error()); | 1282 EXPECT_EQ(0, installer->error()); |
1305 EXPECT_EQ(0, installer->install_count()); | 1283 EXPECT_EQ(0, installer->install_count()); |
1306 | 1284 |
1307 component_updater()->Stop(); | 1285 component_updater()->Stop(); |
1308 } | 1286 } |
1309 | 1287 |
1310 { | 1288 { |
1311 // Second on-demand update check is expected to succeed as well, since there | 1289 // Second on-demand update check is expected to succeed as well, since there |
1312 // is no cooldown interval between calls, due to calling SetOnDemandTime. | 1290 // is no cooldown interval between calls, due to calling SetOnDemandTime. |
1313 test_configurator()->SetOnDemandTime(0); | 1291 test_configurator()->SetOnDemandTime(0); |
1314 test_configurator()->SetLoopCount(1); | 1292 test_configurator()->SetLoopCount(1); |
1315 component_updater()->Start(); | 1293 component_updater()->Start(); |
1316 | 1294 |
1317 CancelResourceController controller; | 1295 CancelResourceController controller; |
1318 | 1296 |
1319 BrowserThread::PostTask( | 1297 BrowserThread::PostTask( |
1320 BrowserThread::IO, | 1298 BrowserThread::IO, FROM_HERE, |
1321 FROM_HERE, | |
1322 base::Bind(base::IgnoreResult(&RequestTestResourceThrottle), | 1299 base::Bind(base::IgnoreResult(&RequestTestResourceThrottle), |
1323 component_updater(), | 1300 component_updater(), &controller, |
1324 &controller, | |
1325 "abagagagagagagagagagagagagagagag")); | 1301 "abagagagagagagagagagagagagagagag")); |
1326 | 1302 |
1327 RunThreads(); | 1303 RunThreads(); |
1328 | 1304 |
1329 EXPECT_EQ(1, post_interceptor_->GetHitCount()); | 1305 EXPECT_EQ(1, post_interceptor_->GetHitCount()); |
1330 EXPECT_EQ(0, installer->error()); | 1306 EXPECT_EQ(0, installer->error()); |
1331 EXPECT_EQ(0, installer->install_count()); | 1307 EXPECT_EQ(0, installer->install_count()); |
1332 | 1308 |
1333 component_updater()->Stop(); | 1309 component_updater()->Stop(); |
1334 } | 1310 } |
1335 | 1311 |
1336 { | 1312 { |
1337 // This on-demand call is expected not to trigger a component update check. | 1313 // This on-demand call is expected not to trigger a component update check. |
1338 test_configurator()->SetOnDemandTime(1000000); | 1314 test_configurator()->SetOnDemandTime(1000000); |
1339 component_updater()->Start(); | 1315 component_updater()->Start(); |
1340 | 1316 |
1341 CancelResourceController controller; | 1317 CancelResourceController controller; |
1342 | 1318 |
1343 BrowserThread::PostTask( | 1319 BrowserThread::PostTask( |
1344 BrowserThread::IO, | 1320 BrowserThread::IO, FROM_HERE, |
1345 FROM_HERE, | |
1346 base::Bind(base::IgnoreResult(&RequestTestResourceThrottle), | 1321 base::Bind(base::IgnoreResult(&RequestTestResourceThrottle), |
1347 component_updater(), | 1322 component_updater(), &controller, |
1348 &controller, | |
1349 "abagagagagagagagagagagagagagagag")); | 1323 "abagagagagagagagagagagagagagagag")); |
1350 RunThreadsUntilIdle(); | 1324 RunThreadsUntilIdle(); |
1351 } | 1325 } |
1352 } | 1326 } |
1353 | 1327 |
1354 // Tests adding and removing observers. | 1328 // Tests adding and removing observers. |
1355 TEST_F(ComponentUpdaterTest, Observer) { | 1329 TEST_F(ComponentUpdaterTest, Observer) { |
1356 MockServiceObserver observer1, observer2; | 1330 MockServiceObserver observer1, observer2; |
1357 | 1331 |
1358 // Expect that two observers see the events. | 1332 // Expect that two observers see the events. |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1415 component_updater()->RemoveObserver(&observer2); | 1389 component_updater()->RemoveObserver(&observer2); |
1416 | 1390 |
1417 test_configurator()->SetLoopCount(1); | 1391 test_configurator()->SetLoopCount(1); |
1418 component_updater()->Start(); | 1392 component_updater()->Start(); |
1419 RunThreads(); | 1393 RunThreads(); |
1420 | 1394 |
1421 component_updater()->Stop(); | 1395 component_updater()->Stop(); |
1422 } | 1396 } |
1423 | 1397 |
1424 } // namespace component_updater | 1398 } // namespace component_updater |
OLD | NEW |