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