[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] | 43eb00a5 | 2013-10-02 23:22:28 | [diff] [blame] | 38 | content::WindowedNotificationObserver observer( |
| 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 | content::NotificationRegistrar registrar; |
| 42 | registrar.Add(this, chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 43 | content::Source<extensions::CrxInstaller>(installer.get())); |
| 44 | |
| 45 | installer->InstallCrx(path); |
[email protected] | 43eb00a5 | 2013-10-02 23:22:28 | [diff] [blame] | 46 | observer.Wait(); |
[email protected] | 1e6e8954 | 2013-03-30 17:08:53 | [diff] [blame] | 47 | |
| 48 | size_t num_after = service->extensions()->size(); |
| 49 | EXPECT_EQ(num_before + 1, num_after); |
| 50 | |
| 51 | extension_loaded_observer.Wait(); |
| 52 | const Extension* extension = service->GetExtensionById( |
| 53 | last_loaded_extension_id_, false); |
| 54 | EXPECT_TRUE(extension != NULL); |
| 55 | } |
| 56 | }; |
| 57 | |
[email protected] | 9289dc9 | 2013-08-07 05:39:55 | [diff] [blame] | 58 | IN_PROC_BROWSER_TEST_F(ExtensionFunctionalTest, |
| 59 | PRE_TestAdblockExtensionCrash) { |
[email protected] | 1e6e8954 | 2013-03-30 17:08:53 | [diff] [blame] | 60 | ExtensionService* service = profile()->GetExtensionService(); |
| 61 | InstallExtensionSilently(service, "adblock.crx"); |
[email protected] | 9289dc9 | 2013-08-07 05:39:55 | [diff] [blame] | 62 | } |
[email protected] | 1e6e8954 | 2013-03-30 17:08:53 | [diff] [blame] | 63 | |
[email protected] | 9289dc9 | 2013-08-07 05:39:55 | [diff] [blame] | 64 | IN_PROC_BROWSER_TEST_F(ExtensionFunctionalTest, TestAdblockExtensionCrash) { |
| 65 | ExtensionService* service = profile()->GetExtensionService(); |
[email protected] | 1e6e8954 | 2013-03-30 17:08:53 | [diff] [blame] | 66 | // Verify that the extension is enabled and allowed in incognito |
| 67 | // is disabled. |
| 68 | EXPECT_TRUE(service->IsExtensionEnabled(last_loaded_extension_id_)); |
[email protected] | a7ff4b7 | 2013-10-17 20:56:02 | [diff] [blame^] | 69 | EXPECT_FALSE(extension_util::IsIncognitoEnabled(last_loaded_extension_id_, |
| 70 | service)); |
[email protected] | 1e6e8954 | 2013-03-30 17:08:53 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | IN_PROC_BROWSER_TEST_F(ExtensionFunctionalTest, TestSetExtensionsState) { |
| 74 | ExtensionService* service = profile()->GetExtensionService(); |
| 75 | InstallExtensionSilently(service, "google_talk.crx"); |
| 76 | |
| 77 | // Disable the extension and verify. |
[email protected] | a7ff4b7 | 2013-10-17 20:56:02 | [diff] [blame^] | 78 | extension_util::SetIsIncognitoEnabled( |
| 79 | last_loaded_extension_id_, service, false); |
[email protected] | 1e6e8954 | 2013-03-30 17:08:53 | [diff] [blame] | 80 | service->DisableExtension(last_loaded_extension_id_, |
| 81 | Extension::DISABLE_USER_ACTION); |
| 82 | EXPECT_FALSE(service->IsExtensionEnabled(last_loaded_extension_id_)); |
| 83 | |
| 84 | // Enable the extension and verify. |
[email protected] | a7ff4b7 | 2013-10-17 20:56:02 | [diff] [blame^] | 85 | extension_util::SetIsIncognitoEnabled( |
| 86 | last_loaded_extension_id_, service, false); |
[email protected] | 1e6e8954 | 2013-03-30 17:08:53 | [diff] [blame] | 87 | service->EnableExtension(last_loaded_extension_id_); |
| 88 | EXPECT_TRUE(service->IsExtensionEnabled(last_loaded_extension_id_)); |
| 89 | |
| 90 | // Allow extension in incognito mode and verify. |
| 91 | service->EnableExtension(last_loaded_extension_id_); |
[email protected] | a7ff4b7 | 2013-10-17 20:56:02 | [diff] [blame^] | 92 | extension_util::SetIsIncognitoEnabled( |
| 93 | last_loaded_extension_id_, service, true); |
| 94 | EXPECT_TRUE(extension_util::IsIncognitoEnabled(last_loaded_extension_id_, |
| 95 | service)); |
[email protected] | 1e6e8954 | 2013-03-30 17:08:53 | [diff] [blame] | 96 | |
| 97 | // Disallow extension in incognito mode and verify. |
| 98 | service->EnableExtension(last_loaded_extension_id_); |
[email protected] | a7ff4b7 | 2013-10-17 20:56:02 | [diff] [blame^] | 99 | extension_util::SetIsIncognitoEnabled( |
| 100 | last_loaded_extension_id_, service, false); |
| 101 | EXPECT_FALSE(extension_util::IsIncognitoEnabled(last_loaded_extension_id_, |
| 102 | service)); |
[email protected] | 1e6e8954 | 2013-03-30 17:08:53 | [diff] [blame] | 103 | } |
| 104 | } // namespace extensions |