blob: 78bc0988a622612c3936d63c71658f323b28baba [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]9ea0cd32013-07-12 01:50:365#include "chrome/browser/chrome_notification_types.h"
[email protected]1e6e89542013-03-30 17:08:536#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]a7ff4b72013-10-17 20:56:029#include "chrome/browser/extensions/extension_util.h"
[email protected]1e6e89542013-03-30 17:08:5310#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]5a0613d32013-06-17 20:06:5313#include "content/public/browser/notification_service.h"
[email protected]1e6e89542013-03-30 17:08:5314
15namespace extensions {
16
17class ExtensionFunctionalTest : public ExtensionBrowserTest {
18public:
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]f8636f92013-08-09 21:02:3731 extensions::CrxInstaller::CreateSilent(service));
[email protected]1e6e89542013-03-30 17:08:5332 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]43eb00a52013-10-02 23:22:2838 content::WindowedNotificationObserver observer(
39 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
40 content::Source<extensions::CrxInstaller>(installer.get()));
[email protected]1e6e89542013-03-30 17:08:5341 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]43eb00a52013-10-02 23:22:2846 observer.Wait();
[email protected]1e6e89542013-03-30 17:08:5347
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]9289dc92013-08-07 05:39:5558IN_PROC_BROWSER_TEST_F(ExtensionFunctionalTest,
59 PRE_TestAdblockExtensionCrash) {
[email protected]1e6e89542013-03-30 17:08:5360 ExtensionService* service = profile()->GetExtensionService();
61 InstallExtensionSilently(service, "adblock.crx");
[email protected]9289dc92013-08-07 05:39:5562}
[email protected]1e6e89542013-03-30 17:08:5363
[email protected]9289dc92013-08-07 05:39:5564IN_PROC_BROWSER_TEST_F(ExtensionFunctionalTest, TestAdblockExtensionCrash) {
65 ExtensionService* service = profile()->GetExtensionService();
[email protected]1e6e89542013-03-30 17:08:5366 // Verify that the extension is enabled and allowed in incognito
67 // is disabled.
68 EXPECT_TRUE(service->IsExtensionEnabled(last_loaded_extension_id_));
[email protected]a7ff4b72013-10-17 20:56:0269 EXPECT_FALSE(extension_util::IsIncognitoEnabled(last_loaded_extension_id_,
70 service));
[email protected]1e6e89542013-03-30 17:08:5371}
72
73IN_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]a7ff4b72013-10-17 20:56:0278 extension_util::SetIsIncognitoEnabled(
79 last_loaded_extension_id_, service, false);
[email protected]1e6e89542013-03-30 17:08:5380 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]a7ff4b72013-10-17 20:56:0285 extension_util::SetIsIncognitoEnabled(
86 last_loaded_extension_id_, service, false);
[email protected]1e6e89542013-03-30 17:08:5387 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]a7ff4b72013-10-17 20:56:0292 extension_util::SetIsIncognitoEnabled(
93 last_loaded_extension_id_, service, true);
94 EXPECT_TRUE(extension_util::IsIncognitoEnabled(last_loaded_extension_id_,
95 service));
[email protected]1e6e89542013-03-30 17:08:5396
97 // Disallow extension in incognito mode and verify.
98 service->EnableExtension(last_loaded_extension_id_);
[email protected]a7ff4b72013-10-17 20:56:0299 extension_util::SetIsIncognitoEnabled(
100 last_loaded_extension_id_, service, false);
101 EXPECT_FALSE(extension_util::IsIncognitoEnabled(last_loaded_extension_id_,
102 service));
[email protected]1e6e89542013-03-30 17:08:53103}
104} // namespace extensions