| OLD | NEW |
| 1 // Copyright (c) 2010 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" |
| 11 #include "base/string_split.h" | 11 #include "base/string_split.h" |
| (...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 584 fetch2->AddExtension("12345", "2.0", ManifestFetchData::kNeverPinged, | 584 fetch2->AddExtension("12345", "2.0", ManifestFetchData::kNeverPinged, |
| 585 kEmptyUpdateUrlData); | 585 kEmptyUpdateUrlData); |
| 586 updater->StartUpdateCheck(fetch1); | 586 updater->StartUpdateCheck(fetch1); |
| 587 updater->StartUpdateCheck(fetch2); | 587 updater->StartUpdateCheck(fetch2); |
| 588 | 588 |
| 589 std::string invalid_xml = "invalid xml"; | 589 std::string invalid_xml = "invalid xml"; |
| 590 fetcher = factory.GetFetcherByID(ExtensionUpdater::kManifestFetcherId); | 590 fetcher = factory.GetFetcherByID(ExtensionUpdater::kManifestFetcherId); |
| 591 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); | 591 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); |
| 592 EXPECT_TRUE(fetcher->load_flags() == expected_load_flags); | 592 EXPECT_TRUE(fetcher->load_flags() == expected_load_flags); |
| 593 fetcher->delegate()->OnURLFetchComplete( | 593 fetcher->delegate()->OnURLFetchComplete( |
| 594 fetcher, url1, URLRequestStatus(), 200, ResponseCookies(), | 594 fetcher, url1, net::URLRequestStatus(), 200, ResponseCookies(), |
| 595 invalid_xml); | 595 invalid_xml); |
| 596 | 596 |
| 597 // Now that the first request is complete, make sure the second one has | 597 // Now that the first request is complete, make sure the second one has |
| 598 // been started. | 598 // been started. |
| 599 const std::string kValidXml = | 599 const std::string kValidXml = |
| 600 "<?xml version='1.0' encoding='UTF-8'?>" | 600 "<?xml version='1.0' encoding='UTF-8'?>" |
| 601 "<gupdate xmlns='http://www.google.com/update2/response'" | 601 "<gupdate xmlns='http://www.google.com/update2/response'" |
| 602 " protocol='2.0'>" | 602 " protocol='2.0'>" |
| 603 " <app appid='12345'>" | 603 " <app appid='12345'>" |
| 604 " <updatecheck codebase='http://example.com/extension_1.2.3.4.crx'" | 604 " <updatecheck codebase='http://example.com/extension_1.2.3.4.crx'" |
| 605 " version='1.2.3.4' prodversionmin='2.0.143.0' />" | 605 " version='1.2.3.4' prodversionmin='2.0.143.0' />" |
| 606 " </app>" | 606 " </app>" |
| 607 "</gupdate>"; | 607 "</gupdate>"; |
| 608 fetcher = factory.GetFetcherByID(ExtensionUpdater::kManifestFetcherId); | 608 fetcher = factory.GetFetcherByID(ExtensionUpdater::kManifestFetcherId); |
| 609 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); | 609 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); |
| 610 EXPECT_TRUE(fetcher->load_flags() == expected_load_flags); | 610 EXPECT_TRUE(fetcher->load_flags() == expected_load_flags); |
| 611 fetcher->delegate()->OnURLFetchComplete( | 611 fetcher->delegate()->OnURLFetchComplete( |
| 612 fetcher, url2, URLRequestStatus(), 200, ResponseCookies(), | 612 fetcher, url2, net::URLRequestStatus(), 200, ResponseCookies(), |
| 613 kValidXml); | 613 kValidXml); |
| 614 | 614 |
| 615 // This should run the manifest parsing, then we want to make sure that our | 615 // This should run the manifest parsing, then we want to make sure that our |
| 616 // service was called with GetExtensionById with the matching id from | 616 // service was called with GetExtensionById with the matching id from |
| 617 // kValidXml. | 617 // kValidXml. |
| 618 file_thread.Stop(); | 618 file_thread.Stop(); |
| 619 io_thread.Stop(); | 619 io_thread.Stop(); |
| 620 ui_loop.RunAllPending(); | 620 ui_loop.RunAllPending(); |
| 621 EXPECT_EQ("12345", service.last_inquired_extension_id()); | 621 EXPECT_EQ("12345", service.last_inquired_extension_id()); |
| 622 xmlCleanupGlobals(); | 622 xmlCleanupGlobals(); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 659 kInitialIncognitoEnabled, Extension::INTERNAL); | 659 kInitialIncognitoEnabled, Extension::INTERNAL); |
| 660 service.set_pending_extensions(pending_extensions); | 660 service.set_pending_extensions(pending_extensions); |
| 661 } | 661 } |
| 662 | 662 |
| 663 // Call back the ExtensionUpdater with a 200 response and some test data | 663 // Call back the ExtensionUpdater with a 200 response and some test data |
| 664 std::string extension_data("whatever"); | 664 std::string extension_data("whatever"); |
| 665 fetcher = factory.GetFetcherByID(ExtensionUpdater::kExtensionFetcherId); | 665 fetcher = factory.GetFetcherByID(ExtensionUpdater::kExtensionFetcherId); |
| 666 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); | 666 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); |
| 667 EXPECT_TRUE(fetcher->load_flags() == expected_load_flags); | 667 EXPECT_TRUE(fetcher->load_flags() == expected_load_flags); |
| 668 fetcher->delegate()->OnURLFetchComplete( | 668 fetcher->delegate()->OnURLFetchComplete( |
| 669 fetcher, test_url, URLRequestStatus(), 200, ResponseCookies(), | 669 fetcher, test_url, net::URLRequestStatus(), 200, ResponseCookies(), |
| 670 extension_data); | 670 extension_data); |
| 671 | 671 |
| 672 file_thread.Stop(); | 672 file_thread.Stop(); |
| 673 ui_loop.RunAllPending(); | 673 ui_loop.RunAllPending(); |
| 674 | 674 |
| 675 // Expect that ExtensionUpdater asked the mock extensions service to install | 675 // Expect that ExtensionUpdater asked the mock extensions service to install |
| 676 // a file with the test data for the right id. | 676 // a file with the test data for the right id. |
| 677 EXPECT_EQ(id, service.extension_id()); | 677 EXPECT_EQ(id, service.extension_id()); |
| 678 FilePath tmpfile_path = service.install_path(); | 678 FilePath tmpfile_path = service.install_path(); |
| 679 EXPECT_FALSE(tmpfile_path.empty()); | 679 EXPECT_FALSE(tmpfile_path.empty()); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 709 | 709 |
| 710 std::string version = "0.0.1"; | 710 std::string version = "0.0.1"; |
| 711 updater->FetchUpdatedExtension(id, test_url, hash, version); | 711 updater->FetchUpdatedExtension(id, test_url, hash, version); |
| 712 | 712 |
| 713 // Call back the ExtensionUpdater with a 200 response and some test data | 713 // Call back the ExtensionUpdater with a 200 response and some test data |
| 714 std::string extension_data("aaabbb"); | 714 std::string extension_data("aaabbb"); |
| 715 fetcher = factory.GetFetcherByID(ExtensionUpdater::kExtensionFetcherId); | 715 fetcher = factory.GetFetcherByID(ExtensionUpdater::kExtensionFetcherId); |
| 716 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); | 716 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); |
| 717 EXPECT_TRUE(fetcher->load_flags() == expected_load_flags); | 717 EXPECT_TRUE(fetcher->load_flags() == expected_load_flags); |
| 718 fetcher->delegate()->OnURLFetchComplete( | 718 fetcher->delegate()->OnURLFetchComplete( |
| 719 fetcher, test_url, URLRequestStatus(), 200, ResponseCookies(), | 719 fetcher, test_url, net::URLRequestStatus(), 200, ResponseCookies(), |
| 720 extension_data); | 720 extension_data); |
| 721 | 721 |
| 722 message_loop.RunAllPending(); | 722 message_loop.RunAllPending(); |
| 723 | 723 |
| 724 // The updater should have called extension service to process the | 724 // The updater should have called extension service to process the |
| 725 // blacklist. | 725 // blacklist. |
| 726 EXPECT_TRUE(service.processed_blacklist()); | 726 EXPECT_TRUE(service.processed_blacklist()); |
| 727 | 727 |
| 728 EXPECT_EQ(version, service.pref_service()-> | 728 EXPECT_EQ(version, service.pref_service()-> |
| 729 GetString(prefs::kExtensionBlacklistUpdateVersion)); | 729 GetString(prefs::kExtensionBlacklistUpdateVersion)); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 761 // Start two fetches | 761 // Start two fetches |
| 762 updater->FetchUpdatedExtension(id1, url1, hash1, version1); | 762 updater->FetchUpdatedExtension(id1, url1, hash1, version1); |
| 763 updater->FetchUpdatedExtension(id2, url2, hash2, version2); | 763 updater->FetchUpdatedExtension(id2, url2, hash2, version2); |
| 764 | 764 |
| 765 // Make the first fetch complete. | 765 // Make the first fetch complete. |
| 766 std::string extension_data1("whatever"); | 766 std::string extension_data1("whatever"); |
| 767 fetcher = factory.GetFetcherByID(ExtensionUpdater::kExtensionFetcherId); | 767 fetcher = factory.GetFetcherByID(ExtensionUpdater::kExtensionFetcherId); |
| 768 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); | 768 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); |
| 769 EXPECT_TRUE(fetcher->load_flags() == expected_load_flags); | 769 EXPECT_TRUE(fetcher->load_flags() == expected_load_flags); |
| 770 fetcher->delegate()->OnURLFetchComplete( | 770 fetcher->delegate()->OnURLFetchComplete( |
| 771 fetcher, url1, URLRequestStatus(), 200, ResponseCookies(), | 771 fetcher, url1, net::URLRequestStatus(), 200, ResponseCookies(), |
| 772 extension_data1); | 772 extension_data1); |
| 773 message_loop.RunAllPending(); | 773 message_loop.RunAllPending(); |
| 774 | 774 |
| 775 // Expect that the service was asked to do an install with the right data. | 775 // Expect that the service was asked to do an install with the right data. |
| 776 FilePath tmpfile_path = service.install_path(); | 776 FilePath tmpfile_path = service.install_path(); |
| 777 EXPECT_FALSE(tmpfile_path.empty()); | 777 EXPECT_FALSE(tmpfile_path.empty()); |
| 778 EXPECT_EQ(id1, service.extension_id()); | 778 EXPECT_EQ(id1, service.extension_id()); |
| 779 EXPECT_EQ(url1, service.download_url()); | 779 EXPECT_EQ(url1, service.download_url()); |
| 780 message_loop.RunAllPending(); | 780 message_loop.RunAllPending(); |
| 781 file_util::Delete(tmpfile_path, false); | 781 file_util::Delete(tmpfile_path, false); |
| 782 | 782 |
| 783 // Make sure the second fetch finished and asked the service to do an | 783 // Make sure the second fetch finished and asked the service to do an |
| 784 // update. | 784 // update. |
| 785 std::string extension_data2("whatever2"); | 785 std::string extension_data2("whatever2"); |
| 786 fetcher = factory.GetFetcherByID(ExtensionUpdater::kExtensionFetcherId); | 786 fetcher = factory.GetFetcherByID(ExtensionUpdater::kExtensionFetcherId); |
| 787 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); | 787 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); |
| 788 EXPECT_TRUE(fetcher->load_flags() == expected_load_flags); | 788 EXPECT_TRUE(fetcher->load_flags() == expected_load_flags); |
| 789 fetcher->delegate()->OnURLFetchComplete( | 789 fetcher->delegate()->OnURLFetchComplete( |
| 790 fetcher, url2, URLRequestStatus(), 200, ResponseCookies(), | 790 fetcher, url2, net::URLRequestStatus(), 200, ResponseCookies(), |
| 791 extension_data2); | 791 extension_data2); |
| 792 message_loop.RunAllPending(); | 792 message_loop.RunAllPending(); |
| 793 EXPECT_EQ(id2, service.extension_id()); | 793 EXPECT_EQ(id2, service.extension_id()); |
| 794 EXPECT_EQ(url2, service.download_url()); | 794 EXPECT_EQ(url2, service.download_url()); |
| 795 EXPECT_FALSE(service.install_path().empty()); | 795 EXPECT_FALSE(service.install_path().empty()); |
| 796 | 796 |
| 797 // Make sure the correct crx contents were passed for the update call. | 797 // Make sure the correct crx contents were passed for the update call. |
| 798 std::string file_contents; | 798 std::string file_contents; |
| 799 EXPECT_TRUE(file_util::ReadFileToString(service.install_path(), | 799 EXPECT_TRUE(file_util::ReadFileToString(service.install_path(), |
| 800 &file_contents)); | 800 &file_contents)); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 838 | 838 |
| 839 // Make the updater do manifest fetching, and note the urls it tries to | 839 // Make the updater do manifest fetching, and note the urls it tries to |
| 840 // fetch. | 840 // fetch. |
| 841 std::vector<GURL> fetched_urls; | 841 std::vector<GURL> fetched_urls; |
| 842 updater->CheckNow(); | 842 updater->CheckNow(); |
| 843 TestURLFetcher* fetcher = | 843 TestURLFetcher* fetcher = |
| 844 factory.GetFetcherByID(ExtensionUpdater::kManifestFetcherId); | 844 factory.GetFetcherByID(ExtensionUpdater::kManifestFetcherId); |
| 845 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); | 845 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); |
| 846 fetched_urls.push_back(fetcher->original_url()); | 846 fetched_urls.push_back(fetcher->original_url()); |
| 847 fetcher->delegate()->OnURLFetchComplete( | 847 fetcher->delegate()->OnURLFetchComplete( |
| 848 fetcher, fetched_urls[0], URLRequestStatus(), 500, ResponseCookies(), ""); | 848 fetcher, fetched_urls[0], net::URLRequestStatus(), 500, |
| 849 ResponseCookies(), ""); |
| 849 fetcher = | 850 fetcher = |
| 850 factory.GetFetcherByID(ExtensionUpdater::kManifestFetcherId); | 851 factory.GetFetcherByID(ExtensionUpdater::kManifestFetcherId); |
| 851 fetched_urls.push_back(fetcher->original_url()); | 852 fetched_urls.push_back(fetcher->original_url()); |
| 852 | 853 |
| 853 // The urls could have been fetched in either order, so use the host to | 854 // The urls could have been fetched in either order, so use the host to |
| 854 // tell them apart and note the query each used. | 855 // tell them apart and note the query each used. |
| 855 std::string url1_query; | 856 std::string url1_query; |
| 856 std::string url2_query; | 857 std::string url2_query; |
| 857 if (fetched_urls[0].host() == url1.host()) { | 858 if (fetched_urls[0].host() == url1.host()) { |
| 858 url1_query = fetched_urls[0].query(); | 859 url1_query = fetched_urls[0].query(); |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1064 // -prodversionmin (shouldn't update if browser version too old) | 1065 // -prodversionmin (shouldn't update if browser version too old) |
| 1065 // -manifests & updates arriving out of order / interleaved | 1066 // -manifests & updates arriving out of order / interleaved |
| 1066 // -Profile::GetDefaultRequestContext() returning null | 1067 // -Profile::GetDefaultRequestContext() returning null |
| 1067 // (should not crash, but just do check later) | 1068 // (should not crash, but just do check later) |
| 1068 // -malformed update url (empty, file://, has query, has a # fragment, etc.) | 1069 // -malformed update url (empty, file://, has query, has a # fragment, etc.) |
| 1069 // -An extension gets uninstalled while updates are in progress (so it doesn't | 1070 // -An extension gets uninstalled while updates are in progress (so it doesn't |
| 1070 // "come back from the dead") | 1071 // "come back from the dead") |
| 1071 // -An extension gets manually updated to v3 while we're downloading v2 (ie | 1072 // -An extension gets manually updated to v3 while we're downloading v2 (ie |
| 1072 // you don't get downgraded accidentally) | 1073 // you don't get downgraded accidentally) |
| 1073 // -An update manifest mentions multiple updates | 1074 // -An update manifest mentions multiple updates |
| OLD | NEW |