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/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 // Disable blacklist checks (tested elsewhere) so that we only see the | 345 // Disable blacklist checks (tested elsewhere) so that we only see the |
346 // update HTTP request. | 346 // update HTTP request. |
347 updater.set_blacklist_checks_enabled(false); | 347 updater.set_blacklist_checks_enabled(false); |
348 | 348 |
349 // Tell the update that it's time to do update checks. | 349 // Tell the update that it's time to do update checks. |
350 SimulateTimerFired(&updater); | 350 SimulateTimerFired(&updater); |
351 | 351 |
352 // Get the url our mock fetcher was asked to fetch. | 352 // Get the url our mock fetcher was asked to fetch. |
353 TestURLFetcher* fetcher = | 353 TestURLFetcher* fetcher = |
354 factory.GetFetcherByID(ExtensionUpdater::kManifestFetcherId); | 354 factory.GetFetcherByID(ExtensionUpdater::kManifestFetcherId); |
355 const GURL& url = fetcher->original_url(); | 355 const GURL& url = fetcher->GetOriginalUrl(); |
356 EXPECT_FALSE(url.is_empty()); | 356 EXPECT_FALSE(url.is_empty()); |
357 EXPECT_TRUE(url.is_valid()); | 357 EXPECT_TRUE(url.is_valid()); |
358 EXPECT_TRUE(url.SchemeIs("http")); | 358 EXPECT_TRUE(url.SchemeIs("http")); |
359 EXPECT_EQ("foo.com", url.host()); | 359 EXPECT_EQ("foo.com", url.host()); |
360 EXPECT_EQ("/bar", url.path()); | 360 EXPECT_EQ("/bar", url.path()); |
361 | 361 |
362 // Validate the extension request parameters in the query. It should | 362 // Validate the extension request parameters in the query. It should |
363 // look something like "?x=id%3D<id>%26v%3D<version>%26uc". | 363 // look something like "?x=id%3D<id>%26v%3D<version>%26uc". |
364 EXPECT_TRUE(url.has_query()); | 364 EXPECT_TRUE(url.has_query()); |
365 std::vector<std::string> parts; | 365 std::vector<std::string> parts; |
(...skipping 29 matching lines...) Expand all Loading... |
395 service.profile(), 60*60*24); | 395 service.profile(), 60*60*24); |
396 updater.Start(); | 396 updater.Start(); |
397 | 397 |
398 // Tell the updater that it's time to do update checks. | 398 // Tell the updater that it's time to do update checks. |
399 SimulateTimerFired(&updater); | 399 SimulateTimerFired(&updater); |
400 | 400 |
401 // Get the url our mock fetcher was asked to fetch. | 401 // Get the url our mock fetcher was asked to fetch. |
402 TestURLFetcher* fetcher = | 402 TestURLFetcher* fetcher = |
403 factory.GetFetcherByID(ExtensionUpdater::kManifestFetcherId); | 403 factory.GetFetcherByID(ExtensionUpdater::kManifestFetcherId); |
404 ASSERT_FALSE(fetcher == NULL); | 404 ASSERT_FALSE(fetcher == NULL); |
405 const GURL& url = fetcher->original_url(); | 405 const GURL& url = fetcher->GetOriginalUrl(); |
406 | 406 |
407 EXPECT_FALSE(url.is_empty()); | 407 EXPECT_FALSE(url.is_empty()); |
408 EXPECT_TRUE(url.is_valid()); | 408 EXPECT_TRUE(url.is_valid()); |
409 EXPECT_TRUE(url.SchemeIs("https")); | 409 EXPECT_TRUE(url.SchemeIs("https")); |
410 EXPECT_EQ("clients2.google.com", url.host()); | 410 EXPECT_EQ("clients2.google.com", url.host()); |
411 EXPECT_EQ("/service/update2/crx", url.path()); | 411 EXPECT_EQ("/service/update2/crx", url.path()); |
412 | 412 |
413 // Validate the extension request parameters in the query. It should | 413 // Validate the extension request parameters in the query. It should |
414 // look something like "?x=id%3D<id>%26v%3D<version>%26uc". | 414 // look something like "?x=id%3D<id>%26v%3D<version>%26uc". |
415 EXPECT_TRUE(url.has_query()); | 415 EXPECT_TRUE(url.has_query()); |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
596 ManifestFetchData::PingData zeroDays(0, 0); | 596 ManifestFetchData::PingData zeroDays(0, 0); |
597 fetch1->AddExtension("1111", "1.0", zeroDays, kEmptyUpdateUrlData); | 597 fetch1->AddExtension("1111", "1.0", zeroDays, kEmptyUpdateUrlData); |
598 fetch2->AddExtension("12345", "2.0", kNeverPingedData, | 598 fetch2->AddExtension("12345", "2.0", kNeverPingedData, |
599 kEmptyUpdateUrlData); | 599 kEmptyUpdateUrlData); |
600 updater.StartUpdateCheck(fetch1); | 600 updater.StartUpdateCheck(fetch1); |
601 updater.StartUpdateCheck(fetch2); | 601 updater.StartUpdateCheck(fetch2); |
602 | 602 |
603 std::string invalid_xml = "invalid xml"; | 603 std::string invalid_xml = "invalid xml"; |
604 fetcher = factory.GetFetcherByID(ExtensionUpdater::kManifestFetcherId); | 604 fetcher = factory.GetFetcherByID(ExtensionUpdater::kManifestFetcherId); |
605 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); | 605 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); |
606 EXPECT_TRUE(fetcher->load_flags() == expected_load_flags); | 606 EXPECT_TRUE(fetcher->GetLoadFlags() == expected_load_flags); |
607 | 607 |
608 fetcher->set_url(url1); | 608 fetcher->set_url(url1); |
609 fetcher->set_status(net::URLRequestStatus()); | 609 fetcher->set_status(net::URLRequestStatus()); |
610 fetcher->set_response_code(200); | 610 fetcher->set_response_code(200); |
611 fetcher->SetResponseString(invalid_xml); | 611 fetcher->SetResponseString(invalid_xml); |
612 fetcher->delegate()->OnURLFetchComplete(fetcher); | 612 fetcher->delegate()->OnURLFetchComplete(fetcher); |
613 | 613 |
614 // Now that the first request is complete, make sure the second one has | 614 // Now that the first request is complete, make sure the second one has |
615 // been started. | 615 // been started. |
616 const std::string kValidXml = | 616 const std::string kValidXml = |
617 "<?xml version='1.0' encoding='UTF-8'?>" | 617 "<?xml version='1.0' encoding='UTF-8'?>" |
618 "<gupdate xmlns='http://www.google.com/update2/response'" | 618 "<gupdate xmlns='http://www.google.com/update2/response'" |
619 " protocol='2.0'>" | 619 " protocol='2.0'>" |
620 " <app appid='12345'>" | 620 " <app appid='12345'>" |
621 " <updatecheck codebase='http://example.com/extension_1.2.3.4.crx'" | 621 " <updatecheck codebase='http://example.com/extension_1.2.3.4.crx'" |
622 " version='1.2.3.4' prodversionmin='2.0.143.0' />" | 622 " version='1.2.3.4' prodversionmin='2.0.143.0' />" |
623 " </app>" | 623 " </app>" |
624 "</gupdate>"; | 624 "</gupdate>"; |
625 fetcher = factory.GetFetcherByID(ExtensionUpdater::kManifestFetcherId); | 625 fetcher = factory.GetFetcherByID(ExtensionUpdater::kManifestFetcherId); |
626 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); | 626 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); |
627 EXPECT_TRUE(fetcher->load_flags() == expected_load_flags); | 627 EXPECT_TRUE(fetcher->GetLoadFlags() == expected_load_flags); |
628 | 628 |
629 fetcher->set_url(url2); | 629 fetcher->set_url(url2); |
630 fetcher->set_status(net::URLRequestStatus()); | 630 fetcher->set_status(net::URLRequestStatus()); |
631 fetcher->set_response_code(200); | 631 fetcher->set_response_code(200); |
632 fetcher->SetResponseString(kValidXml); | 632 fetcher->SetResponseString(kValidXml); |
633 fetcher->delegate()->OnURLFetchComplete(fetcher); | 633 fetcher->delegate()->OnURLFetchComplete(fetcher); |
634 | 634 |
635 // This should run the manifest parsing, then we want to make sure that our | 635 // This should run the manifest parsing, then we want to make sure that our |
636 // service was called with GetExtensionById with the matching id from | 636 // service was called with GetExtensionById with the matching id from |
637 // kValidXml. | 637 // kValidXml. |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
681 id, | 681 id, |
682 PendingExtensionInfo(test_url, &ShouldAlwaysInstall, kIsFromSync, | 682 PendingExtensionInfo(test_url, &ShouldAlwaysInstall, kIsFromSync, |
683 kInstallSilently, | 683 kInstallSilently, |
684 Extension::INTERNAL)); | 684 Extension::INTERNAL)); |
685 } | 685 } |
686 | 686 |
687 // Call back the ExtensionUpdater with a 200 response and some test data | 687 // Call back the ExtensionUpdater with a 200 response and some test data |
688 FilePath extension_file_path(FILE_PATH_LITERAL("/whatever")); | 688 FilePath extension_file_path(FILE_PATH_LITERAL("/whatever")); |
689 fetcher = factory.GetFetcherByID(ExtensionUpdater::kExtensionFetcherId); | 689 fetcher = factory.GetFetcherByID(ExtensionUpdater::kExtensionFetcherId); |
690 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); | 690 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); |
691 EXPECT_TRUE(fetcher->load_flags() == expected_load_flags); | 691 EXPECT_TRUE(fetcher->GetLoadFlags() == expected_load_flags); |
692 | 692 |
693 fetcher->set_url(test_url); | 693 fetcher->set_url(test_url); |
694 fetcher->set_status(net::URLRequestStatus()); | 694 fetcher->set_status(net::URLRequestStatus()); |
695 fetcher->set_response_code(200); | 695 fetcher->set_response_code(200); |
696 fetcher->SetResponseFilePath(extension_file_path); | 696 fetcher->SetResponseFilePath(extension_file_path); |
697 fetcher->delegate()->OnURLFetchComplete(fetcher); | 697 fetcher->delegate()->OnURLFetchComplete(fetcher); |
698 | 698 |
699 file_thread.Stop(); | 699 file_thread.Stop(); |
700 ui_loop.RunAllPending(); | 700 ui_loop.RunAllPending(); |
701 | 701 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
735 "2CE109E9D0FAF820B2434E166297934E6177B65AB9951DBC3E204CAD4689B39C"; | 735 "2CE109E9D0FAF820B2434E166297934E6177B65AB9951DBC3E204CAD4689B39C"; |
736 | 736 |
737 std::string version = "0.0.1"; | 737 std::string version = "0.0.1"; |
738 updater.FetchUpdatedExtension(id, test_url, hash, version); | 738 updater.FetchUpdatedExtension(id, test_url, hash, version); |
739 | 739 |
740 // Call back the ExtensionUpdater with a 200 response and some test data. | 740 // Call back the ExtensionUpdater with a 200 response and some test data. |
741 std::string extension_data("aaabbb"); | 741 std::string extension_data("aaabbb"); |
742 | 742 |
743 fetcher = factory.GetFetcherByID(ExtensionUpdater::kExtensionFetcherId); | 743 fetcher = factory.GetFetcherByID(ExtensionUpdater::kExtensionFetcherId); |
744 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); | 744 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); |
745 EXPECT_TRUE(fetcher->load_flags() == expected_load_flags); | 745 EXPECT_TRUE(fetcher->GetLoadFlags() == expected_load_flags); |
746 | 746 |
747 fetcher->set_url(test_url); | 747 fetcher->set_url(test_url); |
748 fetcher->set_status(net::URLRequestStatus()); | 748 fetcher->set_status(net::URLRequestStatus()); |
749 fetcher->set_response_code(200); | 749 fetcher->set_response_code(200); |
750 fetcher->SetResponseString(extension_data); | 750 fetcher->SetResponseString(extension_data); |
751 fetcher->delegate()->OnURLFetchComplete(fetcher); | 751 fetcher->delegate()->OnURLFetchComplete(fetcher); |
752 | 752 |
753 message_loop.RunAllPending(); | 753 message_loop.RunAllPending(); |
754 | 754 |
755 // The updater should have called extension service to process the | 755 // The updater should have called extension service to process the |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
794 std::string version2 = "0.1"; | 794 std::string version2 = "0.1"; |
795 // Start two fetches | 795 // Start two fetches |
796 updater.FetchUpdatedExtension(id1, url1, hash1, version1); | 796 updater.FetchUpdatedExtension(id1, url1, hash1, version1); |
797 updater.FetchUpdatedExtension(id2, url2, hash2, version2); | 797 updater.FetchUpdatedExtension(id2, url2, hash2, version2); |
798 | 798 |
799 // Make the first fetch complete. | 799 // Make the first fetch complete. |
800 FilePath extension_file_path(FILE_PATH_LITERAL("/whatever")); | 800 FilePath extension_file_path(FILE_PATH_LITERAL("/whatever")); |
801 | 801 |
802 fetcher = factory.GetFetcherByID(ExtensionUpdater::kExtensionFetcherId); | 802 fetcher = factory.GetFetcherByID(ExtensionUpdater::kExtensionFetcherId); |
803 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); | 803 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); |
804 EXPECT_TRUE(fetcher->load_flags() == expected_load_flags); | 804 EXPECT_TRUE(fetcher->GetLoadFlags() == expected_load_flags); |
805 | 805 |
806 // We need some CrxInstallers, and CrxInstallers require a real | 806 // We need some CrxInstallers, and CrxInstallers require a real |
807 // ExtensionService. Create one on the testing profile. Any action | 807 // ExtensionService. Create one on the testing profile. Any action |
808 // the CrxInstallers take is on the testing profile's extension | 808 // the CrxInstallers take is on the testing profile's extension |
809 // service, not on our mock |service|. This allows us to fake | 809 // service, not on our mock |service|. This allows us to fake |
810 // the CrxInstaller actions we want. | 810 // the CrxInstaller actions we want. |
811 TestingProfile profile; | 811 TestingProfile profile; |
812 profile.CreateExtensionService( | 812 profile.CreateExtensionService( |
813 CommandLine::ForCurrentProcess(), | 813 CommandLine::ForCurrentProcess(), |
814 FilePath(), | 814 FilePath(), |
(...skipping 28 matching lines...) Expand all Loading... |
843 EXPECT_FALSE(tmpfile_path.empty()); | 843 EXPECT_FALSE(tmpfile_path.empty()); |
844 EXPECT_EQ(id1, service.extension_id()); | 844 EXPECT_EQ(id1, service.extension_id()); |
845 EXPECT_EQ(url1, service.download_url()); | 845 EXPECT_EQ(url1, service.download_url()); |
846 message_loop.RunAllPending(); | 846 message_loop.RunAllPending(); |
847 | 847 |
848 // Make sure the second fetch finished and asked the service to do an | 848 // Make sure the second fetch finished and asked the service to do an |
849 // update. | 849 // update. |
850 FilePath extension_file_path2(FILE_PATH_LITERAL("/whatever2")); | 850 FilePath extension_file_path2(FILE_PATH_LITERAL("/whatever2")); |
851 fetcher = factory.GetFetcherByID(ExtensionUpdater::kExtensionFetcherId); | 851 fetcher = factory.GetFetcherByID(ExtensionUpdater::kExtensionFetcherId); |
852 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); | 852 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); |
853 EXPECT_TRUE(fetcher->load_flags() == expected_load_flags); | 853 EXPECT_TRUE(fetcher->GetLoadFlags() == expected_load_flags); |
854 | 854 |
855 fetcher->set_url(url2); | 855 fetcher->set_url(url2); |
856 fetcher->set_status(net::URLRequestStatus()); | 856 fetcher->set_status(net::URLRequestStatus()); |
857 fetcher->set_response_code(200); | 857 fetcher->set_response_code(200); |
858 fetcher->SetResponseFilePath(extension_file_path2); | 858 fetcher->SetResponseFilePath(extension_file_path2); |
859 fetcher->delegate()->OnURLFetchComplete(fetcher); | 859 fetcher->delegate()->OnURLFetchComplete(fetcher); |
860 message_loop.RunAllPending(); | 860 message_loop.RunAllPending(); |
861 | 861 |
862 if (updates_start_running) { | 862 if (updates_start_running) { |
863 EXPECT_TRUE(updater.crx_install_is_running_); | 863 EXPECT_TRUE(updater.crx_install_is_running_); |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
981 updater.Start(); | 981 updater.Start(); |
982 updater.set_blacklist_checks_enabled(false); | 982 updater.set_blacklist_checks_enabled(false); |
983 | 983 |
984 // Make the updater do manifest fetching, and note the urls it tries to | 984 // Make the updater do manifest fetching, and note the urls it tries to |
985 // fetch. | 985 // fetch. |
986 std::vector<GURL> fetched_urls; | 986 std::vector<GURL> fetched_urls; |
987 updater.CheckNow(); | 987 updater.CheckNow(); |
988 TestURLFetcher* fetcher = | 988 TestURLFetcher* fetcher = |
989 factory.GetFetcherByID(ExtensionUpdater::kManifestFetcherId); | 989 factory.GetFetcherByID(ExtensionUpdater::kManifestFetcherId); |
990 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); | 990 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); |
991 fetched_urls.push_back(fetcher->original_url()); | 991 fetched_urls.push_back(fetcher->GetOriginalUrl()); |
992 | 992 |
993 fetcher->set_url(fetched_urls[0]); | 993 fetcher->set_url(fetched_urls[0]); |
994 fetcher->set_status(net::URLRequestStatus()); | 994 fetcher->set_status(net::URLRequestStatus()); |
995 fetcher->set_response_code(500); | 995 fetcher->set_response_code(500); |
996 fetcher->SetResponseString(""); | 996 fetcher->SetResponseString(""); |
997 fetcher->delegate()->OnURLFetchComplete(fetcher); | 997 fetcher->delegate()->OnURLFetchComplete(fetcher); |
998 | 998 |
999 fetcher = factory.GetFetcherByID(ExtensionUpdater::kManifestFetcherId); | 999 fetcher = factory.GetFetcherByID(ExtensionUpdater::kManifestFetcherId); |
1000 fetched_urls.push_back(fetcher->original_url()); | 1000 fetched_urls.push_back(fetcher->GetOriginalUrl()); |
1001 | 1001 |
1002 // The urls could have been fetched in either order, so use the host to | 1002 // The urls could have been fetched in either order, so use the host to |
1003 // tell them apart and note the query each used. | 1003 // tell them apart and note the query each used. |
1004 std::string url1_query; | 1004 std::string url1_query; |
1005 std::string url2_query; | 1005 std::string url2_query; |
1006 if (fetched_urls[0].host() == url1.host()) { | 1006 if (fetched_urls[0].host() == url1.host()) { |
1007 url1_query = fetched_urls[0].query(); | 1007 url1_query = fetched_urls[0].query(); |
1008 url2_query = fetched_urls[1].query(); | 1008 url2_query = fetched_urls[1].query(); |
1009 } else if (fetched_urls[0].host() == url2.host()) { | 1009 } else if (fetched_urls[0].host() == url2.host()) { |
1010 url1_query = fetched_urls[1].query(); | 1010 url1_query = fetched_urls[1].query(); |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1259 | 1259 |
1260 // TODO(asargent) - (http://crbug.com/12780) add tests for: | 1260 // TODO(asargent) - (http://crbug.com/12780) add tests for: |
1261 // -prodversionmin (shouldn't update if browser version too old) | 1261 // -prodversionmin (shouldn't update if browser version too old) |
1262 // -manifests & updates arriving out of order / interleaved | 1262 // -manifests & updates arriving out of order / interleaved |
1263 // -malformed update url (empty, file://, has query, has a # fragment, etc.) | 1263 // -malformed update url (empty, file://, has query, has a # fragment, etc.) |
1264 // -An extension gets uninstalled while updates are in progress (so it doesn't | 1264 // -An extension gets uninstalled while updates are in progress (so it doesn't |
1265 // "come back from the dead") | 1265 // "come back from the dead") |
1266 // -An extension gets manually updated to v3 while we're downloading v2 (ie | 1266 // -An extension gets manually updated to v3 while we're downloading v2 (ie |
1267 // you don't get downgraded accidentally) | 1267 // you don't get downgraded accidentally) |
1268 // -An update manifest mentions multiple updates | 1268 // -An update manifest mentions multiple updates |
OLD | NEW |