Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <list> | 5 #include <list> |
| 6 #include <map> | 6 #include <map> |
| 7 #include <set> | 7 #include <set> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 109 false, | 109 false, |
| 110 }; | 110 }; |
| 111 | 111 |
| 112 const char kEmptyUpdateUrlData[] = ""; | 112 const char kEmptyUpdateUrlData[] = ""; |
| 113 | 113 |
| 114 int kExpectedLoadFlags = | 114 int kExpectedLoadFlags = |
| 115 net::LOAD_DO_NOT_SEND_COOKIES | | 115 net::LOAD_DO_NOT_SEND_COOKIES | |
| 116 net::LOAD_DO_NOT_SAVE_COOKIES | | 116 net::LOAD_DO_NOT_SAVE_COOKIES | |
| 117 net::LOAD_DISABLE_CACHE; | 117 net::LOAD_DISABLE_CACHE; |
| 118 | 118 |
| 119 int kExpectedLoadFlagsForProtectedDownload = net::LOAD_DISABLE_CACHE; | |
| 120 | |
| 119 const ManifestFetchData::PingData kNeverPingedData( | 121 const ManifestFetchData::PingData kNeverPingedData( |
| 120 ManifestFetchData::kNeverPinged, ManifestFetchData::kNeverPinged, true); | 122 ManifestFetchData::kNeverPinged, ManifestFetchData::kNeverPinged, true); |
| 121 | 123 |
| 122 class MockExtensionDownloaderDelegate : public ExtensionDownloaderDelegate { | 124 class MockExtensionDownloaderDelegate : public ExtensionDownloaderDelegate { |
| 123 public: | 125 public: |
| 124 MOCK_METHOD4(OnExtensionDownloadFailed, void(const std::string&, | 126 MOCK_METHOD4(OnExtensionDownloadFailed, void(const std::string&, |
| 125 Error, | 127 Error, |
| 126 const PingResult&, | 128 const PingResult&, |
| 127 const std::set<int>&)); | 129 const std::set<int>&)); |
| 128 MOCK_METHOD7(OnExtensionDownloadFinished, void(const std::string&, | 130 MOCK_METHOD7(OnExtensionDownloadFinished, void(const std::string&, |
| (...skipping 911 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1040 | 1042 |
| 1041 // Expect that ExtensionUpdater asked the mock extensions service to install | 1043 // Expect that ExtensionUpdater asked the mock extensions service to install |
| 1042 // a file with the test data for the right id. | 1044 // a file with the test data for the right id. |
| 1043 EXPECT_EQ(id, service->extension_id()); | 1045 EXPECT_EQ(id, service->extension_id()); |
| 1044 base::FilePath tmpfile_path = service->install_path(); | 1046 base::FilePath tmpfile_path = service->install_path(); |
| 1045 EXPECT_FALSE(tmpfile_path.empty()); | 1047 EXPECT_FALSE(tmpfile_path.empty()); |
| 1046 EXPECT_EQ(test_url, service->download_url()); | 1048 EXPECT_EQ(test_url, service->download_url()); |
| 1047 EXPECT_EQ(extension_file_path, tmpfile_path); | 1049 EXPECT_EQ(extension_file_path, tmpfile_path); |
| 1048 } | 1050 } |
| 1049 | 1051 |
| 1052 // Update a single extension in an environment where the download request | |
| 1053 // initially responds with a 403 status. Expect the fetcher to automatically | |
| 1054 // retry with cookies enabled. | |
| 1055 void TestSingleProtectedExtensionDownloading() { | |
| 1056 net::TestURLFetcherFactory factory; | |
| 1057 net::TestURLFetcher* fetcher = NULL; | |
| 1058 scoped_ptr<ServiceForDownloadTests> service( | |
| 1059 new ServiceForDownloadTests(prefs_.get())); | |
| 1060 ExtensionUpdater updater(service.get(), service->extension_prefs(), | |
| 1061 service->pref_service(), | |
| 1062 service->profile(), | |
| 1063 kUpdateFrequencySecs, | |
| 1064 NULL); | |
| 1065 updater.Start(); | |
| 1066 ResetDownloader( | |
| 1067 &updater, | |
| 1068 new ExtensionDownloader(&updater, service->request_context())); | |
| 1069 updater.downloader_->extensions_queue_.set_backoff_policy( | |
| 1070 &kNoBackoffPolicy); | |
| 1071 | |
| 1072 GURL test_url("http://localhost/extension.crx"); | |
| 1073 | |
| 1074 std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; | |
| 1075 std::string hash; | |
| 1076 Version version("0.0.1"); | |
| 1077 std::set<int> requests; | |
| 1078 requests.insert(0); | |
| 1079 scoped_ptr<ExtensionDownloader::ExtensionFetch> fetch( | |
| 1080 new ExtensionDownloader::ExtensionFetch( | |
| 1081 id, test_url, hash, version.GetString(), requests)); | |
| 1082 updater.downloader_->FetchUpdatedExtension(fetch.Pass()); | |
| 1083 | |
| 1084 fetcher = factory.GetFetcherByID(ExtensionDownloader::kExtensionFetcherId); | |
| 1085 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); | |
| 1086 EXPECT_TRUE(fetcher->GetLoadFlags() == kExpectedLoadFlags); | |
| 1087 | |
| 1088 // Fake a 403 response. | |
| 1089 fetcher->set_url(test_url); | |
| 1090 fetcher->set_status(net::URLRequestStatus()); | |
| 1091 fetcher->set_response_code(403); | |
| 1092 fetcher->delegate()->OnURLFetchComplete(fetcher); | |
| 1093 RunUntilIdle(); | |
| 1094 | |
| 1095 // Verify that the fetcher has been switched to protected download mode | |
| 1096 // so that cookies would be sent with the next request. | |
| 1097 fetcher = factory.GetFetcherByID(ExtensionDownloader::kExtensionFetcherId); | |
| 1098 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); | |
| 1099 EXPECT_TRUE( | |
| 1100 fetcher->GetLoadFlags() == kExpectedLoadFlagsForProtectedDownload); | |
| 1101 | |
| 1102 // Attempt to fetch again after the auth failure, but succeed this time. | |
| 1103 base::FilePath extension_file_path(FILE_PATH_LITERAL("/whatever")); | |
| 1104 fetcher->set_url(test_url); | |
| 1105 fetcher->set_status(net::URLRequestStatus()); | |
| 1106 fetcher->set_response_code(200); | |
| 1107 fetcher->SetResponseFilePath(extension_file_path); | |
| 1108 fetcher->delegate()->OnURLFetchComplete(fetcher); | |
| 1109 | |
| 1110 RunUntilIdle(); | |
| 1111 | |
| 1112 // Verify installation would proceed as normal. | |
| 1113 EXPECT_EQ(id, service->extension_id()); | |
| 1114 base::FilePath tmpfile_path = service->install_path(); | |
| 1115 EXPECT_FALSE(tmpfile_path.empty()); | |
| 1116 EXPECT_EQ(test_url, service->download_url()); | |
| 1117 EXPECT_EQ(extension_file_path, tmpfile_path); | |
| 1118 } | |
| 1119 | |
|
asargent_no_longer_on_chrome
2014/01/31 18:22:26
Can you also add a test that proves that going int
Ken Rockot(use gerrit already)
2014/01/31 22:12:58
Done. Also added a test to verify that non-https d
| |
| 1050 // Two extensions are updated. If |updates_start_running| is true, the | 1120 // Two extensions are updated. If |updates_start_running| is true, the |
| 1051 // mock extensions service has UpdateExtension(...) return true, and | 1121 // mock extensions service has UpdateExtension(...) return true, and |
| 1052 // the test is responsible for creating fake CrxInstallers. Otherwise, | 1122 // the test is responsible for creating fake CrxInstallers. Otherwise, |
| 1053 // UpdateExtension() returns false, signaling install failures. | 1123 // UpdateExtension() returns false, signaling install failures. |
| 1054 void TestMultipleExtensionDownloading(bool updates_start_running) { | 1124 void TestMultipleExtensionDownloading(bool updates_start_running) { |
| 1055 net::TestURLFetcherFactory factory; | 1125 net::TestURLFetcherFactory factory; |
| 1056 net::TestURLFetcher* fetcher = NULL; | 1126 net::TestURLFetcher* fetcher = NULL; |
| 1057 ServiceForDownloadTests service(prefs_.get()); | 1127 ServiceForDownloadTests service(prefs_.get()); |
| 1058 ExtensionUpdater updater( | 1128 ExtensionUpdater updater( |
| 1059 &service, service.extension_prefs(), service.pref_service(), | 1129 &service, service.extension_prefs(), service.pref_service(), |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1447 } | 1517 } |
| 1448 | 1518 |
| 1449 TEST_F(ExtensionUpdaterTest, TestSingleExtensionDownloadingWithRetry) { | 1519 TEST_F(ExtensionUpdaterTest, TestSingleExtensionDownloadingWithRetry) { |
| 1450 TestSingleExtensionDownloading(false, true); | 1520 TestSingleExtensionDownloading(false, true); |
| 1451 } | 1521 } |
| 1452 | 1522 |
| 1453 TEST_F(ExtensionUpdaterTest, TestSingleExtensionDownloadingPendingWithRetry) { | 1523 TEST_F(ExtensionUpdaterTest, TestSingleExtensionDownloadingPendingWithRetry) { |
| 1454 TestSingleExtensionDownloading(true, true); | 1524 TestSingleExtensionDownloading(true, true); |
| 1455 } | 1525 } |
| 1456 | 1526 |
| 1527 TEST_F(ExtensionUpdaterTest, TestSingleProtectedExtensionDownloading) { | |
| 1528 TestSingleProtectedExtensionDownloading(); | |
| 1529 } | |
| 1530 | |
| 1457 TEST_F(ExtensionUpdaterTest, TestMultipleExtensionDownloadingUpdatesFail) { | 1531 TEST_F(ExtensionUpdaterTest, TestMultipleExtensionDownloadingUpdatesFail) { |
| 1458 TestMultipleExtensionDownloading(false); | 1532 TestMultipleExtensionDownloading(false); |
| 1459 } | 1533 } |
| 1460 TEST_F(ExtensionUpdaterTest, TestMultipleExtensionDownloadingUpdatesSucceed) { | 1534 TEST_F(ExtensionUpdaterTest, TestMultipleExtensionDownloadingUpdatesSucceed) { |
| 1461 TestMultipleExtensionDownloading(true); | 1535 TestMultipleExtensionDownloading(true); |
| 1462 } | 1536 } |
| 1463 | 1537 |
| 1464 TEST_F(ExtensionUpdaterTest, TestManifestRetryDownloading) { | 1538 TEST_F(ExtensionUpdaterTest, TestManifestRetryDownloading) { |
| 1465 TestManifestRetryDownloading(); | 1539 TestManifestRetryDownloading(); |
| 1466 } | 1540 } |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1640 // -prodversionmin (shouldn't update if browser version too old) | 1714 // -prodversionmin (shouldn't update if browser version too old) |
| 1641 // -manifests & updates arriving out of order / interleaved | 1715 // -manifests & updates arriving out of order / interleaved |
| 1642 // -malformed update url (empty, file://, has query, has a # fragment, etc.) | 1716 // -malformed update url (empty, file://, has query, has a # fragment, etc.) |
| 1643 // -An extension gets uninstalled while updates are in progress (so it doesn't | 1717 // -An extension gets uninstalled while updates are in progress (so it doesn't |
| 1644 // "come back from the dead") | 1718 // "come back from the dead") |
| 1645 // -An extension gets manually updated to v3 while we're downloading v2 (ie | 1719 // -An extension gets manually updated to v3 while we're downloading v2 (ie |
| 1646 // you don't get downgraded accidentally) | 1720 // you don't get downgraded accidentally) |
| 1647 // -An update manifest mentions multiple updates | 1721 // -An update manifest mentions multiple updates |
| 1648 | 1722 |
| 1649 } // namespace extensions | 1723 } // namespace extensions |
| OLD | NEW |