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