OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <map> | 5 #include <map> |
6 | 6 |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/stl_util-inl.h" | 10 #include "base/stl_util-inl.h" |
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
570 fetch1->AddExtension("1111", "1.0", zeroDays, kEmptyUpdateUrlData); | 570 fetch1->AddExtension("1111", "1.0", zeroDays, kEmptyUpdateUrlData); |
571 fetch2->AddExtension("12345", "2.0", kNeverPingedData, | 571 fetch2->AddExtension("12345", "2.0", kNeverPingedData, |
572 kEmptyUpdateUrlData); | 572 kEmptyUpdateUrlData); |
573 updater.StartUpdateCheck(fetch1); | 573 updater.StartUpdateCheck(fetch1); |
574 updater.StartUpdateCheck(fetch2); | 574 updater.StartUpdateCheck(fetch2); |
575 | 575 |
576 std::string invalid_xml = "invalid xml"; | 576 std::string invalid_xml = "invalid xml"; |
577 fetcher = factory.GetFetcherByID(ExtensionUpdater::kManifestFetcherId); | 577 fetcher = factory.GetFetcherByID(ExtensionUpdater::kManifestFetcherId); |
578 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); | 578 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); |
579 EXPECT_TRUE(fetcher->load_flags() == expected_load_flags); | 579 EXPECT_TRUE(fetcher->load_flags() == expected_load_flags); |
580 fetcher->delegate()->OnURLFetchComplete( | 580 |
581 fetcher, url1, net::URLRequestStatus(), 200, net::ResponseCookies(), | 581 fetcher->set_url(url1); |
582 invalid_xml); | 582 fetcher->set_status(net::URLRequestStatus()); |
| 583 fetcher->set_response_code(200); |
| 584 fetcher->SetResponseString(invalid_xml); |
| 585 fetcher->delegate()->OnURLFetchComplete(fetcher); |
583 | 586 |
584 // Now that the first request is complete, make sure the second one has | 587 // Now that the first request is complete, make sure the second one has |
585 // been started. | 588 // been started. |
586 const std::string kValidXml = | 589 const std::string kValidXml = |
587 "<?xml version='1.0' encoding='UTF-8'?>" | 590 "<?xml version='1.0' encoding='UTF-8'?>" |
588 "<gupdate xmlns='http://www.google.com/update2/response'" | 591 "<gupdate xmlns='http://www.google.com/update2/response'" |
589 " protocol='2.0'>" | 592 " protocol='2.0'>" |
590 " <app appid='12345'>" | 593 " <app appid='12345'>" |
591 " <updatecheck codebase='http://example.com/extension_1.2.3.4.crx'" | 594 " <updatecheck codebase='http://example.com/extension_1.2.3.4.crx'" |
592 " version='1.2.3.4' prodversionmin='2.0.143.0' />" | 595 " version='1.2.3.4' prodversionmin='2.0.143.0' />" |
593 " </app>" | 596 " </app>" |
594 "</gupdate>"; | 597 "</gupdate>"; |
595 fetcher = factory.GetFetcherByID(ExtensionUpdater::kManifestFetcherId); | 598 fetcher = factory.GetFetcherByID(ExtensionUpdater::kManifestFetcherId); |
596 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); | 599 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); |
597 EXPECT_TRUE(fetcher->load_flags() == expected_load_flags); | 600 EXPECT_TRUE(fetcher->load_flags() == expected_load_flags); |
598 fetcher->delegate()->OnURLFetchComplete( | 601 |
599 fetcher, url2, net::URLRequestStatus(), 200, net::ResponseCookies(), | 602 fetcher->set_url(url2); |
600 kValidXml); | 603 fetcher->set_status(net::URLRequestStatus()); |
| 604 fetcher->set_response_code(200); |
| 605 fetcher->SetResponseString(kValidXml); |
| 606 fetcher->delegate()->OnURLFetchComplete(fetcher); |
601 | 607 |
602 // This should run the manifest parsing, then we want to make sure that our | 608 // This should run the manifest parsing, then we want to make sure that our |
603 // service was called with GetExtensionById with the matching id from | 609 // service was called with GetExtensionById with the matching id from |
604 // kValidXml. | 610 // kValidXml. |
605 file_thread.Stop(); | 611 file_thread.Stop(); |
606 io_thread.Stop(); | 612 io_thread.Stop(); |
607 ui_loop.RunAllPending(); | 613 ui_loop.RunAllPending(); |
608 EXPECT_EQ("12345", service->last_inquired_extension_id()); | 614 EXPECT_EQ("12345", service->last_inquired_extension_id()); |
609 xmlCleanupGlobals(); | 615 xmlCleanupGlobals(); |
610 | 616 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
646 PendingExtensionManager* pending_extension_manager = | 652 PendingExtensionManager* pending_extension_manager = |
647 service->pending_extension_manager(); | 653 service->pending_extension_manager(); |
648 pending_extension_manager->AddForTesting( | 654 pending_extension_manager->AddForTesting( |
649 id, | 655 id, |
650 PendingExtensionInfo(test_url, &ShouldAlwaysInstall, kIsFromSync, | 656 PendingExtensionInfo(test_url, &ShouldAlwaysInstall, kIsFromSync, |
651 kInstallSilently, | 657 kInstallSilently, |
652 Extension::INTERNAL)); | 658 Extension::INTERNAL)); |
653 } | 659 } |
654 | 660 |
655 // Call back the ExtensionUpdater with a 200 response and some test data | 661 // Call back the ExtensionUpdater with a 200 response and some test data |
656 std::string extension_data("whatever"); | 662 FilePath extension_file_path(FILE_PATH_LITERAL("/whatever")); |
657 fetcher = factory.GetFetcherByID(ExtensionUpdater::kExtensionFetcherId); | 663 fetcher = factory.GetFetcherByID(ExtensionUpdater::kExtensionFetcherId); |
658 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); | 664 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); |
659 EXPECT_TRUE(fetcher->load_flags() == expected_load_flags); | 665 EXPECT_TRUE(fetcher->load_flags() == expected_load_flags); |
660 fetcher->delegate()->OnURLFetchComplete( | 666 |
661 fetcher, test_url, net::URLRequestStatus(), 200, net::ResponseCookies(), | 667 fetcher->set_url(test_url); |
662 extension_data); | 668 fetcher->set_status(net::URLRequestStatus()); |
| 669 fetcher->set_response_code(200); |
| 670 fetcher->SetResponseFilePath(extension_file_path); |
| 671 fetcher->delegate()->OnURLFetchComplete(fetcher); |
663 | 672 |
664 file_thread.Stop(); | 673 file_thread.Stop(); |
665 ui_loop.RunAllPending(); | 674 ui_loop.RunAllPending(); |
666 | 675 |
667 // Expect that ExtensionUpdater asked the mock extensions service to install | 676 // Expect that ExtensionUpdater asked the mock extensions service to install |
668 // a file with the test data for the right id. | 677 // a file with the test data for the right id. |
669 EXPECT_EQ(id, service->extension_id()); | 678 EXPECT_EQ(id, service->extension_id()); |
670 FilePath tmpfile_path = service->install_path(); | 679 FilePath tmpfile_path = service->install_path(); |
671 EXPECT_FALSE(tmpfile_path.empty()); | 680 EXPECT_FALSE(tmpfile_path.empty()); |
672 EXPECT_EQ(test_url, service->download_url()); | 681 EXPECT_EQ(test_url, service->download_url()); |
673 std::string file_contents; | 682 EXPECT_EQ(extension_file_path, tmpfile_path); |
674 EXPECT_TRUE(file_util::ReadFileToString(tmpfile_path, &file_contents)); | |
675 EXPECT_TRUE(extension_data == file_contents); | |
676 | 683 |
677 // The FILE thread is needed for |service|'s cleanup, | 684 // The FILE thread is needed for |service|'s cleanup, |
678 // because of ImportantFileWriter. | 685 // because of ImportantFileWriter. |
679 file_thread.Start(); | 686 file_thread.Start(); |
680 service.reset(); | 687 service.reset(); |
681 | 688 |
682 file_util::Delete(tmpfile_path, false); | |
683 URLFetcher::set_factory(NULL); | 689 URLFetcher::set_factory(NULL); |
684 } | 690 } |
685 | 691 |
686 static void TestBlacklistDownloading() { | 692 static void TestBlacklistDownloading() { |
687 MessageLoop message_loop; | 693 MessageLoop message_loop; |
688 BrowserThread ui_thread(BrowserThread::UI, &message_loop); | 694 BrowserThread ui_thread(BrowserThread::UI, &message_loop); |
689 BrowserThread file_thread(BrowserThread::FILE, &message_loop); | 695 BrowserThread file_thread(BrowserThread::FILE, &message_loop); |
690 BrowserThread io_thread(BrowserThread::IO); | 696 BrowserThread io_thread(BrowserThread::IO); |
691 io_thread.Start(); | 697 io_thread.Start(); |
692 | 698 |
693 TestURLFetcherFactory factory; | 699 TestURLFetcherFactory factory; |
694 TestURLFetcher* fetcher = NULL; | 700 TestURLFetcher* fetcher = NULL; |
695 URLFetcher::set_factory(&factory); | 701 URLFetcher::set_factory(&factory); |
696 ServiceForBlacklistTests service; | 702 ServiceForBlacklistTests service; |
697 ExtensionUpdater updater( | 703 ExtensionUpdater updater( |
698 &service, service.extension_prefs(), service.pref_service(), | 704 &service, service.extension_prefs(), service.pref_service(), |
699 service.profile(), kUpdateFrequencySecs); | 705 service.profile(), kUpdateFrequencySecs); |
700 updater.Start(); | 706 updater.Start(); |
701 GURL test_url("http://localhost/extension.crx"); | 707 GURL test_url("http://localhost/extension.crx"); |
702 | 708 |
703 std::string id = "com.google.crx.blacklist"; | 709 std::string id = "com.google.crx.blacklist"; |
704 | 710 |
705 std::string hash = | 711 std::string hash = |
706 "2CE109E9D0FAF820B2434E166297934E6177B65AB9951DBC3E204CAD4689B39C"; | 712 "2CE109E9D0FAF820B2434E166297934E6177B65AB9951DBC3E204CAD4689B39C"; |
707 | 713 |
708 std::string version = "0.0.1"; | 714 std::string version = "0.0.1"; |
709 updater.FetchUpdatedExtension(id, test_url, hash, version); | 715 updater.FetchUpdatedExtension(id, test_url, hash, version); |
710 | 716 |
711 // Call back the ExtensionUpdater with a 200 response and some test data | 717 // Call back the ExtensionUpdater with a 200 response and some test data. |
712 std::string extension_data("aaabbb"); | 718 std::string extension_data("aaabbb"); |
| 719 |
713 fetcher = factory.GetFetcherByID(ExtensionUpdater::kExtensionFetcherId); | 720 fetcher = factory.GetFetcherByID(ExtensionUpdater::kExtensionFetcherId); |
714 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); | 721 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); |
715 EXPECT_TRUE(fetcher->load_flags() == expected_load_flags); | 722 EXPECT_TRUE(fetcher->load_flags() == expected_load_flags); |
716 fetcher->delegate()->OnURLFetchComplete( | 723 |
717 fetcher, test_url, net::URLRequestStatus(), 200, net::ResponseCookies(), | 724 fetcher->set_url(test_url); |
718 extension_data); | 725 fetcher->set_status(net::URLRequestStatus()); |
| 726 fetcher->set_response_code(200); |
| 727 fetcher->SetResponseString(extension_data); |
| 728 fetcher->delegate()->OnURLFetchComplete(fetcher); |
719 | 729 |
720 message_loop.RunAllPending(); | 730 message_loop.RunAllPending(); |
721 | 731 |
722 // The updater should have called extension service to process the | 732 // The updater should have called extension service to process the |
723 // blacklist. | 733 // blacklist. |
724 EXPECT_TRUE(service.processed_blacklist()); | 734 EXPECT_TRUE(service.processed_blacklist()); |
725 | 735 |
726 EXPECT_EQ(version, service.pref_service()-> | 736 EXPECT_EQ(version, service.pref_service()-> |
727 GetString(prefs::kExtensionBlacklistUpdateVersion)); | 737 GetString(prefs::kExtensionBlacklistUpdateVersion)); |
728 | 738 |
(...skipping 25 matching lines...) Expand all Loading... |
754 std::string hash1 = ""; | 764 std::string hash1 = ""; |
755 std::string hash2 = ""; | 765 std::string hash2 = ""; |
756 | 766 |
757 std::string version1 = "0.1"; | 767 std::string version1 = "0.1"; |
758 std::string version2 = "0.1"; | 768 std::string version2 = "0.1"; |
759 // Start two fetches | 769 // Start two fetches |
760 updater.FetchUpdatedExtension(id1, url1, hash1, version1); | 770 updater.FetchUpdatedExtension(id1, url1, hash1, version1); |
761 updater.FetchUpdatedExtension(id2, url2, hash2, version2); | 771 updater.FetchUpdatedExtension(id2, url2, hash2, version2); |
762 | 772 |
763 // Make the first fetch complete. | 773 // Make the first fetch complete. |
764 std::string extension_data1("whatever"); | 774 FilePath extension_file_path(FILE_PATH_LITERAL("/whatever")); |
| 775 |
765 fetcher = factory.GetFetcherByID(ExtensionUpdater::kExtensionFetcherId); | 776 fetcher = factory.GetFetcherByID(ExtensionUpdater::kExtensionFetcherId); |
766 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); | 777 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); |
767 EXPECT_TRUE(fetcher->load_flags() == expected_load_flags); | 778 EXPECT_TRUE(fetcher->load_flags() == expected_load_flags); |
768 fetcher->delegate()->OnURLFetchComplete( | 779 |
769 fetcher, url1, net::URLRequestStatus(), 200, net::ResponseCookies(), | 780 fetcher->set_url(url1); |
770 extension_data1); | 781 fetcher->set_status(net::URLRequestStatus()); |
| 782 fetcher->set_response_code(200); |
| 783 fetcher->SetResponseFilePath(extension_file_path); |
| 784 fetcher->delegate()->OnURLFetchComplete(fetcher); |
| 785 |
771 message_loop.RunAllPending(); | 786 message_loop.RunAllPending(); |
772 | 787 |
773 // Expect that the service was asked to do an install with the right data. | 788 // Expect that the service was asked to do an install with the right data. |
774 FilePath tmpfile_path = service.install_path(); | 789 FilePath tmpfile_path = service.install_path(); |
775 EXPECT_FALSE(tmpfile_path.empty()); | 790 EXPECT_FALSE(tmpfile_path.empty()); |
776 EXPECT_EQ(id1, service.extension_id()); | 791 EXPECT_EQ(id1, service.extension_id()); |
777 EXPECT_EQ(url1, service.download_url()); | 792 EXPECT_EQ(url1, service.download_url()); |
778 message_loop.RunAllPending(); | 793 message_loop.RunAllPending(); |
779 file_util::Delete(tmpfile_path, false); | |
780 | 794 |
781 // Make sure the second fetch finished and asked the service to do an | 795 // Make sure the second fetch finished and asked the service to do an |
782 // update. | 796 // update. |
783 std::string extension_data2("whatever2"); | 797 FilePath extension_file_path2(FILE_PATH_LITERAL("/whatever2")); |
784 fetcher = factory.GetFetcherByID(ExtensionUpdater::kExtensionFetcherId); | 798 fetcher = factory.GetFetcherByID(ExtensionUpdater::kExtensionFetcherId); |
785 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); | 799 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); |
786 EXPECT_TRUE(fetcher->load_flags() == expected_load_flags); | 800 EXPECT_TRUE(fetcher->load_flags() == expected_load_flags); |
787 fetcher->delegate()->OnURLFetchComplete( | 801 |
788 fetcher, url2, net::URLRequestStatus(), 200, net::ResponseCookies(), | 802 fetcher->set_url(url2); |
789 extension_data2); | 803 fetcher->set_status(net::URLRequestStatus()); |
| 804 fetcher->set_response_code(200); |
| 805 fetcher->SetResponseFilePath(extension_file_path2); |
| 806 fetcher->delegate()->OnURLFetchComplete(fetcher); |
790 message_loop.RunAllPending(); | 807 message_loop.RunAllPending(); |
791 EXPECT_EQ(id2, service.extension_id()); | 808 EXPECT_EQ(id2, service.extension_id()); |
792 EXPECT_EQ(url2, service.download_url()); | 809 EXPECT_EQ(url2, service.download_url()); |
793 EXPECT_FALSE(service.install_path().empty()); | 810 EXPECT_FALSE(service.install_path().empty()); |
794 | 811 |
795 // Make sure the correct crx contents were passed for the update call. | 812 // Make sure the correct crx contents were passed for the update call. |
796 std::string file_contents; | 813 EXPECT_EQ(extension_file_path2, service.install_path()); |
797 EXPECT_TRUE(file_util::ReadFileToString(service.install_path(), | |
798 &file_contents)); | |
799 EXPECT_TRUE(extension_data2 == file_contents); | |
800 file_util::Delete(service.install_path(), false); | |
801 } | 814 } |
802 | 815 |
803 // Test requests to both a Google server and a non-google server. This allows | 816 // Test requests to both a Google server and a non-google server. This allows |
804 // us to test various combinations of installed (ie roll call) and active | 817 // us to test various combinations of installed (ie roll call) and active |
805 // (ie app launch) ping scenarios. The invariant is that each type of ping | 818 // (ie app launch) ping scenarios. The invariant is that each type of ping |
806 // value should be present at most once per day, and can be calculated based | 819 // value should be present at most once per day, and can be calculated based |
807 // on the delta between now and the last ping time (or in the case of active | 820 // on the delta between now and the last ping time (or in the case of active |
808 // pings, that delta plus whether the app has been active). | 821 // pings, that delta plus whether the app has been active). |
809 static void TestGalleryRequests(int rollcall_ping_days, | 822 static void TestGalleryRequests(int rollcall_ping_days, |
810 int active_ping_days, | 823 int active_ping_days, |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
860 updater.set_blacklist_checks_enabled(false); | 873 updater.set_blacklist_checks_enabled(false); |
861 | 874 |
862 // Make the updater do manifest fetching, and note the urls it tries to | 875 // Make the updater do manifest fetching, and note the urls it tries to |
863 // fetch. | 876 // fetch. |
864 std::vector<GURL> fetched_urls; | 877 std::vector<GURL> fetched_urls; |
865 updater.CheckNow(); | 878 updater.CheckNow(); |
866 TestURLFetcher* fetcher = | 879 TestURLFetcher* fetcher = |
867 factory.GetFetcherByID(ExtensionUpdater::kManifestFetcherId); | 880 factory.GetFetcherByID(ExtensionUpdater::kManifestFetcherId); |
868 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); | 881 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); |
869 fetched_urls.push_back(fetcher->original_url()); | 882 fetched_urls.push_back(fetcher->original_url()); |
870 fetcher->delegate()->OnURLFetchComplete( | 883 |
871 fetcher, fetched_urls[0], net::URLRequestStatus(), 500, | 884 fetcher->set_url(fetched_urls[0]); |
872 net::ResponseCookies(), ""); | 885 fetcher->set_status(net::URLRequestStatus()); |
873 fetcher = | 886 fetcher->set_response_code(500); |
874 factory.GetFetcherByID(ExtensionUpdater::kManifestFetcherId); | 887 fetcher->SetResponseString(""); |
| 888 fetcher->delegate()->OnURLFetchComplete(fetcher); |
| 889 |
| 890 fetcher = factory.GetFetcherByID(ExtensionUpdater::kManifestFetcherId); |
875 fetched_urls.push_back(fetcher->original_url()); | 891 fetched_urls.push_back(fetcher->original_url()); |
876 | 892 |
877 // The urls could have been fetched in either order, so use the host to | 893 // The urls could have been fetched in either order, so use the host to |
878 // tell them apart and note the query each used. | 894 // tell them apart and note the query each used. |
879 std::string url1_query; | 895 std::string url1_query; |
880 std::string url2_query; | 896 std::string url2_query; |
881 if (fetched_urls[0].host() == url1.host()) { | 897 if (fetched_urls[0].host() == url1.host()) { |
882 url1_query = fetched_urls[0].query(); | 898 url1_query = fetched_urls[0].query(); |
883 url2_query = fetched_urls[1].query(); | 899 url2_query = fetched_urls[1].query(); |
884 } else if (fetched_urls[0].host() == url2.host()) { | 900 } else if (fetched_urls[0].host() == url2.host()) { |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1138 | 1154 |
1139 // TODO(asargent) - (http://crbug.com/12780) add tests for: | 1155 // TODO(asargent) - (http://crbug.com/12780) add tests for: |
1140 // -prodversionmin (shouldn't update if browser version too old) | 1156 // -prodversionmin (shouldn't update if browser version too old) |
1141 // -manifests & updates arriving out of order / interleaved | 1157 // -manifests & updates arriving out of order / interleaved |
1142 // -malformed update url (empty, file://, has query, has a # fragment, etc.) | 1158 // -malformed update url (empty, file://, has query, has a # fragment, etc.) |
1143 // -An extension gets uninstalled while updates are in progress (so it doesn't | 1159 // -An extension gets uninstalled while updates are in progress (so it doesn't |
1144 // "come back from the dead") | 1160 // "come back from the dead") |
1145 // -An extension gets manually updated to v3 while we're downloading v2 (ie | 1161 // -An extension gets manually updated to v3 while we're downloading v2 (ie |
1146 // you don't get downgraded accidentally) | 1162 // you don't get downgraded accidentally) |
1147 // -An update manifest mentions multiple updates | 1163 // -An update manifest mentions multiple updates |
OLD | NEW |