OLD | NEW |
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 Loading... |
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 Loading... |
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::external_extension_prompt(), false) { |
517 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, | 522 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
518 content::NotificationService::AllSources()); | 523 content::NotificationService::AllSources()); |
519 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | 524 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
520 content::NotificationService::AllSources()); | 525 content::NotificationService::AllSources()); |
521 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALLED, | 526 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALLED, |
522 content::NotificationService::AllSources()); | 527 content::NotificationService::AllSources()); |
523 } | 528 } |
524 | 529 |
525 virtual void Observe(int type, | 530 virtual void Observe(int type, |
526 const content::NotificationSource& source, | 531 const content::NotificationSource& source, |
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
994 iter != value.end(); ++iter) | 999 iter != value.end(); ++iter) |
995 list_value->Append(Value::CreateStringValue(*iter)); | 1000 list_value->Append(Value::CreateStringValue(*iter)); |
996 | 1001 |
997 SetPref(extension_id, pref_path, list_value, msg); | 1002 SetPref(extension_id, pref_path, list_value, msg); |
998 } | 1003 } |
999 | 1004 |
1000 protected: | 1005 protected: |
1001 extensions::ExtensionList loaded_; | 1006 extensions::ExtensionList loaded_; |
1002 std::string unloaded_id_; | 1007 std::string unloaded_id_; |
1003 const Extension* installed_; | 1008 const Extension* installed_; |
| 1009 extensions::FeatureSwitch::ScopedOverride override_external_install_prompt_; |
1004 | 1010 |
1005 private: | 1011 private: |
1006 content::NotificationRegistrar registrar_; | 1012 content::NotificationRegistrar registrar_; |
1007 }; | 1013 }; |
1008 | 1014 |
1009 // Receives notifications from a PackExtensionJob, indicating either that | 1015 // Receives notifications from a PackExtensionJob, indicating either that |
1010 // packing succeeded or that there was some error. | 1016 // packing succeeded or that there was some error. |
1011 class PackExtensionTestClient : public extensions::PackExtensionJob::Client { | 1017 class PackExtensionTestClient : public extensions::PackExtensionJob::Client { |
1012 public: | 1018 public: |
1013 PackExtensionTestClient(const FilePath& expected_crx_path, | 1019 PackExtensionTestClient(const FilePath& expected_crx_path, |
(...skipping 4537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5551 | 5557 |
5552 // Wait for the external source to install. | 5558 // Wait for the external source to install. |
5553 WaitForCrxInstall(crx_path_, INSTALL_NEW); | 5559 WaitForCrxInstall(crx_path_, INSTALL_NEW); |
5554 ASSERT_TRUE(IsCrxInstalled()); | 5560 ASSERT_TRUE(IsCrxInstalled()); |
5555 | 5561 |
5556 // Now that the extension is installed, sync request should fail | 5562 // Now that the extension is installed, sync request should fail |
5557 // because the extension is already installed. | 5563 // because the extension is already installed. |
5558 ASSERT_FALSE(AddPendingSyncInstall()); | 5564 ASSERT_FALSE(AddPendingSyncInstall()); |
5559 } | 5565 } |
5560 | 5566 |
5561 TEST_F(ExtensionServiceTest, AlertableExtensionHappyPath) { | 5567 // Test that installing an external extension displays a GlobalError. |
| 5568 TEST_F(ExtensionServiceTest, ExternalInstallGlobalError) { |
| 5569 extensions::FeatureSwitch::ScopedOverride prompt( |
| 5570 extensions::FeatureSwitch::external_extension_prompt(), true); |
| 5571 |
5562 InitializeEmptyExtensionService(); | 5572 InitializeEmptyExtensionService(); |
5563 scoped_ptr<ExtensionErrorUI> extension_error_ui( | |
5564 ExtensionErrorUI::Create(service_)); | |
5565 MockExtensionProvider* provider = | 5573 MockExtensionProvider* provider = |
5566 new MockExtensionProvider(service_, Extension::EXTERNAL_PREF); | 5574 new MockExtensionProvider(service_, Extension::EXTERNAL_PREF); |
5567 AddMockExternalProvider(provider); | 5575 AddMockExternalProvider(provider); |
5568 | 5576 |
5569 // Should return false, meaning there aren't any extensions that the user | 5577 // Should return false, meaning there aren't any extensions that the user |
5570 // needs to know about. | 5578 // needs to know about. |
5571 ASSERT_FALSE(service_->PopulateExtensionErrorUI(extension_error_ui.get())); | 5579 service_->UpdateExternalExtensionAlert(); |
| 5580 EXPECT_FALSE(extensions::HasExternalInstallError(service_)); |
5572 | 5581 |
5573 // This is a normal extension, installed normally. | 5582 // This is a normal extension, installed normally. |
5574 // This should NOT trigger an alert. | 5583 // This should NOT trigger an alert. |
5575 set_extensions_enabled(true); | 5584 set_extensions_enabled(true); |
5576 FilePath path = data_dir_.AppendASCII("good.crx"); | 5585 FilePath path = data_dir_.AppendASCII("good.crx"); |
5577 InstallCRX(path, INSTALL_NEW); | 5586 InstallCRX(path, INSTALL_NEW); |
5578 | 5587 |
5579 // Another normal extension, but installed externally. | 5588 service_->CheckForExternalUpdates(); |
5580 // This SHOULD trigger an alert. | 5589 loop_.RunAllPending(); |
5581 provider->UpdateOrAddExtension(page_action, "1.0.0.0", | 5590 EXPECT_FALSE(extensions::HasExternalInstallError(service_)); |
5582 data_dir_.AppendASCII("page_action.crx")); | |
5583 | 5591 |
5584 // A hosted app, installed externally. | 5592 // A hosted app, installed externally. |
5585 // This should NOT trigger an alert. | 5593 // This should NOT trigger an alert. |
5586 provider->UpdateOrAddExtension(hosted_app, "1.0.0.0", | 5594 provider->UpdateOrAddExtension(hosted_app, "1.0.0.0", |
5587 data_dir_.AppendASCII("hosted_app.crx")); | 5595 data_dir_.AppendASCII("hosted_app.crx")); |
5588 | 5596 |
5589 service_->CheckForExternalUpdates(); | 5597 service_->CheckForExternalUpdates(); |
5590 loop_.RunAllPending(); | 5598 loop_.RunAllPending(); |
| 5599 EXPECT_FALSE(extensions::HasExternalInstallError(service_)); |
5591 | 5600 |
5592 ASSERT_TRUE(service_->PopulateExtensionErrorUI(extension_error_ui.get())); | 5601 // Another normal extension, but installed externally. |
5593 ASSERT_EQ(1u, extension_error_ui->get_external_extension_ids()->size()); | 5602 // This SHOULD trigger an alert. |
| 5603 provider->UpdateOrAddExtension(page_action, "1.0.0.0", |
| 5604 data_dir_.AppendASCII("page_action.crx")); |
| 5605 |
| 5606 service_->CheckForExternalUpdates(); |
| 5607 loop_.RunAllPending(); |
| 5608 EXPECT_TRUE(extensions::HasExternalInstallError(service_)); |
5594 } | 5609 } |
| 5610 |
| 5611 // Test that external extensions are initially disabled, and that enabling |
| 5612 // them clears the prompt. |
| 5613 TEST_F(ExtensionServiceTest, ExternalInstallInitiallyDisabled) { |
| 5614 extensions::FeatureSwitch::ScopedOverride prompt( |
| 5615 extensions::FeatureSwitch::external_extension_prompt(), true); |
| 5616 |
| 5617 InitializeEmptyExtensionService(); |
| 5618 MockExtensionProvider* provider = |
| 5619 new MockExtensionProvider(service_, Extension::EXTERNAL_PREF); |
| 5620 AddMockExternalProvider(provider); |
| 5621 |
| 5622 provider->UpdateOrAddExtension(page_action, "1.0.0.0", |
| 5623 data_dir_.AppendASCII("page_action.crx")); |
| 5624 |
| 5625 service_->CheckForExternalUpdates(); |
| 5626 loop_.RunAllPending(); |
| 5627 EXPECT_TRUE(extensions::HasExternalInstallError(service_)); |
| 5628 EXPECT_FALSE(service_->IsExtensionEnabled(page_action)); |
| 5629 |
| 5630 const Extension* extension = |
| 5631 service_->disabled_extensions()->GetByID(page_action); |
| 5632 EXPECT_TRUE(extension); |
| 5633 EXPECT_EQ(page_action, extension->id()); |
| 5634 |
| 5635 service_->EnableExtension(page_action); |
| 5636 EXPECT_FALSE(extensions::HasExternalInstallError(service_)); |
| 5637 EXPECT_TRUE(service_->IsExtensionEnabled(page_action)); |
| 5638 } |
OLD | NEW |