Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / extensions / extension_functional_browsertest.cc
blob6221e34f429aa9e3093fbfaf0be79eb1c30f506d
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.
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/extensions/extension_util.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/ui/browser_commands.h"
11 #include "content/public/browser/notification_service.h"
12 #include "content/public/test/test_utils.h"
13 #include "extensions/browser/extension_registry.h"
14 #include "extensions/browser/extension_system.h"
15 #include "extensions/browser/notification_types.h"
17 namespace extensions {
19 class ExtensionFunctionalTest : public ExtensionBrowserTest {
20 public:
21 void InstallExtensionSilently(ExtensionService* service,
22 const char* filename) {
23 service->set_show_extensions_prompts(false);
24 ExtensionRegistry* registry = ExtensionRegistry::Get(profile());
25 size_t num_before = registry->enabled_extensions().size();
27 base::FilePath path = test_data_dir_.AppendASCII(filename);
29 content::WindowedNotificationObserver extension_loaded_observer(
30 extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED,
31 content::NotificationService::AllSources());
33 scoped_refptr<extensions::CrxInstaller> installer(
34 extensions::CrxInstaller::CreateSilent(service));
35 installer->set_is_gallery_install(false);
36 installer->set_allow_silent_install(true);
37 installer->set_install_source(Manifest::INTERNAL);
38 installer->set_off_store_install_allow_reason(
39 extensions::CrxInstaller::OffStoreInstallAllowedInTest);
41 observer_->Watch(
42 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
43 content::Source<extensions::CrxInstaller>(installer.get()));
45 installer->InstallCrx(path);
46 observer_->Wait();
48 size_t num_after = registry->enabled_extensions().size();
49 EXPECT_EQ(num_before + 1, num_after);
51 extension_loaded_observer.Wait();
52 const Extension* extension =
53 registry->enabled_extensions().GetByID(last_loaded_extension_id());
54 EXPECT_TRUE(extension);
58 IN_PROC_BROWSER_TEST_F(ExtensionFunctionalTest,
59 PRE_TestAdblockExtensionCrash) {
60 InstallExtensionSilently(extension_service(), "adblock.crx");
63 // Timing out on XP and Vista: http://crbug.com/387866
64 #if defined(OS_WIN)
65 #define MAYBE_TestAdblockExtensionCrash DISABLED_TestAdblockExtensionCrash
66 #else
67 #define MAYBE_TestAdblockExtensionCrash TestAdblockExtensionCrash
68 #endif
69 IN_PROC_BROWSER_TEST_F(ExtensionFunctionalTest,
70 MAYBE_TestAdblockExtensionCrash) {
71 ExtensionService* service = extension_service();
72 // Verify that the extension is enabled and allowed in incognito
73 // is disabled.
74 EXPECT_TRUE(service->IsExtensionEnabled(last_loaded_extension_id()));
75 EXPECT_FALSE(util::IsIncognitoEnabled(last_loaded_extension_id(), profile()));
78 // Failing on XP: http://crbug.com/389545
79 #if defined(OS_WIN)
80 #define MAYBE_TestSetExtensionsState DISABLED_TestSetExtensionsState
81 #else
82 #define MAYBE_TestSetExtensionsState TestSetExtensionsState
83 #endif
84 IN_PROC_BROWSER_TEST_F(ExtensionFunctionalTest, MAYBE_TestSetExtensionsState) {
85 InstallExtensionSilently(extension_service(), "google_talk.crx");
87 // Disable the extension and verify.
88 util::SetIsIncognitoEnabled(last_loaded_extension_id(), profile(), false);
89 ExtensionService* service = extension_service();
90 service->DisableExtension(last_loaded_extension_id(),
91 Extension::DISABLE_USER_ACTION);
92 EXPECT_FALSE(service->IsExtensionEnabled(last_loaded_extension_id()));
94 // Enable the extension and verify.
95 util::SetIsIncognitoEnabled(last_loaded_extension_id(), profile(), false);
96 service->EnableExtension(last_loaded_extension_id());
97 EXPECT_TRUE(service->IsExtensionEnabled(last_loaded_extension_id()));
99 // Allow extension in incognito mode and verify.
100 service->EnableExtension(last_loaded_extension_id());
101 util::SetIsIncognitoEnabled(last_loaded_extension_id(), profile(), true);
102 EXPECT_TRUE(util::IsIncognitoEnabled(last_loaded_extension_id(), profile()));
104 // Disallow extension in incognito mode and verify.
105 service->EnableExtension(last_loaded_extension_id());
106 util::SetIsIncognitoEnabled(last_loaded_extension_id(), profile(), false);
107 EXPECT_FALSE(util::IsIncognitoEnabled(last_loaded_extension_id(), profile()));
109 } // namespace extensions