| 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/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 std::set<std::string> updated_; | 155 std::set<std::string> updated_; |
| 156 | 156 |
| 157 DISALLOW_COPY_AND_ASSIGN(NotificationsObserver); | 157 DISALLOW_COPY_AND_ASSIGN(NotificationsObserver); |
| 158 }; | 158 }; |
| 159 | 159 |
| 160 } // namespace | 160 } // namespace |
| 161 | 161 |
| 162 // Base class for further specialized test classes. | 162 // Base class for further specialized test classes. |
| 163 class MockService : public TestExtensionService { | 163 class MockService : public TestExtensionService { |
| 164 public: | 164 public: |
| 165 MockService() | 165 explicit MockService(TestExtensionPrefs* prefs) |
| 166 : pending_extension_manager_(ALLOW_THIS_IN_INITIALIZER_LIST(*this)) { | 166 : prefs_(prefs), |
| 167 pending_extension_manager_(ALLOW_THIS_IN_INITIALIZER_LIST(*this)) { |
| 167 profile_.CreateRequestContext(); | 168 profile_.CreateRequestContext(); |
| 168 } | 169 } |
| 170 |
| 169 virtual ~MockService() {} | 171 virtual ~MockService() {} |
| 170 | 172 |
| 171 virtual PendingExtensionManager* pending_extension_manager() OVERRIDE { | 173 virtual PendingExtensionManager* pending_extension_manager() OVERRIDE { |
| 172 ADD_FAILURE() << "Subclass should override this if it will " | 174 ADD_FAILURE() << "Subclass should override this if it will " |
| 173 << "be accessed by a test."; | 175 << "be accessed by a test."; |
| 174 return &pending_extension_manager_; | 176 return &pending_extension_manager_; |
| 175 } | 177 } |
| 176 | 178 |
| 177 Profile* profile() { return &profile_; } | 179 Profile* profile() { return &profile_; } |
| 178 | 180 |
| 179 net::URLRequestContextGetter* request_context() { | 181 net::URLRequestContextGetter* request_context() { |
| 180 return profile_.GetRequestContext(); | 182 return profile_.GetRequestContext(); |
| 181 } | 183 } |
| 182 | 184 |
| 183 ExtensionPrefs* extension_prefs() { return prefs_.prefs(); } | 185 ExtensionPrefs* extension_prefs() { return prefs_->prefs(); } |
| 184 | 186 |
| 185 PrefService* pref_service() { return prefs_.pref_service(); } | 187 PrefService* pref_service() { return prefs_->pref_service(); } |
| 186 | 188 |
| 187 // Creates test extensions and inserts them into list. The name and | 189 // Creates test extensions and inserts them into list. The name and |
| 188 // version are all based on their index. If |update_url| is non-null, it | 190 // version are all based on their index. If |update_url| is non-null, it |
| 189 // will be used as the update_url for each extension. | 191 // will be used as the update_url for each extension. |
| 190 // The |id| is used to distinguish extension names and make sure that | 192 // The |id| is used to distinguish extension names and make sure that |
| 191 // no two extensions share the same name. | 193 // no two extensions share the same name. |
| 192 void CreateTestExtensions(int id, int count, ExtensionList *list, | 194 void CreateTestExtensions(int id, int count, ExtensionList *list, |
| 193 const std::string* update_url, | 195 const std::string* update_url, |
| 194 Extension::Location location) { | 196 Extension::Location location) { |
| 195 for (int i = 1; i <= count; i++) { | 197 for (int i = 1; i <= count; i++) { |
| 196 DictionaryValue manifest; | 198 DictionaryValue manifest; |
| 197 manifest.SetString(extension_manifest_keys::kVersion, | 199 manifest.SetString(extension_manifest_keys::kVersion, |
| 198 base::StringPrintf("%d.0.0.0", i)); | 200 base::StringPrintf("%d.0.0.0", i)); |
| 199 manifest.SetString(extension_manifest_keys::kName, | 201 manifest.SetString(extension_manifest_keys::kName, |
| 200 base::StringPrintf("Extension %d.%d", id, i)); | 202 base::StringPrintf("Extension %d.%d", id, i)); |
| 201 if (update_url) | 203 if (update_url) |
| 202 manifest.SetString(extension_manifest_keys::kUpdateURL, *update_url); | 204 manifest.SetString(extension_manifest_keys::kUpdateURL, *update_url); |
| 203 scoped_refptr<Extension> e = | 205 scoped_refptr<Extension> e = |
| 204 prefs_.AddExtensionWithManifest(manifest, location); | 206 prefs_->AddExtensionWithManifest(manifest, location); |
| 205 ASSERT_TRUE(e != NULL); | 207 ASSERT_TRUE(e != NULL); |
| 206 list->push_back(e); | 208 list->push_back(e); |
| 207 } | 209 } |
| 208 } | 210 } |
| 209 | 211 |
| 210 protected: | 212 protected: |
| 213 TestExtensionPrefs* const prefs_; |
| 211 PendingExtensionManager pending_extension_manager_; | 214 PendingExtensionManager pending_extension_manager_; |
| 212 TestExtensionPrefs prefs_; | |
| 213 TestingProfile profile_; | 215 TestingProfile profile_; |
| 214 | 216 |
| 215 private: | 217 private: |
| 216 DISALLOW_COPY_AND_ASSIGN(MockService); | 218 DISALLOW_COPY_AND_ASSIGN(MockService); |
| 217 }; | 219 }; |
| 218 | 220 |
| 219 | 221 |
| 220 std::string GenerateId(std::string input) { | 222 std::string GenerateId(std::string input) { |
| 221 std::string result; | 223 std::string result; |
| 222 EXPECT_TRUE(Extension::GenerateId(input, &result)); | 224 EXPECT_TRUE(Extension::GenerateId(input, &result)); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 253 Version(), | 255 Version(), |
| 254 should_allow_install, | 256 should_allow_install, |
| 255 kIsFromSync, | 257 kIsFromSync, |
| 256 kInstallSilently, | 258 kInstallSilently, |
| 257 Extension::INTERNAL)); | 259 Extension::INTERNAL)); |
| 258 } | 260 } |
| 259 } | 261 } |
| 260 | 262 |
| 261 class ServiceForManifestTests : public MockService { | 263 class ServiceForManifestTests : public MockService { |
| 262 public: | 264 public: |
| 263 ServiceForManifestTests() {} | 265 explicit ServiceForManifestTests(TestExtensionPrefs* prefs) |
| 266 : MockService(prefs) { |
| 267 } |
| 264 | 268 |
| 265 virtual ~ServiceForManifestTests() {} | 269 virtual ~ServiceForManifestTests() {} |
| 266 | 270 |
| 267 virtual const Extension* GetExtensionById( | 271 virtual const Extension* GetExtensionById( |
| 268 const std::string& id, bool include_disabled) const OVERRIDE { | 272 const std::string& id, bool include_disabled) const OVERRIDE { |
| 269 const Extension* result = extensions_.GetByID(id); | 273 const Extension* result = extensions_.GetByID(id); |
| 270 if (result || !include_disabled) | 274 if (result || !include_disabled) |
| 271 return result; | 275 return result; |
| 272 return disabled_extensions_.GetByID(id); | 276 return disabled_extensions_.GetByID(id); |
| 273 } | 277 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 298 } | 302 } |
| 299 } | 303 } |
| 300 | 304 |
| 301 private: | 305 private: |
| 302 ExtensionSet extensions_; | 306 ExtensionSet extensions_; |
| 303 ExtensionSet disabled_extensions_; | 307 ExtensionSet disabled_extensions_; |
| 304 }; | 308 }; |
| 305 | 309 |
| 306 class ServiceForDownloadTests : public MockService { | 310 class ServiceForDownloadTests : public MockService { |
| 307 public: | 311 public: |
| 308 ServiceForDownloadTests() | 312 explicit ServiceForDownloadTests(TestExtensionPrefs* prefs) |
| 309 : MockService() { | 313 : MockService(prefs) { |
| 310 } | 314 } |
| 311 | 315 |
| 312 // Add a fake crx installer to be returned by a call to UpdateExtension() | 316 // Add a fake crx installer to be returned by a call to UpdateExtension() |
| 313 // with a specific ID. Caller keeps ownership of |crx_installer|. | 317 // with a specific ID. Caller keeps ownership of |crx_installer|. |
| 314 void AddFakeCrxInstaller(const std::string& id, CrxInstaller* crx_installer) { | 318 void AddFakeCrxInstaller(const std::string& id, CrxInstaller* crx_installer) { |
| 315 fake_crx_installers_[id] = crx_installer; | 319 fake_crx_installers_[id] = crx_installer; |
| 316 } | 320 } |
| 317 | 321 |
| 318 bool UpdateExtension( | 322 bool UpdateExtension( |
| 319 const std::string& id, | 323 const std::string& id, |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 | 366 |
| 363 // The last extension ID that GetExtensionById was called with. | 367 // The last extension ID that GetExtensionById was called with. |
| 364 // Mutable because the method that sets it (GetExtensionById) is const | 368 // Mutable because the method that sets it (GetExtensionById) is const |
| 365 // in the actual extension service, but must record the last extension | 369 // in the actual extension service, but must record the last extension |
| 366 // ID in this test class. | 370 // ID in this test class. |
| 367 mutable std::string last_inquired_extension_id_; | 371 mutable std::string last_inquired_extension_id_; |
| 368 }; | 372 }; |
| 369 | 373 |
| 370 class ServiceForBlacklistTests : public MockService { | 374 class ServiceForBlacklistTests : public MockService { |
| 371 public: | 375 public: |
| 372 ServiceForBlacklistTests() | 376 explicit ServiceForBlacklistTests(TestExtensionPrefs* prefs) |
| 373 : MockService(), | 377 : MockService(prefs), |
| 374 processed_blacklist_(false) { | 378 processed_blacklist_(false) { |
| 375 } | 379 } |
| 376 virtual void UpdateExtensionBlacklist( | 380 virtual void UpdateExtensionBlacklist( |
| 377 const std::vector<std::string>& blacklist) OVERRIDE { | 381 const std::vector<std::string>& blacklist) OVERRIDE { |
| 378 processed_blacklist_ = true; | 382 processed_blacklist_ = true; |
| 379 return; | 383 return; |
| 380 } | 384 } |
| 381 bool processed_blacklist() { return processed_blacklist_; } | 385 bool processed_blacklist() { return processed_blacklist_; } |
| 382 const std::string& extension_id() { return extension_id_; } | 386 const std::string& extension_id() { return extension_id_; } |
| 383 | 387 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 410 } | 414 } |
| 411 } | 415 } |
| 412 | 416 |
| 413 // All of our tests that need to use private APIs of ExtensionUpdater live | 417 // All of our tests that need to use private APIs of ExtensionUpdater live |
| 414 // inside this class (which is a friend to ExtensionUpdater). | 418 // inside this class (which is a friend to ExtensionUpdater). |
| 415 class ExtensionUpdaterTest : public testing::Test { | 419 class ExtensionUpdaterTest : public testing::Test { |
| 416 public: | 420 public: |
| 417 ExtensionUpdaterTest() | 421 ExtensionUpdaterTest() |
| 418 : ui_thread_(BrowserThread::UI, &loop_), | 422 : ui_thread_(BrowserThread::UI, &loop_), |
| 419 file_thread_(BrowserThread::FILE, &loop_), | 423 file_thread_(BrowserThread::FILE, &loop_), |
| 420 io_thread_(BrowserThread::IO, &loop_) {} | 424 io_thread_(BrowserThread::IO, &loop_) { |
| 425 } |
| 426 |
| 427 virtual ~ExtensionUpdaterTest() { |
| 428 } |
| 429 |
| 430 virtual void SetUp() OVERRIDE { |
| 431 prefs_.reset(new TestExtensionPrefs(loop_.message_loop_proxy())); |
| 432 } |
| 421 | 433 |
| 422 virtual void TearDown() OVERRIDE { | 434 virtual void TearDown() OVERRIDE { |
| 423 // Some tests create URLRequestContextGetters, whose destruction must run | 435 // Some tests create URLRequestContextGetters, whose destruction must run |
| 424 // on the IO thread. Make sure the IO loop spins before shutdown so that | 436 // on the IO thread. Make sure the IO loop spins before shutdown so that |
| 425 // those objects are released. | 437 // those objects are released. |
| 426 loop_.RunAllPending(); | 438 RunUntilIdle(); |
| 439 prefs_.reset(); |
| 427 } | 440 } |
| 428 | 441 |
| 429 void RunAllPending() { | 442 void RunUntilIdle() { |
| 430 loop_.RunAllPending(); | 443 prefs_->pref_service()->CommitPendingWrite(); |
| 444 loop_.RunUntilIdle(); |
| 431 } | 445 } |
| 432 | 446 |
| 433 void SimulateTimerFired(ExtensionUpdater* updater) { | 447 void SimulateTimerFired(ExtensionUpdater* updater) { |
| 434 EXPECT_TRUE(updater->timer_.IsRunning()); | 448 EXPECT_TRUE(updater->timer_.IsRunning()); |
| 435 updater->timer_.Stop(); | 449 updater->timer_.Stop(); |
| 436 updater->TimerFired(); | 450 updater->TimerFired(); |
| 437 } | 451 } |
| 438 | 452 |
| 439 // Adds a Result with the given data to results. | 453 // Adds a Result with the given data to results. |
| 440 void AddParseResult(const std::string& id, | 454 void AddParseResult(const std::string& id, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 459 downloader->StartUpdateCheck(fetch_data); | 473 downloader->StartUpdateCheck(fetch_data); |
| 460 } | 474 } |
| 461 | 475 |
| 462 size_t ManifestFetchersCount(ExtensionDownloader* downloader) { | 476 size_t ManifestFetchersCount(ExtensionDownloader* downloader) { |
| 463 return downloader->manifests_pending_.size() + | 477 return downloader->manifests_pending_.size() + |
| 464 (downloader->manifest_fetcher_.get() ? 1 : 0); | 478 (downloader->manifest_fetcher_.get() ? 1 : 0); |
| 465 } | 479 } |
| 466 | 480 |
| 467 void TestExtensionUpdateCheckRequests(bool pending) { | 481 void TestExtensionUpdateCheckRequests(bool pending) { |
| 468 // Create an extension with an update_url. | 482 // Create an extension with an update_url. |
| 469 ServiceForManifestTests service; | 483 ServiceForManifestTests service(prefs_.get()); |
| 470 std::string update_url("http://foo.com/bar"); | 484 std::string update_url("http://foo.com/bar"); |
| 471 ExtensionList extensions; | 485 ExtensionList extensions; |
| 472 PendingExtensionManager* pending_extension_manager = | 486 PendingExtensionManager* pending_extension_manager = |
| 473 service.pending_extension_manager(); | 487 service.pending_extension_manager(); |
| 474 if (pending) { | 488 if (pending) { |
| 475 SetupPendingExtensionManagerForTest(1, GURL(update_url), | 489 SetupPendingExtensionManagerForTest(1, GURL(update_url), |
| 476 pending_extension_manager); | 490 pending_extension_manager); |
| 477 } else { | 491 } else { |
| 478 service.CreateTestExtensions(1, 1, &extensions, &update_url, | 492 service.CreateTestExtensions(1, 1, &extensions, &update_url, |
| 479 Extension::INTERNAL); | 493 Extension::INTERNAL); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 519 EXPECT_EQ("0.0.0.0", params["v"]); | 533 EXPECT_EQ("0.0.0.0", params["v"]); |
| 520 } else { | 534 } else { |
| 521 EXPECT_EQ(extensions[0]->id(), params["id"]); | 535 EXPECT_EQ(extensions[0]->id(), params["id"]); |
| 522 EXPECT_EQ(extensions[0]->VersionString(), params["v"]); | 536 EXPECT_EQ(extensions[0]->VersionString(), params["v"]); |
| 523 } | 537 } |
| 524 EXPECT_EQ("", params["uc"]); | 538 EXPECT_EQ("", params["uc"]); |
| 525 } | 539 } |
| 526 | 540 |
| 527 void TestBlacklistUpdateCheckRequests() { | 541 void TestBlacklistUpdateCheckRequests() { |
| 528 // Setup and start the updater. | 542 // Setup and start the updater. |
| 529 ServiceForManifestTests service; | 543 ServiceForManifestTests service(prefs_.get()); |
| 530 | 544 |
| 531 net::TestURLFetcherFactory factory; | 545 net::TestURLFetcherFactory factory; |
| 532 ExtensionUpdater updater( | 546 ExtensionUpdater updater( |
| 533 &service, service.extension_prefs(), service.pref_service(), | 547 &service, service.extension_prefs(), service.pref_service(), |
| 534 service.profile(), 60*60*24); | 548 service.profile(), 60*60*24); |
| 535 updater.Start(); | 549 updater.Start(); |
| 536 | 550 |
| 537 // Tell the updater that it's time to do update checks. | 551 // Tell the updater that it's time to do update checks. |
| 538 SimulateTimerFired(&updater); | 552 SimulateTimerFired(&updater); |
| 539 | 553 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 601 ManifestFetchData fetch_data(GURL("http://localhost/foo")); | 615 ManifestFetchData fetch_data(GURL("http://localhost/foo")); |
| 602 fetch_data.AddExtension(id, version, &kNeverPingedData, "a=1&b=2&c", ""); | 616 fetch_data.AddExtension(id, version, &kNeverPingedData, "a=1&b=2&c", ""); |
| 603 EXPECT_EQ("http://localhost/foo\?x=id%3Daaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" | 617 EXPECT_EQ("http://localhost/foo\?x=id%3Daaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" |
| 604 "%26v%3D1.0%26uc%26ap%3Da%253D1%2526b%253D2%2526c", | 618 "%26v%3D1.0%26uc%26ap%3Da%253D1%2526b%253D2%2526c", |
| 605 fetch_data.full_url().spec()); | 619 fetch_data.full_url().spec()); |
| 606 } | 620 } |
| 607 | 621 |
| 608 void TestUpdateUrlDataFromGallery(const std::string& gallery_url) { | 622 void TestUpdateUrlDataFromGallery(const std::string& gallery_url) { |
| 609 net::TestURLFetcherFactory factory; | 623 net::TestURLFetcherFactory factory; |
| 610 | 624 |
| 611 MockService service; | 625 MockService service(prefs_.get()); |
| 612 MockExtensionDownloaderDelegate delegate; | 626 MockExtensionDownloaderDelegate delegate; |
| 613 ExtensionDownloader downloader(&delegate, service.request_context()); | 627 ExtensionDownloader downloader(&delegate, service.request_context()); |
| 614 ExtensionList extensions; | 628 ExtensionList extensions; |
| 615 std::string url(gallery_url); | 629 std::string url(gallery_url); |
| 616 | 630 |
| 617 service.CreateTestExtensions(1, 1, &extensions, &url, Extension::INTERNAL); | 631 service.CreateTestExtensions(1, 1, &extensions, &url, Extension::INTERNAL); |
| 618 | 632 |
| 619 const std::string& id = extensions[0]->id(); | 633 const std::string& id = extensions[0]->id(); |
| 620 EXPECT_CALL(delegate, GetPingDataForExtension(id, _)); | 634 EXPECT_CALL(delegate, GetPingDataForExtension(id, _)); |
| 621 | 635 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 682 .WillOnce(DoAll(SetArgPointee<1>("2.0.0.0"), | 696 .WillOnce(DoAll(SetArgPointee<1>("2.0.0.0"), |
| 683 Return(true))); | 697 Return(true))); |
| 684 | 698 |
| 685 downloader.DetermineUpdates(fetch_data, updates, &updateable); | 699 downloader.DetermineUpdates(fetch_data, updates, &updateable); |
| 686 EXPECT_EQ(1u, updateable.size()); | 700 EXPECT_EQ(1u, updateable.size()); |
| 687 EXPECT_EQ(0, updateable[0]); | 701 EXPECT_EQ(0, updateable[0]); |
| 688 } | 702 } |
| 689 | 703 |
| 690 void TestDetermineUpdatesPending() { | 704 void TestDetermineUpdatesPending() { |
| 691 // Create a set of test extensions | 705 // Create a set of test extensions |
| 692 ServiceForManifestTests service; | 706 ServiceForManifestTests service(prefs_.get()); |
| 693 PendingExtensionManager* pending_extension_manager = | 707 PendingExtensionManager* pending_extension_manager = |
| 694 service.pending_extension_manager(); | 708 service.pending_extension_manager(); |
| 695 SetupPendingExtensionManagerForTest(3, GURL(), pending_extension_manager); | 709 SetupPendingExtensionManagerForTest(3, GURL(), pending_extension_manager); |
| 696 | 710 |
| 697 TestingProfile profile; | 711 TestingProfile profile; |
| 698 profile.CreateRequestContext(); | 712 profile.CreateRequestContext(); |
| 699 MockExtensionDownloaderDelegate delegate; | 713 MockExtensionDownloaderDelegate delegate; |
| 700 ExtensionDownloader downloader(&delegate, profile.GetRequestContext()); | 714 ExtensionDownloader downloader(&delegate, profile.GetRequestContext()); |
| 701 | 715 |
| 702 ManifestFetchData fetch_data(GURL("http://localhost/foo")); | 716 ManifestFetchData fetch_data(GURL("http://localhost/foo")); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 724 EXPECT_EQ(3u, updateable.size()); | 738 EXPECT_EQ(3u, updateable.size()); |
| 725 for (std::vector<int>::size_type i = 0; i < updateable.size(); ++i) { | 739 for (std::vector<int>::size_type i = 0; i < updateable.size(); ++i) { |
| 726 EXPECT_EQ(static_cast<int>(i), updateable[i]); | 740 EXPECT_EQ(static_cast<int>(i), updateable[i]); |
| 727 } | 741 } |
| 728 } | 742 } |
| 729 | 743 |
| 730 void TestMultipleManifestDownloading() { | 744 void TestMultipleManifestDownloading() { |
| 731 net::TestURLFetcherFactory factory; | 745 net::TestURLFetcherFactory factory; |
| 732 net::TestURLFetcher* fetcher = NULL; | 746 net::TestURLFetcher* fetcher = NULL; |
| 733 NotificationsObserver observer; | 747 NotificationsObserver observer; |
| 734 MockService service; | 748 MockService service(prefs_.get()); |
| 735 MockExtensionDownloaderDelegate delegate; | 749 MockExtensionDownloaderDelegate delegate; |
| 736 ExtensionDownloader downloader(&delegate, service.request_context()); | 750 ExtensionDownloader downloader(&delegate, service.request_context()); |
| 737 | 751 |
| 738 GURL kUpdateUrl("http://localhost/manifest1"); | 752 GURL kUpdateUrl("http://localhost/manifest1"); |
| 739 | 753 |
| 740 ManifestFetchData* fetch1 = new ManifestFetchData(kUpdateUrl); | 754 ManifestFetchData* fetch1 = new ManifestFetchData(kUpdateUrl); |
| 741 ManifestFetchData* fetch2 = new ManifestFetchData(kUpdateUrl); | 755 ManifestFetchData* fetch2 = new ManifestFetchData(kUpdateUrl); |
| 742 ManifestFetchData* fetch3 = new ManifestFetchData(kUpdateUrl); | 756 ManifestFetchData* fetch3 = new ManifestFetchData(kUpdateUrl); |
| 743 ManifestFetchData* fetch4 = new ManifestFetchData(kUpdateUrl); | 757 ManifestFetchData* fetch4 = new ManifestFetchData(kUpdateUrl); |
| 744 ManifestFetchData::PingData zeroDays(0, 0); | 758 ManifestFetchData::PingData zeroDays(0, 0); |
| 745 fetch1->AddExtension("1111", "1.0", &zeroDays, kEmptyUpdateUrlData, ""); | 759 fetch1->AddExtension("1111", "1.0", &zeroDays, kEmptyUpdateUrlData, ""); |
| 746 fetch2->AddExtension("2222", "2.0", &zeroDays, kEmptyUpdateUrlData, ""); | 760 fetch2->AddExtension("2222", "2.0", &zeroDays, kEmptyUpdateUrlData, ""); |
| 747 fetch3->AddExtension("3333", "3.0", &zeroDays, kEmptyUpdateUrlData, ""); | 761 fetch3->AddExtension("3333", "3.0", &zeroDays, kEmptyUpdateUrlData, ""); |
| 748 fetch4->AddExtension("4444", "4.0", &zeroDays, kEmptyUpdateUrlData, ""); | 762 fetch4->AddExtension("4444", "4.0", &zeroDays, kEmptyUpdateUrlData, ""); |
| 749 | 763 |
| 750 // This will start the first fetcher and queue the others. The next in queue | 764 // This will start the first fetcher and queue the others. The next in queue |
| 751 // is started as each fetcher receives its response. | 765 // is started as each fetcher receives its response. |
| 752 downloader.StartUpdateCheck(fetch1); | 766 downloader.StartUpdateCheck(fetch1); |
| 753 downloader.StartUpdateCheck(fetch2); | 767 downloader.StartUpdateCheck(fetch2); |
| 754 downloader.StartUpdateCheck(fetch3); | 768 downloader.StartUpdateCheck(fetch3); |
| 755 downloader.StartUpdateCheck(fetch4); | 769 downloader.StartUpdateCheck(fetch4); |
| 756 RunAllPending(); | 770 RunUntilIdle(); |
| 757 | 771 |
| 758 // The first fetch will fail. | 772 // The first fetch will fail. |
| 759 fetcher = factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId); | 773 fetcher = factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId); |
| 760 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); | 774 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); |
| 761 EXPECT_TRUE(fetcher->GetLoadFlags() == kExpectedLoadFlags); | 775 EXPECT_TRUE(fetcher->GetLoadFlags() == kExpectedLoadFlags); |
| 762 EXPECT_CALL(delegate, OnExtensionDownloadFailed( | 776 EXPECT_CALL(delegate, OnExtensionDownloadFailed( |
| 763 "1111", ExtensionDownloaderDelegate::MANIFEST_FETCH_FAILED, _)); | 777 "1111", ExtensionDownloaderDelegate::MANIFEST_FETCH_FAILED, _)); |
| 764 fetcher->set_url(kUpdateUrl); | 778 fetcher->set_url(kUpdateUrl); |
| 765 fetcher->set_status(net::URLRequestStatus()); | 779 fetcher->set_status(net::URLRequestStatus()); |
| 766 fetcher->set_response_code(400); | 780 fetcher->set_response_code(400); |
| 767 fetcher->delegate()->OnURLFetchComplete(fetcher); | 781 fetcher->delegate()->OnURLFetchComplete(fetcher); |
| 768 RunAllPending(); | 782 RunUntilIdle(); |
| 769 Mock::VerifyAndClearExpectations(&delegate); | 783 Mock::VerifyAndClearExpectations(&delegate); |
| 770 | 784 |
| 771 // The second fetch gets invalid data. | 785 // The second fetch gets invalid data. |
| 772 const std::string kInvalidXml = "invalid xml"; | 786 const std::string kInvalidXml = "invalid xml"; |
| 773 fetcher = factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId); | 787 fetcher = factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId); |
| 774 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); | 788 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); |
| 775 EXPECT_TRUE(fetcher->GetLoadFlags() == kExpectedLoadFlags); | 789 EXPECT_TRUE(fetcher->GetLoadFlags() == kExpectedLoadFlags); |
| 776 EXPECT_CALL(delegate, OnExtensionDownloadFailed( | 790 EXPECT_CALL(delegate, OnExtensionDownloadFailed( |
| 777 "2222", ExtensionDownloaderDelegate::MANIFEST_INVALID, _)); | 791 "2222", ExtensionDownloaderDelegate::MANIFEST_INVALID, _)); |
| 778 fetcher->set_url(kUpdateUrl); | 792 fetcher->set_url(kUpdateUrl); |
| 779 fetcher->set_status(net::URLRequestStatus()); | 793 fetcher->set_status(net::URLRequestStatus()); |
| 780 fetcher->set_response_code(200); | 794 fetcher->set_response_code(200); |
| 781 fetcher->SetResponseString(kInvalidXml); | 795 fetcher->SetResponseString(kInvalidXml); |
| 782 fetcher->delegate()->OnURLFetchComplete(fetcher); | 796 fetcher->delegate()->OnURLFetchComplete(fetcher); |
| 783 RunAllPending(); | 797 RunUntilIdle(); |
| 784 Mock::VerifyAndClearExpectations(&delegate); | 798 Mock::VerifyAndClearExpectations(&delegate); |
| 785 | 799 |
| 786 // The third fetcher doesn't have an update available. | 800 // The third fetcher doesn't have an update available. |
| 787 const std::string kNoUpdate = | 801 const std::string kNoUpdate = |
| 788 "<?xml version='1.0' encoding='UTF-8'?>" | 802 "<?xml version='1.0' encoding='UTF-8'?>" |
| 789 "<gupdate xmlns='http://www.google.com/update2/response'" | 803 "<gupdate xmlns='http://www.google.com/update2/response'" |
| 790 " protocol='2.0'>" | 804 " protocol='2.0'>" |
| 791 " <app appid='3333'>" | 805 " <app appid='3333'>" |
| 792 " <updatecheck codebase='http://example.com/extension_3.0.0.0.crx'" | 806 " <updatecheck codebase='http://example.com/extension_3.0.0.0.crx'" |
| 793 " version='3.0.0.0' prodversionmin='3.0.0.0' />" | 807 " version='3.0.0.0' prodversionmin='3.0.0.0' />" |
| 794 " </app>" | 808 " </app>" |
| 795 "</gupdate>"; | 809 "</gupdate>"; |
| 796 fetcher = factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId); | 810 fetcher = factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId); |
| 797 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); | 811 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); |
| 798 EXPECT_TRUE(fetcher->GetLoadFlags() == kExpectedLoadFlags); | 812 EXPECT_TRUE(fetcher->GetLoadFlags() == kExpectedLoadFlags); |
| 799 EXPECT_CALL(delegate, IsExtensionPending("3333")).WillOnce(Return(false)); | 813 EXPECT_CALL(delegate, IsExtensionPending("3333")).WillOnce(Return(false)); |
| 800 EXPECT_CALL(delegate, GetExtensionExistingVersion("3333", _)) | 814 EXPECT_CALL(delegate, GetExtensionExistingVersion("3333", _)) |
| 801 .WillOnce(DoAll(SetArgPointee<1>("3.0.0.0"), | 815 .WillOnce(DoAll(SetArgPointee<1>("3.0.0.0"), |
| 802 Return(true))); | 816 Return(true))); |
| 803 EXPECT_CALL(delegate, OnExtensionDownloadFailed( | 817 EXPECT_CALL(delegate, OnExtensionDownloadFailed( |
| 804 "3333", ExtensionDownloaderDelegate::NO_UPDATE_AVAILABLE, _)); | 818 "3333", ExtensionDownloaderDelegate::NO_UPDATE_AVAILABLE, _)); |
| 805 fetcher->set_url(kUpdateUrl); | 819 fetcher->set_url(kUpdateUrl); |
| 806 fetcher->set_status(net::URLRequestStatus()); | 820 fetcher->set_status(net::URLRequestStatus()); |
| 807 fetcher->set_response_code(200); | 821 fetcher->set_response_code(200); |
| 808 fetcher->SetResponseString(kNoUpdate); | 822 fetcher->SetResponseString(kNoUpdate); |
| 809 fetcher->delegate()->OnURLFetchComplete(fetcher); | 823 fetcher->delegate()->OnURLFetchComplete(fetcher); |
| 810 RunAllPending(); | 824 RunUntilIdle(); |
| 811 Mock::VerifyAndClearExpectations(&delegate); | 825 Mock::VerifyAndClearExpectations(&delegate); |
| 812 | 826 |
| 813 // The last fetcher has an update. | 827 // The last fetcher has an update. |
| 814 const std::string kUpdateAvailable = | 828 const std::string kUpdateAvailable = |
| 815 "<?xml version='1.0' encoding='UTF-8'?>" | 829 "<?xml version='1.0' encoding='UTF-8'?>" |
| 816 "<gupdate xmlns='http://www.google.com/update2/response'" | 830 "<gupdate xmlns='http://www.google.com/update2/response'" |
| 817 " protocol='2.0'>" | 831 " protocol='2.0'>" |
| 818 " <app appid='4444'>" | 832 " <app appid='4444'>" |
| 819 " <updatecheck codebase='http://example.com/extension_1.2.3.4.crx'" | 833 " <updatecheck codebase='http://example.com/extension_1.2.3.4.crx'" |
| 820 " version='4.0.42.0' prodversionmin='4.0.42.0' />" | 834 " version='4.0.42.0' prodversionmin='4.0.42.0' />" |
| 821 " </app>" | 835 " </app>" |
| 822 "</gupdate>"; | 836 "</gupdate>"; |
| 823 fetcher = factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId); | 837 fetcher = factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId); |
| 824 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); | 838 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); |
| 825 EXPECT_TRUE(fetcher->GetLoadFlags() == kExpectedLoadFlags); | 839 EXPECT_TRUE(fetcher->GetLoadFlags() == kExpectedLoadFlags); |
| 826 EXPECT_CALL(delegate, IsExtensionPending("4444")).WillOnce(Return(false)); | 840 EXPECT_CALL(delegate, IsExtensionPending("4444")).WillOnce(Return(false)); |
| 827 EXPECT_CALL(delegate, GetExtensionExistingVersion("4444", _)) | 841 EXPECT_CALL(delegate, GetExtensionExistingVersion("4444", _)) |
| 828 .WillOnce(DoAll(SetArgPointee<1>("4.0.0.0"), | 842 .WillOnce(DoAll(SetArgPointee<1>("4.0.0.0"), |
| 829 Return(true))); | 843 Return(true))); |
| 830 fetcher->set_url(kUpdateUrl); | 844 fetcher->set_url(kUpdateUrl); |
| 831 fetcher->set_status(net::URLRequestStatus()); | 845 fetcher->set_status(net::URLRequestStatus()); |
| 832 fetcher->set_response_code(200); | 846 fetcher->set_response_code(200); |
| 833 fetcher->SetResponseString(kUpdateAvailable); | 847 fetcher->SetResponseString(kUpdateAvailable); |
| 834 fetcher->delegate()->OnURLFetchComplete(fetcher); | 848 fetcher->delegate()->OnURLFetchComplete(fetcher); |
| 835 RunAllPending(); | 849 RunUntilIdle(); |
| 836 Mock::VerifyAndClearExpectations(&delegate); | 850 Mock::VerifyAndClearExpectations(&delegate); |
| 837 | 851 |
| 838 // Verify that the downloader decided to update this extension. | 852 // Verify that the downloader decided to update this extension. |
| 839 EXPECT_EQ(1u, observer.UpdatedCount()); | 853 EXPECT_EQ(1u, observer.UpdatedCount()); |
| 840 EXPECT_TRUE(observer.Updated("4444")); | 854 EXPECT_TRUE(observer.Updated("4444")); |
| 841 } | 855 } |
| 842 | 856 |
| 843 void TestSingleExtensionDownloading(bool pending) { | 857 void TestSingleExtensionDownloading(bool pending) { |
| 844 net::TestURLFetcherFactory factory; | 858 net::TestURLFetcherFactory factory; |
| 845 net::TestURLFetcher* fetcher = NULL; | 859 net::TestURLFetcher* fetcher = NULL; |
| 846 scoped_ptr<ServiceForDownloadTests> service(new ServiceForDownloadTests); | 860 scoped_ptr<ServiceForDownloadTests> service( |
| 861 new ServiceForDownloadTests(prefs_.get())); |
| 847 ExtensionUpdater updater(service.get(), service->extension_prefs(), | 862 ExtensionUpdater updater(service.get(), service->extension_prefs(), |
| 848 service->pref_service(), | 863 service->pref_service(), |
| 849 service->profile(), | 864 service->profile(), |
| 850 kUpdateFrequencySecs); | 865 kUpdateFrequencySecs); |
| 851 updater.Start(); | 866 updater.Start(); |
| 852 ResetDownloader( | 867 ResetDownloader( |
| 853 &updater, | 868 &updater, |
| 854 new ExtensionDownloader(&updater, service->request_context())); | 869 new ExtensionDownloader(&updater, service->request_context())); |
| 855 | 870 |
| 856 GURL test_url("http://localhost/extension.crx"); | 871 GURL test_url("http://localhost/extension.crx"); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 878 fetcher = factory.GetFetcherByID(ExtensionDownloader::kExtensionFetcherId); | 893 fetcher = factory.GetFetcherByID(ExtensionDownloader::kExtensionFetcherId); |
| 879 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); | 894 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); |
| 880 EXPECT_TRUE(fetcher->GetLoadFlags() == kExpectedLoadFlags); | 895 EXPECT_TRUE(fetcher->GetLoadFlags() == kExpectedLoadFlags); |
| 881 | 896 |
| 882 fetcher->set_url(test_url); | 897 fetcher->set_url(test_url); |
| 883 fetcher->set_status(net::URLRequestStatus()); | 898 fetcher->set_status(net::URLRequestStatus()); |
| 884 fetcher->set_response_code(200); | 899 fetcher->set_response_code(200); |
| 885 fetcher->SetResponseFilePath(extension_file_path); | 900 fetcher->SetResponseFilePath(extension_file_path); |
| 886 fetcher->delegate()->OnURLFetchComplete(fetcher); | 901 fetcher->delegate()->OnURLFetchComplete(fetcher); |
| 887 | 902 |
| 888 RunAllPending(); | 903 RunUntilIdle(); |
| 889 | 904 |
| 890 // Expect that ExtensionUpdater asked the mock extensions service to install | 905 // Expect that ExtensionUpdater asked the mock extensions service to install |
| 891 // a file with the test data for the right id. | 906 // a file with the test data for the right id. |
| 892 EXPECT_EQ(id, service->extension_id()); | 907 EXPECT_EQ(id, service->extension_id()); |
| 893 FilePath tmpfile_path = service->install_path(); | 908 FilePath tmpfile_path = service->install_path(); |
| 894 EXPECT_FALSE(tmpfile_path.empty()); | 909 EXPECT_FALSE(tmpfile_path.empty()); |
| 895 EXPECT_EQ(test_url, service->download_url()); | 910 EXPECT_EQ(test_url, service->download_url()); |
| 896 EXPECT_EQ(extension_file_path, tmpfile_path); | 911 EXPECT_EQ(extension_file_path, tmpfile_path); |
| 897 } | 912 } |
| 898 | 913 |
| 899 void TestBlacklistDownloading() { | 914 void TestBlacklistDownloading() { |
| 900 net::TestURLFetcherFactory factory; | 915 net::TestURLFetcherFactory factory; |
| 901 net::TestURLFetcher* fetcher = NULL; | 916 net::TestURLFetcher* fetcher = NULL; |
| 902 ServiceForBlacklistTests service; | 917 ServiceForBlacklistTests service(prefs_.get()); |
| 903 ExtensionUpdater updater( | 918 ExtensionUpdater updater( |
| 904 &service, service.extension_prefs(), service.pref_service(), | 919 &service, service.extension_prefs(), service.pref_service(), |
| 905 service.profile(), kUpdateFrequencySecs); | 920 service.profile(), kUpdateFrequencySecs); |
| 906 updater.Start(); | 921 updater.Start(); |
| 907 ResetDownloader( | 922 ResetDownloader( |
| 908 &updater, | 923 &updater, |
| 909 new ExtensionDownloader(&updater, service.request_context())); | 924 new ExtensionDownloader(&updater, service.request_context())); |
| 910 GURL test_url("http://localhost/extension.crx"); | 925 GURL test_url("http://localhost/extension.crx"); |
| 911 | 926 |
| 912 std::string id = "com.google.crx.blacklist"; | 927 std::string id = "com.google.crx.blacklist"; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 923 fetcher = factory.GetFetcherByID(ExtensionDownloader::kExtensionFetcherId); | 938 fetcher = factory.GetFetcherByID(ExtensionDownloader::kExtensionFetcherId); |
| 924 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); | 939 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); |
| 925 EXPECT_TRUE(fetcher->GetLoadFlags() == kExpectedLoadFlags); | 940 EXPECT_TRUE(fetcher->GetLoadFlags() == kExpectedLoadFlags); |
| 926 | 941 |
| 927 fetcher->set_url(test_url); | 942 fetcher->set_url(test_url); |
| 928 fetcher->set_status(net::URLRequestStatus()); | 943 fetcher->set_status(net::URLRequestStatus()); |
| 929 fetcher->set_response_code(200); | 944 fetcher->set_response_code(200); |
| 930 fetcher->SetResponseString(extension_data); | 945 fetcher->SetResponseString(extension_data); |
| 931 fetcher->delegate()->OnURLFetchComplete(fetcher); | 946 fetcher->delegate()->OnURLFetchComplete(fetcher); |
| 932 | 947 |
| 933 RunAllPending(); | 948 RunUntilIdle(); |
| 934 | 949 |
| 935 // The updater should have called extension service to process the | 950 // The updater should have called extension service to process the |
| 936 // blacklist. | 951 // blacklist. |
| 937 EXPECT_TRUE(service.processed_blacklist()); | 952 EXPECT_TRUE(service.processed_blacklist()); |
| 938 | 953 |
| 939 EXPECT_EQ(version, service.pref_service()-> | 954 EXPECT_EQ(version, service.pref_service()-> |
| 940 GetString(prefs::kExtensionBlacklistUpdateVersion)); | 955 GetString(prefs::kExtensionBlacklistUpdateVersion)); |
| 941 } | 956 } |
| 942 | 957 |
| 943 // Two extensions are updated. If |updates_start_running| is true, the | 958 // Two extensions are updated. If |updates_start_running| is true, the |
| 944 // mock extensions service has UpdateExtension(...) return true, and | 959 // mock extensions service has UpdateExtension(...) return true, and |
| 945 // the test is responsible for creating fake CrxInstallers. Otherwise, | 960 // the test is responsible for creating fake CrxInstallers. Otherwise, |
| 946 // UpdateExtension() returns false, signaling install failures. | 961 // UpdateExtension() returns false, signaling install failures. |
| 947 void TestMultipleExtensionDownloading(bool updates_start_running) { | 962 void TestMultipleExtensionDownloading(bool updates_start_running) { |
| 948 net::TestURLFetcherFactory factory; | 963 net::TestURLFetcherFactory factory; |
| 949 net::TestURLFetcher* fetcher = NULL; | 964 net::TestURLFetcher* fetcher = NULL; |
| 950 ServiceForDownloadTests service; | 965 ServiceForDownloadTests service(prefs_.get()); |
| 951 ExtensionUpdater updater( | 966 ExtensionUpdater updater( |
| 952 &service, service.extension_prefs(), service.pref_service(), | 967 &service, service.extension_prefs(), service.pref_service(), |
| 953 service.profile(), kUpdateFrequencySecs); | 968 service.profile(), kUpdateFrequencySecs); |
| 954 updater.Start(); | 969 updater.Start(); |
| 955 ResetDownloader( | 970 ResetDownloader( |
| 956 &updater, | 971 &updater, |
| 957 new ExtensionDownloader(&updater, service.request_context())); | 972 new ExtensionDownloader(&updater, service.request_context())); |
| 958 | 973 |
| 959 EXPECT_FALSE(updater.crx_install_is_running_); | 974 EXPECT_FALSE(updater.crx_install_is_running_); |
| 960 | 975 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1010 // If we don't add fake CRX installers, the mock service fakes a failure | 1025 // If we don't add fake CRX installers, the mock service fakes a failure |
| 1011 // starting the install. | 1026 // starting the install. |
| 1012 } | 1027 } |
| 1013 | 1028 |
| 1014 fetcher->set_url(url1); | 1029 fetcher->set_url(url1); |
| 1015 fetcher->set_status(net::URLRequestStatus()); | 1030 fetcher->set_status(net::URLRequestStatus()); |
| 1016 fetcher->set_response_code(200); | 1031 fetcher->set_response_code(200); |
| 1017 fetcher->SetResponseFilePath(extension_file_path); | 1032 fetcher->SetResponseFilePath(extension_file_path); |
| 1018 fetcher->delegate()->OnURLFetchComplete(fetcher); | 1033 fetcher->delegate()->OnURLFetchComplete(fetcher); |
| 1019 | 1034 |
| 1020 RunAllPending(); | 1035 RunUntilIdle(); |
| 1021 | 1036 |
| 1022 // Expect that the service was asked to do an install with the right data. | 1037 // Expect that the service was asked to do an install with the right data. |
| 1023 FilePath tmpfile_path = service.install_path(); | 1038 FilePath tmpfile_path = service.install_path(); |
| 1024 EXPECT_FALSE(tmpfile_path.empty()); | 1039 EXPECT_FALSE(tmpfile_path.empty()); |
| 1025 EXPECT_EQ(id1, service.extension_id()); | 1040 EXPECT_EQ(id1, service.extension_id()); |
| 1026 EXPECT_EQ(url1, service.download_url()); | 1041 EXPECT_EQ(url1, service.download_url()); |
| 1027 RunAllPending(); | 1042 RunUntilIdle(); |
| 1028 | 1043 |
| 1029 // Make sure the second fetch finished and asked the service to do an | 1044 // Make sure the second fetch finished and asked the service to do an |
| 1030 // update. | 1045 // update. |
| 1031 FilePath extension_file_path2(FILE_PATH_LITERAL("/whatever2")); | 1046 FilePath extension_file_path2(FILE_PATH_LITERAL("/whatever2")); |
| 1032 fetcher = factory.GetFetcherByID(ExtensionDownloader::kExtensionFetcherId); | 1047 fetcher = factory.GetFetcherByID(ExtensionDownloader::kExtensionFetcherId); |
| 1033 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); | 1048 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); |
| 1034 EXPECT_TRUE(fetcher->GetLoadFlags() == kExpectedLoadFlags); | 1049 EXPECT_TRUE(fetcher->GetLoadFlags() == kExpectedLoadFlags); |
| 1035 | 1050 |
| 1036 fetcher->set_url(url2); | 1051 fetcher->set_url(url2); |
| 1037 fetcher->set_status(net::URLRequestStatus()); | 1052 fetcher->set_status(net::URLRequestStatus()); |
| 1038 fetcher->set_response_code(200); | 1053 fetcher->set_response_code(200); |
| 1039 fetcher->SetResponseFilePath(extension_file_path2); | 1054 fetcher->SetResponseFilePath(extension_file_path2); |
| 1040 fetcher->delegate()->OnURLFetchComplete(fetcher); | 1055 fetcher->delegate()->OnURLFetchComplete(fetcher); |
| 1041 RunAllPending(); | 1056 RunUntilIdle(); |
| 1042 | 1057 |
| 1043 if (updates_start_running) { | 1058 if (updates_start_running) { |
| 1044 EXPECT_TRUE(updater.crx_install_is_running_); | 1059 EXPECT_TRUE(updater.crx_install_is_running_); |
| 1045 | 1060 |
| 1046 // The second install should not have run, because the first has not | 1061 // The second install should not have run, because the first has not |
| 1047 // sent a notification that it finished. | 1062 // sent a notification that it finished. |
| 1048 EXPECT_EQ(id1, service.extension_id()); | 1063 EXPECT_EQ(id1, service.extension_id()); |
| 1049 EXPECT_EQ(url1, service.download_url()); | 1064 EXPECT_EQ(url1, service.download_url()); |
| 1050 | 1065 |
| 1051 // Fake install notice. This should start the second installation, | 1066 // Fake install notice. This should start the second installation, |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1109 // on the delta between now and the last ping time (or in the case of active | 1124 // on the delta between now and the last ping time (or in the case of active |
| 1110 // pings, that delta plus whether the app has been active). | 1125 // pings, that delta plus whether the app has been active). |
| 1111 void TestGalleryRequests(int rollcall_ping_days, | 1126 void TestGalleryRequests(int rollcall_ping_days, |
| 1112 int active_ping_days, | 1127 int active_ping_days, |
| 1113 bool active_bit, | 1128 bool active_bit, |
| 1114 bool expect_brand_code) { | 1129 bool expect_brand_code) { |
| 1115 net::TestURLFetcherFactory factory; | 1130 net::TestURLFetcherFactory factory; |
| 1116 | 1131 |
| 1117 // Set up 2 mock extensions, one with a google.com update url and one | 1132 // Set up 2 mock extensions, one with a google.com update url and one |
| 1118 // without. | 1133 // without. |
| 1119 ServiceForManifestTests service; | 1134 prefs_.reset(new TestExtensionPrefs(loop_.message_loop_proxy())); |
| 1135 ServiceForManifestTests service(prefs_.get()); |
| 1120 ExtensionList tmp; | 1136 ExtensionList tmp; |
| 1121 GURL url1("http://clients2.google.com/service/update2/crx"); | 1137 GURL url1("http://clients2.google.com/service/update2/crx"); |
| 1122 GURL url2("http://www.somewebsite.com"); | 1138 GURL url2("http://www.somewebsite.com"); |
| 1123 service.CreateTestExtensions(1, 1, &tmp, &url1.possibly_invalid_spec(), | 1139 service.CreateTestExtensions(1, 1, &tmp, &url1.possibly_invalid_spec(), |
| 1124 Extension::INTERNAL); | 1140 Extension::INTERNAL); |
| 1125 service.CreateTestExtensions(2, 1, &tmp, &url2.possibly_invalid_spec(), | 1141 service.CreateTestExtensions(2, 1, &tmp, &url2.possibly_invalid_spec(), |
| 1126 Extension::INTERNAL); | 1142 Extension::INTERNAL); |
| 1127 EXPECT_EQ(2u, tmp.size()); | 1143 EXPECT_EQ(2u, tmp.size()); |
| 1128 service.set_extensions(tmp); | 1144 service.set_extensions(tmp); |
| 1129 | 1145 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1221 if (expect_brand_code) { | 1237 if (expect_brand_code) { |
| 1222 EXPECT_TRUE(url1_query.find(brand_string) != std::string::npos); | 1238 EXPECT_TRUE(url1_query.find(brand_string) != std::string::npos); |
| 1223 } else { | 1239 } else { |
| 1224 EXPECT_TRUE(url1_query.find(brand_string) == std::string::npos); | 1240 EXPECT_TRUE(url1_query.find(brand_string) == std::string::npos); |
| 1225 } | 1241 } |
| 1226 #else | 1242 #else |
| 1227 // Chromium builds never add the brand to the parameter, even for google | 1243 // Chromium builds never add the brand to the parameter, even for google |
| 1228 // queries. | 1244 // queries. |
| 1229 EXPECT_TRUE(url1_query.find(brand_string) == std::string::npos); | 1245 EXPECT_TRUE(url1_query.find(brand_string) == std::string::npos); |
| 1230 #endif | 1246 #endif |
| 1247 |
| 1248 RunUntilIdle(); |
| 1231 } | 1249 } |
| 1232 | 1250 |
| 1233 // This makes sure that the extension updater properly stores the results | 1251 // This makes sure that the extension updater properly stores the results |
| 1234 // of a <daystart> tag from a manifest fetch in one of two cases: 1) This is | 1252 // of a <daystart> tag from a manifest fetch in one of two cases: 1) This is |
| 1235 // the first time we fetched the extension, or 2) We sent a ping value of | 1253 // the first time we fetched the extension, or 2) We sent a ping value of |
| 1236 // >= 1 day for the extension. | 1254 // >= 1 day for the extension. |
| 1237 void TestHandleManifestResults() { | 1255 void TestHandleManifestResults() { |
| 1238 ServiceForManifestTests service; | 1256 ServiceForManifestTests service(prefs_.get()); |
| 1239 GURL update_url("http://www.google.com/manifest"); | 1257 GURL update_url("http://www.google.com/manifest"); |
| 1240 ExtensionList tmp; | 1258 ExtensionList tmp; |
| 1241 service.CreateTestExtensions(1, 1, &tmp, &update_url.spec(), | 1259 service.CreateTestExtensions(1, 1, &tmp, &update_url.spec(), |
| 1242 Extension::INTERNAL); | 1260 Extension::INTERNAL); |
| 1243 service.set_extensions(tmp); | 1261 service.set_extensions(tmp); |
| 1244 | 1262 |
| 1245 ExtensionUpdater updater( | 1263 ExtensionUpdater updater( |
| 1246 &service, service.extension_prefs(), service.pref_service(), | 1264 &service, service.extension_prefs(), service.pref_service(), |
| 1247 service.profile(), kUpdateFrequencySecs); | 1265 service.profile(), kUpdateFrequencySecs); |
| 1248 updater.Start(); | 1266 updater.Start(); |
| 1249 ResetDownloader( | 1267 ResetDownloader( |
| 1250 &updater, | 1268 &updater, |
| 1251 new ExtensionDownloader(&updater, service.request_context())); | 1269 new ExtensionDownloader(&updater, service.request_context())); |
| 1252 | 1270 |
| 1253 ManifestFetchData fetch_data(update_url); | 1271 ManifestFetchData fetch_data(update_url); |
| 1254 const Extension* extension = tmp[0]; | 1272 const Extension* extension = tmp[0]; |
| 1255 fetch_data.AddExtension(extension->id(), extension->VersionString(), | 1273 fetch_data.AddExtension(extension->id(), extension->VersionString(), |
| 1256 &kNeverPingedData, kEmptyUpdateUrlData, ""); | 1274 &kNeverPingedData, kEmptyUpdateUrlData, ""); |
| 1257 UpdateManifest::Results results; | 1275 UpdateManifest::Results results; |
| 1258 results.daystart_elapsed_seconds = 750; | 1276 results.daystart_elapsed_seconds = 750; |
| 1259 | 1277 |
| 1260 updater.downloader_->HandleManifestResults(fetch_data, &results); | 1278 updater.downloader_->HandleManifestResults(fetch_data, &results); |
| 1261 Time last_ping_day = | 1279 Time last_ping_day = |
| 1262 service.extension_prefs()->LastPingDay(extension->id()); | 1280 service.extension_prefs()->LastPingDay(extension->id()); |
| 1263 EXPECT_FALSE(last_ping_day.is_null()); | 1281 EXPECT_FALSE(last_ping_day.is_null()); |
| 1264 int64 seconds_diff = (Time::Now() - last_ping_day).InSeconds(); | 1282 int64 seconds_diff = (Time::Now() - last_ping_day).InSeconds(); |
| 1265 EXPECT_LT(seconds_diff - results.daystart_elapsed_seconds, 5); | 1283 EXPECT_LT(seconds_diff - results.daystart_elapsed_seconds, 5); |
| 1266 } | 1284 } |
| 1267 | 1285 |
| 1286 protected: |
| 1287 scoped_ptr<TestExtensionPrefs> prefs_; |
| 1288 |
| 1268 private: | 1289 private: |
| 1269 MessageLoop loop_; | 1290 MessageLoop loop_; |
| 1270 content::TestBrowserThread ui_thread_; | 1291 content::TestBrowserThread ui_thread_; |
| 1271 content::TestBrowserThread file_thread_; | 1292 content::TestBrowserThread file_thread_; |
| 1272 content::TestBrowserThread io_thread_; | 1293 content::TestBrowserThread io_thread_; |
| 1273 }; | 1294 }; |
| 1274 | 1295 |
| 1275 // Because we test some private methods of ExtensionUpdater, it's easier for the | 1296 // Because we test some private methods of ExtensionUpdater, it's easier for the |
| 1276 // actual test code to live in ExtenionUpdaterTest methods instead of TEST_F | 1297 // actual test code to live in ExtenionUpdaterTest methods instead of TEST_F |
| 1277 // subclasses where friendship with ExtenionUpdater is not inherited. | 1298 // subclasses where friendship with ExtenionUpdater is not inherited. |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1338 TEST_F(ExtensionUpdaterTest, TestGalleryRequestsWithNonOrganicBrand) { | 1359 TEST_F(ExtensionUpdaterTest, TestGalleryRequestsWithNonOrganicBrand) { |
| 1339 TestGalleryRequestsWithBrand(false); | 1360 TestGalleryRequestsWithBrand(false); |
| 1340 } | 1361 } |
| 1341 | 1362 |
| 1342 TEST_F(ExtensionUpdaterTest, TestHandleManifestResults) { | 1363 TEST_F(ExtensionUpdaterTest, TestHandleManifestResults) { |
| 1343 TestHandleManifestResults(); | 1364 TestHandleManifestResults(); |
| 1344 } | 1365 } |
| 1345 | 1366 |
| 1346 TEST_F(ExtensionUpdaterTest, TestNonAutoUpdateableLocations) { | 1367 TEST_F(ExtensionUpdaterTest, TestNonAutoUpdateableLocations) { |
| 1347 net::TestURLFetcherFactory factory; | 1368 net::TestURLFetcherFactory factory; |
| 1348 ServiceForManifestTests service; | 1369 ServiceForManifestTests service(prefs_.get()); |
| 1349 ExtensionUpdater updater(&service, service.extension_prefs(), | 1370 ExtensionUpdater updater(&service, service.extension_prefs(), |
| 1350 service.pref_service(), service.profile(), | 1371 service.pref_service(), service.profile(), |
| 1351 kUpdateFrequencySecs); | 1372 kUpdateFrequencySecs); |
| 1352 MockExtensionDownloaderDelegate delegate; | 1373 MockExtensionDownloaderDelegate delegate; |
| 1353 // Set the downloader directly, so that all its events end up in the mock | 1374 // Set the downloader directly, so that all its events end up in the mock |
| 1354 // |delegate|. | 1375 // |delegate|. |
| 1355 ExtensionDownloader* downloader = | 1376 ExtensionDownloader* downloader = |
| 1356 new ExtensionDownloader(&delegate, service.request_context()); | 1377 new ExtensionDownloader(&delegate, service.request_context()); |
| 1357 ResetDownloader(&updater, downloader); | 1378 ResetDownloader(&updater, downloader); |
| 1358 | 1379 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1369 EXPECT_CALL(delegate, GetPingDataForExtension(updateable_id, _)); | 1390 EXPECT_CALL(delegate, GetPingDataForExtension(updateable_id, _)); |
| 1370 | 1391 |
| 1371 service.set_extensions(extensions); | 1392 service.set_extensions(extensions); |
| 1372 updater.set_blacklist_checks_enabled(false); | 1393 updater.set_blacklist_checks_enabled(false); |
| 1373 updater.Start(); | 1394 updater.Start(); |
| 1374 updater.CheckNow(); | 1395 updater.CheckNow(); |
| 1375 } | 1396 } |
| 1376 | 1397 |
| 1377 TEST_F(ExtensionUpdaterTest, TestUpdatingDisabledExtensions) { | 1398 TEST_F(ExtensionUpdaterTest, TestUpdatingDisabledExtensions) { |
| 1378 net::TestURLFetcherFactory factory; | 1399 net::TestURLFetcherFactory factory; |
| 1379 ServiceForManifestTests service; | 1400 ServiceForManifestTests service(prefs_.get()); |
| 1380 ExtensionUpdater updater(&service, service.extension_prefs(), | 1401 ExtensionUpdater updater(&service, service.extension_prefs(), |
| 1381 service.pref_service(), service.profile(), | 1402 service.pref_service(), service.profile(), |
| 1382 kUpdateFrequencySecs); | 1403 kUpdateFrequencySecs); |
| 1383 MockExtensionDownloaderDelegate delegate; | 1404 MockExtensionDownloaderDelegate delegate; |
| 1384 // Set the downloader directly, so that all its events end up in the mock | 1405 // Set the downloader directly, so that all its events end up in the mock |
| 1385 // |delegate|. | 1406 // |delegate|. |
| 1386 ExtensionDownloader* downloader = | 1407 ExtensionDownloader* downloader = |
| 1387 new ExtensionDownloader(&delegate, service.request_context()); | 1408 new ExtensionDownloader(&delegate, service.request_context()); |
| 1388 ResetDownloader(&updater, downloader); | 1409 ResetDownloader(&updater, downloader); |
| 1389 | 1410 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1407 | 1428 |
| 1408 service.set_extensions(enabled_extensions); | 1429 service.set_extensions(enabled_extensions); |
| 1409 service.set_disabled_extensions(disabled_extensions); | 1430 service.set_disabled_extensions(disabled_extensions); |
| 1410 updater.set_blacklist_checks_enabled(false); | 1431 updater.set_blacklist_checks_enabled(false); |
| 1411 updater.Start(); | 1432 updater.Start(); |
| 1412 updater.CheckNow(); | 1433 updater.CheckNow(); |
| 1413 } | 1434 } |
| 1414 | 1435 |
| 1415 TEST_F(ExtensionUpdaterTest, TestManifestFetchesBuilderAddExtension) { | 1436 TEST_F(ExtensionUpdaterTest, TestManifestFetchesBuilderAddExtension) { |
| 1416 net::TestURLFetcherFactory factory; | 1437 net::TestURLFetcherFactory factory; |
| 1417 MockService service; | 1438 MockService service(prefs_.get()); |
| 1418 MockExtensionDownloaderDelegate delegate; | 1439 MockExtensionDownloaderDelegate delegate; |
| 1419 scoped_ptr<ExtensionDownloader> downloader( | 1440 scoped_ptr<ExtensionDownloader> downloader( |
| 1420 new ExtensionDownloader(&delegate, service.request_context())); | 1441 new ExtensionDownloader(&delegate, service.request_context())); |
| 1421 EXPECT_EQ(0u, ManifestFetchersCount(downloader.get())); | 1442 EXPECT_EQ(0u, ManifestFetchersCount(downloader.get())); |
| 1422 | 1443 |
| 1423 // First, verify that adding valid extensions does invoke the callbacks on | 1444 // First, verify that adding valid extensions does invoke the callbacks on |
| 1424 // the delegate. | 1445 // the delegate. |
| 1425 std::string id = GenerateId("foo"); | 1446 std::string id = GenerateId("foo"); |
| 1426 EXPECT_CALL(delegate, GetPingDataForExtension(id, _)).WillOnce(Return(false)); | 1447 EXPECT_CALL(delegate, GetPingDataForExtension(id, _)).WillOnce(Return(false)); |
| 1427 EXPECT_TRUE( | 1448 EXPECT_TRUE( |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1459 EXPECT_EQ(1u, ManifestFetchersCount(downloader.get())); | 1480 EXPECT_EQ(1u, ManifestFetchersCount(downloader.get())); |
| 1460 | 1481 |
| 1461 net::TestURLFetcher* fetcher = | 1482 net::TestURLFetcher* fetcher = |
| 1462 factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId); | 1483 factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId); |
| 1463 ASSERT_TRUE(fetcher); | 1484 ASSERT_TRUE(fetcher); |
| 1464 EXPECT_FALSE(fetcher->GetOriginalURL().is_empty()); | 1485 EXPECT_FALSE(fetcher->GetOriginalURL().is_empty()); |
| 1465 } | 1486 } |
| 1466 | 1487 |
| 1467 TEST_F(ExtensionUpdaterTest, TestStartUpdateCheckMemory) { | 1488 TEST_F(ExtensionUpdaterTest, TestStartUpdateCheckMemory) { |
| 1468 net::TestURLFetcherFactory factory; | 1489 net::TestURLFetcherFactory factory; |
| 1469 MockService service; | 1490 MockService service(prefs_.get()); |
| 1470 MockExtensionDownloaderDelegate delegate; | 1491 MockExtensionDownloaderDelegate delegate; |
| 1471 ExtensionDownloader downloader(&delegate, service.request_context()); | 1492 ExtensionDownloader downloader(&delegate, service.request_context()); |
| 1472 | 1493 |
| 1473 StartUpdateCheck(&downloader, new ManifestFetchData(GURL())); | 1494 StartUpdateCheck(&downloader, new ManifestFetchData(GURL())); |
| 1474 // This should delete the newly-created ManifestFetchData. | 1495 // This should delete the newly-created ManifestFetchData. |
| 1475 StartUpdateCheck(&downloader, new ManifestFetchData(GURL())); | 1496 StartUpdateCheck(&downloader, new ManifestFetchData(GURL())); |
| 1476 // This should add into |manifests_pending_|. | 1497 // This should add into |manifests_pending_|. |
| 1477 StartUpdateCheck(&downloader, new ManifestFetchData(GURL( | 1498 StartUpdateCheck(&downloader, new ManifestFetchData(GURL( |
| 1478 GURL("http://www.google.com")))); | 1499 GURL("http://www.google.com")))); |
| 1479 // The dtor of |downloader| should delete the pending fetchers. | 1500 // The dtor of |downloader| should delete the pending fetchers. |
| 1480 } | 1501 } |
| 1481 | 1502 |
| 1482 TEST_F(ExtensionUpdaterTest, TestCheckSoon) { | 1503 TEST_F(ExtensionUpdaterTest, TestCheckSoon) { |
| 1483 ServiceForManifestTests service; | 1504 ServiceForManifestTests service(prefs_.get()); |
| 1484 net::TestURLFetcherFactory factory; | 1505 net::TestURLFetcherFactory factory; |
| 1485 ExtensionUpdater updater( | 1506 ExtensionUpdater updater( |
| 1486 &service, service.extension_prefs(), service.pref_service(), | 1507 &service, service.extension_prefs(), service.pref_service(), |
| 1487 service.profile(), kUpdateFrequencySecs); | 1508 service.profile(), kUpdateFrequencySecs); |
| 1488 EXPECT_FALSE(updater.WillCheckSoon()); | 1509 EXPECT_FALSE(updater.WillCheckSoon()); |
| 1489 updater.Start(); | 1510 updater.Start(); |
| 1490 EXPECT_FALSE(updater.WillCheckSoon()); | 1511 EXPECT_FALSE(updater.WillCheckSoon()); |
| 1491 updater.CheckSoon(); | 1512 updater.CheckSoon(); |
| 1492 EXPECT_TRUE(updater.WillCheckSoon()); | 1513 EXPECT_TRUE(updater.WillCheckSoon()); |
| 1493 updater.CheckSoon(); | 1514 updater.CheckSoon(); |
| 1494 EXPECT_TRUE(updater.WillCheckSoon()); | 1515 EXPECT_TRUE(updater.WillCheckSoon()); |
| 1495 RunAllPending(); | 1516 RunUntilIdle(); |
| 1496 EXPECT_FALSE(updater.WillCheckSoon()); | 1517 EXPECT_FALSE(updater.WillCheckSoon()); |
| 1497 updater.CheckSoon(); | 1518 updater.CheckSoon(); |
| 1498 EXPECT_TRUE(updater.WillCheckSoon()); | 1519 EXPECT_TRUE(updater.WillCheckSoon()); |
| 1499 updater.Stop(); | 1520 updater.Stop(); |
| 1500 EXPECT_FALSE(updater.WillCheckSoon()); | 1521 EXPECT_FALSE(updater.WillCheckSoon()); |
| 1501 } | 1522 } |
| 1502 | 1523 |
| 1503 // TODO(asargent) - (http://crbug.com/12780) add tests for: | 1524 // TODO(asargent) - (http://crbug.com/12780) add tests for: |
| 1504 // -prodversionmin (shouldn't update if browser version too old) | 1525 // -prodversionmin (shouldn't update if browser version too old) |
| 1505 // -manifests & updates arriving out of order / interleaved | 1526 // -manifests & updates arriving out of order / interleaved |
| 1506 // -malformed update url (empty, file://, has query, has a # fragment, etc.) | 1527 // -malformed update url (empty, file://, has query, has a # fragment, etc.) |
| 1507 // -An extension gets uninstalled while updates are in progress (so it doesn't | 1528 // -An extension gets uninstalled while updates are in progress (so it doesn't |
| 1508 // "come back from the dead") | 1529 // "come back from the dead") |
| 1509 // -An extension gets manually updated to v3 while we're downloading v2 (ie | 1530 // -An extension gets manually updated to v3 while we're downloading v2 (ie |
| 1510 // you don't get downgraded accidentally) | 1531 // you don't get downgraded accidentally) |
| 1511 // -An update manifest mentions multiple updates | 1532 // -An update manifest mentions multiple updates |
| 1512 | 1533 |
| 1513 } // namespace extensions | 1534 } // namespace extensions |
| OLD | NEW |