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 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. |
| 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
885 static void TestHandleManifestResults() { | 887 static void TestHandleManifestResults() { |
886 ServiceForManifestTests service; | 888 ServiceForManifestTests service; |
887 MessageLoop message_loop; | 889 MessageLoop message_loop; |
888 scoped_refptr<ExtensionUpdater> updater( | 890 scoped_refptr<ExtensionUpdater> updater( |
889 new ExtensionUpdater(&service, service.pref_service(), | 891 new ExtensionUpdater(&service, service.pref_service(), |
890 kUpdateFrequencySecs)); | 892 kUpdateFrequencySecs)); |
891 updater->Start(); | 893 updater->Start(); |
892 | 894 |
893 GURL update_url("http://www.google.com/manifest"); | 895 GURL update_url("http://www.google.com/manifest"); |
894 ExtensionList tmp; | 896 ExtensionList tmp; |
895 service.CreateTestExtensions(1, &tmp, &update_url.spec(), | 897 service.CreateTestExtensions(1, 1, &tmp, &update_url.spec(), |
896 Extension::INTERNAL); | 898 Extension::INTERNAL); |
897 service.set_extensions(tmp); | 899 service.set_extensions(tmp); |
898 | 900 |
899 ManifestFetchData fetch_data(update_url); | 901 ManifestFetchData fetch_data(update_url); |
900 const Extension* extension = tmp[0]; | 902 const Extension* extension = tmp[0]; |
901 fetch_data.AddExtension(extension->id(), extension->VersionString(), | 903 fetch_data.AddExtension(extension->id(), extension->VersionString(), |
902 ManifestFetchData::kNeverPinged, | 904 ManifestFetchData::kNeverPinged, |
903 kEmptyUpdateUrlData); | 905 kEmptyUpdateUrlData); |
904 UpdateManifest::Results results; | 906 UpdateManifest::Results results; |
905 results.daystart_elapsed_seconds = 750; | 907 results.daystart_elapsed_seconds = 750; |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
980 ExtensionUpdaterTest::TestHandleManifestResults(); | 982 ExtensionUpdaterTest::TestHandleManifestResults(); |
981 } | 983 } |
982 | 984 |
983 TEST(ExtensionUpdaterTest, TestManifestFetchesBuilderAddExtension) { | 985 TEST(ExtensionUpdaterTest, TestManifestFetchesBuilderAddExtension) { |
984 MockService service; | 986 MockService service; |
985 ManifestFetchesBuilder builder(&service); | 987 ManifestFetchesBuilder builder(&service); |
986 | 988 |
987 // Non-internal non-external extensions should be rejected. | 989 // Non-internal non-external extensions should be rejected. |
988 { | 990 { |
989 ExtensionList extensions; | 991 ExtensionList extensions; |
990 service.CreateTestExtensions(1, &extensions, NULL, Extension::INVALID); | 992 service.CreateTestExtensions(1, 1, &extensions, NULL, Extension::INVALID); |
991 ASSERT_FALSE(extensions.empty()); | 993 ASSERT_FALSE(extensions.empty()); |
992 builder.AddExtension(*extensions[0]); | 994 builder.AddExtension(*extensions[0]); |
993 EXPECT_TRUE(builder.GetFetches().empty()); | 995 EXPECT_TRUE(builder.GetFetches().empty()); |
994 } | 996 } |
995 | 997 |
996 // Extensions with invalid update URLs should be rejected. | 998 // Extensions with invalid update URLs should be rejected. |
997 builder.AddPendingExtension( | 999 builder.AddPendingExtension( |
998 GenerateId("foo"), PendingExtensionInfo(GURL("http:google.com:foo"), | 1000 GenerateId("foo"), PendingExtensionInfo(GURL("http:google.com:foo"), |
999 &ShouldInstallExtensionsOnly, | 1001 &ShouldInstallExtensionsOnly, |
1000 false, false, true, false, | 1002 false, false, true, false, |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1065 // -prodversionmin (shouldn't update if browser version too old) | 1067 // -prodversionmin (shouldn't update if browser version too old) |
1066 // -manifests & updates arriving out of order / interleaved | 1068 // -manifests & updates arriving out of order / interleaved |
1067 // -Profile::GetDefaultRequestContext() returning null | 1069 // -Profile::GetDefaultRequestContext() returning null |
1068 // (should not crash, but just do check later) | 1070 // (should not crash, but just do check later) |
1069 // -malformed update url (empty, file://, has query, has a # fragment, etc.) | 1071 // -malformed update url (empty, file://, has query, has a # fragment, etc.) |
1070 // -An extension gets uninstalled while updates are in progress (so it doesn't | 1072 // -An extension gets uninstalled while updates are in progress (so it doesn't |
1071 // "come back from the dead") | 1073 // "come back from the dead") |
1072 // -An extension gets manually updated to v3 while we're downloading v2 (ie | 1074 // -An extension gets manually updated to v3 while we're downloading v2 (ie |
1073 // you don't get downgraded accidentally) | 1075 // you don't get downgraded accidentally) |
1074 // -An update manifest mentions multiple updates | 1076 // -An update manifest mentions multiple updates |
OLD | NEW |