Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(307)

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

Issue 9595001: Apps on NTP should be in order of installation (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Unit test fixes Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <list>
5 #include <map> 6 #include <map>
6 #include <set> 7 #include <set>
7 #include <vector> 8 #include <vector>
8 9
9 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
10 #include "base/file_util.h" 11 #include "base/file_util.h"
11 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
13 #include "base/stl_util.h" 14 #include "base/stl_util.h"
14 #include "base/string_number_conversions.h" 15 #include "base/string_number_conversions.h"
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 228
228 bool ShouldInstallThemesOnly(const Extension& extension) { 229 bool ShouldInstallThemesOnly(const Extension& extension) {
229 return extension.is_theme(); 230 return extension.is_theme();
230 } 231 }
231 232
232 bool ShouldAlwaysInstall(const Extension& extension) { 233 bool ShouldAlwaysInstall(const Extension& extension) {
233 return true; 234 return true;
234 } 235 }
235 236
236 // Loads some pending extension records into a pending extension manager. 237 // Loads some pending extension records into a pending extension manager.
238 // Require that there are no pending extensions in the pending extension manager
Aaron Boodman 2012/05/11 19:23:55 Put this comment above the assertion. Or just kill
239 // prior to this function call.
237 void SetupPendingExtensionManagerForTest( 240 void SetupPendingExtensionManagerForTest(
238 int count, 241 int count,
239 const GURL& update_url, 242 const GURL& update_url,
240 PendingExtensionManager* pending_extension_manager) { 243 PendingExtensionManager* pending_extension_manager) {
241 for (int i = 1; i <= count; i++) { 244 ASSERT_EQ(0u, pending_extension_manager->pending_extension_list_.size());
245
246 for (int i = count; i >= 1; --i) {
242 PendingExtensionInfo::ShouldAllowInstallPredicate should_allow_install = 247 PendingExtensionInfo::ShouldAllowInstallPredicate should_allow_install =
243 (i % 2 == 0) ? &ShouldInstallThemesOnly : &ShouldInstallExtensionsOnly; 248 (i % 2 == 0) ? &ShouldInstallThemesOnly : &ShouldInstallExtensionsOnly;
244 const bool kIsFromSync = true; 249 const bool kIsFromSync = true;
245 const bool kInstallSilently = true; 250 const bool kInstallSilently = true;
246 std::string id = GenerateId(base::StringPrintf("extension%i", i)); 251 std::string id = GenerateId(base::StringPrintf("extension%i", i));
247 252
248 pending_extension_manager->AddForTesting( 253 pending_extension_manager->AddForTesting(
249 id, 254 PendingExtensionInfo(id,
250 PendingExtensionInfo(update_url, 255 update_url,
251 Version(), 256 Version(),
252 should_allow_install, 257 should_allow_install,
253 kIsFromSync, 258 kIsFromSync,
254 kInstallSilently, 259 kInstallSilently,
255 Extension::INTERNAL)); 260 Extension::INTERNAL));
256 } 261 }
262
263 // Check to see if the order in which the extensions were added is preserved.
264 std::list<std::string> pending_ids;
265 pending_extension_manager->GetPendingIdsForUpdateCheck(&pending_ids);
266 int i = count;
267 for (std::list<std::string>::const_iterator it = pending_ids.begin();
Aaron Boodman 2012/05/11 19:23:55 This is fine, but not sure if it's really worth te
268 it != pending_ids.end(); ++it, --i) {
269 ASSERT_EQ(*it, base::StringPrintf("extension%i", i));
270 }
257 } 271 }
258 272
259 class ServiceForManifestTests : public MockService { 273 class ServiceForManifestTests : public MockService {
260 public: 274 public:
261 ServiceForManifestTests() {} 275 ServiceForManifestTests() {}
262 276
263 virtual ~ServiceForManifestTests() {} 277 virtual ~ServiceForManifestTests() {}
264 278
265 virtual const Extension* GetExtensionById( 279 virtual const Extension* GetExtensionById(
266 const std::string& id, bool include_disabled) const OVERRIDE { 280 const std::string& id, bool include_disabled) const OVERRIDE {
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after
694 SetupPendingExtensionManagerForTest(3, GURL(), pending_extension_manager); 708 SetupPendingExtensionManagerForTest(3, GURL(), pending_extension_manager);
695 709
696 TestingProfile profile; 710 TestingProfile profile;
697 profile.CreateRequestContext(); 711 profile.CreateRequestContext();
698 MockExtensionDownloaderDelegate delegate; 712 MockExtensionDownloaderDelegate delegate;
699 ExtensionDownloader downloader(&delegate, profile.GetRequestContext()); 713 ExtensionDownloader downloader(&delegate, profile.GetRequestContext());
700 714
701 ManifestFetchData fetch_data(GURL("http://localhost/foo")); 715 ManifestFetchData fetch_data(GURL("http://localhost/foo"));
702 UpdateManifest::Results updates; 716 UpdateManifest::Results updates;
703 717
704 std::set<std::string> ids_for_update_check; 718 std::list<std::string> ids_for_update_check;
705 pending_extension_manager->GetPendingIdsForUpdateCheck( 719 pending_extension_manager->GetPendingIdsForUpdateCheck(
706 &ids_for_update_check); 720 &ids_for_update_check);
707 721
708 std::set<std::string>::const_iterator it; 722 std::list<std::string>::const_iterator it;
709 for (it = ids_for_update_check.begin(); 723 for (it = ids_for_update_check.begin();
710 it != ids_for_update_check.end(); ++it) { 724 it != ids_for_update_check.end(); ++it) {
711 fetch_data.AddExtension(*it, "1.0.0.0", 725 fetch_data.AddExtension(*it, "1.0.0.0",
712 &kNeverPingedData, kEmptyUpdateUrlData, ""); 726 &kNeverPingedData, kEmptyUpdateUrlData, "");
713 AddParseResult(*it, "1.1", "http://localhost/e1_1.1.crx", &updates); 727 AddParseResult(*it, "1.1", "http://localhost/e1_1.1.crx", &updates);
714 } 728 }
715 729
716 // The delegate will tell the downloader that all the extensions are 730 // The delegate will tell the downloader that all the extensions are
717 // pending. 731 // pending.
718 EXPECT_CALL(delegate, IsExtensionPending(_)).WillRepeatedly(Return(true)); 732 EXPECT_CALL(delegate, IsExtensionPending(_)).WillRepeatedly(Return(true));
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
860 ASSERT_TRUE(version.get()); 874 ASSERT_TRUE(version.get());
861 updater.downloader_->FetchUpdatedExtension( 875 updater.downloader_->FetchUpdatedExtension(
862 id, test_url, hash, version->GetString()); 876 id, test_url, hash, version->GetString());
863 877
864 if (pending) { 878 if (pending) {
865 const bool kIsFromSync = true; 879 const bool kIsFromSync = true;
866 const bool kInstallSilently = true; 880 const bool kInstallSilently = true;
867 PendingExtensionManager* pending_extension_manager = 881 PendingExtensionManager* pending_extension_manager =
868 service->pending_extension_manager(); 882 service->pending_extension_manager();
869 pending_extension_manager->AddForTesting( 883 pending_extension_manager->AddForTesting(
870 id, 884 PendingExtensionInfo(id, test_url, *version,
871 PendingExtensionInfo(test_url, *version,
872 &ShouldAlwaysInstall, kIsFromSync, 885 &ShouldAlwaysInstall, kIsFromSync,
873 kInstallSilently, 886 kInstallSilently,
874 Extension::INTERNAL)); 887 Extension::INTERNAL));
875 } 888 }
876 889
877 // Call back the ExtensionUpdater with a 200 response and some test data 890 // Call back the ExtensionUpdater with a 200 response and some test data
878 FilePath extension_file_path(FILE_PATH_LITERAL("/whatever")); 891 FilePath extension_file_path(FILE_PATH_LITERAL("/whatever"));
879 fetcher = factory.GetFetcherByID(ExtensionDownloader::kExtensionFetcherId); 892 fetcher = factory.GetFetcherByID(ExtensionDownloader::kExtensionFetcherId);
880 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); 893 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL);
881 EXPECT_TRUE(fetcher->GetLoadFlags() == kExpectedLoadFlags); 894 EXPECT_TRUE(fetcher->GetLoadFlags() == kExpectedLoadFlags);
(...skipping 625 matching lines...) Expand 10 before | Expand all | Expand 10 after
1507 // -prodversionmin (shouldn't update if browser version too old) 1520 // -prodversionmin (shouldn't update if browser version too old)
1508 // -manifests & updates arriving out of order / interleaved 1521 // -manifests & updates arriving out of order / interleaved
1509 // -malformed update url (empty, file://, has query, has a # fragment, etc.) 1522 // -malformed update url (empty, file://, has query, has a # fragment, etc.)
1510 // -An extension gets uninstalled while updates are in progress (so it doesn't 1523 // -An extension gets uninstalled while updates are in progress (so it doesn't
1511 // "come back from the dead") 1524 // "come back from the dead")
1512 // -An extension gets manually updated to v3 while we're downloading v2 (ie 1525 // -An extension gets manually updated to v3 while we're downloading v2 (ie
1513 // you don't get downgraded accidentally) 1526 // you don't get downgraded accidentally)
1514 // -An update manifest mentions multiple updates 1527 // -An update manifest mentions multiple updates
1515 1528
1516 } // namespace extensions 1529 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/updater/extension_updater.cc ('k') | chrome/browser/sync/test/integration/sync_app_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698