Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 84 return false; | 84 return false; |
| 85 } | 85 } |
| 86 | 86 |
| 87 virtual ExtensionPrefs* extension_prefs() { return prefs_.prefs(); } | 87 virtual ExtensionPrefs* extension_prefs() { return prefs_.prefs(); } |
| 88 | 88 |
| 89 PrefService* pref_service() { return prefs_.pref_service(); } | 89 PrefService* pref_service() { return prefs_.pref_service(); } |
| 90 | 90 |
| 91 // Creates test extensions and inserts them into list. The name and | 91 // Creates test extensions and inserts them into list. The name and |
| 92 // version are all based on their index. If |update_url| is non-null, it | 92 // version are all based on their index. If |update_url| is non-null, it |
| 93 // will be used as the update_url for each extension. | 93 // will be used as the update_url for each extension. |
| 94 void CreateTestExtensions(int count, ExtensionList *list, | 94 // The |id| is used to distinguish extension names and make sure that |
| 95 // no two extensions share the same name. | |
|
Mattias Nissler (ping if slow)
2011/01/05 12:08:07
Out of curiosity: Why is this now required?
battre
2011/01/05 20:23:08
Otherwise the two extensions receive the same hash
| |
| 96 void CreateTestExtensions(int id, int count, ExtensionList *list, | |
| 95 const std::string* update_url, | 97 const std::string* update_url, |
| 96 Extension::Location location) { | 98 Extension::Location location) { |
| 97 for (int i = 1; i <= count; i++) { | 99 for (int i = 1; i <= count; i++) { |
| 98 DictionaryValue manifest; | 100 DictionaryValue manifest; |
| 99 manifest.SetString(extension_manifest_keys::kVersion, | 101 manifest.SetString(extension_manifest_keys::kVersion, |
| 100 base::StringPrintf("%d.0.0.0", i)); | 102 base::StringPrintf("%d.0.0.0", i)); |
| 101 manifest.SetString(extension_manifest_keys::kName, | 103 manifest.SetString(extension_manifest_keys::kName, |
| 102 base::StringPrintf("Extension %d", i)); | 104 base::StringPrintf("Extension %d.%d", id, i)); |
| 103 if (update_url) | 105 if (update_url) |
| 104 manifest.SetString(extension_manifest_keys::kUpdateURL, *update_url); | 106 manifest.SetString(extension_manifest_keys::kUpdateURL, *update_url); |
| 105 scoped_refptr<Extension> e = | 107 scoped_refptr<Extension> e = |
| 106 prefs_.AddExtensionWithManifest(manifest, location); | 108 prefs_.AddExtensionWithManifest(manifest, location); |
| 107 ASSERT_TRUE(e != NULL); | 109 ASSERT_TRUE(e != NULL); |
| 108 list->push_back(e); | 110 list->push_back(e); |
| 109 } | 111 } |
| 110 } | 112 } |
| 111 | 113 |
| 112 protected: | 114 protected: |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 309 static void TestExtensionUpdateCheckRequests(bool pending) { | 311 static void TestExtensionUpdateCheckRequests(bool pending) { |
| 310 // Create an extension with an update_url. | 312 // Create an extension with an update_url. |
| 311 ServiceForManifestTests service; | 313 ServiceForManifestTests service; |
| 312 std::string update_url("http://foo.com/bar"); | 314 std::string update_url("http://foo.com/bar"); |
| 313 ExtensionList extensions; | 315 ExtensionList extensions; |
| 314 PendingExtensionMap pending_extensions; | 316 PendingExtensionMap pending_extensions; |
| 315 if (pending) { | 317 if (pending) { |
| 316 CreateTestPendingExtensions(1, GURL(update_url), &pending_extensions); | 318 CreateTestPendingExtensions(1, GURL(update_url), &pending_extensions); |
| 317 service.set_pending_extensions(pending_extensions); | 319 service.set_pending_extensions(pending_extensions); |
| 318 } else { | 320 } else { |
| 319 service.CreateTestExtensions(1, &extensions, &update_url, | 321 service.CreateTestExtensions(1, 1, &extensions, &update_url, |
| 320 Extension::INTERNAL); | 322 Extension::INTERNAL); |
| 321 service.set_extensions(extensions); | 323 service.set_extensions(extensions); |
| 322 } | 324 } |
| 323 | 325 |
| 324 // Setup and start the updater. | 326 // Setup and start the updater. |
| 325 MessageLoop message_loop; | 327 MessageLoop message_loop; |
| 326 BrowserThread io_thread(BrowserThread::IO); | 328 BrowserThread io_thread(BrowserThread::IO); |
| 327 io_thread.Start(); | 329 io_thread.Start(); |
| 328 | 330 |
| 329 TestURLFetcherFactory factory; | 331 TestURLFetcherFactory factory; |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 461 "%26v%3D1.0%26uc%26ap%3Da%253D1%2526b%253D2%2526c", | 463 "%26v%3D1.0%26uc%26ap%3Da%253D1%2526b%253D2%2526c", |
| 462 fetch_data.full_url().spec()); | 464 fetch_data.full_url().spec()); |
| 463 } | 465 } |
| 464 | 466 |
| 465 static void TestUpdateUrlDataFromGallery(const std::string& gallery_url) { | 467 static void TestUpdateUrlDataFromGallery(const std::string& gallery_url) { |
| 466 MockService service; | 468 MockService service; |
| 467 ManifestFetchesBuilder builder(&service); | 469 ManifestFetchesBuilder builder(&service); |
| 468 ExtensionList extensions; | 470 ExtensionList extensions; |
| 469 std::string url(gallery_url); | 471 std::string url(gallery_url); |
| 470 | 472 |
| 471 service.CreateTestExtensions(1, &extensions, &url, Extension::INTERNAL); | 473 service.CreateTestExtensions(1, 1, &extensions, &url, Extension::INTERNAL); |
| 472 builder.AddExtension(*extensions[0]); | 474 builder.AddExtension(*extensions[0]); |
| 473 std::vector<ManifestFetchData*> fetches = builder.GetFetches(); | 475 std::vector<ManifestFetchData*> fetches = builder.GetFetches(); |
| 474 EXPECT_EQ(1u, fetches.size()); | 476 EXPECT_EQ(1u, fetches.size()); |
| 475 scoped_ptr<ManifestFetchData> fetch(fetches[0]); | 477 scoped_ptr<ManifestFetchData> fetch(fetches[0]); |
| 476 fetches.clear(); | 478 fetches.clear(); |
| 477 | 479 |
| 478 // Make sure that extensions that update from the gallery ignore any | 480 // Make sure that extensions that update from the gallery ignore any |
| 479 // update URL data. | 481 // update URL data. |
| 480 const std::string& update_url = fetch->full_url().spec(); | 482 const std::string& update_url = fetch->full_url().spec(); |
| 481 std::string::size_type x = update_url.find("x="); | 483 std::string::size_type x = update_url.find("x="); |
| 482 EXPECT_NE(std::string::npos, x); | 484 EXPECT_NE(std::string::npos, x); |
| 483 std::string::size_type ap = update_url.find("ap%3D", x); | 485 std::string::size_type ap = update_url.find("ap%3D", x); |
| 484 EXPECT_EQ(std::string::npos, ap); | 486 EXPECT_EQ(std::string::npos, ap); |
| 485 } | 487 } |
| 486 | 488 |
| 487 static void TestDetermineUpdates() { | 489 static void TestDetermineUpdates() { |
| 488 // Create a set of test extensions | 490 // Create a set of test extensions |
| 489 ServiceForManifestTests service; | 491 ServiceForManifestTests service; |
| 490 ExtensionList tmp; | 492 ExtensionList tmp; |
| 491 service.CreateTestExtensions(3, &tmp, NULL, Extension::INTERNAL); | 493 service.CreateTestExtensions(1, 3, &tmp, NULL, Extension::INTERNAL); |
| 492 service.set_extensions(tmp); | 494 service.set_extensions(tmp); |
| 493 | 495 |
| 494 MessageLoop message_loop; | 496 MessageLoop message_loop; |
| 495 scoped_refptr<ExtensionUpdater> updater( | 497 scoped_refptr<ExtensionUpdater> updater( |
| 496 new ExtensionUpdater(&service, service.pref_service(), | 498 new ExtensionUpdater(&service, service.pref_service(), |
| 497 kUpdateFrequencySecs)); | 499 kUpdateFrequencySecs)); |
| 498 updater->Start(); | 500 updater->Start(); |
| 499 | 501 |
| 500 // Check passing an empty list of parse results to DetermineUpdates | 502 // Check passing an empty list of parse results to DetermineUpdates |
| 501 ManifestFetchData fetch_data(GURL("http://localhost/foo")); | 503 ManifestFetchData fetch_data(GURL("http://localhost/foo")); |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 805 static void TestGalleryRequests(int ping_days) { | 807 static void TestGalleryRequests(int ping_days) { |
| 806 TestURLFetcherFactory factory; | 808 TestURLFetcherFactory factory; |
| 807 URLFetcher::set_factory(&factory); | 809 URLFetcher::set_factory(&factory); |
| 808 | 810 |
| 809 // Set up 2 mock extensions, one with a google.com update url and one | 811 // Set up 2 mock extensions, one with a google.com update url and one |
| 810 // without. | 812 // without. |
| 811 ServiceForManifestTests service; | 813 ServiceForManifestTests service; |
| 812 ExtensionList tmp; | 814 ExtensionList tmp; |
| 813 GURL url1("http://clients2.google.com/service/update2/crx"); | 815 GURL url1("http://clients2.google.com/service/update2/crx"); |
| 814 GURL url2("http://www.somewebsite.com"); | 816 GURL url2("http://www.somewebsite.com"); |
| 815 service.CreateTestExtensions(1, &tmp, &url1.possibly_invalid_spec(), | 817 service.CreateTestExtensions(1, 1, &tmp, &url1.possibly_invalid_spec(), |
| 816 Extension::INTERNAL); | 818 Extension::INTERNAL); |
| 817 service.CreateTestExtensions(1, &tmp, &url2.possibly_invalid_spec(), | 819 service.CreateTestExtensions(2, 1, &tmp, &url2.possibly_invalid_spec(), |
| 818 Extension::INTERNAL); | 820 Extension::INTERNAL); |
| 819 EXPECT_EQ(2u, tmp.size()); | 821 EXPECT_EQ(2u, tmp.size()); |
| 820 service.set_extensions(tmp); | 822 service.set_extensions(tmp); |
| 821 | 823 |
| 822 Time now = Time::Now(); | 824 Time now = Time::Now(); |
| 823 if (ping_days == 0) { | 825 if (ping_days == 0) { |
| 824 service.extension_prefs()->SetLastPingDay( | 826 service.extension_prefs()->SetLastPingDay( |
| 825 tmp[0]->id(), now - TimeDelta::FromSeconds(15)); | 827 tmp[0]->id(), now - TimeDelta::FromSeconds(15)); |
| 826 } else if (ping_days > 0) { | 828 } else if (ping_days > 0) { |
| 827 Time last_ping_day = | 829 Time last_ping_day = |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 884 static void TestHandleManifestResults() { | 886 static void TestHandleManifestResults() { |
| 885 ServiceForManifestTests service; | 887 ServiceForManifestTests service; |
| 886 MessageLoop message_loop; | 888 MessageLoop message_loop; |
| 887 scoped_refptr<ExtensionUpdater> updater( | 889 scoped_refptr<ExtensionUpdater> updater( |
| 888 new ExtensionUpdater(&service, service.pref_service(), | 890 new ExtensionUpdater(&service, service.pref_service(), |
| 889 kUpdateFrequencySecs)); | 891 kUpdateFrequencySecs)); |
| 890 updater->Start(); | 892 updater->Start(); |
| 891 | 893 |
| 892 GURL update_url("http://www.google.com/manifest"); | 894 GURL update_url("http://www.google.com/manifest"); |
| 893 ExtensionList tmp; | 895 ExtensionList tmp; |
| 894 service.CreateTestExtensions(1, &tmp, &update_url.spec(), | 896 service.CreateTestExtensions(1, 1, &tmp, &update_url.spec(), |
| 895 Extension::INTERNAL); | 897 Extension::INTERNAL); |
| 896 service.set_extensions(tmp); | 898 service.set_extensions(tmp); |
| 897 | 899 |
| 898 ManifestFetchData fetch_data(update_url); | 900 ManifestFetchData fetch_data(update_url); |
| 899 const Extension* extension = tmp[0]; | 901 const Extension* extension = tmp[0]; |
| 900 fetch_data.AddExtension(extension->id(), extension->VersionString(), | 902 fetch_data.AddExtension(extension->id(), extension->VersionString(), |
| 901 ManifestFetchData::kNeverPinged, | 903 ManifestFetchData::kNeverPinged, |
| 902 kEmptyUpdateUrlData); | 904 kEmptyUpdateUrlData); |
| 903 UpdateManifest::Results results; | 905 UpdateManifest::Results results; |
| 904 results.daystart_elapsed_seconds = 750; | 906 results.daystart_elapsed_seconds = 750; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 979 ExtensionUpdaterTest::TestHandleManifestResults(); | 981 ExtensionUpdaterTest::TestHandleManifestResults(); |
| 980 } | 982 } |
| 981 | 983 |
| 982 TEST(ExtensionUpdaterTest, TestManifestFetchesBuilderAddExtension) { | 984 TEST(ExtensionUpdaterTest, TestManifestFetchesBuilderAddExtension) { |
| 983 MockService service; | 985 MockService service; |
| 984 ManifestFetchesBuilder builder(&service); | 986 ManifestFetchesBuilder builder(&service); |
| 985 | 987 |
| 986 // Non-internal non-external extensions should be rejected. | 988 // Non-internal non-external extensions should be rejected. |
| 987 { | 989 { |
| 988 ExtensionList extensions; | 990 ExtensionList extensions; |
| 989 service.CreateTestExtensions(1, &extensions, NULL, Extension::INVALID); | 991 service.CreateTestExtensions(1, 1, &extensions, NULL, Extension::INVALID); |
| 990 ASSERT_FALSE(extensions.empty()); | 992 ASSERT_FALSE(extensions.empty()); |
| 991 builder.AddExtension(*extensions[0]); | 993 builder.AddExtension(*extensions[0]); |
| 992 EXPECT_TRUE(builder.GetFetches().empty()); | 994 EXPECT_TRUE(builder.GetFetches().empty()); |
| 993 } | 995 } |
| 994 | 996 |
| 995 // Extensions with invalid update URLs should be rejected. | 997 // Extensions with invalid update URLs should be rejected. |
| 996 builder.AddPendingExtension( | 998 builder.AddPendingExtension( |
| 997 GenerateId("foo"), PendingExtensionInfo(GURL("http:google.com:foo"), | 999 GenerateId("foo"), PendingExtensionInfo(GURL("http:google.com:foo"), |
| 998 &ShouldInstallExtensionsOnly, | 1000 &ShouldInstallExtensionsOnly, |
| 999 false, false, true, false, | 1001 false, false, true, false, |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1064 // -prodversionmin (shouldn't update if browser version too old) | 1066 // -prodversionmin (shouldn't update if browser version too old) |
| 1065 // -manifests & updates arriving out of order / interleaved | 1067 // -manifests & updates arriving out of order / interleaved |
| 1066 // -Profile::GetDefaultRequestContext() returning null | 1068 // -Profile::GetDefaultRequestContext() returning null |
| 1067 // (should not crash, but just do check later) | 1069 // (should not crash, but just do check later) |
| 1068 // -malformed update url (empty, file://, has query, has a # fragment, etc.) | 1070 // -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 | 1071 // -An extension gets uninstalled while updates are in progress (so it doesn't |
| 1070 // "come back from the dead") | 1072 // "come back from the dead") |
| 1071 // -An extension gets manually updated to v3 while we're downloading v2 (ie | 1073 // -An extension gets manually updated to v3 while we're downloading v2 (ie |
| 1072 // you don't get downgraded accidentally) | 1074 // you don't get downgraded accidentally) |
| 1073 // -An update manifest mentions multiple updates | 1075 // -An update manifest mentions multiple updates |
| OLD | NEW |