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

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

Issue 11150002: New post-sideload UI: (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: !!! Created 8 years, 2 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 | 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 21 matching lines...) Expand all
32 #include "chrome/browser/extensions/crx_installer.h" 32 #include "chrome/browser/extensions/crx_installer.h"
33 #include "chrome/browser/extensions/default_apps.h" 33 #include "chrome/browser/extensions/default_apps.h"
34 #include "chrome/browser/extensions/extension_creator.h" 34 #include "chrome/browser/extensions/extension_creator.h"
35 #include "chrome/browser/extensions/extension_error_reporter.h" 35 #include "chrome/browser/extensions/extension_error_reporter.h"
36 #include "chrome/browser/extensions/extension_error_ui.h" 36 #include "chrome/browser/extensions/extension_error_ui.h"
37 #include "chrome/browser/extensions/extension_service.h" 37 #include "chrome/browser/extensions/extension_service.h"
38 #include "chrome/browser/extensions/extension_sorting.h" 38 #include "chrome/browser/extensions/extension_sorting.h"
39 #include "chrome/browser/extensions/extension_special_storage_policy.h" 39 #include "chrome/browser/extensions/extension_special_storage_policy.h"
40 #include "chrome/browser/extensions/extension_sync_data.h" 40 #include "chrome/browser/extensions/extension_sync_data.h"
41 #include "chrome/browser/extensions/extension_system.h" 41 #include "chrome/browser/extensions/extension_system.h"
42 #include "chrome/browser/extensions/external_install_ui.h"
42 #include "chrome/browser/extensions/external_pref_loader.h" 43 #include "chrome/browser/extensions/external_pref_loader.h"
43 #include "chrome/browser/extensions/external_provider_impl.h" 44 #include "chrome/browser/extensions/external_provider_impl.h"
44 #include "chrome/browser/extensions/external_provider_interface.h" 45 #include "chrome/browser/extensions/external_provider_interface.h"
45 #include "chrome/browser/extensions/installed_loader.h" 46 #include "chrome/browser/extensions/installed_loader.h"
46 #include "chrome/browser/extensions/pack_extension_job.h" 47 #include "chrome/browser/extensions/pack_extension_job.h"
47 #include "chrome/browser/extensions/pending_extension_info.h" 48 #include "chrome/browser/extensions/pending_extension_info.h"
48 #include "chrome/browser/extensions/pending_extension_manager.h" 49 #include "chrome/browser/extensions/pending_extension_manager.h"
49 #include "chrome/browser/extensions/test_extension_system.h" 50 #include "chrome/browser/extensions/test_extension_system.h"
50 #include "chrome/browser/extensions/test_management_policy.h" 51 #include "chrome/browser/extensions/test_management_policy.h"
51 #include "chrome/browser/extensions/unpacked_installer.h" 52 #include "chrome/browser/extensions/unpacked_installer.h"
52 #include "chrome/browser/extensions/updater/extension_updater.h" 53 #include "chrome/browser/extensions/updater/extension_updater.h"
53 #include "chrome/browser/plugins/plugin_prefs_factory.h" 54 #include "chrome/browser/plugins/plugin_prefs_factory.h"
54 #include "chrome/browser/prefs/browser_prefs.h" 55 #include "chrome/browser/prefs/browser_prefs.h"
55 #include "chrome/browser/prefs/pref_service_mock_builder.h" 56 #include "chrome/browser/prefs/pref_service_mock_builder.h"
56 #include "chrome/browser/prefs/scoped_user_pref_update.h" 57 #include "chrome/browser/prefs/scoped_user_pref_update.h"
57 #include "chrome/common/chrome_constants.h" 58 #include "chrome/common/chrome_constants.h"
58 #include "chrome/common/chrome_notification_types.h" 59 #include "chrome/common/chrome_notification_types.h"
59 #include "chrome/common/chrome_paths.h" 60 #include "chrome/common/chrome_paths.h"
60 #include "chrome/common/chrome_switches.h" 61 #include "chrome/common/chrome_switches.h"
61 #include "chrome/common/extensions/extension.h" 62 #include "chrome/common/extensions/extension.h"
62 #include "chrome/common/extensions/extension_l10n_util.h" 63 #include "chrome/common/extensions/extension_l10n_util.h"
63 #include "chrome/common/extensions/extension_manifest_constants.h" 64 #include "chrome/common/extensions/extension_manifest_constants.h"
64 #include "chrome/common/extensions/extension_resource.h" 65 #include "chrome/common/extensions/extension_resource.h"
66 #include "chrome/common/extensions/feature_switch.h"
65 #include "chrome/common/extensions/permissions/permission_set.h" 67 #include "chrome/common/extensions/permissions/permission_set.h"
66 #include "chrome/common/extensions/url_pattern.h" 68 #include "chrome/common/extensions/url_pattern.h"
67 #include "chrome/common/pref_names.h" 69 #include "chrome/common/pref_names.h"
68 #include "chrome/common/url_constants.h" 70 #include "chrome/common/url_constants.h"
69 #include "chrome/test/base/testing_profile.h" 71 #include "chrome/test/base/testing_profile.h"
70 #include "content/public/browser/dom_storage_context.h" 72 #include "content/public/browser/dom_storage_context.h"
71 #include "content/public/browser/gpu_data_manager.h" 73 #include "content/public/browser/gpu_data_manager.h"
72 #include "content/public/browser/indexed_db_context.h" 74 #include "content/public/browser/indexed_db_context.h"
73 #include "content/public/browser/notification_registrar.h" 75 #include "content/public/browser/notification_registrar.h"
74 #include "content/public/browser/notification_service.h" 76 #include "content/public/browser/notification_service.h"
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 ExtensionErrorReporter::Init(false); // no noisy errors 508 ExtensionErrorReporter::Init(false); // no noisy errors
507 } 509 }
508 510
509 void ExtensionServiceTestBase::SetUp() { 511 void ExtensionServiceTestBase::SetUp() {
510 ExtensionErrorReporter::GetInstance()->ClearErrors(); 512 ExtensionErrorReporter::GetInstance()->ClearErrors();
511 } 513 }
512 514
513 class ExtensionServiceTest 515 class ExtensionServiceTest
514 : public ExtensionServiceTestBase, public content::NotificationObserver { 516 : public ExtensionServiceTestBase, public content::NotificationObserver {
515 public: 517 public:
516 ExtensionServiceTest() : installed_(NULL) { 518 ExtensionServiceTest()
519 : installed_(NULL),
520 override_external_install_prompt_(
521 extensions::FeatureSwitch::prompt_for_external_extensions(),
522 false) {
517 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, 523 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED,
518 content::NotificationService::AllSources()); 524 content::NotificationService::AllSources());
519 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, 525 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED,
520 content::NotificationService::AllSources()); 526 content::NotificationService::AllSources());
521 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALLED, 527 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALLED,
522 content::NotificationService::AllSources()); 528 content::NotificationService::AllSources());
523 } 529 }
524 530
525 virtual void Observe(int type, 531 virtual void Observe(int type,
526 const content::NotificationSource& source, 532 const content::NotificationSource& source,
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after
994 iter != value.end(); ++iter) 1000 iter != value.end(); ++iter)
995 list_value->Append(Value::CreateStringValue(*iter)); 1001 list_value->Append(Value::CreateStringValue(*iter));
996 1002
997 SetPref(extension_id, pref_path, list_value, msg); 1003 SetPref(extension_id, pref_path, list_value, msg);
998 } 1004 }
999 1005
1000 protected: 1006 protected:
1001 extensions::ExtensionList loaded_; 1007 extensions::ExtensionList loaded_;
1002 std::string unloaded_id_; 1008 std::string unloaded_id_;
1003 const Extension* installed_; 1009 const Extension* installed_;
1010 extensions::FeatureSwitch::ScopedOverride override_external_install_prompt_;
1004 1011
1005 private: 1012 private:
1006 content::NotificationRegistrar registrar_; 1013 content::NotificationRegistrar registrar_;
1007 }; 1014 };
1008 1015
1009 // Receives notifications from a PackExtensionJob, indicating either that 1016 // Receives notifications from a PackExtensionJob, indicating either that
1010 // packing succeeded or that there was some error. 1017 // packing succeeded or that there was some error.
1011 class PackExtensionTestClient : public extensions::PackExtensionJob::Client { 1018 class PackExtensionTestClient : public extensions::PackExtensionJob::Client {
1012 public: 1019 public:
1013 PackExtensionTestClient(const FilePath& expected_crx_path, 1020 PackExtensionTestClient(const FilePath& expected_crx_path,
(...skipping 4537 matching lines...) Expand 10 before | Expand all | Expand 10 after
5551 5558
5552 // Wait for the external source to install. 5559 // Wait for the external source to install.
5553 WaitForCrxInstall(crx_path_, INSTALL_NEW); 5560 WaitForCrxInstall(crx_path_, INSTALL_NEW);
5554 ASSERT_TRUE(IsCrxInstalled()); 5561 ASSERT_TRUE(IsCrxInstalled());
5555 5562
5556 // Now that the extension is installed, sync request should fail 5563 // Now that the extension is installed, sync request should fail
5557 // because the extension is already installed. 5564 // because the extension is already installed.
5558 ASSERT_FALSE(AddPendingSyncInstall()); 5565 ASSERT_FALSE(AddPendingSyncInstall());
5559 } 5566 }
5560 5567
5561 TEST_F(ExtensionServiceTest, AlertableExtensionHappyPath) { 5568 #if !defined(OS_CHROMEOS)
5569 // Test that installing an external extension displays a GlobalError.
5570 TEST_F(ExtensionServiceTest, ExternalInstallGlobalError) {
5571 extensions::FeatureSwitch::ScopedOverride prompt(
5572 extensions::FeatureSwitch::prompt_for_external_extensions(), true);
5573
5562 InitializeEmptyExtensionService(); 5574 InitializeEmptyExtensionService();
5563 scoped_ptr<ExtensionErrorUI> extension_error_ui(
5564 ExtensionErrorUI::Create(service_));
5565 MockExtensionProvider* provider = 5575 MockExtensionProvider* provider =
5566 new MockExtensionProvider(service_, Extension::EXTERNAL_PREF); 5576 new MockExtensionProvider(service_, Extension::EXTERNAL_PREF);
5567 AddMockExternalProvider(provider); 5577 AddMockExternalProvider(provider);
5568 5578
5579 service_->UpdateExternalExtensionAlert();
5569 // Should return false, meaning there aren't any extensions that the user 5580 // Should return false, meaning there aren't any extensions that the user
5570 // needs to know about. 5581 // needs to know about.
5571 ASSERT_FALSE(service_->PopulateExtensionErrorUI(extension_error_ui.get())); 5582 EXPECT_FALSE(extensions::HasExternalInstallError(service_));
5572 5583
5573 // This is a normal extension, installed normally. 5584 // This is a normal extension, installed normally.
5574 // This should NOT trigger an alert. 5585 // This should NOT trigger an alert.
5575 set_extensions_enabled(true); 5586 set_extensions_enabled(true);
5576 FilePath path = data_dir_.AppendASCII("good.crx"); 5587 FilePath path = data_dir_.AppendASCII("good.crx");
5577 InstallCRX(path, INSTALL_NEW); 5588 InstallCRX(path, INSTALL_NEW);
5578 5589
5579 // Another normal extension, but installed externally. 5590 service_->CheckForExternalUpdates();
5580 // This SHOULD trigger an alert. 5591 loop_.RunAllPending();
5581 provider->UpdateOrAddExtension(page_action, "1.0.0.0", 5592 EXPECT_FALSE(extensions::HasExternalInstallError(service_));
5582 data_dir_.AppendASCII("page_action.crx"));
5583 5593
5584 // A hosted app, installed externally. 5594 // A hosted app, installed externally.
5585 // This should NOT trigger an alert. 5595 // This should NOT trigger an alert.
5586 provider->UpdateOrAddExtension(hosted_app, "1.0.0.0", 5596 provider->UpdateOrAddExtension(hosted_app, "1.0.0.0",
5587 data_dir_.AppendASCII("hosted_app.crx")); 5597 data_dir_.AppendASCII("hosted_app.crx"));
5588 5598
5589 service_->CheckForExternalUpdates(); 5599 service_->CheckForExternalUpdates();
5590 loop_.RunAllPending(); 5600 loop_.RunAllPending();
5601 EXPECT_FALSE(extensions::HasExternalInstallError(service_));
5591 5602
5592 ASSERT_TRUE(service_->PopulateExtensionErrorUI(extension_error_ui.get())); 5603 // Another normal extension, but installed externally.
5593 ASSERT_EQ(1u, extension_error_ui->get_external_extension_ids()->size()); 5604 // This SHOULD trigger an alert.
5605 provider->UpdateOrAddExtension(page_action, "1.0.0.0",
5606 data_dir_.AppendASCII("page_action.crx"));
5607
5608 service_->CheckForExternalUpdates();
5609 loop_.RunAllPending();
5610 EXPECT_TRUE(extensions::HasExternalInstallError(service_));
5594 } 5611 }
5612
5613 // Test that external extensions are initially disabled, and that enabling
5614 // them clears the prompt.
5615 TEST_F(ExtensionServiceTest, ExternalInstallInitiallyDisabled) {
5616 extensions::FeatureSwitch::ScopedOverride prompt(
5617 extensions::FeatureSwitch::prompt_for_external_extensions(), true);
5618
5619 InitializeEmptyExtensionService();
5620 MockExtensionProvider* provider =
5621 new MockExtensionProvider(service_, Extension::EXTERNAL_PREF);
5622 AddMockExternalProvider(provider);
5623
5624 provider->UpdateOrAddExtension(page_action, "1.0.0.0",
5625 data_dir_.AppendASCII("page_action.crx"));
5626
5627 service_->CheckForExternalUpdates();
5628 loop_.RunAllPending();
5629 EXPECT_TRUE(extensions::HasExternalInstallError(service_));
5630 EXPECT_FALSE(service_->IsExtensionEnabled(page_action));
5631
5632 const Extension* extension =
5633 service_->disabled_extensions()->GetByID(page_action);
5634 EXPECT_TRUE(extension);
5635 EXPECT_EQ(page_action, extension->id());
5636
5637 service_->EnableExtension(page_action);
5638 EXPECT_FALSE(extensions::HasExternalInstallError(service_));
5639 EXPECT_TRUE(service_->IsExtensionEnabled(page_action));
5640 }
5641
5642 // Test that installing multiple external extensions works.
5643 TEST_F(ExtensionServiceTest, ExternalInstallMultiple) {
5644 extensions::FeatureSwitch::ScopedOverride prompt(
5645 extensions::FeatureSwitch::prompt_for_external_extensions(), true);
5646
5647 InitializeEmptyExtensionService();
5648 MockExtensionProvider* provider =
5649 new MockExtensionProvider(service_, Extension::EXTERNAL_PREF);
5650 AddMockExternalProvider(provider);
5651
5652 provider->UpdateOrAddExtension(page_action, "1.0.0.0",
5653 data_dir_.AppendASCII("page_action.crx"));
5654 provider->UpdateOrAddExtension(good_crx, "1.0.0.0",
5655 data_dir_.AppendASCII("good.crx"));
5656 provider->UpdateOrAddExtension(theme_crx, "2.0",
5657 data_dir_.AppendASCII("theme.crx"));
5658
5659 service_->CheckForExternalUpdates();
5660 loop_.RunAllPending();
5661 EXPECT_TRUE(extensions::HasExternalInstallError(service_));
5662 EXPECT_FALSE(service_->IsExtensionEnabled(page_action));
5663 EXPECT_FALSE(service_->IsExtensionEnabled(good_crx));
5664 EXPECT_FALSE(service_->IsExtensionEnabled(theme_crx));
5665
5666 service_->EnableExtension(page_action);
5667 EXPECT_TRUE(extensions::HasExternalInstallError(service_));
5668 service_->EnableExtension(theme_crx);
5669 EXPECT_TRUE(extensions::HasExternalInstallError(service_));
5670 service_->EnableExtension(good_crx);
5671 EXPECT_FALSE(extensions::HasExternalInstallError(service_));
5672 }
5673 #endif // !defined(OS_CHROMEOS)
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_service.cc ('k') | chrome/browser/extensions/external_install_ui.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698