blob: b1b86b19889e34835fcbebdf78da1696ddaa9efc [file] [log] [blame]
[email protected]4d2451652012-02-14 23:54:261// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]038d52e12009-10-14 16:53:412// 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#include <stdint.h>
7
[email protected]f0488f2f2009-07-01 05:25:228#include <vector>
9
brettwf1958912015-10-07 19:43:1210#include "base/base_switches.h"
[email protected]f0488f2f2009-07-01 05:25:2211#include "base/command_line.h"
[email protected]57999812013-02-24 05:40:5212#include "base/files/file_path.h"
thestig18dfb7a52014-08-26 10:44:0413#include "base/files/file_util.h"
[email protected]f0488f2f2009-07-01 05:25:2214#include "base/path_service.h"
[email protected]00e7bef2013-06-10 20:35:1715#include "base/strings/string_util.h"
[email protected]60f7d7a2014-04-03 07:15:1116#include "base/strings/stringprintf.h"
avia2f4804a2015-12-24 23:11:1317#include "build/build_config.h"
[email protected]9ea0cd32013-07-12 01:50:3618#include "chrome/browser/chrome_notification_types.h"
catmullings98cd1942016-08-30 22:31:5919#include "chrome/browser/extensions/extension_browsertest.h"
[email protected]eaa7dd182010-12-14 11:09:0020#include "chrome/browser/extensions/extension_service.h"
[email protected]a7ff4b72013-10-17 20:56:0221#include "chrome/browser/extensions/extension_util.h"
[email protected]60f7d7a2014-04-03 07:15:1122#include "chrome/browser/prefs/chrome_pref_service_factory.h"
[email protected]8ecad5e2010-12-02 21:18:3323#include "chrome/browser/profiles/profile.h"
[email protected]7b5dc002010-11-16 23:08:1024#include "chrome/browser/ui/browser.h"
[email protected]47ae23372013-01-29 01:50:4825#include "chrome/browser/ui/tabs/tab_strip_model.h"
[email protected]e96a0602014-02-15 08:27:4226#include "chrome/common/chrome_constants.h"
[email protected]f0488f2f2009-07-01 05:25:2227#include "chrome/common/chrome_paths.h"
28#include "chrome/common/chrome_switches.h"
[email protected]af44e7fb2011-07-29 18:32:3229#include "chrome/test/base/in_process_browser_test.h"
[email protected]89dbb1772012-07-17 13:47:2530#include "chrome/test/base/testing_profile.h"
[email protected]af44e7fb2011-07-29 18:32:3231#include "chrome/test/base/ui_test_utils.h"
[email protected]6c2381d2011-10-19 02:52:5332#include "content/public/browser/notification_details.h"
[email protected]ad50def52011-10-19 23:17:0733#include "content/public/browser/notification_service.h"
[email protected]4ca15302012-01-03 05:53:2034#include "content/public/browser/web_contents.h"
[email protected]60f7d7a2014-04-03 07:15:1135#include "content/public/common/content_switches.h"
[email protected]7d478cb2012-07-24 17:19:4236#include "content/public/test/browser_test_utils.h"
[email protected]1d5cf4142014-01-24 18:25:2237#include "extensions/browser/extension_registry.h"
[email protected]59b0e602014-01-30 00:41:2438#include "extensions/browser/extension_system.h"
Albert Chaulkb96abb852018-03-02 00:53:1339#include "extensions/browser/shared_user_script_master.h"
[email protected]289c44b2013-12-17 03:26:5740#include "extensions/common/extension.h"
41#include "extensions/common/extension_set.h"
[email protected]5ef835a2013-11-08 20:42:5742#include "extensions/common/feature_switch.h"
emaxx35e8b822017-04-11 02:04:2943#include "extensions/common/manifest.h"
Michael Giuffridab158f3f2017-07-17 19:53:4444#include "extensions/common/switches.h"
[email protected]d96cf752014-04-09 04:05:2845#include "net/base/filename_util.h"
[email protected]f0488f2f2009-07-01 05:25:2246
emaxx35e8b822017-04-11 02:04:2947#if defined(OS_CHROMEOS)
48#include "chrome/browser/chromeos/profiles/profile_helper.h"
49#endif
50
[email protected]00b5d0a52012-10-30 13:13:5351using extensions::FeatureSwitch;
catmullings98cd1942016-08-30 22:31:5952using extensions::ExtensionRegistry;
[email protected]00b5d0a52012-10-30 13:13:5353
[email protected]17c4f3c2009-07-04 16:36:2554// This file contains high-level startup tests for the extensions system. We've
55// had many silly bugs where command line flags did not get propagated correctly
56// into the services, so we didn't start correctly.
[email protected]f0488f2f2009-07-01 05:25:2257
[email protected]3e59bac2010-04-08 16:16:5558class ExtensionStartupTestBase : public InProcessBrowserTest {
[email protected]f0488f2f2009-07-01 05:25:2259 public:
[email protected]60f7d7a2014-04-03 07:15:1160 ExtensionStartupTestBase() : unauthenticated_load_allowed_(true) {
[email protected]fe13bf62010-08-26 14:33:1961 num_expected_extensions_ = 3;
[email protected]f0488f2f2009-07-01 05:25:2262 }
63
64 protected:
65 // InProcessBrowserTest
avi3ef9ec9e2014-12-22 22:50:1766 void SetUpCommandLine(base::CommandLine* command_line) override {
[email protected]60f7d7a2014-04-03 07:15:1167 if (load_extensions_.empty()) {
68 // If no |load_extensions_| were specified, allow unauthenticated
69 // extension settings to be loaded from Preferences as if they had been
70 // authenticated correctly before they were handed to the ExtensionSystem.
71 command_line->AppendSwitchASCII(
72 switches::kForceFieldTrials,
73 base::StringPrintf(
catmullings98cd1942016-08-30 22:31:5974 "%s/%s/", chrome_prefs::internals::kSettingsEnforcementTrialName,
[email protected]60f7d7a2014-04-03 07:15:1175 chrome_prefs::internals::kSettingsEnforcementGroupNoEnforcement));
proberge2562e6f2017-04-10 17:46:5776#if defined(OFFICIAL_BUILD) && (defined(OS_WIN) || defined(OS_MACOSX))
77 // In Windows and MacOS official builds, it is not possible to disable
78 // settings enforcement.
[email protected]55274dd2014-06-23 21:51:1879 unauthenticated_load_allowed_ = false;
[email protected]60f7d7a2014-04-03 07:15:1180#endif
81 } else {
catmullings98cd1942016-08-30 22:31:5982 base::FilePath::StringType paths = base::JoinString(
83 load_extensions_, base::FilePath::StringType(1, ','));
Michael Giuffridab158f3f2017-07-17 19:53:4484 command_line->AppendSwitchNative(extensions::switches::kLoadExtension,
85 paths);
[email protected]10f6b142012-04-14 19:22:4386 command_line->AppendSwitch(switches::kDisableExtensionsFileAccessCheck);
87 }
88 }
89
dchengae36a4a2014-10-21 12:36:3690 bool SetUpUserDataDirectory() override {
[email protected]650b2d52013-02-10 03:41:4591 base::FilePath profile_dir;
Avi Drissman9098f9002018-05-04 00:11:5292 base::PathService::Get(chrome::DIR_USER_DATA, &profile_dir);
[email protected]89dbb1772012-07-17 13:47:2593 profile_dir = profile_dir.AppendASCII(TestingProfile::kTestUserProfileDir);
[email protected]426d1c92013-12-03 20:08:5494 base::CreateDirectory(profile_dir);
[email protected]f0488f2f2009-07-01 05:25:2295
[email protected]e96a0602014-02-15 08:27:4296 preferences_file_ = profile_dir.Append(chrome::kPreferencesFilename);
[email protected]f0488f2f2009-07-01 05:25:2297 user_scripts_dir_ = profile_dir.AppendASCII("User Scripts");
98 extensions_dir_ = profile_dir.AppendASCII("Extensions");
99
[email protected]60f7d7a2014-04-03 07:15:11100 if (load_extensions_.empty()) {
[email protected]650b2d52013-02-10 03:41:45101 base::FilePath src_dir;
Avi Drissman9098f9002018-05-04 00:11:52102 base::PathService::Get(chrome::DIR_TEST_DATA, &src_dir);
[email protected]10f6b142012-04-14 19:22:43103 src_dir = src_dir.AppendASCII("extensions").AppendASCII("good");
[email protected]f0488f2f2009-07-01 05:25:22104
[email protected]e96a0602014-02-15 08:27:42105 base::CopyFile(src_dir.Append(chrome::kPreferencesFilename),
106 preferences_file_);
catmullings98cd1942016-08-30 22:31:59107 base::CopyDirectory(src_dir.AppendASCII("Extensions"), profile_dir,
108 true); // recursive
[email protected]f0488f2f2009-07-01 05:25:22109 }
[email protected]10f6b142012-04-14 19:22:43110 return true;
[email protected]f0488f2f2009-07-01 05:25:22111 }
112
gabbcdefd0cc2015-02-17 18:12:40113 void SetUpInProcessBrowserTestFixture() override {
gabbcdefd0cc2015-02-17 18:12:40114 // Bots are on a domain, turn off the domain check for settings hardening in
115 // order to be able to test all SettingsEnforcement groups.
116 chrome_prefs::DisableDomainCheckForTesting();
117 }
118
dcheng72191812014-10-28 20:49:56119 void TearDown() override {
[email protected]dd3aa792013-07-16 19:10:23120 EXPECT_TRUE(base::DeleteFile(preferences_file_, false));
[email protected]020f49e2010-04-08 19:51:12121
122 // TODO(phajdan.jr): Check return values of the functions below, carefully.
[email protected]dd3aa792013-07-16 19:10:23123 base::DeleteFile(user_scripts_dir_, true);
124 base::DeleteFile(extensions_dir_, true);
[email protected]36fb2c7c2011-04-04 15:49:08125
126 InProcessBrowserTest::TearDown();
[email protected]f0488f2f2009-07-01 05:25:22127 }
128
emaxx35e8b822017-04-11 02:04:29129 static int GetNonComponentEnabledExtensionCount(Profile* profile) {
130 extensions::ExtensionRegistry* registry =
131 extensions::ExtensionRegistry::Get(profile);
132 int found_extensions = 0;
133 for (const auto& extension : registry->enabled_extensions()) {
134 if (!extensions::Manifest::IsComponentLocation(extension->location()))
135 ++found_extensions;
136 }
137 return found_extensions;
138 }
139
[email protected]919ddc82009-07-15 04:30:12140 void WaitForServicesToStart(int num_expected_extensions,
141 bool expect_extensions_enabled) {
[email protected]60f7d7a2014-04-03 07:15:11142 if (!unauthenticated_load_allowed_)
143 num_expected_extensions = 0;
emaxx35e8b822017-04-11 02:04:29144 ASSERT_EQ(num_expected_extensions,
145 GetNonComponentEnabledExtensionCount(browser()->profile()));
reillyga3acbc12014-11-11 23:17:12146
catmullings98cd1942016-08-30 22:31:59147 ExtensionService* service =
148 extensions::ExtensionSystem::Get(browser()->profile())
149 ->extension_service();
[email protected]919ddc82009-07-15 04:30:12150 ASSERT_EQ(expect_extensions_enabled, service->extensions_enabled());
151
[email protected]a7fe9112012-07-20 02:34:45152 content::WindowedNotificationObserver user_scripts_observer(
[email protected]adf5a102014-07-31 12:44:06153 extensions::NOTIFICATION_USER_SCRIPTS_UPDATED,
[email protected]ad50def52011-10-19 23:17:07154 content::NotificationService::AllSources());
[email protected]15ad2ee2014-08-15 19:15:26155 extensions::SharedUserScriptMaster* master =
catmullings98cd1942016-08-30 22:31:59156 extensions::ExtensionSystem::Get(browser()->profile())
157 ->shared_user_script_master();
[email protected]15ad2ee2014-08-15 19:15:26158 if (!master->scripts_ready())
[email protected]120abf132011-09-27 21:38:06159 user_scripts_observer.Wait();
[email protected]15ad2ee2014-08-15 19:15:26160 ASSERT_TRUE(master->scripts_ready());
[email protected]919ddc82009-07-15 04:30:12161 }
162
163 void TestInjection(bool expect_css, bool expect_script) {
[email protected]60f7d7a2014-04-03 07:15:11164 if (!unauthenticated_load_allowed_) {
165 expect_css = false;
166 expect_script = false;
167 }
168
[email protected]919ddc82009-07-15 04:30:12169 // Load a page affected by the content script and test to see the effect.
[email protected]650b2d52013-02-10 03:41:45170 base::FilePath test_file;
Avi Drissman9098f9002018-05-04 00:11:52171 base::PathService::Get(chrome::DIR_TEST_DATA, &test_file);
catmullings98cd1942016-08-30 22:31:59172 test_file =
173 test_file.AppendASCII("extensions").AppendASCII("test_file.html");
[email protected]62771442009-11-22 02:25:04174
175 ui_test_utils::NavigateToURL(browser(), net::FilePathToFileURL(test_file));
[email protected]919ddc82009-07-15 04:30:12176
177 bool result = false;
[email protected]b6987e02013-01-04 18:30:43178 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
[email protected]47ae23372013-01-29 01:50:48179 browser()->tab_strip_model()->GetActiveWebContents(),
[email protected]06bc5d92013-01-02 22:44:13180 "window.domAutomationController.send("
[email protected]b6987e02013-01-04 18:30:43181 " document.defaultView.getComputedStyle(document.body, null)."
182 " getPropertyValue('background-color') == 'rgb(245, 245, 220)')",
[email protected]9fabbf72010-09-30 21:50:05183 &result));
[email protected]919ddc82009-07-15 04:30:12184 EXPECT_EQ(expect_css, result);
185
186 result = false;
[email protected]b6987e02013-01-04 18:30:43187 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
[email protected]47ae23372013-01-29 01:50:48188 browser()->tab_strip_model()->GetActiveWebContents(),
[email protected]06bc5d92013-01-02 22:44:13189 "window.domAutomationController.send(document.title == 'Modified')",
[email protected]9fabbf72010-09-30 21:50:05190 &result));
[email protected]919ddc82009-07-15 04:30:12191 EXPECT_EQ(expect_script, result);
192 }
193
[email protected]650b2d52013-02-10 03:41:45194 base::FilePath preferences_file_;
195 base::FilePath extensions_dir_;
196 base::FilePath user_scripts_dir_;
[email protected]60f7d7a2014-04-03 07:15:11197 // True unless unauthenticated extension settings are not allowed to be
198 // loaded in this configuration.
199 bool unauthenticated_load_allowed_;
[email protected]bfc93562011-12-14 19:40:04200 // Extensions to load from the command line.
[email protected]650b2d52013-02-10 03:41:45201 std::vector<base::FilePath::StringType> load_extensions_;
[email protected]e50013c32010-08-18 21:05:24202
203 int num_expected_extensions_;
[email protected]f0488f2f2009-07-01 05:25:22204};
205
206
207// ExtensionsStartupTest
208// Ensures that we can startup the browser with --enable-extensions and some
209// extensions installed and see them run and do basic things.
[email protected]60f7d7a2014-04-03 07:15:11210typedef ExtensionStartupTestBase ExtensionsStartupTest;
[email protected]f0488f2f2009-07-01 05:25:22211
Nico Weber9ce471d42015-04-13 20:52:39212// Broken in official builds, http://crbug.com/474659
213IN_PROC_BROWSER_TEST_F(ExtensionsStartupTest, DISABLED_Test) {
[email protected]e50013c32010-08-18 21:05:24214 WaitForServicesToStart(num_expected_extensions_, true);
[email protected]919ddc82009-07-15 04:30:12215 TestInjection(true, true);
216}
[email protected]919ddc82009-07-15 04:30:12217
Nico Weber9ce471d42015-04-13 20:52:39218// Broken in official builds, http://crbug.com/474659
[email protected]b2f665f52010-07-02 01:32:09219// Sometimes times out on Mac. http://crbug.com/48151
[email protected]05c82182010-06-24 17:49:08220// Tests that disallowing file access on an extension prevents it from injecting
221// script into a page with a file URL.
Nico Weber9ce471d42015-04-13 20:52:39222IN_PROC_BROWSER_TEST_F(ExtensionsStartupTest, DISABLED_NoFileAccess) {
[email protected]e50013c32010-08-18 21:05:24223 WaitForServicesToStart(num_expected_extensions_, true);
[email protected]05c82182010-06-24 17:49:08224
[email protected]84df8332011-12-06 18:22:46225 // Keep a separate list of extensions for which to disable file access, since
226 // doing so reloads them.
[email protected]1c321ee2012-05-21 03:02:34227 std::vector<const extensions::Extension*> extension_list;
[email protected]84df8332011-12-06 18:22:46228
[email protected]1d5cf4142014-01-24 18:25:22229 extensions::ExtensionRegistry* registry =
230 extensions::ExtensionRegistry::Get(browser()->profile());
[email protected]289c44b2013-12-17 03:26:57231 for (extensions::ExtensionSet::const_iterator it =
[email protected]1d5cf4142014-01-24 18:25:22232 registry->enabled_extensions().begin();
233 it != registry->enabled_extensions().end(); ++it) {
[email protected]1d5e58b2013-01-31 08:41:40234 if ((*it)->location() == extensions::Manifest::COMPONENT)
[email protected]fe13bf62010-08-26 14:33:19235 continue;
[email protected]1d5cf4142014-01-24 18:25:22236 if (extensions::util::AllowFileAccess((*it)->id(), browser()->profile()))
[email protected]cadac622013-06-11 16:46:36237 extension_list.push_back(it->get());
[email protected]84df8332011-12-06 18:22:46238 }
239
240 for (size_t i = 0; i < extension_list.size(); ++i) {
[email protected]a7fe9112012-07-20 02:34:45241 content::WindowedNotificationObserver user_scripts_observer(
[email protected]adf5a102014-07-31 12:44:06242 extensions::NOTIFICATION_USER_SCRIPTS_UPDATED,
[email protected]84df8332011-12-06 18:22:46243 content::NotificationService::AllSources());
catmullings98cd1942016-08-30 22:31:59244 extensions::util::SetAllowFileAccess(extension_list[i]->id(),
245 browser()->profile(), false);
[email protected]84df8332011-12-06 18:22:46246 user_scripts_observer.Wait();
[email protected]05c82182010-06-24 17:49:08247 }
248
249 TestInjection(false, false);
250}
251
[email protected]919ddc82009-07-15 04:30:12252// ExtensionsLoadTest
253// Ensures that we can startup the browser with --load-extension and see them
254// run.
[email protected]919ddc82009-07-15 04:30:12255class ExtensionsLoadTest : public ExtensionStartupTestBase {
256 public:
257 ExtensionsLoadTest() {
[email protected]650b2d52013-02-10 03:41:45258 base::FilePath one_extension_path;
Avi Drissman9098f9002018-05-04 00:11:52259 base::PathService::Get(chrome::DIR_TEST_DATA, &one_extension_path);
catmullings98cd1942016-08-30 22:31:59260 one_extension_path = one_extension_path.AppendASCII("extensions")
261 .AppendASCII("good")
262 .AppendASCII("Extensions")
263 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
264 .AppendASCII("1.0.0.0");
[email protected]bfc93562011-12-14 19:40:04265 load_extensions_.push_back(one_extension_path.value());
[email protected]f0488f2f2009-07-01 05:25:22266 }
[email protected]919ddc82009-07-15 04:30:12267};
[email protected]f0488f2f2009-07-01 05:25:22268
[email protected]dc128022012-02-17 23:14:58269IN_PROC_BROWSER_TEST_F(ExtensionsLoadTest, Test) {
[email protected]d728e002010-12-08 04:46:23270 WaitForServicesToStart(1, true);
[email protected]919ddc82009-07-15 04:30:12271 TestInjection(true, true);
[email protected]f0488f2f2009-07-01 05:25:22272}
[email protected]bfc93562011-12-14 19:40:04273
emaxx35e8b822017-04-11 02:04:29274#if defined(OS_CHROMEOS)
275
emaxxb4c388b2017-05-11 18:11:24276IN_PROC_BROWSER_TEST_F(ExtensionsLoadTest,
Maksim Ivanov8646d4392017-05-11 20:18:54277 SigninProfileCommandLineExtensionsDontLoad) {
emaxx35e8b822017-04-11 02:04:29278 // The --load-extension command line flag should not be applied to the sign-in
279 // profile.
280 EXPECT_EQ(0, GetNonComponentEnabledExtensionCount(
281 chromeos::ProfileHelper::GetSigninProfile()));
282}
283
284#endif // defined(OS_CHROMEOS)
285
[email protected]bfc93562011-12-14 19:40:04286// ExtensionsLoadMultipleTest
287// Ensures that we can startup the browser with multiple extensions
288// via --load-extension=X1,X2,X3.
289class ExtensionsLoadMultipleTest : public ExtensionStartupTestBase {
290 public:
291 ExtensionsLoadMultipleTest() {
[email protected]650b2d52013-02-10 03:41:45292 base::FilePath one_extension_path;
Avi Drissman9098f9002018-05-04 00:11:52293 base::PathService::Get(chrome::DIR_TEST_DATA, &one_extension_path);
catmullings98cd1942016-08-30 22:31:59294 one_extension_path = one_extension_path.AppendASCII("extensions")
295 .AppendASCII("good")
296 .AppendASCII("Extensions")
297 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
298 .AppendASCII("1.0.0.0");
[email protected]bfc93562011-12-14 19:40:04299 load_extensions_.push_back(one_extension_path.value());
300
[email protected]650b2d52013-02-10 03:41:45301 base::FilePath second_extension_path;
Avi Drissman9098f9002018-05-04 00:11:52302 base::PathService::Get(chrome::DIR_TEST_DATA, &second_extension_path);
catmullings98cd1942016-08-30 22:31:59303 second_extension_path =
304 second_extension_path.AppendASCII("extensions").AppendASCII("app");
[email protected]bfc93562011-12-14 19:40:04305 load_extensions_.push_back(second_extension_path.value());
306
[email protected]650b2d52013-02-10 03:41:45307 base::FilePath third_extension_path;
Avi Drissman9098f9002018-05-04 00:11:52308 base::PathService::Get(chrome::DIR_TEST_DATA, &third_extension_path);
catmullings98cd1942016-08-30 22:31:59309 third_extension_path =
310 third_extension_path.AppendASCII("extensions").AppendASCII("app1");
[email protected]bfc93562011-12-14 19:40:04311 load_extensions_.push_back(third_extension_path.value());
312
[email protected]650b2d52013-02-10 03:41:45313 base::FilePath fourth_extension_path;
Avi Drissman9098f9002018-05-04 00:11:52314 base::PathService::Get(chrome::DIR_TEST_DATA, &fourth_extension_path);
catmullings98cd1942016-08-30 22:31:59315 fourth_extension_path =
316 fourth_extension_path.AppendASCII("extensions").AppendASCII("app2");
[email protected]bfc93562011-12-14 19:40:04317 load_extensions_.push_back(fourth_extension_path.value());
318 }
319};
320
321IN_PROC_BROWSER_TEST_F(ExtensionsLoadMultipleTest, Test) {
322 WaitForServicesToStart(4, true);
323 TestInjection(true, true);
324}
catmullings98cd1942016-08-30 22:31:59325
catmullings1cc8fc72016-12-05 23:39:23326// TODO(catmullings): Remove test in future chrome release, perhaps M59.
327class DeprecatedLoadComponentExtensionSwitchBrowserTest
328 : public ExtensionBrowserTest {
329 public:
330 DeprecatedLoadComponentExtensionSwitchBrowserTest() {}
331
332 void SetUpCommandLine(base::CommandLine* command_line) override;
333
334 ExtensionRegistry* GetExtensionRegistry() {
335 return ExtensionRegistry::Get(browser()->profile());
336 }
337};
338
339void DeprecatedLoadComponentExtensionSwitchBrowserTest::SetUpCommandLine(
340 base::CommandLine* command_line) {
341 ExtensionBrowserTest::SetUpCommandLine(command_line);
342 base::FilePath fp1(test_data_dir_.AppendASCII("app_dot_com_app/"));
343 base::FilePath fp2(test_data_dir_.AppendASCII("app/"));
344
345 command_line->AppendSwitchASCII(
346 "load-component-extension",
347 fp1.AsUTF8Unsafe() + "," + fp2.AsUTF8Unsafe());
348}
349
350// Tests that the --load-component-extension flag is not supported.
351IN_PROC_BROWSER_TEST_F(DeprecatedLoadComponentExtensionSwitchBrowserTest,
352 DefunctLoadComponentExtensionFlag) {
353 EXPECT_TRUE(extension_service()->extensions_enabled());
354
355 // Checks that the extensions loaded with the --load-component-extension flag
356 // are not installed.
357 bool is_app_dot_com_extension_installed = false;
358 bool is_app_test_extension_installed = false;
359 for (const scoped_refptr<const extensions::Extension>& extension :
360 GetExtensionRegistry()->enabled_extensions()) {
361 if (extension->name() == "App Dot Com: The App") {
362 is_app_dot_com_extension_installed = true;
363 } else if (extension->name() == "App Test") {
364 is_app_test_extension_installed = true;
365 } else {
366 EXPECT_TRUE(
367 extensions::Manifest::IsComponentLocation(extension->location()));
368 }
369 }
370 EXPECT_FALSE(is_app_dot_com_extension_installed);
371 EXPECT_FALSE(is_app_test_extension_installed);
372}
373
catmullings98cd1942016-08-30 22:31:59374class DisableExtensionsExceptBrowserTest : public ExtensionBrowserTest {
375 public:
376 DisableExtensionsExceptBrowserTest() {}
377
378 void SetUpCommandLine(base::CommandLine* command_line) override;
379
380 ExtensionRegistry* GetExtensionRegistry() {
381 return ExtensionRegistry::Get(browser()->profile());
382 }
383};
384
385void DisableExtensionsExceptBrowserTest::SetUpCommandLine(
386 base::CommandLine* command_line) {
387 ExtensionBrowserTest::SetUpCommandLine(command_line);
388 base::FilePath fp1(test_data_dir_.AppendASCII("app_dot_com_app/"));
389 base::FilePath fp2(test_data_dir_.AppendASCII("app/"));
390
391 command_line->AppendSwitchASCII(
392 switches::kDisableExtensionsExcept,
393 fp1.AsUTF8Unsafe() + "," + fp2.AsUTF8Unsafe());
antrim58769562016-11-14 14:48:41394
395 command_line->AppendSwitch(switches::kNoErrorDialogs);
catmullings98cd1942016-08-30 22:31:59396}
397
398// Tests disabling all extensions except those listed
399// (--disable-extensions-except).
400IN_PROC_BROWSER_TEST_F(DisableExtensionsExceptBrowserTest,
401 DisableExtensionsExceptFlag) {
402 EXPECT_FALSE(extension_service()->extensions_enabled());
403
404 // Checks that the extensions loaded with the --disable-extensions-except flag
405 // are enabled.
406 bool is_app_dot_com_extension_enabled = false;
407 bool is_app_test_extension_enabled = false;
408 for (const scoped_refptr<const extensions::Extension>& extension :
409 GetExtensionRegistry()->enabled_extensions()) {
410 if (extension->name() == "App Dot Com: The App") {
411 is_app_dot_com_extension_enabled = true;
412 } else if (extension->name() == "App Test") {
413 is_app_test_extension_enabled = true;
414 } else {
415 EXPECT_TRUE(
416 extensions::Manifest::IsComponentLocation(extension->location()));
417 }
418 }
419 EXPECT_TRUE(is_app_dot_com_extension_enabled);
420 EXPECT_TRUE(is_app_test_extension_enabled);
421}