| 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 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 // Add a fake crx installer to be returned by a call to UpdateExtension() | 404 // Add a fake crx installer to be returned by a call to UpdateExtension() |
| 405 // with a specific ID. Caller keeps ownership of |crx_installer|. | 405 // with a specific ID. Caller keeps ownership of |crx_installer|. |
| 406 void AddFakeCrxInstaller(const std::string& id, CrxInstaller* crx_installer) { | 406 void AddFakeCrxInstaller(const std::string& id, CrxInstaller* crx_installer) { |
| 407 fake_crx_installers_[id] = crx_installer; | 407 fake_crx_installers_[id] = crx_installer; |
| 408 } | 408 } |
| 409 | 409 |
| 410 virtual bool UpdateExtension( | 410 virtual bool UpdateExtension( |
| 411 const std::string& id, | 411 const std::string& id, |
| 412 const base::FilePath& extension_path, | 412 const base::FilePath& extension_path, |
| 413 bool file_ownership_passed, | 413 bool file_ownership_passed, |
| 414 const GURL& download_url, | |
| 415 CrxInstaller** out_crx_installer) OVERRIDE { | 414 CrxInstaller** out_crx_installer) OVERRIDE { |
| 416 extension_id_ = id; | 415 extension_id_ = id; |
| 417 install_path_ = extension_path; | 416 install_path_ = extension_path; |
| 418 download_url_ = download_url; | |
| 419 | 417 |
| 420 if (ContainsKey(fake_crx_installers_, id)) { | 418 if (ContainsKey(fake_crx_installers_, id)) { |
| 421 *out_crx_installer = fake_crx_installers_[id]; | 419 *out_crx_installer = fake_crx_installers_[id]; |
| 422 return true; | 420 return true; |
| 423 } | 421 } |
| 424 | 422 |
| 425 return false; | 423 return false; |
| 426 } | 424 } |
| 427 | 425 |
| 428 virtual PendingExtensionManager* pending_extension_manager() OVERRIDE { | 426 virtual PendingExtensionManager* pending_extension_manager() OVERRIDE { |
| 429 return &pending_extension_manager_; | 427 return &pending_extension_manager_; |
| 430 } | 428 } |
| 431 | 429 |
| 432 virtual const Extension* GetExtensionById( | 430 virtual const Extension* GetExtensionById( |
| 433 const std::string& id, bool) const OVERRIDE { | 431 const std::string& id, bool) const OVERRIDE { |
| 434 last_inquired_extension_id_ = id; | 432 last_inquired_extension_id_ = id; |
| 435 return NULL; | 433 return NULL; |
| 436 } | 434 } |
| 437 | 435 |
| 438 const std::string& extension_id() const { return extension_id_; } | 436 const std::string& extension_id() const { return extension_id_; } |
| 439 const base::FilePath& install_path() const { return install_path_; } | 437 const base::FilePath& install_path() const { return install_path_; } |
| 440 const GURL& download_url() const { return download_url_; } | |
| 441 | 438 |
| 442 private: | 439 private: |
| 443 // Hold the set of ids that UpdateExtension() should fake success on. | 440 // Hold the set of ids that UpdateExtension() should fake success on. |
| 444 // UpdateExtension(id, ...) will return true iff fake_crx_installers_ | 441 // UpdateExtension(id, ...) will return true iff fake_crx_installers_ |
| 445 // contains key |id|. |out_install_notification_source| will be set | 442 // contains key |id|. |out_install_notification_source| will be set |
| 446 // to Source<CrxInstaller(fake_crx_installers_[i]). | 443 // to Source<CrxInstaller(fake_crx_installers_[i]). |
| 447 std::map<std::string, CrxInstaller*> fake_crx_installers_; | 444 std::map<std::string, CrxInstaller*> fake_crx_installers_; |
| 448 | 445 |
| 449 std::string extension_id_; | 446 std::string extension_id_; |
| 450 base::FilePath install_path_; | 447 base::FilePath install_path_; |
| (...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1071 | 1068 |
| 1072 if (fail) { | 1069 if (fail) { |
| 1073 // Don't expect any extension to have been installed. | 1070 // Don't expect any extension to have been installed. |
| 1074 EXPECT_TRUE(service->extension_id().empty()); | 1071 EXPECT_TRUE(service->extension_id().empty()); |
| 1075 } else { | 1072 } else { |
| 1076 // Expect that ExtensionUpdater asked the mock extensions service to | 1073 // Expect that ExtensionUpdater asked the mock extensions service to |
| 1077 // install a file with the test data for the right id. | 1074 // install a file with the test data for the right id. |
| 1078 EXPECT_EQ(id, service->extension_id()); | 1075 EXPECT_EQ(id, service->extension_id()); |
| 1079 base::FilePath tmpfile_path = service->install_path(); | 1076 base::FilePath tmpfile_path = service->install_path(); |
| 1080 EXPECT_FALSE(tmpfile_path.empty()); | 1077 EXPECT_FALSE(tmpfile_path.empty()); |
| 1081 EXPECT_EQ(test_url, service->download_url()); | |
| 1082 EXPECT_EQ(extension_file_path, tmpfile_path); | 1078 EXPECT_EQ(extension_file_path, tmpfile_path); |
| 1083 } | 1079 } |
| 1084 } | 1080 } |
| 1085 | 1081 |
| 1086 // Update a single extension in an environment where the download request | 1082 // Update a single extension in an environment where the download request |
| 1087 // initially responds with a 403 status. Expect the fetcher to automatically | 1083 // initially responds with a 403 status. Expect the fetcher to automatically |
| 1088 // retry with cookies enabled. | 1084 // retry with cookies enabled. |
| 1089 void TestSingleProtectedExtensionDownloading(bool use_https, bool fail) { | 1085 void TestSingleProtectedExtensionDownloading(bool use_https, bool fail) { |
| 1090 net::TestURLFetcherFactory factory; | 1086 net::TestURLFetcherFactory factory; |
| 1091 net::TestURLFetcher* fetcher = NULL; | 1087 net::TestURLFetcher* fetcher = NULL; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1154 fetcher->set_status(net::URLRequestStatus()); | 1150 fetcher->set_status(net::URLRequestStatus()); |
| 1155 fetcher->set_response_code(200); | 1151 fetcher->set_response_code(200); |
| 1156 fetcher->SetResponseFilePath(extension_file_path); | 1152 fetcher->SetResponseFilePath(extension_file_path); |
| 1157 fetcher->delegate()->OnURLFetchComplete(fetcher); | 1153 fetcher->delegate()->OnURLFetchComplete(fetcher); |
| 1158 RunUntilIdle(); | 1154 RunUntilIdle(); |
| 1159 | 1155 |
| 1160 // Verify installation would proceed as normal. | 1156 // Verify installation would proceed as normal. |
| 1161 EXPECT_EQ(id, service->extension_id()); | 1157 EXPECT_EQ(id, service->extension_id()); |
| 1162 base::FilePath tmpfile_path = service->install_path(); | 1158 base::FilePath tmpfile_path = service->install_path(); |
| 1163 EXPECT_FALSE(tmpfile_path.empty()); | 1159 EXPECT_FALSE(tmpfile_path.empty()); |
| 1164 EXPECT_EQ(test_url, service->download_url()); | |
| 1165 EXPECT_EQ(extension_file_path, tmpfile_path); | 1160 EXPECT_EQ(extension_file_path, tmpfile_path); |
| 1166 } | 1161 } |
| 1167 } | 1162 } |
| 1168 | 1163 |
| 1169 // Two extensions are updated. If |updates_start_running| is true, the | 1164 // Two extensions are updated. If |updates_start_running| is true, the |
| 1170 // mock extensions service has UpdateExtension(...) return true, and | 1165 // mock extensions service has UpdateExtension(...) return true, and |
| 1171 // the test is responsible for creating fake CrxInstallers. Otherwise, | 1166 // the test is responsible for creating fake CrxInstallers. Otherwise, |
| 1172 // UpdateExtension() returns false, signaling install failures. | 1167 // UpdateExtension() returns false, signaling install failures. |
| 1173 void TestMultipleExtensionDownloading(bool updates_start_running) { | 1168 void TestMultipleExtensionDownloading(bool updates_start_running) { |
| 1174 net::TestURLFetcherFactory factory; | 1169 net::TestURLFetcherFactory factory; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1252 fetcher->set_response_code(200); | 1247 fetcher->set_response_code(200); |
| 1253 fetcher->SetResponseFilePath(extension_file_path); | 1248 fetcher->SetResponseFilePath(extension_file_path); |
| 1254 fetcher->delegate()->OnURLFetchComplete(fetcher); | 1249 fetcher->delegate()->OnURLFetchComplete(fetcher); |
| 1255 | 1250 |
| 1256 RunUntilIdle(); | 1251 RunUntilIdle(); |
| 1257 | 1252 |
| 1258 // Expect that the service was asked to do an install with the right data. | 1253 // Expect that the service was asked to do an install with the right data. |
| 1259 base::FilePath tmpfile_path = service.install_path(); | 1254 base::FilePath tmpfile_path = service.install_path(); |
| 1260 EXPECT_FALSE(tmpfile_path.empty()); | 1255 EXPECT_FALSE(tmpfile_path.empty()); |
| 1261 EXPECT_EQ(id1, service.extension_id()); | 1256 EXPECT_EQ(id1, service.extension_id()); |
| 1262 EXPECT_EQ(url1, service.download_url()); | |
| 1263 RunUntilIdle(); | 1257 RunUntilIdle(); |
| 1264 | 1258 |
| 1265 // Make sure the second fetch finished and asked the service to do an | 1259 // Make sure the second fetch finished and asked the service to do an |
| 1266 // update. | 1260 // update. |
| 1267 base::FilePath extension_file_path2(FILE_PATH_LITERAL("/whatever2")); | 1261 base::FilePath extension_file_path2(FILE_PATH_LITERAL("/whatever2")); |
| 1268 fetcher = factory.GetFetcherByID(ExtensionDownloader::kExtensionFetcherId); | 1262 fetcher = factory.GetFetcherByID(ExtensionDownloader::kExtensionFetcherId); |
| 1269 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); | 1263 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); |
| 1270 EXPECT_TRUE(fetcher->GetLoadFlags() == kExpectedLoadFlags); | 1264 EXPECT_TRUE(fetcher->GetLoadFlags() == kExpectedLoadFlags); |
| 1271 | 1265 |
| 1272 fetcher->set_url(url2); | 1266 fetcher->set_url(url2); |
| 1273 fetcher->set_status(net::URLRequestStatus()); | 1267 fetcher->set_status(net::URLRequestStatus()); |
| 1274 fetcher->set_response_code(200); | 1268 fetcher->set_response_code(200); |
| 1275 fetcher->SetResponseFilePath(extension_file_path2); | 1269 fetcher->SetResponseFilePath(extension_file_path2); |
| 1276 fetcher->delegate()->OnURLFetchComplete(fetcher); | 1270 fetcher->delegate()->OnURLFetchComplete(fetcher); |
| 1277 RunUntilIdle(); | 1271 RunUntilIdle(); |
| 1278 | 1272 |
| 1279 if (updates_start_running) { | 1273 if (updates_start_running) { |
| 1280 EXPECT_TRUE(updater.crx_install_is_running_); | 1274 EXPECT_TRUE(updater.crx_install_is_running_); |
| 1281 | 1275 |
| 1282 // The second install should not have run, because the first has not | 1276 // The second install should not have run, because the first has not |
| 1283 // sent a notification that it finished. | 1277 // sent a notification that it finished. |
| 1284 EXPECT_EQ(id1, service.extension_id()); | 1278 EXPECT_EQ(id1, service.extension_id()); |
| 1285 EXPECT_EQ(url1, service.download_url()); | |
| 1286 | 1279 |
| 1287 // Fake install notice. This should start the second installation, | 1280 // Fake install notice. This should start the second installation, |
| 1288 // which will be checked below. | 1281 // which will be checked below. |
| 1289 fake_crx1->NotifyCrxInstallComplete(false); | 1282 fake_crx1->NotifyCrxInstallComplete(false); |
| 1290 | 1283 |
| 1291 EXPECT_TRUE(updater.crx_install_is_running_); | 1284 EXPECT_TRUE(updater.crx_install_is_running_); |
| 1292 } | 1285 } |
| 1293 | 1286 |
| 1294 EXPECT_EQ(id2, service.extension_id()); | 1287 EXPECT_EQ(id2, service.extension_id()); |
| 1295 EXPECT_EQ(url2, service.download_url()); | |
| 1296 EXPECT_FALSE(service.install_path().empty()); | 1288 EXPECT_FALSE(service.install_path().empty()); |
| 1297 | 1289 |
| 1298 // Make sure the correct crx contents were passed for the update call. | 1290 // Make sure the correct crx contents were passed for the update call. |
| 1299 EXPECT_EQ(extension_file_path2, service.install_path()); | 1291 EXPECT_EQ(extension_file_path2, service.install_path()); |
| 1300 | 1292 |
| 1301 if (updates_start_running) { | 1293 if (updates_start_running) { |
| 1302 EXPECT_TRUE(updater.crx_install_is_running_); | 1294 EXPECT_TRUE(updater.crx_install_is_running_); |
| 1303 fake_crx2->NotifyCrxInstallComplete(false); | 1295 fake_crx2->NotifyCrxInstallComplete(false); |
| 1304 } | 1296 } |
| 1305 EXPECT_FALSE(updater.crx_install_is_running_); | 1297 EXPECT_FALSE(updater.crx_install_is_running_); |
| (...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1790 // -prodversionmin (shouldn't update if browser version too old) | 1782 // -prodversionmin (shouldn't update if browser version too old) |
| 1791 // -manifests & updates arriving out of order / interleaved | 1783 // -manifests & updates arriving out of order / interleaved |
| 1792 // -malformed update url (empty, file://, has query, has a # fragment, etc.) | 1784 // -malformed update url (empty, file://, has query, has a # fragment, etc.) |
| 1793 // -An extension gets uninstalled while updates are in progress (so it doesn't | 1785 // -An extension gets uninstalled while updates are in progress (so it doesn't |
| 1794 // "come back from the dead") | 1786 // "come back from the dead") |
| 1795 // -An extension gets manually updated to v3 while we're downloading v2 (ie | 1787 // -An extension gets manually updated to v3 while we're downloading v2 (ie |
| 1796 // you don't get downgraded accidentally) | 1788 // you don't get downgraded accidentally) |
| 1797 // -An update manifest mentions multiple updates | 1789 // -An update manifest mentions multiple updates |
| 1798 | 1790 |
| 1799 } // namespace extensions | 1791 } // namespace extensions |
| OLD | NEW |