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

Side by Side Diff: chrome/browser/extensions/extension_service_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: ExtensionInstallUI -> ExtensionInstallPrompt Created 8 years, 6 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 "chrome/browser/extensions/extension_service_unittest.h" 5 #include "chrome/browser/extensions/extension_service_unittest.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 2479 matching lines...) Expand 10 before | Expand all | Expand 10 after
2490 InitializeEmptyExtensionService(); 2490 InitializeEmptyExtensionService();
2491 2491
2492 const std::string kFakeId(all_zero); 2492 const std::string kFakeId(all_zero);
2493 const GURL kFakeUpdateURL("http:://fake.update/url"); 2493 const GURL kFakeUpdateURL("http:://fake.update/url");
2494 const bool kFakeInstallSilently(true); 2494 const bool kFakeInstallSilently(true);
2495 2495
2496 EXPECT_TRUE(service_->pending_extension_manager()->AddFromSync( 2496 EXPECT_TRUE(service_->pending_extension_manager()->AddFromSync(
2497 kFakeId, kFakeUpdateURL, &IsExtension, 2497 kFakeId, kFakeUpdateURL, &IsExtension,
2498 kFakeInstallSilently)); 2498 kFakeInstallSilently));
2499 2499
2500 PendingExtensionInfo pending_extension_info; 2500 const PendingExtensionInfo* pending_extension_info;
2501 ASSERT_TRUE(service_->pending_extension_manager()->GetById( 2501 ASSERT_TRUE((pending_extension_info = service_->pending_extension_manager()->
2502 kFakeId, &pending_extension_info)); 2502 GetById(kFakeId)));
2503 EXPECT_EQ(kFakeUpdateURL, pending_extension_info.update_url()); 2503 EXPECT_EQ(kFakeUpdateURL, pending_extension_info->update_url());
2504 EXPECT_EQ(&IsExtension, pending_extension_info.should_allow_install_); 2504 EXPECT_EQ(&IsExtension, pending_extension_info->should_allow_install_);
2505 EXPECT_EQ(kFakeInstallSilently, pending_extension_info.install_silently()); 2505 EXPECT_EQ(kFakeInstallSilently, pending_extension_info->install_silently());
2506 } 2506 }
2507 2507
2508 namespace { 2508 namespace {
2509 const char kGoodId[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; 2509 const char kGoodId[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf";
2510 const char kGoodUpdateURL[] = "http://good.update/url"; 2510 const char kGoodUpdateURL[] = "http://good.update/url";
2511 const bool kGoodIsFromSync = true; 2511 const bool kGoodIsFromSync = true;
2512 const bool kGoodInstallSilently = true; 2512 const bool kGoodInstallSilently = true;
2513 } // namespace 2513 } // namespace
2514 2514
2515 // Test updating a pending extension. 2515 // Test updating a pending extension.
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
2593 // but a sync update should not overwrite a non-sync update. 2593 // but a sync update should not overwrite a non-sync update.
2594 TEST_F(ExtensionServiceTest, UpdatePendingExternalCrxWinsOverSync) { 2594 TEST_F(ExtensionServiceTest, UpdatePendingExternalCrxWinsOverSync) {
2595 InitializeEmptyExtensionService(); 2595 InitializeEmptyExtensionService();
2596 2596
2597 // Add a crx to be installed from the update mechanism. 2597 // Add a crx to be installed from the update mechanism.
2598 EXPECT_TRUE(service_->pending_extension_manager()->AddFromSync( 2598 EXPECT_TRUE(service_->pending_extension_manager()->AddFromSync(
2599 kGoodId, GURL(kGoodUpdateURL), &IsExtension, 2599 kGoodId, GURL(kGoodUpdateURL), &IsExtension,
2600 kGoodInstallSilently)); 2600 kGoodInstallSilently));
2601 2601
2602 // Check that there is a pending crx, with is_from_sync set to true. 2602 // Check that there is a pending crx, with is_from_sync set to true.
2603 PendingExtensionInfo pending_extension_info; 2603 const PendingExtensionInfo* pending_extension_info;
2604 ASSERT_TRUE(service_->pending_extension_manager()->GetById( 2604 ASSERT_TRUE((pending_extension_info = service_->pending_extension_manager()->
2605 kGoodId, &pending_extension_info)); 2605 GetById(kGoodId)));
2606 EXPECT_TRUE(pending_extension_info.is_from_sync()); 2606 EXPECT_TRUE(pending_extension_info->is_from_sync());
2607 2607
2608 // Add a crx to be updated, with the same ID, from a non-sync source. 2608 // Add a crx to be updated, with the same ID, from a non-sync source.
2609 EXPECT_TRUE(service_->pending_extension_manager()->AddFromExternalUpdateUrl( 2609 EXPECT_TRUE(service_->pending_extension_manager()->AddFromExternalUpdateUrl(
2610 kGoodId, GURL(kGoodUpdateURL), Extension::EXTERNAL_PREF_DOWNLOAD)); 2610 kGoodId, GURL(kGoodUpdateURL), Extension::EXTERNAL_PREF_DOWNLOAD));
2611 2611
2612 // Check that there is a pending crx, with is_from_sync set to false. 2612 // Check that there is a pending crx, with is_from_sync set to false.
2613 ASSERT_TRUE(service_->pending_extension_manager()->GetById( 2613 ASSERT_TRUE((pending_extension_info = service_->pending_extension_manager()->
2614 kGoodId, &pending_extension_info)); 2614 GetById(kGoodId)));
2615 EXPECT_FALSE(pending_extension_info.is_from_sync()); 2615 EXPECT_FALSE(pending_extension_info->is_from_sync());
2616 EXPECT_EQ(Extension::EXTERNAL_PREF_DOWNLOAD, 2616 EXPECT_EQ(Extension::EXTERNAL_PREF_DOWNLOAD,
2617 pending_extension_info.install_source()); 2617 pending_extension_info->install_source());
2618 2618
2619 // Add a crx to be installed from the update mechanism. 2619 // Add a crx to be installed from the update mechanism.
2620 EXPECT_FALSE(service_->pending_extension_manager()->AddFromSync( 2620 EXPECT_FALSE(service_->pending_extension_manager()->AddFromSync(
2621 kGoodId, GURL(kGoodUpdateURL), &IsExtension, 2621 kGoodId, GURL(kGoodUpdateURL), &IsExtension,
2622 kGoodInstallSilently)); 2622 kGoodInstallSilently));
2623 2623
2624 // Check that the external, non-sync update was not overridden. 2624 // Check that the external, non-sync update was not overridden.
2625 ASSERT_TRUE(service_->pending_extension_manager()->GetById( 2625 ASSERT_TRUE((pending_extension_info = service_->pending_extension_manager()->
2626 kGoodId, &pending_extension_info)); 2626 GetById(kGoodId)));
2627 EXPECT_FALSE(pending_extension_info.is_from_sync()); 2627 EXPECT_FALSE(pending_extension_info->is_from_sync());
2628 EXPECT_EQ(Extension::EXTERNAL_PREF_DOWNLOAD, 2628 EXPECT_EQ(Extension::EXTERNAL_PREF_DOWNLOAD,
2629 pending_extension_info.install_source()); 2629 pending_extension_info->install_source());
2630 } 2630 }
2631 2631
2632 // Updating a theme should fail if the updater is explicitly told that 2632 // Updating a theme should fail if the updater is explicitly told that
2633 // the CRX is not a theme. 2633 // the CRX is not a theme.
2634 TEST_F(ExtensionServiceTest, UpdatePendingCrxThemeMismatch) { 2634 TEST_F(ExtensionServiceTest, UpdatePendingCrxThemeMismatch) {
2635 InitializeEmptyExtensionService(); 2635 InitializeEmptyExtensionService();
2636 EXPECT_TRUE(service_->pending_extension_manager()->AddFromSync( 2636 EXPECT_TRUE(service_->pending_extension_manager()->AddFromSync(
2637 theme_crx, GURL(), &IsExtension, true)); 2637 theme_crx, GURL(), &IsExtension, true));
2638 2638
2639 EXPECT_TRUE(service_->pending_extension_manager()->IsIdPending(theme_crx)); 2639 EXPECT_TRUE(service_->pending_extension_manager()->IsIdPending(theme_crx));
(...skipping 2063 matching lines...) Expand 10 before | Expand all | Expand 10 after
4703 list[0] = sync_change; 4703 list[0] = sync_change;
4704 4704
4705 4705
4706 EXPECT_TRUE(service_->IsExtensionEnabled(good_crx)); 4706 EXPECT_TRUE(service_->IsExtensionEnabled(good_crx));
4707 EXPECT_FALSE(service_->IsIncognitoEnabled(good_crx)); 4707 EXPECT_FALSE(service_->IsIncognitoEnabled(good_crx));
4708 service_->ProcessSyncChanges(FROM_HERE, list); 4708 service_->ProcessSyncChanges(FROM_HERE, list);
4709 EXPECT_TRUE(service_->updater()->WillCheckSoon()); 4709 EXPECT_TRUE(service_->updater()->WillCheckSoon());
4710 EXPECT_FALSE(service_->IsExtensionEnabled(good_crx)); 4710 EXPECT_FALSE(service_->IsExtensionEnabled(good_crx));
4711 EXPECT_TRUE(service_->IsIncognitoEnabled(good_crx)); 4711 EXPECT_TRUE(service_->IsIncognitoEnabled(good_crx));
4712 4712
4713 PendingExtensionInfo info; 4713 const PendingExtensionInfo* info;
4714 EXPECT_TRUE( 4714 EXPECT_TRUE((info = service_->pending_extension_manager()->
4715 service_->pending_extension_manager()->GetById(good_crx, &info)); 4715 GetById(good_crx)));
4716 EXPECT_EQ(ext_specifics->update_url(), info.update_url().spec()); 4716 EXPECT_EQ(ext_specifics->update_url(), info->update_url().spec());
4717 EXPECT_TRUE(info.is_from_sync()); 4717 EXPECT_TRUE(info->is_from_sync());
4718 EXPECT_TRUE(info.install_silently()); 4718 EXPECT_TRUE(info->install_silently());
4719 EXPECT_EQ(Extension::INTERNAL, info.install_source()); 4719 EXPECT_EQ(Extension::INTERNAL, info->install_source());
4720 // TODO(akalin): Figure out a way to test |info.ShouldAllowInstall()|. 4720 // TODO(akalin): Figure out a way to test |info.ShouldAllowInstall()|.
4721 } 4721 }
4722 4722
4723 TEST_F(ExtensionServiceTest, InstallPriorityExternalUpdateUrl) { 4723 TEST_F(ExtensionServiceTest, InstallPriorityExternalUpdateUrl) {
4724 InitializeEmptyExtensionService(); 4724 InitializeEmptyExtensionService();
4725 4725
4726 FilePath path = data_dir_.AppendASCII("good.crx"); 4726 FilePath path = data_dir_.AppendASCII("good.crx");
4727 InstallCRX(path, INSTALL_NEW); 4727 InstallCRX(path, INSTALL_NEW);
4728 ValidatePrefKeyCount(1u); 4728 ValidatePrefKeyCount(1u);
4729 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); 4729 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
4932 InitializeEmptyExtensionService(); 4932 InitializeEmptyExtensionService();
4933 4933
4934 PendingExtensionManager* pending = service_->pending_extension_manager(); 4934 PendingExtensionManager* pending = service_->pending_extension_manager();
4935 EXPECT_FALSE(pending->IsIdPending(kGoodId)); 4935 EXPECT_FALSE(pending->IsIdPending(kGoodId));
4936 4936
4937 // An external provider starts installing from a local crx. 4937 // An external provider starts installing from a local crx.
4938 EXPECT_TRUE( 4938 EXPECT_TRUE(
4939 service_->OnExternalExtensionFileFound( 4939 service_->OnExternalExtensionFileFound(
4940 kGoodId, &kVersion123, kInvalidPathToCrx, 4940 kGoodId, &kVersion123, kInvalidPathToCrx,
4941 Extension::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged)); 4941 Extension::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged));
4942 PendingExtensionInfo info; 4942 const PendingExtensionInfo* info;
4943 EXPECT_TRUE(pending->GetById(kGoodId, &info)); 4943 EXPECT_TRUE((info = pending->GetById(kGoodId)));
4944 EXPECT_TRUE(info.version().IsValid()); 4944 EXPECT_TRUE(info->version().IsValid());
4945 EXPECT_TRUE(info.version().Equals(kVersion123)); 4945 EXPECT_TRUE(info->version().Equals(kVersion123));
4946 4946
4947 // Adding a newer version overrides the currently pending version. 4947 // Adding a newer version overrides the currently pending version.
4948 EXPECT_TRUE( 4948 EXPECT_TRUE(
4949 service_->OnExternalExtensionFileFound( 4949 service_->OnExternalExtensionFileFound(
4950 kGoodId, &kVersion124, kInvalidPathToCrx, 4950 kGoodId, &kVersion124, kInvalidPathToCrx,
4951 Extension::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged)); 4951 Extension::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged));
4952 EXPECT_TRUE(pending->GetById(kGoodId, &info)); 4952 EXPECT_TRUE((info = pending->GetById(kGoodId)));
4953 EXPECT_TRUE(info.version().IsValid()); 4953 EXPECT_TRUE(info->version().IsValid());
4954 EXPECT_TRUE(info.version().Equals(kVersion124)); 4954 EXPECT_TRUE(info->version().Equals(kVersion124));
4955 4955
4956 // Adding an older version fails. 4956 // Adding an older version fails.
4957 EXPECT_FALSE( 4957 EXPECT_FALSE(
4958 service_->OnExternalExtensionFileFound( 4958 service_->OnExternalExtensionFileFound(
4959 kGoodId, &kVersion123, kInvalidPathToCrx, 4959 kGoodId, &kVersion123, kInvalidPathToCrx,
4960 Extension::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged)); 4960 Extension::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged));
4961 EXPECT_TRUE(pending->GetById(kGoodId, &info)); 4961 EXPECT_TRUE((info = pending->GetById(kGoodId)));
4962 EXPECT_TRUE(info.version().IsValid()); 4962 EXPECT_TRUE(info->version().IsValid());
4963 EXPECT_TRUE(info.version().Equals(kVersion124)); 4963 EXPECT_TRUE(info->version().Equals(kVersion124));
4964 4964
4965 // Adding an older version fails even when coming from a higher-priority 4965 // Adding an older version fails even when coming from a higher-priority
4966 // location. 4966 // location.
4967 EXPECT_FALSE( 4967 EXPECT_FALSE(
4968 service_->OnExternalExtensionFileFound( 4968 service_->OnExternalExtensionFileFound(
4969 kGoodId, &kVersion123, kInvalidPathToCrx, 4969 kGoodId, &kVersion123, kInvalidPathToCrx,
4970 Extension::EXTERNAL_REGISTRY, kCreationFlags, kDontMarkAcknowledged)); 4970 Extension::EXTERNAL_REGISTRY, kCreationFlags, kDontMarkAcknowledged));
4971 EXPECT_TRUE(pending->GetById(kGoodId, &info)); 4971 EXPECT_TRUE((info = pending->GetById(kGoodId)));
4972 EXPECT_TRUE(info.version().IsValid()); 4972 EXPECT_TRUE(info->version().IsValid());
4973 EXPECT_TRUE(info.version().Equals(kVersion124)); 4973 EXPECT_TRUE(info->version().Equals(kVersion124));
4974 4974
4975 // Adding the latest version from the webstore overrides a specific version. 4975 // Adding the latest version from the webstore overrides a specific version.
4976 GURL kUpdateUrl("http://example.com/update"); 4976 GURL kUpdateUrl("http://example.com/update");
4977 EXPECT_TRUE( 4977 EXPECT_TRUE(
4978 service_->OnExternalExtensionUpdateUrlFound( 4978 service_->OnExternalExtensionUpdateUrlFound(
4979 kGoodId, kUpdateUrl, Extension::EXTERNAL_POLICY_DOWNLOAD)); 4979 kGoodId, kUpdateUrl, Extension::EXTERNAL_POLICY_DOWNLOAD));
4980 EXPECT_TRUE(pending->GetById(kGoodId, &info)); 4980 EXPECT_TRUE((info = pending->GetById(kGoodId)));
4981 EXPECT_FALSE(info.version().IsValid()); 4981 EXPECT_FALSE(info->version().IsValid());
4982 } 4982 }
4983 4983
4984 // This makes sure we can package and install CRX files that use whitelisted 4984 // This makes sure we can package and install CRX files that use whitelisted
4985 // permissions. 4985 // permissions.
4986 TEST_F(ExtensionServiceTest, InstallWhitelistedExtension) { 4986 TEST_F(ExtensionServiceTest, InstallWhitelistedExtension) {
4987 std::string test_id = "hdkklepkcpckhnpgjnmbdfhehckloojk"; 4987 std::string test_id = "hdkklepkcpckhnpgjnmbdfhehckloojk";
4988 CommandLine::ForCurrentProcess()->AppendSwitchASCII( 4988 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
4989 switches::kWhitelistedExtensionID, test_id); 4989 switches::kWhitelistedExtensionID, test_id);
4990 4990
4991 InitializeEmptyExtensionService(); 4991 InitializeEmptyExtensionService();
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
5044 scoped_ptr<Version> version; 5044 scoped_ptr<Version> version;
5045 version.reset(Version::GetVersionFromString("1.0.0.0")); 5045 version.reset(Version::GetVersionFromString("1.0.0.0"));
5046 5046
5047 // Get path to the CRX with id |kGoodId|. 5047 // Get path to the CRX with id |kGoodId|.
5048 return service_->OnExternalExtensionUpdateUrlFound( 5048 return service_->OnExternalExtensionUpdateUrlFound(
5049 crx_id_, GURL(), Extension::EXTERNAL_POLICY_DOWNLOAD); 5049 crx_id_, GURL(), Extension::EXTERNAL_POLICY_DOWNLOAD);
5050 } 5050 }
5051 5051
5052 // Get the install source of a pending extension. 5052 // Get the install source of a pending extension.
5053 Extension::Location GetPendingLocation() { 5053 Extension::Location GetPendingLocation() {
5054 PendingExtensionInfo info; 5054 const PendingExtensionInfo* info;
5055 EXPECT_TRUE(service_->pending_extension_manager()->GetById(crx_id_, &info)); 5055 EXPECT_TRUE((info = service_->pending_extension_manager()->
5056 return info.install_source(); 5056 GetById(crx_id_)));
5057 return info->install_source();
5057 } 5058 }
5058 5059
5059 // Is an extension pending from a sync request? 5060 // Is an extension pending from a sync request?
5060 bool GetPendingIsFromSync() { 5061 bool GetPendingIsFromSync() {
5061 PendingExtensionInfo info; 5062 const PendingExtensionInfo* info;
5062 EXPECT_TRUE(service_->pending_extension_manager()->GetById(crx_id_, &info)); 5063 EXPECT_TRUE((info = service_->pending_extension_manager()->
5063 return info.is_from_sync(); 5064 GetById(crx_id_)));
5065 return info->is_from_sync();
5064 } 5066 }
5065 5067
5066 // Is the CRX id these tests use pending? 5068 // Is the CRX id these tests use pending?
5067 bool IsCrxPending() { 5069 bool IsCrxPending() {
5068 return service_->pending_extension_manager()->IsIdPending(crx_id_); 5070 return service_->pending_extension_manager()->IsIdPending(crx_id_);
5069 } 5071 }
5070 5072
5071 // Is an extension installed? 5073 // Is an extension installed?
5072 bool IsCrxInstalled() { 5074 bool IsCrxInstalled() {
5073 return (service_->GetExtensionById(crx_id_, true) != NULL); 5075 return (service_->GetExtensionById(crx_id_, true) != NULL);
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
5184 provider->UpdateOrAddExtension(hosted_app, "1.0.0.0", 5186 provider->UpdateOrAddExtension(hosted_app, "1.0.0.0",
5185 data_dir_.AppendASCII("hosted_app.crx")); 5187 data_dir_.AppendASCII("hosted_app.crx"));
5186 5188
5187 service_->CheckForExternalUpdates(); 5189 service_->CheckForExternalUpdates();
5188 loop_.RunAllPending(); 5190 loop_.RunAllPending();
5189 5191
5190 ASSERT_TRUE(service_->PopulateExtensionGlobalError( 5192 ASSERT_TRUE(service_->PopulateExtensionGlobalError(
5191 extension_global_error.get())); 5193 extension_global_error.get()));
5192 ASSERT_EQ(1u, extension_global_error->get_external_extension_ids()->size()); 5194 ASSERT_EQ(1u, extension_global_error->get_external_extension_ids()->size());
5193 } 5195 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_service.cc ('k') | chrome/browser/extensions/pending_extension_info.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698