blob: 079b63818cddbd596583fab6886c6c7c1bd8aa94 [file] [log] [blame]
[email protected]1e6e89542013-03-30 17:08:531// 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]1e6e89542013-03-30 17:08:535#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]a7ff4b72013-10-17 20:56:028#include "chrome/browser/extensions/extension_util.h"
[email protected]1e6e89542013-03-30 17:08:539#include "chrome/browser/profiles/profile.h"
10#include "chrome/browser/ui/browser_commands.h"
[email protected]5a0613d32013-06-17 20:06:5311#include "content/public/browser/notification_service.h"
thestigaf7f4152014-10-31 23:19:1512#include "content/public/test/test_utils.h"
[email protected]03d25812014-06-22 19:41:5513#include "extensions/browser/extension_system.h"
[email protected]adf5a102014-07-31 12:44:0614#include "extensions/browser/notification_types.h"
[email protected]1e6e89542013-03-30 17:08:5315
16namespace extensions {
17
18class ExtensionFunctionalTest : public ExtensionBrowserTest {
[email protected]03d25812014-06-22 19:41:5519 public:
[email protected]1e6e89542013-03-30 17:08:5320 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]adf5a102014-07-31 12:44:0628 extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED,
[email protected]1e6e89542013-03-30 17:08:5329 content::NotificationService::AllSources());
30
31 scoped_refptr<extensions::CrxInstaller> installer(
[email protected]f8636f92013-08-09 21:02:3732 extensions::CrxInstaller::CreateSilent(service));
[email protected]1e6e89542013-03-30 17:08:5333 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]918c2712013-10-21 23:59:5639 observer_->Watch(
[email protected]adf5a102014-07-31 12:44:0640 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
[email protected]43eb00a52013-10-02 23:22:2841 content::Source<extensions::CrxInstaller>(installer.get()));
[email protected]1e6e89542013-03-30 17:08:5342
43 installer->InstallCrx(path);
[email protected]918c2712013-10-21 23:59:5644 observer_->Wait();
[email protected]1e6e89542013-03-30 17:08:5345
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]918c2712013-10-21 23:59:5651 last_loaded_extension_id(), false);
[email protected]1e6e89542013-03-30 17:08:5352 EXPECT_TRUE(extension != NULL);
53 }
[email protected]03d25812014-06-22 19:41:5554
55 ExtensionService* GetExtensionService() {
56 return ExtensionSystem::Get(profile())->extension_service();
57 }
[email protected]1e6e89542013-03-30 17:08:5358};
59
[email protected]9289dc92013-08-07 05:39:5560IN_PROC_BROWSER_TEST_F(ExtensionFunctionalTest,
61 PRE_TestAdblockExtensionCrash) {
[email protected]3c175952014-06-24 21:57:4062 InstallExtensionSilently(GetExtensionService(), "adblock.crx");
[email protected]9289dc92013-08-07 05:39:5563}
[email protected]1e6e89542013-03-30 17:08:5364
[email protected]e8885292014-06-24 09:04:0765// 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
71IN_PROC_BROWSER_TEST_F(ExtensionFunctionalTest,
72 MAYBE_TestAdblockExtensionCrash) {
[email protected]03d25812014-06-22 19:41:5573 ExtensionService* service = GetExtensionService();
[email protected]1e6e89542013-03-30 17:08:5374 // Verify that the extension is enabled and allowed in incognito
75 // is disabled.
[email protected]918c2712013-10-21 23:59:5676 EXPECT_TRUE(service->IsExtensionEnabled(last_loaded_extension_id()));
[email protected]1d5cf4142014-01-24 18:25:2277 EXPECT_FALSE(util::IsIncognitoEnabled(last_loaded_extension_id(), profile()));
[email protected]1e6e89542013-03-30 17:08:5378}
79
[email protected]cb723f42014-06-27 14:30:2980// 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
86IN_PROC_BROWSER_TEST_F(ExtensionFunctionalTest, MAYBE_TestSetExtensionsState) {
[email protected]03d25812014-06-22 19:41:5587 InstallExtensionSilently(GetExtensionService(), "google_talk.crx");
[email protected]1e6e89542013-03-30 17:08:5388
89 // Disable the extension and verify.
[email protected]1d5cf4142014-01-24 18:25:2290 util::SetIsIncognitoEnabled(last_loaded_extension_id(), profile(), false);
[email protected]03d25812014-06-22 19:41:5591 ExtensionService* service = GetExtensionService();
[email protected]918c2712013-10-21 23:59:5692 service->DisableExtension(last_loaded_extension_id(),
[email protected]1e6e89542013-03-30 17:08:5393 Extension::DISABLE_USER_ACTION);
[email protected]918c2712013-10-21 23:59:5694 EXPECT_FALSE(service->IsExtensionEnabled(last_loaded_extension_id()));
[email protected]1e6e89542013-03-30 17:08:5395
96 // Enable the extension and verify.
[email protected]1d5cf4142014-01-24 18:25:2297 util::SetIsIncognitoEnabled(last_loaded_extension_id(), profile(), false);
[email protected]918c2712013-10-21 23:59:5698 service->EnableExtension(last_loaded_extension_id());
99 EXPECT_TRUE(service->IsExtensionEnabled(last_loaded_extension_id()));
[email protected]1e6e89542013-03-30 17:08:53100
101 // Allow extension in incognito mode and verify.
[email protected]918c2712013-10-21 23:59:56102 service->EnableExtension(last_loaded_extension_id());
[email protected]1d5cf4142014-01-24 18:25:22103 util::SetIsIncognitoEnabled(last_loaded_extension_id(), profile(), true);
104 EXPECT_TRUE(util::IsIncognitoEnabled(last_loaded_extension_id(), profile()));
[email protected]1e6e89542013-03-30 17:08:53105
106 // Disallow extension in incognito mode and verify.
[email protected]918c2712013-10-21 23:59:56107 service->EnableExtension(last_loaded_extension_id());
[email protected]1d5cf4142014-01-24 18:25:22108 util::SetIsIncognitoEnabled(last_loaded_extension_id(), profile(), false);
109 EXPECT_FALSE(util::IsIncognitoEnabled(last_loaded_extension_id(), profile()));
[email protected]1e6e89542013-03-30 17:08:53110}
111} // namespace extensions