blob: cf43c565a35c348a76279b26b5a006941a40b3e5 [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]918c2712013-10-21 23:59:5638 observer_->Watch(
[email protected]43eb00a52013-10-02 23:22:2839 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
40 content::Source<extensions::CrxInstaller>(installer.get()));
[email protected]1e6e89542013-03-30 17:08:5341
42 installer->InstallCrx(path);
[email protected]918c2712013-10-21 23:59:5643 observer_->Wait();
[email protected]1e6e89542013-03-30 17:08:5344
45 size_t num_after = service->extensions()->size();
46 EXPECT_EQ(num_before + 1, num_after);
47
48 extension_loaded_observer.Wait();
49 const Extension* extension = service->GetExtensionById(
[email protected]918c2712013-10-21 23:59:5650 last_loaded_extension_id(), false);
[email protected]1e6e89542013-03-30 17:08:5351 EXPECT_TRUE(extension != NULL);
52 }
53};
54
[email protected]9289dc92013-08-07 05:39:5555IN_PROC_BROWSER_TEST_F(ExtensionFunctionalTest,
56 PRE_TestAdblockExtensionCrash) {
[email protected]1e6e89542013-03-30 17:08:5357 ExtensionService* service = profile()->GetExtensionService();
58 InstallExtensionSilently(service, "adblock.crx");
[email protected]9289dc92013-08-07 05:39:5559}
[email protected]1e6e89542013-03-30 17:08:5360
[email protected]9289dc92013-08-07 05:39:5561IN_PROC_BROWSER_TEST_F(ExtensionFunctionalTest, TestAdblockExtensionCrash) {
62 ExtensionService* service = profile()->GetExtensionService();
[email protected]1e6e89542013-03-30 17:08:5363 // Verify that the extension is enabled and allowed in incognito
64 // is disabled.
[email protected]918c2712013-10-21 23:59:5665 EXPECT_TRUE(service->IsExtensionEnabled(last_loaded_extension_id()));
66 EXPECT_FALSE(
67 extension_util::IsIncognitoEnabled(last_loaded_extension_id(), service));
[email protected]1e6e89542013-03-30 17:08:5368}
69
70IN_PROC_BROWSER_TEST_F(ExtensionFunctionalTest, TestSetExtensionsState) {
71 ExtensionService* service = profile()->GetExtensionService();
72 InstallExtensionSilently(service, "google_talk.crx");
73
74 // Disable the extension and verify.
[email protected]a7ff4b72013-10-17 20:56:0275 extension_util::SetIsIncognitoEnabled(
[email protected]918c2712013-10-21 23:59:5676 last_loaded_extension_id(), service, false);
77 service->DisableExtension(last_loaded_extension_id(),
[email protected]1e6e89542013-03-30 17:08:5378 Extension::DISABLE_USER_ACTION);
[email protected]918c2712013-10-21 23:59:5679 EXPECT_FALSE(service->IsExtensionEnabled(last_loaded_extension_id()));
[email protected]1e6e89542013-03-30 17:08:5380
81 // Enable the extension and verify.
[email protected]a7ff4b72013-10-17 20:56:0282 extension_util::SetIsIncognitoEnabled(
[email protected]918c2712013-10-21 23:59:5683 last_loaded_extension_id(), service, false);
84 service->EnableExtension(last_loaded_extension_id());
85 EXPECT_TRUE(service->IsExtensionEnabled(last_loaded_extension_id()));
[email protected]1e6e89542013-03-30 17:08:5386
87 // Allow extension in incognito mode and verify.
[email protected]918c2712013-10-21 23:59:5688 service->EnableExtension(last_loaded_extension_id());
[email protected]a7ff4b72013-10-17 20:56:0289 extension_util::SetIsIncognitoEnabled(
[email protected]918c2712013-10-21 23:59:5690 last_loaded_extension_id(), service, true);
91 EXPECT_TRUE(
92 extension_util::IsIncognitoEnabled(last_loaded_extension_id(), service));
[email protected]1e6e89542013-03-30 17:08:5393
94 // Disallow extension in incognito mode and verify.
[email protected]918c2712013-10-21 23:59:5695 service->EnableExtension(last_loaded_extension_id());
[email protected]a7ff4b72013-10-17 20:56:0296 extension_util::SetIsIncognitoEnabled(
[email protected]918c2712013-10-21 23:59:5697 last_loaded_extension_id(), service, false);
98 EXPECT_FALSE(
99 extension_util::IsIncognitoEnabled(last_loaded_extension_id(), service));
[email protected]1e6e89542013-03-30 17:08:53100}
101} // namespace extensions