[email protected] | 1e6e8954 | 2013-03-30 17:08:53 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
avi | a2f4804a | 2015-12-24 23:11:13 | [diff] [blame] | 5 | #include <stddef.h> |
| 6 | |
| 7 | #include "build/build_config.h" |
[email protected] | 1e6e8954 | 2013-03-30 17:08:53 | [diff] [blame] | 8 | #include "chrome/browser/extensions/crx_installer.h" |
| 9 | #include "chrome/browser/extensions/extension_browsertest.h" |
| 10 | #include "chrome/browser/extensions/extension_service.h" |
[email protected] | a7ff4b7 | 2013-10-17 20:56:02 | [diff] [blame] | 11 | #include "chrome/browser/extensions/extension_util.h" |
[email protected] | 1e6e8954 | 2013-03-30 17:08:53 | [diff] [blame] | 12 | #include "chrome/browser/profiles/profile.h" |
| 13 | #include "chrome/browser/ui/browser_commands.h" |
[email protected] | 5a0613d3 | 2013-06-17 20:06:53 | [diff] [blame] | 14 | #include "content/public/browser/notification_service.h" |
thestig | af7f415 | 2014-10-31 23:19:15 | [diff] [blame] | 15 | #include "content/public/test/test_utils.h" |
reillyg | a3acbc1 | 2014-11-11 23:17:12 | [diff] [blame] | 16 | #include "extensions/browser/extension_registry.h" |
[email protected] | 03d2581 | 2014-06-22 19:41:55 | [diff] [blame] | 17 | #include "extensions/browser/extension_system.h" |
karandeepb | 810e3340 | 2017-04-05 23:41:22 | [diff] [blame] | 18 | #include "extensions/browser/extension_util.h" |
[email protected] | adf5a10 | 2014-07-31 12:44:06 | [diff] [blame] | 19 | #include "extensions/browser/notification_types.h" |
sooho1000 | 5109c32 | 2015-11-09 00:38:21 | [diff] [blame] | 20 | #include "extensions/browser/test_extension_registry_observer.h" |
[email protected] | 1e6e8954 | 2013-03-30 17:08:53 | [diff] [blame] | 21 | |
| 22 | namespace extensions { |
| 23 | |
| 24 | class ExtensionFunctionalTest : public ExtensionBrowserTest { |
[email protected] | 03d2581 | 2014-06-22 19:41:55 | [diff] [blame] | 25 | public: |
[email protected] | 1e6e8954 | 2013-03-30 17:08:53 | [diff] [blame] | 26 | void InstallExtensionSilently(ExtensionService* service, |
| 27 | const char* filename) { |
reillyg | a3acbc1 | 2014-11-11 23:17:12 | [diff] [blame] | 28 | ExtensionRegistry* registry = ExtensionRegistry::Get(profile()); |
| 29 | size_t num_before = registry->enabled_extensions().size(); |
[email protected] | 1e6e8954 | 2013-03-30 17:08:53 | [diff] [blame] | 30 | |
| 31 | base::FilePath path = test_data_dir_.AppendASCII(filename); |
| 32 | |
thestig | 199d81f2 | 2016-07-02 02:03:18 | [diff] [blame] | 33 | TestExtensionRegistryObserver extension_observer(registry); |
[email protected] | 1e6e8954 | 2013-03-30 17:08:53 | [diff] [blame] | 34 | |
thestig | 199d81f2 | 2016-07-02 02:03:18 | [diff] [blame] | 35 | scoped_refptr<CrxInstaller> installer(CrxInstaller::CreateSilent(service)); |
[email protected] | 1e6e8954 | 2013-03-30 17:08:53 | [diff] [blame] | 36 | installer->set_is_gallery_install(false); |
| 37 | installer->set_allow_silent_install(true); |
| 38 | installer->set_install_source(Manifest::INTERNAL); |
| 39 | installer->set_off_store_install_allow_reason( |
thestig | 199d81f2 | 2016-07-02 02:03:18 | [diff] [blame] | 40 | CrxInstaller::OffStoreInstallAllowedInTest); |
[email protected] | 1e6e8954 | 2013-03-30 17:08:53 | [diff] [blame] | 41 | |
thestig | 199d81f2 | 2016-07-02 02:03:18 | [diff] [blame] | 42 | observer_->Watch(NOTIFICATION_CRX_INSTALLER_DONE, |
| 43 | content::Source<CrxInstaller>(installer.get())); |
[email protected] | 1e6e8954 | 2013-03-30 17:08:53 | [diff] [blame] | 44 | |
| 45 | installer->InstallCrx(path); |
[email protected] | 918c271 | 2013-10-21 23:59:56 | [diff] [blame] | 46 | observer_->Wait(); |
[email protected] | 1e6e8954 | 2013-03-30 17:08:53 | [diff] [blame] | 47 | |
reillyg | a3acbc1 | 2014-11-11 23:17:12 | [diff] [blame] | 48 | size_t num_after = registry->enabled_extensions().size(); |
[email protected] | 1e6e8954 | 2013-03-30 17:08:53 | [diff] [blame] | 49 | EXPECT_EQ(num_before + 1, num_after); |
| 50 | |
sooho1000 | 5109c32 | 2015-11-09 00:38:21 | [diff] [blame] | 51 | extension_observer.WaitForExtensionLoaded(); |
reillyg | a3acbc1 | 2014-11-11 23:17:12 | [diff] [blame] | 52 | const Extension* extension = |
| 53 | registry->enabled_extensions().GetByID(last_loaded_extension_id()); |
| 54 | EXPECT_TRUE(extension); |
[email protected] | 03d2581 | 2014-06-22 19:41:55 | [diff] [blame] | 55 | } |
[email protected] | 1e6e8954 | 2013-03-30 17:08:53 | [diff] [blame] | 56 | }; |
| 57 | |
[email protected] | 9289dc9 | 2013-08-07 05:39:55 | [diff] [blame] | 58 | IN_PROC_BROWSER_TEST_F(ExtensionFunctionalTest, |
| 59 | PRE_TestAdblockExtensionCrash) { |
reillyg | a3acbc1 | 2014-11-11 23:17:12 | [diff] [blame] | 60 | InstallExtensionSilently(extension_service(), "adblock.crx"); |
[email protected] | 9289dc9 | 2013-08-07 05:39:55 | [diff] [blame] | 61 | } |
[email protected] | 1e6e8954 | 2013-03-30 17:08:53 | [diff] [blame] | 62 | |
[email protected] | e888529 | 2014-06-24 09:04:07 | [diff] [blame] | 63 | // Timing out on XP and Vista: http://crbug.com/387866 |
| 64 | #if defined(OS_WIN) |
| 65 | #define MAYBE_TestAdblockExtensionCrash DISABLED_TestAdblockExtensionCrash |
| 66 | #else |
| 67 | #define MAYBE_TestAdblockExtensionCrash TestAdblockExtensionCrash |
| 68 | #endif |
| 69 | IN_PROC_BROWSER_TEST_F(ExtensionFunctionalTest, |
| 70 | MAYBE_TestAdblockExtensionCrash) { |
reillyg | a3acbc1 | 2014-11-11 23:17:12 | [diff] [blame] | 71 | ExtensionService* service = extension_service(); |
[email protected] | 1e6e8954 | 2013-03-30 17:08:53 | [diff] [blame] | 72 | // Verify that the extension is enabled and allowed in incognito |
| 73 | // is disabled. |
[email protected] | 918c271 | 2013-10-21 23:59:56 | [diff] [blame] | 74 | EXPECT_TRUE(service->IsExtensionEnabled(last_loaded_extension_id())); |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 75 | EXPECT_FALSE(util::IsIncognitoEnabled(last_loaded_extension_id(), profile())); |
[email protected] | 1e6e8954 | 2013-03-30 17:08:53 | [diff] [blame] | 76 | } |
| 77 | |
loyso | 2d28ada | 2016-10-12 02:32:46 | [diff] [blame] | 78 | // Failing on Linux: http://crbug.com/654945 |
| 79 | #if defined(OS_LINUX) |
| 80 | #define MAYBE_TestSetExtensionsState DISABLED_TestSetExtensionsState |
| 81 | #else |
| 82 | #define MAYBE_TestSetExtensionsState TestSetExtensionsState |
| 83 | #endif |
| 84 | IN_PROC_BROWSER_TEST_F(ExtensionFunctionalTest, MAYBE_TestSetExtensionsState) { |
reillyg | a3acbc1 | 2014-11-11 23:17:12 | [diff] [blame] | 85 | InstallExtensionSilently(extension_service(), "google_talk.crx"); |
[email protected] | 1e6e8954 | 2013-03-30 17:08:53 | [diff] [blame] | 86 | |
| 87 | // Disable the extension and verify. |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 88 | util::SetIsIncognitoEnabled(last_loaded_extension_id(), profile(), false); |
reillyg | a3acbc1 | 2014-11-11 23:17:12 | [diff] [blame] | 89 | ExtensionService* service = extension_service(); |
[email protected] | 918c271 | 2013-10-21 23:59:56 | [diff] [blame] | 90 | service->DisableExtension(last_loaded_extension_id(), |
Minh X. Nguyen | 4547901 | 2017-08-18 21:35:36 | [diff] [blame] | 91 | disable_reason::DISABLE_USER_ACTION); |
[email protected] | 918c271 | 2013-10-21 23:59:56 | [diff] [blame] | 92 | EXPECT_FALSE(service->IsExtensionEnabled(last_loaded_extension_id())); |
[email protected] | 1e6e8954 | 2013-03-30 17:08:53 | [diff] [blame] | 93 | |
| 94 | // Enable the extension and verify. |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 95 | util::SetIsIncognitoEnabled(last_loaded_extension_id(), profile(), false); |
[email protected] | 918c271 | 2013-10-21 23:59:56 | [diff] [blame] | 96 | service->EnableExtension(last_loaded_extension_id()); |
| 97 | EXPECT_TRUE(service->IsExtensionEnabled(last_loaded_extension_id())); |
[email protected] | 1e6e8954 | 2013-03-30 17:08:53 | [diff] [blame] | 98 | |
| 99 | // Allow extension in incognito mode and verify. |
[email protected] | 918c271 | 2013-10-21 23:59:56 | [diff] [blame] | 100 | service->EnableExtension(last_loaded_extension_id()); |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 101 | util::SetIsIncognitoEnabled(last_loaded_extension_id(), profile(), true); |
| 102 | EXPECT_TRUE(util::IsIncognitoEnabled(last_loaded_extension_id(), profile())); |
[email protected] | 1e6e8954 | 2013-03-30 17:08:53 | [diff] [blame] | 103 | |
| 104 | // Disallow extension in incognito mode and verify. |
[email protected] | 918c271 | 2013-10-21 23:59:56 | [diff] [blame] | 105 | service->EnableExtension(last_loaded_extension_id()); |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 106 | util::SetIsIncognitoEnabled(last_loaded_extension_id(), profile(), false); |
| 107 | EXPECT_FALSE(util::IsIncognitoEnabled(last_loaded_extension_id(), profile())); |
[email protected] | 1e6e8954 | 2013-03-30 17:08:53 | [diff] [blame] | 108 | } |
thestig | 199d81f2 | 2016-07-02 02:03:18 | [diff] [blame] | 109 | |
[email protected] | 1e6e8954 | 2013-03-30 17:08:53 | [diff] [blame] | 110 | } // namespace extensions |