Chromium Code Reviews

Side by Side Diff: chrome/browser/extensions/extension_updater_unittest.cc

Issue 2819023: Reworked ExtensionsService::AddPendingExtension(). (Closed)
Patch Set: Fixed browsertest test failure Created 10 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/rand_util.h" 8 #include "base/rand_util.h"
9 #include "base/scoped_ptr.h" 9 #include "base/scoped_ptr.h"
10 #include "base/stl_util-inl.h" 10 #include "base/stl_util-inl.h"
(...skipping 97 matching lines...)
108 return result; 108 return result;
109 } 109 }
110 110
111 // Creates test pending extensions and inserts them into list. The 111 // Creates test pending extensions and inserts them into list. The
112 // name and version are all based on their index. 112 // name and version are all based on their index.
113 void CreateTestPendingExtensions(int count, const GURL& update_url, 113 void CreateTestPendingExtensions(int count, const GURL& update_url,
114 PendingExtensionMap* pending_extensions) { 114 PendingExtensionMap* pending_extensions) {
115 for (int i = 1; i <= count; i++) { 115 for (int i = 1; i <= count; i++) {
116 bool is_theme = (i % 2) == 0; 116 bool is_theme = (i % 2) == 0;
117 const bool kInstallSilently = true; 117 const bool kInstallSilently = true;
118 scoped_ptr<Version> version( 118 const Extension::State kInitialState = Extension::ENABLED;
119 Version::GetVersionFromString(StringPrintf("%d.0.0.0", i))); 119 const bool kInitialIncognitoEnabled = false;
120 ASSERT_TRUE(version.get());
121 std::string id = GenerateId(StringPrintf("extension%i", i)); 120 std::string id = GenerateId(StringPrintf("extension%i", i));
122 (*pending_extensions)[id] = 121 (*pending_extensions)[id] =
123 PendingExtensionInfo(update_url, *version, 122 PendingExtensionInfo(update_url, is_theme, kInstallSilently,
124 is_theme, kInstallSilently); 123 kInitialState, kInitialIncognitoEnabled);
125 } 124 }
126 } 125 }
127 126
128 class ServiceForManifestTests : public MockService { 127 class ServiceForManifestTests : public MockService {
129 public: 128 public:
130 ServiceForManifestTests() : has_installed_extensions_(false) {} 129 ServiceForManifestTests() : has_installed_extensions_(false) {}
131 130
132 virtual ~ServiceForManifestTests() {} 131 virtual ~ServiceForManifestTests() {}
133 132
134 virtual Extension* GetExtensionById(const std::string& id, bool) { 133 virtual Extension* GetExtensionById(const std::string& id, bool) {
(...skipping 184 matching lines...)
319 std::vector<std::string> parts; 318 std::vector<std::string> parts;
320 SplitString(url.query(), '=', &parts); 319 SplitString(url.query(), '=', &parts);
321 EXPECT_EQ(2u, parts.size()); 320 EXPECT_EQ(2u, parts.size());
322 EXPECT_EQ("x", parts[0]); 321 EXPECT_EQ("x", parts[0]);
323 std::string decoded = UnescapeURLComponent(parts[1], 322 std::string decoded = UnescapeURLComponent(parts[1],
324 UnescapeRule::URL_SPECIAL_CHARS); 323 UnescapeRule::URL_SPECIAL_CHARS);
325 std::map<std::string, std::string> params; 324 std::map<std::string, std::string> params;
326 ExtractParameters(decoded, &params); 325 ExtractParameters(decoded, &params);
327 if (pending) { 326 if (pending) {
328 EXPECT_EQ(pending_extensions.begin()->first, params["id"]); 327 EXPECT_EQ(pending_extensions.begin()->first, params["id"]);
329 EXPECT_EQ("1.0.0.0", params["v"]); 328 EXPECT_EQ("0.0.0.0", params["v"]);
330 } else { 329 } else {
331 EXPECT_EQ(extensions[0]->id(), params["id"]); 330 EXPECT_EQ(extensions[0]->id(), params["id"]);
332 EXPECT_EQ(extensions[0]->VersionString(), params["v"]); 331 EXPECT_EQ(extensions[0]->VersionString(), params["v"]);
333 } 332 }
334 EXPECT_EQ("", params["uc"]); 333 EXPECT_EQ("", params["uc"]);
335 334
336 if (!pending) { 335 if (!pending) {
337 STLDeleteElements(&extensions); 336 STLDeleteElements(&extensions);
338 } 337 }
339 } 338 }
(...skipping 99 matching lines...)
439 438
440 MessageLoop message_loop; 439 MessageLoop message_loop;
441 scoped_refptr<ExtensionUpdater> updater = 440 scoped_refptr<ExtensionUpdater> updater =
442 new ExtensionUpdater(&service, service.pref_service(), 441 new ExtensionUpdater(&service, service.pref_service(),
443 kUpdateFrequencySecs); 442 kUpdateFrequencySecs);
444 443
445 ManifestFetchData fetch_data(GURL("http://localhost/foo")); 444 ManifestFetchData fetch_data(GURL("http://localhost/foo"));
446 UpdateManifest::Results updates; 445 UpdateManifest::Results updates;
447 for (PendingExtensionMap::const_iterator it = pending_extensions.begin(); 446 for (PendingExtensionMap::const_iterator it = pending_extensions.begin();
448 it != pending_extensions.end(); ++it) { 447 it != pending_extensions.end(); ++it) {
449 fetch_data.AddExtension(it->first, 448 fetch_data.AddExtension(it->first, "1.0.0.0",
450 it->second.version.GetString(),
451 ManifestFetchData::kNeverPinged); 449 ManifestFetchData::kNeverPinged);
452 AddParseResult(it->first, 450 AddParseResult(it->first,
453 "1.1", "http://localhost/e1_1.1.crx", &updates); 451 "1.1", "http://localhost/e1_1.1.crx", &updates);
454 } 452 }
455 std::vector<int> updateable = 453 std::vector<int> updateable =
456 updater->DetermineUpdates(fetch_data, updates); 454 updater->DetermineUpdates(fetch_data, updates);
457 // Only the first one is updateable. 455 // All the apps should be updateable.
458 EXPECT_EQ(1u, updateable.size()); 456 EXPECT_EQ(3u, updateable.size());
459 for (std::vector<int>::size_type i = 0; i < updateable.size(); ++i) { 457 for (std::vector<int>::size_type i = 0; i < updateable.size(); ++i) {
460 EXPECT_EQ(static_cast<int>(i), updateable[i]); 458 EXPECT_EQ(static_cast<int>(i), updateable[i]);
461 } 459 }
462 } 460 }
463 461
464 static void TestMultipleManifestDownloading() { 462 static void TestMultipleManifestDownloading() {
465 MessageLoop ui_loop; 463 MessageLoop ui_loop;
466 ChromeThread ui_thread(ChromeThread::UI, &ui_loop); 464 ChromeThread ui_thread(ChromeThread::UI, &ui_loop);
467 ChromeThread file_thread(ChromeThread::FILE); 465 ChromeThread file_thread(ChromeThread::FILE);
468 file_thread.Start(); 466 file_thread.Start();
(...skipping 76 matching lines...)
545 543
546 std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; 544 std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
547 std::string hash = ""; 545 std::string hash = "";
548 scoped_ptr<Version> version(Version::GetVersionFromString("0.0.1")); 546 scoped_ptr<Version> version(Version::GetVersionFromString("0.0.1"));
549 ASSERT_TRUE(version.get()); 547 ASSERT_TRUE(version.get());
550 updater->FetchUpdatedExtension(id, test_url, hash, version->GetString()); 548 updater->FetchUpdatedExtension(id, test_url, hash, version->GetString());
551 549
552 if (pending) { 550 if (pending) {
553 const bool kIsTheme = false; 551 const bool kIsTheme = false;
554 const bool kInstallSilently = true; 552 const bool kInstallSilently = true;
553 const Extension::State kInitialState = Extension::ENABLED;
554 const bool kInitialIncognitoEnabled = false;
555 PendingExtensionMap pending_extensions; 555 PendingExtensionMap pending_extensions;
556 pending_extensions[id] = 556 pending_extensions[id] =
557 PendingExtensionInfo(test_url, *version, 557 PendingExtensionInfo(test_url, kIsTheme, kInstallSilently,
558 kIsTheme, kInstallSilently); 558 kInitialState, kInitialIncognitoEnabled);
559 service.set_pending_extensions(pending_extensions); 559 service.set_pending_extensions(pending_extensions);
560 } 560 }
561 561
562 // Call back the ExtensionUpdater with a 200 response and some test data 562 // Call back the ExtensionUpdater with a 200 response and some test data
563 std::string extension_data("whatever"); 563 std::string extension_data("whatever");
564 fetcher = factory.GetFetcherByID(ExtensionUpdater::kExtensionFetcherId); 564 fetcher = factory.GetFetcherByID(ExtensionUpdater::kExtensionFetcherId);
565 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); 565 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL);
566 EXPECT_TRUE(fetcher->load_flags() == expected_load_flags); 566 EXPECT_TRUE(fetcher->load_flags() == expected_load_flags);
567 fetcher->delegate()->OnURLFetchComplete( 567 fetcher->delegate()->OnURLFetchComplete(
568 fetcher, test_url, URLRequestStatus(), 200, ResponseCookies(), 568 fetcher, test_url, URLRequestStatus(), 200, ResponseCookies(),
(...skipping 304 matching lines...)
873 { 873 {
874 ExtensionList extensions; 874 ExtensionList extensions;
875 service.CreateTestExtensions(1, &extensions, NULL); 875 service.CreateTestExtensions(1, &extensions, NULL);
876 ASSERT_FALSE(extensions.empty()); 876 ASSERT_FALSE(extensions.empty());
877 extensions[0]->set_location(Extension::INVALID); 877 extensions[0]->set_location(Extension::INVALID);
878 builder.AddExtension(*extensions[0]); 878 builder.AddExtension(*extensions[0]);
879 EXPECT_TRUE(builder.GetFetches().empty()); 879 EXPECT_TRUE(builder.GetFetches().empty());
880 STLDeleteElements(&extensions); 880 STLDeleteElements(&extensions);
881 } 881 }
882 882
883 scoped_ptr<Version> version(Version::GetVersionFromString("0"));
884 ASSERT_TRUE(version.get());
885
886 // Extensions with invalid update URLs should be rejected. 883 // Extensions with invalid update URLs should be rejected.
887 builder.AddPendingExtension( 884 builder.AddPendingExtension(
888 GenerateId("foo"), PendingExtensionInfo(GURL("http:google.com:foo"), 885 GenerateId("foo"), PendingExtensionInfo(GURL("http:google.com:foo"),
889 *version, false, false)); 886 false, false, true, false));
890 EXPECT_TRUE(builder.GetFetches().empty()); 887 EXPECT_TRUE(builder.GetFetches().empty());
891 888
892 // Extensions with empty IDs should be rejected. 889 // Extensions with empty IDs should be rejected.
893 builder.AddPendingExtension( 890 builder.AddPendingExtension(
894 "", PendingExtensionInfo(GURL(), *version, false, false)); 891 "", PendingExtensionInfo(GURL(), false, false, true, false));
895 EXPECT_TRUE(builder.GetFetches().empty()); 892 EXPECT_TRUE(builder.GetFetches().empty());
896 893
897 // TODO(akalin): Test that extensions with empty update URLs 894 // TODO(akalin): Test that extensions with empty update URLs
898 // converted from user scripts are rejected. 895 // converted from user scripts are rejected.
899 896
900 // Extensions with empty update URLs should have a default one 897 // Extensions with empty update URLs should have a default one
901 // filled in. 898 // filled in.
902 builder.AddPendingExtension( 899 builder.AddPendingExtension(
903 GenerateId("foo"), PendingExtensionInfo(GURL(), *version, false, false)); 900 GenerateId("foo"), PendingExtensionInfo(GURL(),
901 false, false, true, false));
904 std::vector<ManifestFetchData*> fetches = builder.GetFetches(); 902 std::vector<ManifestFetchData*> fetches = builder.GetFetches();
905 ASSERT_EQ(1u, fetches.size()); 903 ASSERT_EQ(1u, fetches.size());
906 scoped_ptr<ManifestFetchData> fetch(fetches[0]); 904 scoped_ptr<ManifestFetchData> fetch(fetches[0]);
907 fetches.clear(); 905 fetches.clear();
908 EXPECT_FALSE(fetch->base_url().is_empty()); 906 EXPECT_FALSE(fetch->base_url().is_empty());
909 EXPECT_FALSE(fetch->full_url().is_empty()); 907 EXPECT_FALSE(fetch->full_url().is_empty());
910 } 908 }
911 909
912 // TODO(asargent) - (http://crbug.com/12780) add tests for: 910 // TODO(asargent) - (http://crbug.com/12780) add tests for:
913 // -prodversionmin (shouldn't update if browser version too old) 911 // -prodversionmin (shouldn't update if browser version too old)
914 // -manifests & updates arriving out of order / interleaved 912 // -manifests & updates arriving out of order / interleaved
915 // -Profile::GetDefaultRequestContext() returning null 913 // -Profile::GetDefaultRequestContext() returning null
916 // (should not crash, but just do check later) 914 // (should not crash, but just do check later)
917 // -malformed update url (empty, file://, has query, has a # fragment, etc.) 915 // -malformed update url (empty, file://, has query, has a # fragment, etc.)
918 // -An extension gets uninstalled while updates are in progress (so it doesn't 916 // -An extension gets uninstalled while updates are in progress (so it doesn't
919 // "come back from the dead") 917 // "come back from the dead")
920 // -An extension gets manually updated to v3 while we're downloading v2 (ie 918 // -An extension gets manually updated to v3 while we're downloading v2 (ie
921 // you don't get downgraded accidentally) 919 // you don't get downgraded accidentally)
922 // -An update manifest mentions multiple updates 920 // -An update manifest mentions multiple updates
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_updater.cc ('k') | chrome/browser/extensions/extensions_service.h » ('j') | no next file with comments »

Powered by Google App Engine