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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 63 #if defined(OS_CHROMEOS) | 63 #if defined(OS_CHROMEOS) |
| 64 #include "chrome/browser/chromeos/login/user_manager.h" | 64 #include "chrome/browser/chromeos/login/user_manager.h" |
| 65 #include "chrome/browser/chromeos/settings/cros_settings.h" | 65 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 66 #include "chrome/browser/chromeos/settings/device_settings_service.h" | 66 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
| 67 #endif | 67 #endif |
| 68 | 68 |
| 69 using base::Time; | 69 using base::Time; |
| 70 using base::TimeDelta; | 70 using base::TimeDelta; |
| 71 using content::BrowserThread; | 71 using content::BrowserThread; |
| 72 using testing::DoAll; | 72 using testing::DoAll; |
| 73 using testing::Invoke; | |
| 73 using testing::InvokeWithoutArgs; | 74 using testing::InvokeWithoutArgs; |
| 74 using testing::Mock; | 75 using testing::Mock; |
| 75 using testing::Return; | 76 using testing::Return; |
| 76 using testing::SetArgPointee; | 77 using testing::SetArgPointee; |
| 77 using testing::_; | 78 using testing::_; |
| 78 | 79 |
| 79 namespace extensions { | 80 namespace extensions { |
| 80 | 81 |
| 81 typedef ExtensionDownloaderDelegate::Error Error; | 82 typedef ExtensionDownloaderDelegate::Error Error; |
| 82 typedef ExtensionDownloaderDelegate::PingResult PingResult; | 83 typedef ExtensionDownloaderDelegate::PingResult PingResult; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 144 new content::MessageLoopRunner; | 145 new content::MessageLoopRunner; |
| 145 quit_closure_ = runner->QuitClosure(); | 146 quit_closure_ = runner->QuitClosure(); |
| 146 runner->Run(); | 147 runner->Run(); |
| 147 quit_closure_.Reset(); | 148 quit_closure_.Reset(); |
| 148 } | 149 } |
| 149 | 150 |
| 150 void Quit() { | 151 void Quit() { |
| 151 quit_closure_.Run(); | 152 quit_closure_.Run(); |
| 152 } | 153 } |
| 153 | 154 |
| 155 void DelegateTo(ExtensionDownloaderDelegate* delegate) { | |
| 156 ON_CALL(*this, OnExtensionDownloadFailed(_, _, _, _)) | |
| 157 .WillByDefault(Invoke(delegate, | |
| 158 &ExtensionDownloaderDelegate::OnExtensionDownloadFailed)); | |
| 159 ON_CALL(*this, OnExtensionDownloadFinished(_, _, _, _, _, _, _)) | |
| 160 .WillByDefault(Invoke(delegate, | |
| 161 &ExtensionDownloaderDelegate::OnExtensionDownloadFinished)); | |
| 162 ON_CALL(*this, GetPingDataForExtension(_, _)) | |
| 163 .WillByDefault(Invoke(delegate, | |
| 164 &ExtensionDownloaderDelegate::GetPingDataForExtension)); | |
| 165 ON_CALL(*this, GetUpdateUrlData(_)) | |
| 166 .WillByDefault(Invoke(delegate, | |
| 167 &ExtensionDownloaderDelegate::GetUpdateUrlData)); | |
| 168 ON_CALL(*this, IsExtensionPending(_)) | |
| 169 .WillByDefault(Invoke(delegate, | |
| 170 &ExtensionDownloaderDelegate::IsExtensionPending)); | |
| 171 ON_CALL(*this, GetExtensionExistingVersion(_, _)) | |
| 172 .WillByDefault(Invoke(delegate, | |
| 173 &ExtensionDownloaderDelegate::GetExtensionExistingVersion)); | |
|
asargent_no_longer_on_chrome
2014/02/01 00:55:05
ZOMG gtest
| |
| 174 } | |
| 175 | |
| 154 private: | 176 private: |
| 155 base::Closure quit_closure_; | 177 base::Closure quit_closure_; |
| 156 }; | 178 }; |
| 157 | 179 |
| 158 const int kNotificationsObserved[] = { | 180 const int kNotificationsObserved[] = { |
| 159 chrome::NOTIFICATION_EXTENSION_UPDATING_STARTED, | 181 chrome::NOTIFICATION_EXTENSION_UPDATING_STARTED, |
| 160 chrome::NOTIFICATION_EXTENSION_UPDATE_FOUND, | 182 chrome::NOTIFICATION_EXTENSION_UPDATE_FOUND, |
| 161 }; | 183 }; |
| 162 | 184 |
| 163 // A class that observes the notifications sent by the ExtensionUpdater and | 185 // A class that observes the notifications sent by the ExtensionUpdater and |
| (...skipping 795 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 959 EXPECT_TRUE(fetcher->GetLoadFlags() == kExpectedLoadFlags); | 981 EXPECT_TRUE(fetcher->GetLoadFlags() == kExpectedLoadFlags); |
| 960 fetcher->set_url(kUpdateUrl); | 982 fetcher->set_url(kUpdateUrl); |
| 961 fetcher->set_status(net::URLRequestStatus()); | 983 fetcher->set_status(net::URLRequestStatus()); |
| 962 fetcher->set_response_code(400); | 984 fetcher->set_response_code(400); |
| 963 fetcher->delegate()->OnURLFetchComplete(fetcher); | 985 fetcher->delegate()->OnURLFetchComplete(fetcher); |
| 964 RunUntilIdle(); | 986 RunUntilIdle(); |
| 965 | 987 |
| 966 Mock::VerifyAndClearExpectations(&delegate); | 988 Mock::VerifyAndClearExpectations(&delegate); |
| 967 } | 989 } |
| 968 | 990 |
| 969 void TestSingleExtensionDownloading(bool pending, bool retry) { | 991 void TestSingleExtensionDownloading(bool pending, bool retry, bool fail) { |
| 970 net::TestURLFetcherFactory factory; | 992 net::TestURLFetcherFactory factory; |
| 971 net::TestURLFetcher* fetcher = NULL; | 993 net::TestURLFetcher* fetcher = NULL; |
| 972 scoped_ptr<ServiceForDownloadTests> service( | 994 scoped_ptr<ServiceForDownloadTests> service( |
| 973 new ServiceForDownloadTests(prefs_.get())); | 995 new ServiceForDownloadTests(prefs_.get())); |
| 974 ExtensionUpdater updater(service.get(), service->extension_prefs(), | 996 ExtensionUpdater updater(service.get(), service->extension_prefs(), |
| 975 service->pref_service(), | 997 service->pref_service(), |
| 976 service->profile(), | 998 service->profile(), |
| 977 kUpdateFrequencySecs, | 999 kUpdateFrequencySecs, |
| 978 NULL); | 1000 NULL); |
| 979 updater.Start(); | 1001 updater.Start(); |
| 1002 MockExtensionDownloaderDelegate delegate; | |
| 1003 delegate.DelegateTo(&updater); | |
| 980 ResetDownloader( | 1004 ResetDownloader( |
| 981 &updater, | 1005 &updater, |
| 982 new ExtensionDownloader(&updater, service->request_context())); | 1006 new ExtensionDownloader(&delegate, service->request_context())); |
| 983 updater.downloader_->extensions_queue_.set_backoff_policy( | 1007 updater.downloader_->extensions_queue_.set_backoff_policy( |
| 984 &kNoBackoffPolicy); | 1008 &kNoBackoffPolicy); |
| 985 | 1009 |
| 986 GURL test_url("http://localhost/extension.crx"); | 1010 GURL test_url("http://localhost/extension.crx"); |
| 987 | 1011 |
| 988 std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; | 1012 std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; |
| 989 std::string hash; | 1013 std::string hash; |
| 990 Version version("0.0.1"); | 1014 Version version("0.0.1"); |
| 991 std::set<int> requests; | 1015 std::set<int> requests; |
| 992 requests.insert(0); | 1016 requests.insert(0); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1025 | 1049 |
| 1026 RunUntilIdle(); | 1050 RunUntilIdle(); |
| 1027 fetcher = factory.GetFetcherByID( | 1051 fetcher = factory.GetFetcherByID( |
| 1028 ExtensionDownloader::kExtensionFetcherId); | 1052 ExtensionDownloader::kExtensionFetcherId); |
| 1029 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); | 1053 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); |
| 1030 EXPECT_TRUE(fetcher->GetLoadFlags() == kExpectedLoadFlags); | 1054 EXPECT_TRUE(fetcher->GetLoadFlags() == kExpectedLoadFlags); |
| 1031 } | 1055 } |
| 1032 | 1056 |
| 1033 fetcher->set_url(test_url); | 1057 fetcher->set_url(test_url); |
| 1034 fetcher->set_status(net::URLRequestStatus()); | 1058 fetcher->set_status(net::URLRequestStatus()); |
| 1035 fetcher->set_response_code(200); | 1059 if (fail) { |
| 1036 fetcher->SetResponseFilePath(extension_file_path); | 1060 fetcher->set_response_code(404); |
| 1061 EXPECT_CALL(delegate, OnExtensionDownloadFailed(id, _, _, requests)); | |
| 1062 } else { | |
| 1063 fetcher->set_response_code(200); | |
| 1064 fetcher->SetResponseFilePath(extension_file_path); | |
| 1065 EXPECT_CALL(delegate, OnExtensionDownloadFinished( | |
| 1066 id, _, _, _, version.GetString(), _, requests)); | |
| 1067 } | |
| 1037 fetcher->delegate()->OnURLFetchComplete(fetcher); | 1068 fetcher->delegate()->OnURLFetchComplete(fetcher); |
| 1038 | 1069 |
| 1039 RunUntilIdle(); | 1070 RunUntilIdle(); |
| 1040 | 1071 |
| 1041 // Expect that ExtensionUpdater asked the mock extensions service to install | 1072 if (fail) { |
| 1042 // a file with the test data for the right id. | 1073 // Don't expect any extension to have been installed. |
| 1043 EXPECT_EQ(id, service->extension_id()); | 1074 EXPECT_TRUE(service->extension_id().empty()); |
| 1044 base::FilePath tmpfile_path = service->install_path(); | 1075 } else { |
| 1045 EXPECT_FALSE(tmpfile_path.empty()); | 1076 // Expect that ExtensionUpdater asked the mock extensions service to |
| 1046 EXPECT_EQ(test_url, service->download_url()); | 1077 // install a file with the test data for the right id. |
| 1047 EXPECT_EQ(extension_file_path, tmpfile_path); | 1078 EXPECT_EQ(id, service->extension_id()); |
| 1079 base::FilePath tmpfile_path = service->install_path(); | |
| 1080 EXPECT_FALSE(tmpfile_path.empty()); | |
| 1081 EXPECT_EQ(test_url, service->download_url()); | |
| 1082 EXPECT_EQ(extension_file_path, tmpfile_path); | |
| 1083 } | |
| 1048 } | 1084 } |
| 1049 | 1085 |
| 1050 // Two extensions are updated. If |updates_start_running| is true, the | 1086 // Two extensions are updated. If |updates_start_running| is true, the |
| 1051 // mock extensions service has UpdateExtension(...) return true, and | 1087 // mock extensions service has UpdateExtension(...) return true, and |
| 1052 // the test is responsible for creating fake CrxInstallers. Otherwise, | 1088 // the test is responsible for creating fake CrxInstallers. Otherwise, |
| 1053 // UpdateExtension() returns false, signaling install failures. | 1089 // UpdateExtension() returns false, signaling install failures. |
| 1054 void TestMultipleExtensionDownloading(bool updates_start_running) { | 1090 void TestMultipleExtensionDownloading(bool updates_start_running) { |
| 1055 net::TestURLFetcherFactory factory; | 1091 net::TestURLFetcherFactory factory; |
| 1056 net::TestURLFetcher* fetcher = NULL; | 1092 net::TestURLFetcher* fetcher = NULL; |
| 1057 ServiceForDownloadTests service(prefs_.get()); | 1093 ServiceForDownloadTests service(prefs_.get()); |
| (...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1432 | 1468 |
| 1433 TEST_F(ExtensionUpdaterTest, TestDetermineUpdatesPending) { | 1469 TEST_F(ExtensionUpdaterTest, TestDetermineUpdatesPending) { |
| 1434 TestDetermineUpdatesPending(); | 1470 TestDetermineUpdatesPending(); |
| 1435 } | 1471 } |
| 1436 | 1472 |
| 1437 TEST_F(ExtensionUpdaterTest, TestMultipleManifestDownloading) { | 1473 TEST_F(ExtensionUpdaterTest, TestMultipleManifestDownloading) { |
| 1438 TestMultipleManifestDownloading(); | 1474 TestMultipleManifestDownloading(); |
| 1439 } | 1475 } |
| 1440 | 1476 |
| 1441 TEST_F(ExtensionUpdaterTest, TestSingleExtensionDownloading) { | 1477 TEST_F(ExtensionUpdaterTest, TestSingleExtensionDownloading) { |
| 1442 TestSingleExtensionDownloading(false, false); | 1478 TestSingleExtensionDownloading(false, false, false); |
| 1443 } | 1479 } |
| 1444 | 1480 |
| 1445 TEST_F(ExtensionUpdaterTest, TestSingleExtensionDownloadingPending) { | 1481 TEST_F(ExtensionUpdaterTest, TestSingleExtensionDownloadingPending) { |
| 1446 TestSingleExtensionDownloading(true, false); | 1482 TestSingleExtensionDownloading(true, false, false); |
| 1447 } | 1483 } |
| 1448 | 1484 |
| 1449 TEST_F(ExtensionUpdaterTest, TestSingleExtensionDownloadingWithRetry) { | 1485 TEST_F(ExtensionUpdaterTest, TestSingleExtensionDownloadingWithRetry) { |
| 1450 TestSingleExtensionDownloading(false, true); | 1486 TestSingleExtensionDownloading(false, true, false); |
| 1451 } | 1487 } |
| 1452 | 1488 |
| 1453 TEST_F(ExtensionUpdaterTest, TestSingleExtensionDownloadingPendingWithRetry) { | 1489 TEST_F(ExtensionUpdaterTest, TestSingleExtensionDownloadingPendingWithRetry) { |
| 1454 TestSingleExtensionDownloading(true, true); | 1490 TestSingleExtensionDownloading(true, true, false); |
| 1491 } | |
| 1492 | |
| 1493 TEST_F(ExtensionUpdaterTest, TestSingleExtensionDownloadingFailure) { | |
| 1494 TestSingleExtensionDownloading(false, false, true); | |
| 1495 } | |
| 1496 | |
| 1497 TEST_F(ExtensionUpdaterTest, TestSingleExtensionDownloadingFailureWithRetry) { | |
| 1498 TestSingleExtensionDownloading(false, true, true); | |
| 1499 } | |
| 1500 | |
| 1501 TEST_F(ExtensionUpdaterTest, TestSingleExtensionDownloadingFailurePending) { | |
| 1502 TestSingleExtensionDownloading(true, false, true); | |
| 1455 } | 1503 } |
| 1456 | 1504 |
| 1457 TEST_F(ExtensionUpdaterTest, TestMultipleExtensionDownloadingUpdatesFail) { | 1505 TEST_F(ExtensionUpdaterTest, TestMultipleExtensionDownloadingUpdatesFail) { |
| 1458 TestMultipleExtensionDownloading(false); | 1506 TestMultipleExtensionDownloading(false); |
| 1459 } | 1507 } |
| 1460 TEST_F(ExtensionUpdaterTest, TestMultipleExtensionDownloadingUpdatesSucceed) { | 1508 TEST_F(ExtensionUpdaterTest, TestMultipleExtensionDownloadingUpdatesSucceed) { |
| 1461 TestMultipleExtensionDownloading(true); | 1509 TestMultipleExtensionDownloading(true); |
| 1462 } | 1510 } |
| 1463 | 1511 |
| 1464 TEST_F(ExtensionUpdaterTest, TestManifestRetryDownloading) { | 1512 TEST_F(ExtensionUpdaterTest, TestManifestRetryDownloading) { |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1640 // -prodversionmin (shouldn't update if browser version too old) | 1688 // -prodversionmin (shouldn't update if browser version too old) |
| 1641 // -manifests & updates arriving out of order / interleaved | 1689 // -manifests & updates arriving out of order / interleaved |
| 1642 // -malformed update url (empty, file://, has query, has a # fragment, etc.) | 1690 // -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 | 1691 // -An extension gets uninstalled while updates are in progress (so it doesn't |
| 1644 // "come back from the dead") | 1692 // "come back from the dead") |
| 1645 // -An extension gets manually updated to v3 while we're downloading v2 (ie | 1693 // -An extension gets manually updated to v3 while we're downloading v2 (ie |
| 1646 // you don't get downgraded accidentally) | 1694 // you don't get downgraded accidentally) |
| 1647 // -An update manifest mentions multiple updates | 1695 // -An update manifest mentions multiple updates |
| 1648 | 1696 |
| 1649 } // namespace extensions | 1697 } // namespace extensions |
| OLD | NEW |