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 (url::ExtractQueryKeyValue( | |
261 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( |
1108 bool use_https, | |
1109 bool fail, | |
1110 int max_authuser, | |
1111 int valid_authuser) { | |
1086 net::TestURLFetcherFactory factory; | 1112 net::TestURLFetcherFactory factory; |
1087 net::TestURLFetcher* fetcher = NULL; | 1113 net::TestURLFetcher* fetcher = NULL; |
1088 scoped_ptr<ServiceForDownloadTests> service( | 1114 scoped_ptr<ServiceForDownloadTests> service( |
1089 new ServiceForDownloadTests(prefs_.get())); | 1115 new ServiceForDownloadTests(prefs_.get())); |
1090 ExtensionUpdater updater(service.get(), service->extension_prefs(), | 1116 ExtensionUpdater updater(service.get(), service->extension_prefs(), |
1091 service->pref_service(), | 1117 service->pref_service(), |
1092 service->profile(), | 1118 service->profile(), |
1093 kUpdateFrequencySecs, | 1119 kUpdateFrequencySecs, |
1094 NULL); | 1120 NULL); |
1095 updater.Start(); | 1121 updater.Start(); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1128 fetcher = factory.GetFetcherByID(ExtensionDownloader::kExtensionFetcherId); | 1154 fetcher = factory.GetFetcherByID(ExtensionDownloader::kExtensionFetcherId); |
1129 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); | 1155 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); |
1130 if (use_https) { | 1156 if (use_https) { |
1131 EXPECT_TRUE( | 1157 EXPECT_TRUE( |
1132 fetcher->GetLoadFlags() == kExpectedLoadFlagsForProtectedDownload); | 1158 fetcher->GetLoadFlags() == kExpectedLoadFlagsForProtectedDownload); |
1133 } else { | 1159 } else { |
1134 EXPECT_TRUE(fetcher->GetLoadFlags() == kExpectedLoadFlags); | 1160 EXPECT_TRUE(fetcher->GetLoadFlags() == kExpectedLoadFlags); |
1135 } | 1161 } |
1136 | 1162 |
1137 // Attempt to fetch again after the auth failure. | 1163 // Attempt to fetch again after the auth failure. |
1164 bool succeed = !fail; | |
1138 if (fail) { | 1165 if (fail) { |
1139 // Fail and verify that the fetch queue is cleared. | 1166 // Do not simulate incremental authuser retries. |
1140 fetcher->set_url(test_url); | 1167 if (max_authuser == 0) { |
1141 fetcher->set_status(net::URLRequestStatus()); | 1168 // Fail and verify that the fetch queue is cleared. |
1142 fetcher->set_response_code(403); | 1169 fetcher->set_url(test_url); |
1143 fetcher->delegate()->OnURLFetchComplete(fetcher); | 1170 fetcher->set_status(net::URLRequestStatus()); |
1144 RunUntilIdle(); | 1171 fetcher->set_response_code(401); |
1145 EXPECT_EQ(0U, updater.downloader_->extensions_queue_.active_request()); | 1172 fetcher->delegate()->OnURLFetchComplete(fetcher); |
1146 } else { | 1173 RunUntilIdle(); |
1147 // Succeed | 1174 |
1175 EXPECT_EQ(0U, updater.downloader_->extensions_queue_.active_request()); | |
1176 return; | |
1177 } | |
1178 | |
1179 // Simulate incremental authuser retries. | |
1180 for (int user_index = 0; user_index <= max_authuser; ++user_index) { | |
1181 const ExtensionDownloader::ExtensionFetch& fetch = | |
1182 *updater.downloader_->extensions_queue_.active_request(); | |
1183 EXPECT_EQ(user_index, GetAuthUserQueryValue(fetch.url)); | |
1184 if (user_index == valid_authuser) { | |
1185 succeed = true; | |
1186 break; | |
1187 } | |
1188 fetcher->set_url(fetch.url); | |
1189 fetcher->set_status(net::URLRequestStatus()); | |
1190 fetcher->set_response_code(403); | |
1191 fetcher->delegate()->OnURLFetchComplete(fetcher); | |
1192 RunUntilIdle(); | |
1193 } | |
1194 } | |
1195 | |
1196 // Succeed | |
1197 if (succeed) { | |
1148 base::FilePath extension_file_path(FILE_PATH_LITERAL("/whatever")); | 1198 base::FilePath extension_file_path(FILE_PATH_LITERAL("/whatever")); |
1149 fetcher->set_url(test_url); | 1199 fetcher->set_url(test_url); |
1150 fetcher->set_status(net::URLRequestStatus()); | 1200 fetcher->set_status(net::URLRequestStatus()); |
1151 fetcher->set_response_code(200); | 1201 fetcher->set_response_code(200); |
1152 fetcher->SetResponseFilePath(extension_file_path); | 1202 fetcher->SetResponseFilePath(extension_file_path); |
1153 fetcher->delegate()->OnURLFetchComplete(fetcher); | 1203 fetcher->delegate()->OnURLFetchComplete(fetcher); |
1154 RunUntilIdle(); | 1204 RunUntilIdle(); |
1155 | 1205 |
1156 // Verify installation would proceed as normal. | 1206 // Verify installation would proceed as normal. |
1157 EXPECT_EQ(id, service->extension_id()); | 1207 EXPECT_EQ(id, service->extension_id()); |
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1579 | 1629 |
1580 TEST_F(ExtensionUpdaterTest, TestSingleExtensionDownloadingFailureWithRetry) { | 1630 TEST_F(ExtensionUpdaterTest, TestSingleExtensionDownloadingFailureWithRetry) { |
1581 TestSingleExtensionDownloading(false, true, true); | 1631 TestSingleExtensionDownloading(false, true, true); |
1582 } | 1632 } |
1583 | 1633 |
1584 TEST_F(ExtensionUpdaterTest, TestSingleExtensionDownloadingFailurePending) { | 1634 TEST_F(ExtensionUpdaterTest, TestSingleExtensionDownloadingFailurePending) { |
1585 TestSingleExtensionDownloading(true, false, true); | 1635 TestSingleExtensionDownloading(true, false, true); |
1586 } | 1636 } |
1587 | 1637 |
1588 TEST_F(ExtensionUpdaterTest, TestSingleProtectedExtensionDownloading) { | 1638 TEST_F(ExtensionUpdaterTest, TestSingleProtectedExtensionDownloading) { |
1589 TestSingleProtectedExtensionDownloading(true, false); | 1639 TestSingleProtectedExtensionDownloading(true, false, 0, 0); |
1590 } | 1640 } |
1591 | 1641 |
1592 TEST_F(ExtensionUpdaterTest, TestSingleProtectedExtensionDownloadingFailure) { | 1642 TEST_F(ExtensionUpdaterTest, TestSingleProtectedExtensionDownloadingFailure) { |
1593 TestSingleProtectedExtensionDownloading(true, true); | 1643 TestSingleProtectedExtensionDownloading(true, true, 0, 0); |
1594 } | 1644 } |
1595 | 1645 |
1596 TEST_F(ExtensionUpdaterTest, TestSingleProtectedExtensionDownloadingNoHTTPS) { | 1646 TEST_F(ExtensionUpdaterTest, TestSingleProtectedExtensionDownloadingNoHTTPS) { |
1597 TestSingleProtectedExtensionDownloading(false, false); | 1647 TestSingleProtectedExtensionDownloading(false, false, 0, 0); |
1648 } | |
1649 | |
1650 TEST_F(ExtensionUpdaterTest, TestSingleProtectedExtensionDownloadingWithNonDefau ltAuthUser1) { | |
asargent_no_longer_on_chrome
2014/05/08 04:27:11
nit: Can probably omit the prefix "Test" from the
Ken Rockot(use gerrit already)
2014/05/08 05:23:09
Done.
| |
1651 TestSingleProtectedExtensionDownloading(true, true, 2, 1); | |
1652 } | |
1653 | |
1654 TEST_F(ExtensionUpdaterTest, TestSingleProtectedExtensionDownloadingWithNonDefau ltAuthUser2) { | |
1655 TestSingleProtectedExtensionDownloading(true, true, 2, 2); | |
1656 } | |
1657 | |
1658 TEST_F(ExtensionUpdaterTest, TestSingleProtectedExtensionDownloadingAuthUserExha ustionFailure) { | |
1659 TestSingleProtectedExtensionDownloading(true, true, 2, 5); | |
1598 } | 1660 } |
1599 | 1661 |
1600 TEST_F(ExtensionUpdaterTest, TestMultipleExtensionDownloadingUpdatesFail) { | 1662 TEST_F(ExtensionUpdaterTest, TestMultipleExtensionDownloadingUpdatesFail) { |
1601 TestMultipleExtensionDownloading(false); | 1663 TestMultipleExtensionDownloading(false); |
1602 } | 1664 } |
1603 TEST_F(ExtensionUpdaterTest, TestMultipleExtensionDownloadingUpdatesSucceed) { | 1665 TEST_F(ExtensionUpdaterTest, TestMultipleExtensionDownloadingUpdatesSucceed) { |
1604 TestMultipleExtensionDownloading(true); | 1666 TestMultipleExtensionDownloading(true); |
1605 } | 1667 } |
1606 | 1668 |
1607 TEST_F(ExtensionUpdaterTest, TestManifestRetryDownloading) { | 1669 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) | 1844 // -prodversionmin (shouldn't update if browser version too old) |
1783 // -manifests & updates arriving out of order / interleaved | 1845 // -manifests & updates arriving out of order / interleaved |
1784 // -malformed update url (empty, file://, has query, has a # fragment, etc.) | 1846 // -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 | 1847 // -An extension gets uninstalled while updates are in progress (so it doesn't |
1786 // "come back from the dead") | 1848 // "come back from the dead") |
1787 // -An extension gets manually updated to v3 while we're downloading v2 (ie | 1849 // -An extension gets manually updated to v3 while we're downloading v2 (ie |
1788 // you don't get downgraded accidentally) | 1850 // you don't get downgraded accidentally) |
1789 // -An update manifest mentions multiple updates | 1851 // -An update manifest mentions multiple updates |
1790 | 1852 |
1791 } // namespace extensions | 1853 } // namespace extensions |
OLD | NEW |