| 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 #include "extensions/common/id_util.h" | 53 #include "extensions/common/id_util.h" |
| 54 #include "extensions/common/manifest_constants.h" | 54 #include "extensions/common/manifest_constants.h" |
| 55 #include "libxml/globals.h" | 55 #include "libxml/globals.h" |
| 56 #include "net/base/backoff_entry.h" | 56 #include "net/base/backoff_entry.h" |
| 57 #include "net/base/escape.h" | 57 #include "net/base/escape.h" |
| 58 #include "net/base/load_flags.h" | 58 #include "net/base/load_flags.h" |
| 59 #include "net/url_request/test_url_fetcher_factory.h" | 59 #include "net/url_request/test_url_fetcher_factory.h" |
| 60 #include "net/url_request/url_request_status.h" | 60 #include "net/url_request/url_request_status.h" |
| 61 #include "testing/gmock/include/gmock/gmock.h" | 61 #include "testing/gmock/include/gmock/gmock.h" |
| 62 #include "testing/gtest/include/gtest/gtest.h" | 62 #include "testing/gtest/include/gtest/gtest.h" |
| 63 #include "url/third_party/mozilla/url_parse.h" |
| 63 | 64 |
| 64 #if defined(OS_CHROMEOS) | 65 #if defined(OS_CHROMEOS) |
| 65 #include "chrome/browser/chromeos/login/user_manager.h" | 66 #include "chrome/browser/chromeos/login/user_manager.h" |
| 66 #include "chrome/browser/chromeos/settings/cros_settings.h" | 67 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 67 #include "chrome/browser/chromeos/settings/device_settings_service.h" | 68 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
| 68 #endif | 69 #endif |
| 69 | 70 |
| 70 using base::Time; | 71 using base::Time; |
| 71 using base::TimeDelta; | 72 using base::TimeDelta; |
| 72 using content::BrowserThread; | 73 using content::BrowserThread; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 // Time to keep an entry from being discarded even when it | 107 // Time to keep an entry from being discarded even when it |
| 107 // has no significant state, -1 to never discard. | 108 // has no significant state, -1 to never discard. |
| 108 -1, | 109 -1, |
| 109 | 110 |
| 110 // Don't use initial delay unless the last request was an error. | 111 // Don't use initial delay unless the last request was an error. |
| 111 false, | 112 false, |
| 112 }; | 113 }; |
| 113 | 114 |
| 114 const char kEmptyUpdateUrlData[] = ""; | 115 const char kEmptyUpdateUrlData[] = ""; |
| 115 | 116 |
| 117 const char kAuthUserQueryKey[] = "authuser"; |
| 118 |
| 116 int kExpectedLoadFlags = | 119 int kExpectedLoadFlags = |
| 117 net::LOAD_DO_NOT_SEND_COOKIES | | 120 net::LOAD_DO_NOT_SEND_COOKIES | |
| 118 net::LOAD_DO_NOT_SAVE_COOKIES | | 121 net::LOAD_DO_NOT_SAVE_COOKIES | |
| 119 net::LOAD_DISABLE_CACHE; | 122 net::LOAD_DISABLE_CACHE; |
| 120 | 123 |
| 121 int kExpectedLoadFlagsForProtectedDownload = net::LOAD_DISABLE_CACHE; | 124 int kExpectedLoadFlagsForProtectedDownload = net::LOAD_DISABLE_CACHE; |
| 122 | 125 |
| 123 const ManifestFetchData::PingData kNeverPingedData( | 126 const ManifestFetchData::PingData kNeverPingedData( |
| 124 ManifestFetchData::kNeverPinged, ManifestFetchData::kNeverPinged, true); | 127 ManifestFetchData::kNeverPinged, ManifestFetchData::kNeverPinged, true); |
| 125 | 128 |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 } | 244 } |
| 242 | 245 |
| 243 content::NotificationRegistrar registrar_; | 246 content::NotificationRegistrar registrar_; |
| 244 size_t count_[arraysize(kNotificationsObserved)]; | 247 size_t count_[arraysize(kNotificationsObserved)]; |
| 245 std::set<std::string> updated_; | 248 std::set<std::string> updated_; |
| 246 base::Closure quit_closure_; | 249 base::Closure quit_closure_; |
| 247 | 250 |
| 248 DISALLOW_COPY_AND_ASSIGN(NotificationsObserver); | 251 DISALLOW_COPY_AND_ASSIGN(NotificationsObserver); |
| 249 }; | 252 }; |
| 250 | 253 |
| 254 // Extracts the integer value of the |authuser| query parameter. Returns 0 if |
| 255 // the parameter is not set. |
| 256 int GetAuthUserQueryValue(const GURL& url) { |
| 257 std::string query_string = url.query(); |
| 258 url::Component query(0, query_string.length()); |
| 259 url::Component key, value; |
| 260 while ( |
| 261 url::ExtractQueryKeyValue(query_string.c_str(), &query, &key, &value)) { |
| 262 std::string key_string = query_string.substr(key.begin, key.len); |
| 263 if (key_string == kAuthUserQueryKey) { |
| 264 int user_index = 0; |
| 265 base::StringToInt(query_string.substr(value.begin, value.len), |
| 266 &user_index); |
| 267 return user_index; |
| 268 } |
| 269 } |
| 270 return 0; |
| 271 } |
| 272 |
| 251 } // namespace | 273 } // namespace |
| 252 | 274 |
| 253 // Base class for further specialized test classes. | 275 // Base class for further specialized test classes. |
| 254 class MockService : public TestExtensionService { | 276 class MockService : public TestExtensionService { |
| 255 public: | 277 public: |
| 256 explicit MockService(TestExtensionPrefs* prefs) | 278 explicit MockService(TestExtensionPrefs* prefs) |
| 257 : prefs_(prefs), pending_extension_manager_(*this, &profile_) {} | 279 : prefs_(prefs), pending_extension_manager_(*this, &profile_) {} |
| 258 | 280 |
| 259 virtual ~MockService() {} | 281 virtual ~MockService() {} |
| 260 | 282 |
| (...skipping 814 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1075 EXPECT_EQ(id, service->extension_id()); | 1097 EXPECT_EQ(id, service->extension_id()); |
| 1076 base::FilePath tmpfile_path = service->install_path(); | 1098 base::FilePath tmpfile_path = service->install_path(); |
| 1077 EXPECT_FALSE(tmpfile_path.empty()); | 1099 EXPECT_FALSE(tmpfile_path.empty()); |
| 1078 EXPECT_EQ(extension_file_path, tmpfile_path); | 1100 EXPECT_EQ(extension_file_path, tmpfile_path); |
| 1079 } | 1101 } |
| 1080 } | 1102 } |
| 1081 | 1103 |
| 1082 // Update a single extension in an environment where the download request | 1104 // Update a single extension in an environment where the download request |
| 1083 // initially responds with a 403 status. Expect the fetcher to automatically | 1105 // initially responds with a 403 status. Expect the fetcher to automatically |
| 1084 // retry with cookies enabled. | 1106 // retry with cookies enabled. |
| 1085 void TestSingleProtectedExtensionDownloading(bool use_https, bool fail) { | 1107 void TestSingleProtectedExtensionDownloading(bool use_https, |
| 1108 bool fail, |
| 1109 int max_authuser, |
| 1110 int valid_authuser) { |
| 1086 net::TestURLFetcherFactory factory; | 1111 net::TestURLFetcherFactory factory; |
| 1087 net::TestURLFetcher* fetcher = NULL; | 1112 net::TestURLFetcher* fetcher = NULL; |
| 1088 scoped_ptr<ServiceForDownloadTests> service( | 1113 scoped_ptr<ServiceForDownloadTests> service( |
| 1089 new ServiceForDownloadTests(prefs_.get())); | 1114 new ServiceForDownloadTests(prefs_.get())); |
| 1090 ExtensionUpdater updater(service.get(), service->extension_prefs(), | 1115 ExtensionUpdater updater(service.get(), service->extension_prefs(), |
| 1091 service->pref_service(), | 1116 service->pref_service(), |
| 1092 service->profile(), | 1117 service->profile(), |
| 1093 kUpdateFrequencySecs, | 1118 kUpdateFrequencySecs, |
| 1094 NULL); | 1119 NULL); |
| 1095 updater.Start(); | 1120 updater.Start(); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1128 fetcher = factory.GetFetcherByID(ExtensionDownloader::kExtensionFetcherId); | 1153 fetcher = factory.GetFetcherByID(ExtensionDownloader::kExtensionFetcherId); |
| 1129 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); | 1154 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); |
| 1130 if (use_https) { | 1155 if (use_https) { |
| 1131 EXPECT_TRUE( | 1156 EXPECT_TRUE( |
| 1132 fetcher->GetLoadFlags() == kExpectedLoadFlagsForProtectedDownload); | 1157 fetcher->GetLoadFlags() == kExpectedLoadFlagsForProtectedDownload); |
| 1133 } else { | 1158 } else { |
| 1134 EXPECT_TRUE(fetcher->GetLoadFlags() == kExpectedLoadFlags); | 1159 EXPECT_TRUE(fetcher->GetLoadFlags() == kExpectedLoadFlags); |
| 1135 } | 1160 } |
| 1136 | 1161 |
| 1137 // Attempt to fetch again after the auth failure. | 1162 // Attempt to fetch again after the auth failure. |
| 1163 bool succeed = !fail; |
| 1138 if (fail) { | 1164 if (fail) { |
| 1139 // Fail and verify that the fetch queue is cleared. | 1165 // Do not simulate incremental authuser retries. |
| 1140 fetcher->set_url(test_url); | 1166 if (max_authuser == 0) { |
| 1141 fetcher->set_status(net::URLRequestStatus()); | 1167 // Fail and verify that the fetch queue is cleared. |
| 1142 fetcher->set_response_code(403); | 1168 fetcher->set_url(test_url); |
| 1143 fetcher->delegate()->OnURLFetchComplete(fetcher); | 1169 fetcher->set_status(net::URLRequestStatus()); |
| 1144 RunUntilIdle(); | 1170 fetcher->set_response_code(401); |
| 1145 EXPECT_EQ(0U, updater.downloader_->extensions_queue_.active_request()); | 1171 fetcher->delegate()->OnURLFetchComplete(fetcher); |
| 1146 } else { | 1172 RunUntilIdle(); |
| 1147 // Succeed | 1173 |
| 1174 EXPECT_EQ(0U, updater.downloader_->extensions_queue_.active_request()); |
| 1175 return; |
| 1176 } |
| 1177 |
| 1178 // Simulate incremental authuser retries. |
| 1179 for (int user_index = 0; user_index <= max_authuser; ++user_index) { |
| 1180 const ExtensionDownloader::ExtensionFetch& fetch = |
| 1181 *updater.downloader_->extensions_queue_.active_request(); |
| 1182 EXPECT_EQ(user_index, GetAuthUserQueryValue(fetch.url)); |
| 1183 if (user_index == valid_authuser) { |
| 1184 succeed = true; |
| 1185 break; |
| 1186 } |
| 1187 fetcher->set_url(fetch.url); |
| 1188 fetcher->set_status(net::URLRequestStatus()); |
| 1189 fetcher->set_response_code(403); |
| 1190 fetcher->delegate()->OnURLFetchComplete(fetcher); |
| 1191 RunUntilIdle(); |
| 1192 } |
| 1193 } |
| 1194 |
| 1195 // Succeed |
| 1196 if (succeed) { |
| 1148 base::FilePath extension_file_path(FILE_PATH_LITERAL("/whatever")); | 1197 base::FilePath extension_file_path(FILE_PATH_LITERAL("/whatever")); |
| 1149 fetcher->set_url(test_url); | 1198 fetcher->set_url(test_url); |
| 1150 fetcher->set_status(net::URLRequestStatus()); | 1199 fetcher->set_status(net::URLRequestStatus()); |
| 1151 fetcher->set_response_code(200); | 1200 fetcher->set_response_code(200); |
| 1152 fetcher->SetResponseFilePath(extension_file_path); | 1201 fetcher->SetResponseFilePath(extension_file_path); |
| 1153 fetcher->delegate()->OnURLFetchComplete(fetcher); | 1202 fetcher->delegate()->OnURLFetchComplete(fetcher); |
| 1154 RunUntilIdle(); | 1203 RunUntilIdle(); |
| 1155 | 1204 |
| 1156 // Verify installation would proceed as normal. | 1205 // Verify installation would proceed as normal. |
| 1157 EXPECT_EQ(id, service->extension_id()); | 1206 EXPECT_EQ(id, service->extension_id()); |
| (...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1578 } | 1627 } |
| 1579 | 1628 |
| 1580 TEST_F(ExtensionUpdaterTest, TestSingleExtensionDownloadingFailureWithRetry) { | 1629 TEST_F(ExtensionUpdaterTest, TestSingleExtensionDownloadingFailureWithRetry) { |
| 1581 TestSingleExtensionDownloading(false, true, true); | 1630 TestSingleExtensionDownloading(false, true, true); |
| 1582 } | 1631 } |
| 1583 | 1632 |
| 1584 TEST_F(ExtensionUpdaterTest, TestSingleExtensionDownloadingFailurePending) { | 1633 TEST_F(ExtensionUpdaterTest, TestSingleExtensionDownloadingFailurePending) { |
| 1585 TestSingleExtensionDownloading(true, false, true); | 1634 TestSingleExtensionDownloading(true, false, true); |
| 1586 } | 1635 } |
| 1587 | 1636 |
| 1588 TEST_F(ExtensionUpdaterTest, TestSingleProtectedExtensionDownloading) { | 1637 TEST_F(ExtensionUpdaterTest, SingleProtectedExtensionDownloading) { |
| 1589 TestSingleProtectedExtensionDownloading(true, false); | 1638 TestSingleProtectedExtensionDownloading(true, false, 0, 0); |
| 1590 } | 1639 } |
| 1591 | 1640 |
| 1592 TEST_F(ExtensionUpdaterTest, TestSingleProtectedExtensionDownloadingFailure) { | 1641 TEST_F(ExtensionUpdaterTest, SingleProtectedExtensionDownloadingFailure) { |
| 1593 TestSingleProtectedExtensionDownloading(true, true); | 1642 TestSingleProtectedExtensionDownloading(true, true, 0, 0); |
| 1594 } | 1643 } |
| 1595 | 1644 |
| 1596 TEST_F(ExtensionUpdaterTest, TestSingleProtectedExtensionDownloadingNoHTTPS) { | 1645 TEST_F(ExtensionUpdaterTest, SingleProtectedExtensionDownloadingNoHTTPS) { |
| 1597 TestSingleProtectedExtensionDownloading(false, false); | 1646 TestSingleProtectedExtensionDownloading(false, false, 0, 0); |
| 1647 } |
| 1648 |
| 1649 TEST_F(ExtensionUpdaterTest, |
| 1650 SingleProtectedExtensionDownloadingWithNonDefaultAuthUser1) { |
| 1651 TestSingleProtectedExtensionDownloading(true, true, 2, 1); |
| 1652 } |
| 1653 |
| 1654 TEST_F(ExtensionUpdaterTest, |
| 1655 SingleProtectedExtensionDownloadingWithNonDefaultAuthUser2) { |
| 1656 TestSingleProtectedExtensionDownloading(true, true, 2, 2); |
| 1657 } |
| 1658 |
| 1659 TEST_F(ExtensionUpdaterTest, |
| 1660 SingleProtectedExtensionDownloadingAuthUserExhaustionFailure) { |
| 1661 TestSingleProtectedExtensionDownloading(true, true, 2, 5); |
| 1598 } | 1662 } |
| 1599 | 1663 |
| 1600 TEST_F(ExtensionUpdaterTest, TestMultipleExtensionDownloadingUpdatesFail) { | 1664 TEST_F(ExtensionUpdaterTest, TestMultipleExtensionDownloadingUpdatesFail) { |
| 1601 TestMultipleExtensionDownloading(false); | 1665 TestMultipleExtensionDownloading(false); |
| 1602 } | 1666 } |
| 1603 TEST_F(ExtensionUpdaterTest, TestMultipleExtensionDownloadingUpdatesSucceed) { | 1667 TEST_F(ExtensionUpdaterTest, TestMultipleExtensionDownloadingUpdatesSucceed) { |
| 1604 TestMultipleExtensionDownloading(true); | 1668 TestMultipleExtensionDownloading(true); |
| 1605 } | 1669 } |
| 1606 | 1670 |
| 1607 TEST_F(ExtensionUpdaterTest, TestManifestRetryDownloading) { | 1671 TEST_F(ExtensionUpdaterTest, TestManifestRetryDownloading) { |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1782 // -prodversionmin (shouldn't update if browser version too old) | 1846 // -prodversionmin (shouldn't update if browser version too old) |
| 1783 // -manifests & updates arriving out of order / interleaved | 1847 // -manifests & updates arriving out of order / interleaved |
| 1784 // -malformed update url (empty, file://, has query, has a # fragment, etc.) | 1848 // -malformed update url (empty, file://, has query, has a # fragment, etc.) |
| 1785 // -An extension gets uninstalled while updates are in progress (so it doesn't | 1849 // -An extension gets uninstalled while updates are in progress (so it doesn't |
| 1786 // "come back from the dead") | 1850 // "come back from the dead") |
| 1787 // -An extension gets manually updated to v3 while we're downloading v2 (ie | 1851 // -An extension gets manually updated to v3 while we're downloading v2 (ie |
| 1788 // you don't get downgraded accidentally) | 1852 // you don't get downgraded accidentally) |
| 1789 // -An update manifest mentions multiple updates | 1853 // -An update manifest mentions multiple updates |
| 1790 | 1854 |
| 1791 } // namespace extensions | 1855 } // namespace extensions |
| OLD | NEW |