blob: 99f885d7acc0d461062d00116d720a8b2a45560d [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
avia2f4804a2015-12-24 23:11:135#include <stddef.h>
6
7#include "build/build_config.h"
[email protected]1e6e89542013-03-30 17:08:538#include "chrome/browser/extensions/crx_installer.h"
9#include "chrome/browser/extensions/extension_browsertest.h"
10#include "chrome/browser/extensions/extension_service.h"
[email protected]a7ff4b72013-10-17 20:56:0211#include "chrome/browser/extensions/extension_util.h"
[email protected]1e6e89542013-03-30 17:08:5312#include "chrome/browser/profiles/profile.h"
13#include "chrome/browser/ui/browser_commands.h"
[email protected]5a0613d32013-06-17 20:06:5314#include "content/public/browser/notification_service.h"
thestigaf7f4152014-10-31 23:19:1515#include "content/public/test/test_utils.h"
reillyga3acbc12014-11-11 23:17:1216#include "extensions/browser/extension_registry.h"
[email protected]03d25812014-06-22 19:41:5517#include "extensions/browser/extension_system.h"
karandeepb810e33402017-04-05 23:41:2218#include "extensions/browser/extension_util.h"
[email protected]adf5a102014-07-31 12:44:0619#include "extensions/browser/notification_types.h"
sooho10005109c322015-11-09 00:38:2120#include "extensions/browser/test_extension_registry_observer.h"
[email protected]1e6e89542013-03-30 17:08:5321
22namespace extensions {
23
24class ExtensionFunctionalTest : public ExtensionBrowserTest {
[email protected]03d25812014-06-22 19:41:5525 public:
[email protected]1e6e89542013-03-30 17:08:5326 void InstallExtensionSilently(ExtensionService* service,
27 const char* filename) {
reillyga3acbc12014-11-11 23:17:1228 ExtensionRegistry* registry = ExtensionRegistry::Get(profile());
29 size_t num_before = registry->enabled_extensions().size();
[email protected]1e6e89542013-03-30 17:08:5330
31 base::FilePath path = test_data_dir_.AppendASCII(filename);
32
thestig199d81f22016-07-02 02:03:1833 TestExtensionRegistryObserver extension_observer(registry);
[email protected]1e6e89542013-03-30 17:08:5334
thestig199d81f22016-07-02 02:03:1835 scoped_refptr<CrxInstaller> installer(CrxInstaller::CreateSilent(service));
[email protected]1e6e89542013-03-30 17:08:5336 installer->set_is_gallery_install(false);
37 installer->set_allow_silent_install(true);
38 installer->set_install_source(Manifest::INTERNAL);
39 installer->set_off_store_install_allow_reason(
thestig199d81f22016-07-02 02:03:1840 CrxInstaller::OffStoreInstallAllowedInTest);
[email protected]1e6e89542013-03-30 17:08:5341
thestig199d81f22016-07-02 02:03:1842 observer_->Watch(NOTIFICATION_CRX_INSTALLER_DONE,
43 content::Source<CrxInstaller>(installer.get()));
[email protected]1e6e89542013-03-30 17:08:5344
45 installer->InstallCrx(path);
[email protected]918c2712013-10-21 23:59:5646 observer_->Wait();
[email protected]1e6e89542013-03-30 17:08:5347
reillyga3acbc12014-11-11 23:17:1248 size_t num_after = registry->enabled_extensions().size();
[email protected]1e6e89542013-03-30 17:08:5349 EXPECT_EQ(num_before + 1, num_after);
50
sooho10005109c322015-11-09 00:38:2151 extension_observer.WaitForExtensionLoaded();
reillyga3acbc12014-11-11 23:17:1252 const Extension* extension =
53 registry->enabled_extensions().GetByID(last_loaded_extension_id());
54 EXPECT_TRUE(extension);
[email protected]03d25812014-06-22 19:41:5555 }
[email protected]1e6e89542013-03-30 17:08:5356};
57
[email protected]9289dc92013-08-07 05:39:5558IN_PROC_BROWSER_TEST_F(ExtensionFunctionalTest,
59 PRE_TestAdblockExtensionCrash) {
reillyga3acbc12014-11-11 23:17:1260 InstallExtensionSilently(extension_service(), "adblock.crx");
[email protected]9289dc92013-08-07 05:39:5561}
[email protected]1e6e89542013-03-30 17:08:5362
[email protected]e8885292014-06-24 09:04:0763// 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
69IN_PROC_BROWSER_TEST_F(ExtensionFunctionalTest,
70 MAYBE_TestAdblockExtensionCrash) {
reillyga3acbc12014-11-11 23:17:1271 ExtensionService* service = extension_service();
[email protected]1e6e89542013-03-30 17:08:5372 // Verify that the extension is enabled and allowed in incognito
73 // is disabled.
[email protected]918c2712013-10-21 23:59:5674 EXPECT_TRUE(service->IsExtensionEnabled(last_loaded_extension_id()));
[email protected]1d5cf4142014-01-24 18:25:2275 EXPECT_FALSE(util::IsIncognitoEnabled(last_loaded_extension_id(), profile()));
[email protected]1e6e89542013-03-30 17:08:5376}
77
loyso2d28ada2016-10-12 02:32:4678// Failing on Linux: http://crbug.com/654945
79#if defined(OS_LINUX)
80#define MAYBE_TestSetExtensionsState DISABLED_TestSetExtensionsState
81#else
82#define MAYBE_TestSetExtensionsState TestSetExtensionsState
83#endif
84IN_PROC_BROWSER_TEST_F(ExtensionFunctionalTest, MAYBE_TestSetExtensionsState) {
reillyga3acbc12014-11-11 23:17:1285 InstallExtensionSilently(extension_service(), "google_talk.crx");
[email protected]1e6e89542013-03-30 17:08:5386
87 // Disable the extension and verify.
[email protected]1d5cf4142014-01-24 18:25:2288 util::SetIsIncognitoEnabled(last_loaded_extension_id(), profile(), false);
reillyga3acbc12014-11-11 23:17:1289 ExtensionService* service = extension_service();
[email protected]918c2712013-10-21 23:59:5690 service->DisableExtension(last_loaded_extension_id(),
Minh X. Nguyen45479012017-08-18 21:35:3691 disable_reason::DISABLE_USER_ACTION);
[email protected]918c2712013-10-21 23:59:5692 EXPECT_FALSE(service->IsExtensionEnabled(last_loaded_extension_id()));
[email protected]1e6e89542013-03-30 17:08:5393
94 // Enable the extension and verify.
[email protected]1d5cf4142014-01-24 18:25:2295 util::SetIsIncognitoEnabled(last_loaded_extension_id(), profile(), false);
[email protected]918c2712013-10-21 23:59:5696 service->EnableExtension(last_loaded_extension_id());
97 EXPECT_TRUE(service->IsExtensionEnabled(last_loaded_extension_id()));
[email protected]1e6e89542013-03-30 17:08:5398
99 // Allow extension in incognito mode and verify.
[email protected]918c2712013-10-21 23:59:56100 service->EnableExtension(last_loaded_extension_id());
[email protected]1d5cf4142014-01-24 18:25:22101 util::SetIsIncognitoEnabled(last_loaded_extension_id(), profile(), true);
102 EXPECT_TRUE(util::IsIncognitoEnabled(last_loaded_extension_id(), profile()));
[email protected]1e6e89542013-03-30 17:08:53103
104 // Disallow extension in incognito mode and verify.
[email protected]918c2712013-10-21 23:59:56105 service->EnableExtension(last_loaded_extension_id());
[email protected]1d5cf4142014-01-24 18:25:22106 util::SetIsIncognitoEnabled(last_loaded_extension_id(), profile(), false);
107 EXPECT_FALSE(util::IsIncognitoEnabled(last_loaded_extension_id(), profile()));
[email protected]1e6e89542013-03-30 17:08:53108}
thestig199d81f22016-07-02 02:03:18109
[email protected]1e6e89542013-03-30 17:08:53110} // namespace extensions