NaCl: Update revision in DEPS, r12770 -> r12773
[chromium-blink-merge.git] / chrome / browser / extensions / extension_functional_browsertest.cc
blobcf54b501e65d19601541fc740e0fa6d5f6881466
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/chrome_notification_types.h"
6 #include "chrome/browser/extensions/crx_installer.h"
7 #include "chrome/browser/extensions/extension_browsertest.h"
8 #include "chrome/browser/extensions/extension_service.h"
9 #include "chrome/browser/extensions/extension_util.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/ui/browser_commands.h"
12 #include "chrome/test/base/ui_test_utils.h"
13 #include "content/public/browser/notification_service.h"
15 namespace extensions {
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();
24 base::FilePath path = test_data_dir_.AppendASCII(filename);
26 content::WindowedNotificationObserver extension_loaded_observer(
27 chrome::NOTIFICATION_EXTENSION_LOADED,
28 content::NotificationService::AllSources());
30 scoped_refptr<extensions::CrxInstaller> installer(
31 extensions::CrxInstaller::CreateSilent(service));
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);
38 observer_->Watch(
39 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
40 content::Source<extensions::CrxInstaller>(installer.get()));
42 installer->InstallCrx(path);
43 observer_->Wait();
45 size_t num_after = service->extensions()->size();
46 EXPECT_EQ(num_before + 1, num_after);
48 extension_loaded_observer.Wait();
49 const Extension* extension = service->GetExtensionById(
50 last_loaded_extension_id(), false);
51 EXPECT_TRUE(extension != NULL);
55 IN_PROC_BROWSER_TEST_F(ExtensionFunctionalTest,
56 PRE_TestAdblockExtensionCrash) {
57 ExtensionService* service = profile()->GetExtensionService();
58 InstallExtensionSilently(service, "adblock.crx");
61 IN_PROC_BROWSER_TEST_F(ExtensionFunctionalTest, TestAdblockExtensionCrash) {
62 ExtensionService* service = profile()->GetExtensionService();
63 // Verify that the extension is enabled and allowed in incognito
64 // is disabled.
65 EXPECT_TRUE(service->IsExtensionEnabled(last_loaded_extension_id()));
66 EXPECT_FALSE(util::IsIncognitoEnabled(last_loaded_extension_id(), profile()));
69 IN_PROC_BROWSER_TEST_F(ExtensionFunctionalTest, TestSetExtensionsState) {
70 ExtensionService* service = profile()->GetExtensionService();
71 InstallExtensionSilently(service, "google_talk.crx");
73 // Disable the extension and verify.
74 util::SetIsIncognitoEnabled(last_loaded_extension_id(), profile(), false);
75 service->DisableExtension(last_loaded_extension_id(),
76 Extension::DISABLE_USER_ACTION);
77 EXPECT_FALSE(service->IsExtensionEnabled(last_loaded_extension_id()));
79 // Enable the extension and verify.
80 util::SetIsIncognitoEnabled(last_loaded_extension_id(), profile(), false);
81 service->EnableExtension(last_loaded_extension_id());
82 EXPECT_TRUE(service->IsExtensionEnabled(last_loaded_extension_id()));
84 // Allow extension in incognito mode and verify.
85 service->EnableExtension(last_loaded_extension_id());
86 util::SetIsIncognitoEnabled(last_loaded_extension_id(), profile(), true);
87 EXPECT_TRUE(util::IsIncognitoEnabled(last_loaded_extension_id(), profile()));
89 // Disallow extension in incognito mode and verify.
90 service->EnableExtension(last_loaded_extension_id());
91 util::SetIsIncognitoEnabled(last_loaded_extension_id(), profile(), false);
92 EXPECT_FALSE(util::IsIncognitoEnabled(last_loaded_extension_id(), profile()));
94 } // namespace extensions