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

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

Issue 11232060: Make sure sideload wipeout doesn't interfere with the tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 1 month 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 | Annotate | Revision Log
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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 using content::DOMStorageContext; 104 using content::DOMStorageContext;
105 using content::IndexedDBContext; 105 using content::IndexedDBContext;
106 using content::PluginService; 106 using content::PluginService;
107 using extensions::APIPermission; 107 using extensions::APIPermission;
108 using extensions::APIPermissionSet; 108 using extensions::APIPermissionSet;
109 using extensions::CrxInstaller; 109 using extensions::CrxInstaller;
110 using extensions::Extension; 110 using extensions::Extension;
111 using extensions::ExtensionCreator; 111 using extensions::ExtensionCreator;
112 using extensions::ExtensionPrefs; 112 using extensions::ExtensionPrefs;
113 using extensions::ExtensionSystem; 113 using extensions::ExtensionSystem;
114 using extensions::FeatureSwitch;
114 using extensions::PermissionSet; 115 using extensions::PermissionSet;
115 116
116 namespace keys = extension_manifest_keys; 117 namespace keys = extension_manifest_keys;
117 118
118 namespace { 119 namespace {
119 120
120 // Extension ids used during testing. 121 // Extension ids used during testing.
121 const char* const all_zero = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; 122 const char* const all_zero = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
122 const char* const zero_n_one = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab"; 123 const char* const zero_n_one = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab";
123 const char* const good0 = "behllobkkfkfnphdnhnkndlbkcpglgmj"; 124 const char* const good0 = "behllobkkfkfnphdnhnkndlbkcpglgmj";
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 void ExtensionServiceTestBase::SetUp() { 512 void ExtensionServiceTestBase::SetUp() {
512 ExtensionErrorReporter::GetInstance()->ClearErrors(); 513 ExtensionErrorReporter::GetInstance()->ClearErrors();
513 } 514 }
514 515
515 class ExtensionServiceTest 516 class ExtensionServiceTest
516 : public ExtensionServiceTestBase, public content::NotificationObserver { 517 : public ExtensionServiceTestBase, public content::NotificationObserver {
517 public: 518 public:
518 ExtensionServiceTest() 519 ExtensionServiceTest()
519 : installed_(NULL), 520 : installed_(NULL),
520 override_external_install_prompt_( 521 override_external_install_prompt_(
521 extensions::FeatureSwitch::prompt_for_external_extensions(), 522 FeatureSwitch::prompt_for_external_extensions(), false),
522 false) { 523 override_sideload_wipeout_(
524 FeatureSwitch::sideload_wipeout(), false) {
523 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, 525 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED,
524 content::NotificationService::AllSources()); 526 content::NotificationService::AllSources());
525 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, 527 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED,
526 content::NotificationService::AllSources()); 528 content::NotificationService::AllSources());
527 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALLED, 529 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALLED,
528 content::NotificationService::AllSources()); 530 content::NotificationService::AllSources());
529 } 531 }
530 532
531 virtual void Observe(int type, 533 virtual void Observe(int type,
532 const content::NotificationSource& source, 534 const content::NotificationSource& source,
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after
1000 iter != value.end(); ++iter) 1002 iter != value.end(); ++iter)
1001 list_value->Append(Value::CreateStringValue(*iter)); 1003 list_value->Append(Value::CreateStringValue(*iter));
1002 1004
1003 SetPref(extension_id, pref_path, list_value, msg); 1005 SetPref(extension_id, pref_path, list_value, msg);
1004 } 1006 }
1005 1007
1006 protected: 1008 protected:
1007 extensions::ExtensionList loaded_; 1009 extensions::ExtensionList loaded_;
1008 std::string unloaded_id_; 1010 std::string unloaded_id_;
1009 const Extension* installed_; 1011 const Extension* installed_;
1010 extensions::FeatureSwitch::ScopedOverride override_external_install_prompt_; 1012 FeatureSwitch::ScopedOverride override_external_install_prompt_;
1013 FeatureSwitch::ScopedOverride override_sideload_wipeout_;
1011 1014
1012 private: 1015 private:
1013 content::NotificationRegistrar registrar_; 1016 content::NotificationRegistrar registrar_;
1014 }; 1017 };
1015 1018
1016 // Receives notifications from a PackExtensionJob, indicating either that 1019 // Receives notifications from a PackExtensionJob, indicating either that
1017 // packing succeeded or that there was some error. 1020 // packing succeeded or that there was some error.
1018 class PackExtensionTestClient : public extensions::PackExtensionJob::Client { 1021 class PackExtensionTestClient : public extensions::PackExtensionJob::Client {
1019 public: 1022 public:
1020 PackExtensionTestClient(const FilePath& expected_crx_path, 1023 PackExtensionTestClient(const FilePath& expected_crx_path,
(...skipping 4540 matching lines...) Expand 10 before | Expand all | Expand 10 after
5561 ASSERT_TRUE(IsCrxInstalled()); 5564 ASSERT_TRUE(IsCrxInstalled());
5562 5565
5563 // Now that the extension is installed, sync request should fail 5566 // Now that the extension is installed, sync request should fail
5564 // because the extension is already installed. 5567 // because the extension is already installed.
5565 ASSERT_FALSE(AddPendingSyncInstall()); 5568 ASSERT_FALSE(AddPendingSyncInstall());
5566 } 5569 }
5567 5570
5568 #if ENABLE_EXTERNAL_INSTALL_UI 5571 #if ENABLE_EXTERNAL_INSTALL_UI
5569 // Test that installing an external extension displays a GlobalError. 5572 // Test that installing an external extension displays a GlobalError.
5570 TEST_F(ExtensionServiceTest, ExternalInstallGlobalError) { 5573 TEST_F(ExtensionServiceTest, ExternalInstallGlobalError) {
5571 extensions::FeatureSwitch::ScopedOverride prompt( 5574 FeatureSwitch::ScopedOverride prompt(
5572 extensions::FeatureSwitch::prompt_for_external_extensions(), true); 5575 FeatureSwitch::prompt_for_external_extensions(), true);
5573 5576
5574 InitializeEmptyExtensionService(); 5577 InitializeEmptyExtensionService();
5575 MockExtensionProvider* provider = 5578 MockExtensionProvider* provider =
5576 new MockExtensionProvider(service_, Extension::EXTERNAL_PREF); 5579 new MockExtensionProvider(service_, Extension::EXTERNAL_PREF);
5577 AddMockExternalProvider(provider); 5580 AddMockExternalProvider(provider);
5578 5581
5579 service_->UpdateExternalExtensionAlert(); 5582 service_->UpdateExternalExtensionAlert();
5580 // Should return false, meaning there aren't any extensions that the user 5583 // Should return false, meaning there aren't any extensions that the user
5581 // needs to know about. 5584 // needs to know about.
5582 EXPECT_FALSE(extensions::HasExternalInstallError(service_)); 5585 EXPECT_FALSE(extensions::HasExternalInstallError(service_));
(...skipping 25 matching lines...) Expand all
5608 data_dir_.AppendASCII("page_action.crx")); 5611 data_dir_.AppendASCII("page_action.crx"));
5609 5612
5610 service_->CheckForExternalUpdates(); 5613 service_->CheckForExternalUpdates();
5611 loop_.RunAllPending(); 5614 loop_.RunAllPending();
5612 EXPECT_TRUE(extensions::HasExternalInstallError(service_)); 5615 EXPECT_TRUE(extensions::HasExternalInstallError(service_));
5613 } 5616 }
5614 5617
5615 // Test that external extensions are initially disabled, and that enabling 5618 // Test that external extensions are initially disabled, and that enabling
5616 // them clears the prompt. 5619 // them clears the prompt.
5617 TEST_F(ExtensionServiceTest, ExternalInstallInitiallyDisabled) { 5620 TEST_F(ExtensionServiceTest, ExternalInstallInitiallyDisabled) {
5618 extensions::FeatureSwitch::ScopedOverride prompt( 5621 FeatureSwitch::ScopedOverride prompt(
5619 extensions::FeatureSwitch::prompt_for_external_extensions(), true); 5622 FeatureSwitch::prompt_for_external_extensions(), true);
5620 5623
5621 InitializeEmptyExtensionService(); 5624 InitializeEmptyExtensionService();
5622 MockExtensionProvider* provider = 5625 MockExtensionProvider* provider =
5623 new MockExtensionProvider(service_, Extension::EXTERNAL_PREF); 5626 new MockExtensionProvider(service_, Extension::EXTERNAL_PREF);
5624 AddMockExternalProvider(provider); 5627 AddMockExternalProvider(provider);
5625 5628
5626 provider->UpdateOrAddExtension(page_action, "1.0.0.0", 5629 provider->UpdateOrAddExtension(page_action, "1.0.0.0",
5627 data_dir_.AppendASCII("page_action.crx")); 5630 data_dir_.AppendASCII("page_action.crx"));
5628 5631
5629 service_->CheckForExternalUpdates(); 5632 service_->CheckForExternalUpdates();
5630 loop_.RunAllPending(); 5633 loop_.RunAllPending();
5631 EXPECT_TRUE(extensions::HasExternalInstallError(service_)); 5634 EXPECT_TRUE(extensions::HasExternalInstallError(service_));
5632 EXPECT_FALSE(service_->IsExtensionEnabled(page_action)); 5635 EXPECT_FALSE(service_->IsExtensionEnabled(page_action));
5633 5636
5634 const Extension* extension = 5637 const Extension* extension =
5635 service_->disabled_extensions()->GetByID(page_action); 5638 service_->disabled_extensions()->GetByID(page_action);
5636 EXPECT_TRUE(extension); 5639 EXPECT_TRUE(extension);
5637 EXPECT_EQ(page_action, extension->id()); 5640 EXPECT_EQ(page_action, extension->id());
5638 5641
5639 service_->EnableExtension(page_action); 5642 service_->EnableExtension(page_action);
5640 EXPECT_FALSE(extensions::HasExternalInstallError(service_)); 5643 EXPECT_FALSE(extensions::HasExternalInstallError(service_));
5641 EXPECT_TRUE(service_->IsExtensionEnabled(page_action)); 5644 EXPECT_TRUE(service_->IsExtensionEnabled(page_action));
5642 } 5645 }
5643 5646
5644 // Test that installing multiple external extensions works. 5647 // Test that installing multiple external extensions works.
5645 TEST_F(ExtensionServiceTest, ExternalInstallMultiple) { 5648 TEST_F(ExtensionServiceTest, ExternalInstallMultiple) {
5646 extensions::FeatureSwitch::ScopedOverride prompt( 5649 FeatureSwitch::ScopedOverride prompt(
5647 extensions::FeatureSwitch::prompt_for_external_extensions(), true); 5650 FeatureSwitch::prompt_for_external_extensions(), true);
5648 5651
5649 InitializeEmptyExtensionService(); 5652 InitializeEmptyExtensionService();
5650 MockExtensionProvider* provider = 5653 MockExtensionProvider* provider =
5651 new MockExtensionProvider(service_, Extension::EXTERNAL_PREF); 5654 new MockExtensionProvider(service_, Extension::EXTERNAL_PREF);
5652 AddMockExternalProvider(provider); 5655 AddMockExternalProvider(provider);
5653 5656
5654 provider->UpdateOrAddExtension(page_action, "1.0.0.0", 5657 provider->UpdateOrAddExtension(page_action, "1.0.0.0",
5655 data_dir_.AppendASCII("page_action.crx")); 5658 data_dir_.AppendASCII("page_action.crx"));
5656 provider->UpdateOrAddExtension(good_crx, "1.0.0.0", 5659 provider->UpdateOrAddExtension(good_crx, "1.0.0.0",
5657 data_dir_.AppendASCII("good.crx")); 5660 data_dir_.AppendASCII("good.crx"));
5658 provider->UpdateOrAddExtension(theme_crx, "2.0", 5661 provider->UpdateOrAddExtension(theme_crx, "2.0",
5659 data_dir_.AppendASCII("theme.crx")); 5662 data_dir_.AppendASCII("theme.crx"));
5660 5663
5661 service_->CheckForExternalUpdates(); 5664 service_->CheckForExternalUpdates();
5662 loop_.RunAllPending(); 5665 loop_.RunAllPending();
5663 EXPECT_TRUE(extensions::HasExternalInstallError(service_)); 5666 EXPECT_TRUE(extensions::HasExternalInstallError(service_));
5664 EXPECT_FALSE(service_->IsExtensionEnabled(page_action)); 5667 EXPECT_FALSE(service_->IsExtensionEnabled(page_action));
5665 EXPECT_FALSE(service_->IsExtensionEnabled(good_crx)); 5668 EXPECT_FALSE(service_->IsExtensionEnabled(good_crx));
5666 EXPECT_FALSE(service_->IsExtensionEnabled(theme_crx)); 5669 EXPECT_FALSE(service_->IsExtensionEnabled(theme_crx));
5667 5670
5668 service_->EnableExtension(page_action); 5671 service_->EnableExtension(page_action);
5669 EXPECT_TRUE(extensions::HasExternalInstallError(service_)); 5672 EXPECT_TRUE(extensions::HasExternalInstallError(service_));
5670 service_->EnableExtension(theme_crx); 5673 service_->EnableExtension(theme_crx);
5671 EXPECT_TRUE(extensions::HasExternalInstallError(service_)); 5674 EXPECT_TRUE(extensions::HasExternalInstallError(service_));
5672 service_->EnableExtension(good_crx); 5675 service_->EnableExtension(good_crx);
5673 EXPECT_FALSE(extensions::HasExternalInstallError(service_)); 5676 EXPECT_FALSE(extensions::HasExternalInstallError(service_));
5674 } 5677 }
5675 #endif // ENABLE_EXTERNAL_INSTALL_UI 5678 #endif // ENABLE_EXTERNAL_INSTALL_UI
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_service.cc ('k') | chrome/browser/ui/views/extensions/disabled_extensions_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698