OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <map> | 5 #include <map> |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/scoped_ptr.h" | 8 #include "base/scoped_ptr.h" |
9 #include "base/stl_util-inl.h" | 9 #include "base/stl_util-inl.h" |
10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 const std::string& url, | 308 const std::string& url, |
309 UpdateManifest::Results* results) { | 309 UpdateManifest::Results* results) { |
310 UpdateManifest::Result result; | 310 UpdateManifest::Result result; |
311 result.extension_id = id; | 311 result.extension_id = id; |
312 result.version = version; | 312 result.version = version; |
313 result.crx_url = GURL(url); | 313 result.crx_url = GURL(url); |
314 results->list.push_back(result); | 314 results->list.push_back(result); |
315 } | 315 } |
316 | 316 |
317 static void TestExtensionUpdateCheckRequests(bool pending) { | 317 static void TestExtensionUpdateCheckRequests(bool pending) { |
| 318 MessageLoop message_loop; |
| 319 BrowserThread file_thread(BrowserThread::FILE, &message_loop); |
| 320 BrowserThread io_thread(BrowserThread::IO); |
| 321 io_thread.Start(); |
| 322 |
318 // Create an extension with an update_url. | 323 // Create an extension with an update_url. |
319 ServiceForManifestTests service; | 324 ServiceForManifestTests service; |
320 std::string update_url("http://foo.com/bar"); | 325 std::string update_url("http://foo.com/bar"); |
321 ExtensionList extensions; | 326 ExtensionList extensions; |
322 PendingExtensionMap pending_extensions; | 327 PendingExtensionMap pending_extensions; |
323 if (pending) { | 328 if (pending) { |
324 CreateTestPendingExtensions(1, GURL(update_url), &pending_extensions); | 329 CreateTestPendingExtensions(1, GURL(update_url), &pending_extensions); |
325 service.set_pending_extensions(pending_extensions); | 330 service.set_pending_extensions(pending_extensions); |
326 } else { | 331 } else { |
327 service.CreateTestExtensions(1, 1, &extensions, &update_url, | 332 service.CreateTestExtensions(1, 1, &extensions, &update_url, |
328 Extension::INTERNAL); | 333 Extension::INTERNAL); |
329 service.set_extensions(extensions); | 334 service.set_extensions(extensions); |
330 } | 335 } |
331 | 336 |
332 // Setup and start the updater. | 337 // Set up and start the updater. |
333 MessageLoop message_loop; | |
334 BrowserThread io_thread(BrowserThread::IO); | |
335 io_thread.Start(); | |
336 | |
337 TestURLFetcherFactory factory; | 338 TestURLFetcherFactory factory; |
338 URLFetcher::set_factory(&factory); | 339 URLFetcher::set_factory(&factory); |
339 scoped_refptr<ExtensionUpdater> updater( | 340 scoped_refptr<ExtensionUpdater> updater( |
340 new ExtensionUpdater(&service, service.pref_service(), 60*60*24)); | 341 new ExtensionUpdater(&service, service.pref_service(), 60*60*24)); |
341 updater->Start(); | 342 updater->Start(); |
342 | 343 |
343 // Tell the update that it's time to do update checks. | 344 // Tell the update that it's time to do update checks. |
344 SimulateTimerFired(updater.get()); | 345 SimulateTimerFired(updater.get()); |
345 | 346 |
346 // Get the url our mock fetcher was asked to fetch. | 347 // Get the url our mock fetcher was asked to fetch. |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 // Make sure that extensions that update from the gallery ignore any | 487 // Make sure that extensions that update from the gallery ignore any |
487 // update URL data. | 488 // update URL data. |
488 const std::string& update_url = fetch->full_url().spec(); | 489 const std::string& update_url = fetch->full_url().spec(); |
489 std::string::size_type x = update_url.find("x="); | 490 std::string::size_type x = update_url.find("x="); |
490 EXPECT_NE(std::string::npos, x); | 491 EXPECT_NE(std::string::npos, x); |
491 std::string::size_type ap = update_url.find("ap%3D", x); | 492 std::string::size_type ap = update_url.find("ap%3D", x); |
492 EXPECT_EQ(std::string::npos, ap); | 493 EXPECT_EQ(std::string::npos, ap); |
493 } | 494 } |
494 | 495 |
495 static void TestDetermineUpdates() { | 496 static void TestDetermineUpdates() { |
| 497 MessageLoop message_loop; |
| 498 BrowserThread file_thread(BrowserThread::FILE, &message_loop); |
| 499 |
496 // Create a set of test extensions | 500 // Create a set of test extensions |
497 ServiceForManifestTests service; | 501 ServiceForManifestTests service; |
498 ExtensionList tmp; | 502 ExtensionList tmp; |
499 service.CreateTestExtensions(1, 3, &tmp, NULL, Extension::INTERNAL); | 503 service.CreateTestExtensions(1, 3, &tmp, NULL, Extension::INTERNAL); |
500 service.set_extensions(tmp); | 504 service.set_extensions(tmp); |
501 | 505 |
502 MessageLoop message_loop; | |
503 scoped_refptr<ExtensionUpdater> updater( | 506 scoped_refptr<ExtensionUpdater> updater( |
504 new ExtensionUpdater(&service, service.pref_service(), | 507 new ExtensionUpdater(&service, service.pref_service(), |
505 kUpdateFrequencySecs)); | 508 kUpdateFrequencySecs)); |
506 updater->Start(); | 509 updater->Start(); |
507 | 510 |
508 // Check passing an empty list of parse results to DetermineUpdates | 511 // Check passing an empty list of parse results to DetermineUpdates |
509 ManifestFetchData fetch_data(GURL("http://localhost/foo")); | 512 ManifestFetchData fetch_data(GURL("http://localhost/foo")); |
510 UpdateManifest::Results updates; | 513 UpdateManifest::Results updates; |
511 std::vector<int> updateable = updater->DetermineUpdates(fetch_data, | 514 std::vector<int> updateable = updater->DetermineUpdates(fetch_data, |
512 updates); | 515 updates); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
568 MessageLoop ui_loop; | 571 MessageLoop ui_loop; |
569 BrowserThread ui_thread(BrowserThread::UI, &ui_loop); | 572 BrowserThread ui_thread(BrowserThread::UI, &ui_loop); |
570 BrowserThread file_thread(BrowserThread::FILE); | 573 BrowserThread file_thread(BrowserThread::FILE); |
571 file_thread.Start(); | 574 file_thread.Start(); |
572 BrowserThread io_thread(BrowserThread::IO); | 575 BrowserThread io_thread(BrowserThread::IO); |
573 io_thread.Start(); | 576 io_thread.Start(); |
574 | 577 |
575 TestURLFetcherFactory factory; | 578 TestURLFetcherFactory factory; |
576 TestURLFetcher* fetcher = NULL; | 579 TestURLFetcher* fetcher = NULL; |
577 URLFetcher::set_factory(&factory); | 580 URLFetcher::set_factory(&factory); |
578 ServiceForDownloadTests service; | 581 scoped_ptr<ServiceForDownloadTests> service(new ServiceForDownloadTests); |
579 scoped_refptr<ExtensionUpdater> updater( | 582 scoped_refptr<ExtensionUpdater> updater( |
580 new ExtensionUpdater(&service, service.pref_service(), | 583 new ExtensionUpdater(service.get(), service->pref_service(), |
581 kUpdateFrequencySecs)); | 584 kUpdateFrequencySecs)); |
582 updater->Start(); | 585 updater->Start(); |
583 | 586 |
584 GURL url1("http://localhost/manifest1"); | 587 GURL url1("http://localhost/manifest1"); |
585 GURL url2("http://localhost/manifest2"); | 588 GURL url2("http://localhost/manifest2"); |
586 | 589 |
587 // Request 2 update checks - the first should begin immediately and the | 590 // Request 2 update checks - the first should begin immediately and the |
588 // second one should be queued up. | 591 // second one should be queued up. |
589 ManifestFetchData* fetch1 = new ManifestFetchData(url1); | 592 ManifestFetchData* fetch1 = new ManifestFetchData(url1); |
590 ManifestFetchData* fetch2 = new ManifestFetchData(url2); | 593 ManifestFetchData* fetch2 = new ManifestFetchData(url2); |
(...skipping 29 matching lines...) Expand all Loading... |
620 fetcher->delegate()->OnURLFetchComplete( | 623 fetcher->delegate()->OnURLFetchComplete( |
621 fetcher, url2, net::URLRequestStatus(), 200, ResponseCookies(), | 624 fetcher, url2, net::URLRequestStatus(), 200, ResponseCookies(), |
622 kValidXml); | 625 kValidXml); |
623 | 626 |
624 // This should run the manifest parsing, then we want to make sure that our | 627 // This should run the manifest parsing, then we want to make sure that our |
625 // service was called with GetExtensionById with the matching id from | 628 // service was called with GetExtensionById with the matching id from |
626 // kValidXml. | 629 // kValidXml. |
627 file_thread.Stop(); | 630 file_thread.Stop(); |
628 io_thread.Stop(); | 631 io_thread.Stop(); |
629 ui_loop.RunAllPending(); | 632 ui_loop.RunAllPending(); |
630 EXPECT_EQ("12345", service.last_inquired_extension_id()); | 633 EXPECT_EQ("12345", service->last_inquired_extension_id()); |
631 xmlCleanupGlobals(); | 634 xmlCleanupGlobals(); |
| 635 |
| 636 // The FILE thread is needed for |service|'s cleanup, |
| 637 // because of ImportantFileWriter. |
| 638 file_thread.Start(); |
| 639 service.reset(); |
632 } | 640 } |
633 | 641 |
634 static void TestSingleExtensionDownloading(bool pending) { | 642 static void TestSingleExtensionDownloading(bool pending) { |
635 MessageLoop ui_loop; | 643 MessageLoop ui_loop; |
636 BrowserThread ui_thread(BrowserThread::UI, &ui_loop); | 644 BrowserThread ui_thread(BrowserThread::UI, &ui_loop); |
637 BrowserThread file_thread(BrowserThread::FILE); | 645 BrowserThread file_thread(BrowserThread::FILE); |
638 file_thread.Start(); | 646 file_thread.Start(); |
639 BrowserThread io_thread(BrowserThread::IO); | 647 BrowserThread io_thread(BrowserThread::IO); |
640 io_thread.Start(); | 648 io_thread.Start(); |
641 | 649 |
642 TestURLFetcherFactory factory; | 650 TestURLFetcherFactory factory; |
643 TestURLFetcher* fetcher = NULL; | 651 TestURLFetcher* fetcher = NULL; |
644 URLFetcher::set_factory(&factory); | 652 URLFetcher::set_factory(&factory); |
645 ServiceForDownloadTests service; | 653 scoped_ptr<ServiceForDownloadTests> service(new ServiceForDownloadTests); |
646 scoped_refptr<ExtensionUpdater> updater( | 654 scoped_refptr<ExtensionUpdater> updater( |
647 new ExtensionUpdater(&service, service.pref_service(), | 655 new ExtensionUpdater(service.get(), service->pref_service(), |
648 kUpdateFrequencySecs)); | 656 kUpdateFrequencySecs)); |
649 updater->Start(); | 657 updater->Start(); |
650 | 658 |
651 GURL test_url("http://localhost/extension.crx"); | 659 GURL test_url("http://localhost/extension.crx"); |
652 | 660 |
653 std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; | 661 std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; |
654 std::string hash = ""; | 662 std::string hash = ""; |
655 scoped_ptr<Version> version(Version::GetVersionFromString("0.0.1")); | 663 scoped_ptr<Version> version(Version::GetVersionFromString("0.0.1")); |
656 ASSERT_TRUE(version.get()); | 664 ASSERT_TRUE(version.get()); |
657 updater->FetchUpdatedExtension(id, test_url, hash, version->GetString()); | 665 updater->FetchUpdatedExtension(id, test_url, hash, version->GetString()); |
658 | 666 |
659 if (pending) { | 667 if (pending) { |
660 const bool kIsFromSync = true; | 668 const bool kIsFromSync = true; |
661 const bool kInstallSilently = true; | 669 const bool kInstallSilently = true; |
662 const Extension::State kInitialState = Extension::ENABLED; | 670 const Extension::State kInitialState = Extension::ENABLED; |
663 const bool kInitialIncognitoEnabled = false; | 671 const bool kInitialIncognitoEnabled = false; |
664 PendingExtensionMap pending_extensions; | 672 PendingExtensionMap pending_extensions; |
665 pending_extensions[id] = | 673 pending_extensions[id] = |
666 PendingExtensionInfo(test_url, &ShouldAlwaysInstall, kIsFromSync, | 674 PendingExtensionInfo(test_url, &ShouldAlwaysInstall, kIsFromSync, |
667 kInstallSilently, kInitialState, | 675 kInstallSilently, kInitialState, |
668 kInitialIncognitoEnabled, Extension::INTERNAL); | 676 kInitialIncognitoEnabled, Extension::INTERNAL); |
669 service.set_pending_extensions(pending_extensions); | 677 service->set_pending_extensions(pending_extensions); |
670 } | 678 } |
671 | 679 |
672 // Call back the ExtensionUpdater with a 200 response and some test data | 680 // Call back the ExtensionUpdater with a 200 response and some test data |
673 std::string extension_data("whatever"); | 681 std::string extension_data("whatever"); |
674 fetcher = factory.GetFetcherByID(ExtensionUpdater::kExtensionFetcherId); | 682 fetcher = factory.GetFetcherByID(ExtensionUpdater::kExtensionFetcherId); |
675 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); | 683 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); |
676 EXPECT_TRUE(fetcher->load_flags() == expected_load_flags); | 684 EXPECT_TRUE(fetcher->load_flags() == expected_load_flags); |
677 fetcher->delegate()->OnURLFetchComplete( | 685 fetcher->delegate()->OnURLFetchComplete( |
678 fetcher, test_url, net::URLRequestStatus(), 200, ResponseCookies(), | 686 fetcher, test_url, net::URLRequestStatus(), 200, ResponseCookies(), |
679 extension_data); | 687 extension_data); |
680 | 688 |
681 file_thread.Stop(); | 689 file_thread.Stop(); |
682 ui_loop.RunAllPending(); | 690 ui_loop.RunAllPending(); |
683 | 691 |
684 // Expect that ExtensionUpdater asked the mock extensions service to install | 692 // Expect that ExtensionUpdater asked the mock extensions service to install |
685 // a file with the test data for the right id. | 693 // a file with the test data for the right id. |
686 EXPECT_EQ(id, service.extension_id()); | 694 EXPECT_EQ(id, service->extension_id()); |
687 FilePath tmpfile_path = service.install_path(); | 695 FilePath tmpfile_path = service->install_path(); |
688 EXPECT_FALSE(tmpfile_path.empty()); | 696 EXPECT_FALSE(tmpfile_path.empty()); |
689 EXPECT_EQ(test_url, service.download_url()); | 697 EXPECT_EQ(test_url, service->download_url()); |
690 std::string file_contents; | 698 std::string file_contents; |
691 EXPECT_TRUE(file_util::ReadFileToString(tmpfile_path, &file_contents)); | 699 EXPECT_TRUE(file_util::ReadFileToString(tmpfile_path, &file_contents)); |
692 EXPECT_TRUE(extension_data == file_contents); | 700 EXPECT_TRUE(extension_data == file_contents); |
693 | 701 |
| 702 // The FILE thread is needed for |service|'s cleanup, |
| 703 // because of ImportantFileWriter. |
| 704 file_thread.Start(); |
| 705 service.reset(); |
| 706 |
694 file_util::Delete(tmpfile_path, false); | 707 file_util::Delete(tmpfile_path, false); |
695 URLFetcher::set_factory(NULL); | 708 URLFetcher::set_factory(NULL); |
696 } | 709 } |
697 | 710 |
698 static void TestBlacklistDownloading() { | 711 static void TestBlacklistDownloading() { |
699 MessageLoop message_loop; | 712 MessageLoop message_loop; |
700 BrowserThread ui_thread(BrowserThread::UI, &message_loop); | 713 BrowserThread ui_thread(BrowserThread::UI, &message_loop); |
| 714 BrowserThread file_thread(BrowserThread::FILE, &message_loop); |
701 BrowserThread io_thread(BrowserThread::IO); | 715 BrowserThread io_thread(BrowserThread::IO); |
702 io_thread.Start(); | 716 io_thread.Start(); |
703 | 717 |
704 TestURLFetcherFactory factory; | 718 TestURLFetcherFactory factory; |
705 TestURLFetcher* fetcher = NULL; | 719 TestURLFetcher* fetcher = NULL; |
706 URLFetcher::set_factory(&factory); | 720 URLFetcher::set_factory(&factory); |
707 ServiceForBlacklistTests service; | 721 ServiceForBlacklistTests service; |
708 scoped_refptr<ExtensionUpdater> updater( | 722 scoped_refptr<ExtensionUpdater> updater( |
709 new ExtensionUpdater(&service, service.pref_service(), | 723 new ExtensionUpdater(&service, service.pref_service(), |
710 kUpdateFrequencySecs)); | 724 kUpdateFrequencySecs)); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
813 | 827 |
814 // Test requests to both a Google server and a non-google server. This allows | 828 // Test requests to both a Google server and a non-google server. This allows |
815 // us to test various combinations of installed (ie roll call) and active | 829 // us to test various combinations of installed (ie roll call) and active |
816 // (ie app launch) ping scenarios. The invariant is that each type of ping | 830 // (ie app launch) ping scenarios. The invariant is that each type of ping |
817 // value should be present at most once per day, and can be calculated based | 831 // value should be present at most once per day, and can be calculated based |
818 // on the delta between now and the last ping time (or in the case of active | 832 // on the delta between now and the last ping time (or in the case of active |
819 // pings, that delta plus whether the app has been active). | 833 // pings, that delta plus whether the app has been active). |
820 static void TestGalleryRequests(int rollcall_ping_days, | 834 static void TestGalleryRequests(int rollcall_ping_days, |
821 int active_ping_days, | 835 int active_ping_days, |
822 bool active_bit) { | 836 bool active_bit) { |
| 837 MessageLoop message_loop; |
| 838 BrowserThread file_thread(BrowserThread::FILE, &message_loop); |
| 839 |
823 TestURLFetcherFactory factory; | 840 TestURLFetcherFactory factory; |
824 URLFetcher::set_factory(&factory); | 841 URLFetcher::set_factory(&factory); |
825 | 842 |
826 // Set up 2 mock extensions, one with a google.com update url and one | 843 // Set up 2 mock extensions, one with a google.com update url and one |
827 // without. | 844 // without. |
828 ServiceForManifestTests service; | 845 ServiceForManifestTests service; |
829 ExtensionList tmp; | 846 ExtensionList tmp; |
830 GURL url1("http://clients2.google.com/service/update2/crx"); | 847 GURL url1("http://clients2.google.com/service/update2/crx"); |
831 GURL url2("http://www.somewebsite.com"); | 848 GURL url2("http://www.somewebsite.com"); |
832 service.CreateTestExtensions(1, 1, &tmp, &url1.possibly_invalid_spec(), | 849 service.CreateTestExtensions(1, 1, &tmp, &url1.possibly_invalid_spec(), |
(...skipping 20 matching lines...) Expand all Loading... |
853 prefs->SetLastActivePingDay(id, now - TimeDelta::FromSeconds(15)); | 870 prefs->SetLastActivePingDay(id, now - TimeDelta::FromSeconds(15)); |
854 } else if (active_ping_days > 0) { | 871 } else if (active_ping_days > 0) { |
855 Time last_active_ping_day = now - | 872 Time last_active_ping_day = now - |
856 TimeDelta::FromDays(active_ping_days) - | 873 TimeDelta::FromDays(active_ping_days) - |
857 TimeDelta::FromSeconds(15); | 874 TimeDelta::FromSeconds(15); |
858 prefs->SetLastActivePingDay(id, last_active_ping_day); | 875 prefs->SetLastActivePingDay(id, last_active_ping_day); |
859 } | 876 } |
860 if (active_bit) | 877 if (active_bit) |
861 prefs->SetActiveBit(id, true); | 878 prefs->SetActiveBit(id, true); |
862 | 879 |
863 MessageLoop message_loop; | |
864 scoped_refptr<ExtensionUpdater> updater( | 880 scoped_refptr<ExtensionUpdater> updater( |
865 new ExtensionUpdater(&service, service.pref_service(), | 881 new ExtensionUpdater(&service, service.pref_service(), |
866 kUpdateFrequencySecs)); | 882 kUpdateFrequencySecs)); |
867 updater->Start(); | 883 updater->Start(); |
868 updater->set_blacklist_checks_enabled(false); | 884 updater->set_blacklist_checks_enabled(false); |
869 | 885 |
870 // Make the updater do manifest fetching, and note the urls it tries to | 886 // Make the updater do manifest fetching, and note the urls it tries to |
871 // fetch. | 887 // fetch. |
872 std::vector<GURL> fetched_urls; | 888 std::vector<GURL> fetched_urls; |
873 updater->CheckNow(); | 889 updater->CheckNow(); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
965 TEST(ExtensionUpdaterTest, TestExtensionUpdateCheckRequestsPending) { | 981 TEST(ExtensionUpdaterTest, TestExtensionUpdateCheckRequestsPending) { |
966 ExtensionUpdaterTest::TestExtensionUpdateCheckRequests(true); | 982 ExtensionUpdaterTest::TestExtensionUpdateCheckRequests(true); |
967 } | 983 } |
968 | 984 |
969 // This test is disabled on Mac, see http://crbug.com/26035. | 985 // This test is disabled on Mac, see http://crbug.com/26035. |
970 TEST(ExtensionUpdaterTest, TestBlacklistUpdateCheckRequests) { | 986 TEST(ExtensionUpdaterTest, TestBlacklistUpdateCheckRequests) { |
971 ExtensionUpdaterTest::TestBlacklistUpdateCheckRequests(); | 987 ExtensionUpdaterTest::TestBlacklistUpdateCheckRequests(); |
972 } | 988 } |
973 | 989 |
974 TEST(ExtensionUpdaterTest, TestUpdateUrlData) { | 990 TEST(ExtensionUpdaterTest, TestUpdateUrlData) { |
| 991 MessageLoop message_loop; |
| 992 BrowserThread file_thread(BrowserThread::FILE, &message_loop); |
| 993 |
975 ExtensionUpdaterTest::TestUpdateUrlDataEmpty(); | 994 ExtensionUpdaterTest::TestUpdateUrlDataEmpty(); |
976 ExtensionUpdaterTest::TestUpdateUrlDataSimple(); | 995 ExtensionUpdaterTest::TestUpdateUrlDataSimple(); |
977 ExtensionUpdaterTest::TestUpdateUrlDataCompound(); | 996 ExtensionUpdaterTest::TestUpdateUrlDataCompound(); |
978 ExtensionUpdaterTest::TestUpdateUrlDataFromGallery( | 997 ExtensionUpdaterTest::TestUpdateUrlDataFromGallery( |
979 Extension::GalleryUpdateUrl(false).spec()); | 998 Extension::GalleryUpdateUrl(false).spec()); |
980 ExtensionUpdaterTest::TestUpdateUrlDataFromGallery( | 999 ExtensionUpdaterTest::TestUpdateUrlDataFromGallery( |
981 Extension::GalleryUpdateUrl(true).spec()); | 1000 Extension::GalleryUpdateUrl(true).spec()); |
982 } | 1001 } |
983 | 1002 |
984 TEST(ExtensionUpdaterTest, TestDetermineUpdates) { | 1003 TEST(ExtensionUpdaterTest, TestDetermineUpdates) { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1037 } | 1056 } |
1038 } | 1057 } |
1039 } | 1058 } |
1040 } | 1059 } |
1041 | 1060 |
1042 TEST(ExtensionUpdaterTest, TestHandleManifestResults) { | 1061 TEST(ExtensionUpdaterTest, TestHandleManifestResults) { |
1043 ExtensionUpdaterTest::TestHandleManifestResults(); | 1062 ExtensionUpdaterTest::TestHandleManifestResults(); |
1044 } | 1063 } |
1045 | 1064 |
1046 TEST(ExtensionUpdaterTest, TestManifestFetchesBuilderAddExtension) { | 1065 TEST(ExtensionUpdaterTest, TestManifestFetchesBuilderAddExtension) { |
| 1066 MessageLoop message_loop; |
| 1067 BrowserThread file_thread(BrowserThread::FILE, &message_loop); |
| 1068 |
1047 MockService service; | 1069 MockService service; |
1048 ManifestFetchesBuilder builder(&service); | 1070 ManifestFetchesBuilder builder(&service); |
1049 | 1071 |
1050 // Non-internal non-external extensions should be rejected. | 1072 // Non-internal non-external extensions should be rejected. |
1051 { | 1073 { |
1052 ExtensionList extensions; | 1074 ExtensionList extensions; |
1053 service.CreateTestExtensions(1, 1, &extensions, NULL, Extension::INVALID); | 1075 service.CreateTestExtensions(1, 1, &extensions, NULL, Extension::INVALID); |
1054 ASSERT_FALSE(extensions.empty()); | 1076 ASSERT_FALSE(extensions.empty()); |
1055 builder.AddExtension(*extensions[0]); | 1077 builder.AddExtension(*extensions[0]); |
1056 EXPECT_TRUE(builder.GetFetches().empty()); | 1078 EXPECT_TRUE(builder.GetFetches().empty()); |
(...skipping 27 matching lines...) Expand all Loading... |
1084 std::vector<ManifestFetchData*> fetches = builder.GetFetches(); | 1106 std::vector<ManifestFetchData*> fetches = builder.GetFetches(); |
1085 ASSERT_EQ(1u, fetches.size()); | 1107 ASSERT_EQ(1u, fetches.size()); |
1086 scoped_ptr<ManifestFetchData> fetch(fetches[0]); | 1108 scoped_ptr<ManifestFetchData> fetch(fetches[0]); |
1087 fetches.clear(); | 1109 fetches.clear(); |
1088 EXPECT_FALSE(fetch->base_url().is_empty()); | 1110 EXPECT_FALSE(fetch->base_url().is_empty()); |
1089 EXPECT_FALSE(fetch->full_url().is_empty()); | 1111 EXPECT_FALSE(fetch->full_url().is_empty()); |
1090 } | 1112 } |
1091 | 1113 |
1092 TEST(ExtensionUpdaterTest, TestStartUpdateCheckMemory) { | 1114 TEST(ExtensionUpdaterTest, TestStartUpdateCheckMemory) { |
1093 MessageLoop message_loop; | 1115 MessageLoop message_loop; |
| 1116 BrowserThread file_thread(BrowserThread::FILE, &message_loop); |
| 1117 |
1094 ServiceForManifestTests service; | 1118 ServiceForManifestTests service; |
1095 TestURLFetcherFactory factory; | 1119 TestURLFetcherFactory factory; |
1096 URLFetcher::set_factory(&factory); | 1120 URLFetcher::set_factory(&factory); |
1097 scoped_refptr<ExtensionUpdater> updater( | 1121 scoped_refptr<ExtensionUpdater> updater( |
1098 new ExtensionUpdater(&service, service.pref_service(), | 1122 new ExtensionUpdater(&service, service.pref_service(), |
1099 kUpdateFrequencySecs)); | 1123 kUpdateFrequencySecs)); |
1100 updater->Start(); | 1124 updater->Start(); |
1101 updater->StartUpdateCheck(new ManifestFetchData(GURL())); | 1125 updater->StartUpdateCheck(new ManifestFetchData(GURL())); |
1102 // This should delete the newly-created ManifestFetchData. | 1126 // This should delete the newly-created ManifestFetchData. |
1103 updater->StartUpdateCheck(new ManifestFetchData(GURL())); | 1127 updater->StartUpdateCheck(new ManifestFetchData(GURL())); |
1104 // This should add into |manifests_pending_|. | 1128 // This should add into |manifests_pending_|. |
1105 updater->StartUpdateCheck(new ManifestFetchData( | 1129 updater->StartUpdateCheck(new ManifestFetchData( |
1106 GURL("http://www.google.com"))); | 1130 GURL("http://www.google.com"))); |
1107 // This should clear out |manifests_pending_|. | 1131 // This should clear out |manifests_pending_|. |
1108 updater->Stop(); | 1132 updater->Stop(); |
1109 } | 1133 } |
1110 | 1134 |
1111 TEST(ExtensionUpdaterTest, TestAfterStopBehavior) { | 1135 TEST(ExtensionUpdaterTest, TestAfterStopBehavior) { |
1112 MessageLoop message_loop; | 1136 MessageLoop message_loop; |
| 1137 BrowserThread file_thread(BrowserThread::FILE, &message_loop); |
| 1138 |
1113 ServiceForManifestTests service; | 1139 ServiceForManifestTests service; |
1114 scoped_refptr<ExtensionUpdater> updater( | 1140 scoped_refptr<ExtensionUpdater> updater( |
1115 new ExtensionUpdater(&service, service.pref_service(), | 1141 new ExtensionUpdater(&service, service.pref_service(), |
1116 kUpdateFrequencySecs)); | 1142 kUpdateFrequencySecs)); |
1117 updater->Start(); | 1143 updater->Start(); |
1118 updater->Stop(); | 1144 updater->Stop(); |
1119 // All the below functions should do nothing. | 1145 // All the below functions should do nothing. |
1120 updater->OnCRXFileWritten("", FilePath(), GURL()); | 1146 updater->OnCRXFileWritten("", FilePath(), GURL()); |
1121 GURL dummy_gurl; | 1147 GURL dummy_gurl; |
1122 ManifestFetchData dummy_manifest_fetch_data(dummy_gurl); | 1148 ManifestFetchData dummy_manifest_fetch_data(dummy_gurl); |
1123 updater->HandleManifestResults(dummy_manifest_fetch_data, | 1149 updater->HandleManifestResults(dummy_manifest_fetch_data, |
1124 UpdateManifest::Results()); | 1150 UpdateManifest::Results()); |
1125 } | 1151 } |
1126 | 1152 |
1127 // TODO(asargent) - (http://crbug.com/12780) add tests for: | 1153 // TODO(asargent) - (http://crbug.com/12780) add tests for: |
1128 // -prodversionmin (shouldn't update if browser version too old) | 1154 // -prodversionmin (shouldn't update if browser version too old) |
1129 // -manifests & updates arriving out of order / interleaved | 1155 // -manifests & updates arriving out of order / interleaved |
1130 // -malformed update url (empty, file://, has query, has a # fragment, etc.) | 1156 // -malformed update url (empty, file://, has query, has a # fragment, etc.) |
1131 // -An extension gets uninstalled while updates are in progress (so it doesn't | 1157 // -An extension gets uninstalled while updates are in progress (so it doesn't |
1132 // "come back from the dead") | 1158 // "come back from the dead") |
1133 // -An extension gets manually updated to v3 while we're downloading v2 (ie | 1159 // -An extension gets manually updated to v3 while we're downloading v2 (ie |
1134 // you don't get downgraded accidentally) | 1160 // you don't get downgraded accidentally) |
1135 // -An update manifest mentions multiple updates | 1161 // -An update manifest mentions multiple updates |
OLD | NEW |