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