blob: a8df54c628808c51e41faf8b6c96e5e19190f502 [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"
Devlin Cronin53d55542018-12-20 22:47:4640#include "extensions/browser/user_script_loader.h"
[email protected]289c44b2013-12-17 03:26:5741#include "extensions/common/extension.h"
42#include "extensions/common/extension_set.h"
[email protected]5ef835a2013-11-08 20:42:5743#include "extensions/common/feature_switch.h"
emaxx35e8b822017-04-11 02:04:2944#include "extensions/common/manifest.h"
Michael Giuffridab158f3f2017-07-17 19:53:4445#include "extensions/common/switches.h"
[email protected]d96cf752014-04-09 04:05:2846#include "net/base/filename_util.h"
[email protected]f0488f2f2009-07-01 05:25:2247
emaxx35e8b822017-04-11 02:04:2948#if defined(OS_CHROMEOS)
49#include "chrome/browser/chromeos/profiles/profile_helper.h"
50#endif
51
[email protected]00b5d0a52012-10-30 13:13:5352using extensions::FeatureSwitch;
catmullings98cd1942016-08-30 22:31:5953using extensions::ExtensionRegistry;
[email protected]00b5d0a52012-10-30 13:13:5354
[email protected]17c4f3c2009-07-04 16:36:2555// This file contains high-level startup tests for the extensions system. We've
56// had many silly bugs where command line flags did not get propagated correctly
57// into the services, so we didn't start correctly.
[email protected]f0488f2f2009-07-01 05:25:2258
[email protected]3e59bac2010-04-08 16:16:5559class ExtensionStartupTestBase : public InProcessBrowserTest {
[email protected]f0488f2f2009-07-01 05:25:2260 public:
[email protected]60f7d7a2014-04-03 07:15:1161 ExtensionStartupTestBase() : unauthenticated_load_allowed_(true) {
[email protected]fe13bf62010-08-26 14:33:1962 num_expected_extensions_ = 3;
[email protected]f0488f2f2009-07-01 05:25:2263 }
64
65 protected:
66 // InProcessBrowserTest
avi3ef9ec9e2014-12-22 22:50:1767 void SetUpCommandLine(base::CommandLine* command_line) override {
[email protected]60f7d7a2014-04-03 07:15:1168 if (load_extensions_.empty()) {
69 // If no |load_extensions_| were specified, allow unauthenticated
70 // extension settings to be loaded from Preferences as if they had been
71 // authenticated correctly before they were handed to the ExtensionSystem.
72 command_line->AppendSwitchASCII(
73 switches::kForceFieldTrials,
74 base::StringPrintf(
catmullings98cd1942016-08-30 22:31:5975 "%s/%s/", chrome_prefs::internals::kSettingsEnforcementTrialName,
[email protected]60f7d7a2014-04-03 07:15:1176 chrome_prefs::internals::kSettingsEnforcementGroupNoEnforcement));
proberge2562e6f2017-04-10 17:46:5777#if defined(OFFICIAL_BUILD) && (defined(OS_WIN) || defined(OS_MACOSX))
78 // In Windows and MacOS official builds, it is not possible to disable
79 // settings enforcement.
[email protected]55274dd2014-06-23 21:51:1880 unauthenticated_load_allowed_ = false;
[email protected]60f7d7a2014-04-03 07:15:1181#endif
82 } else {
catmullings98cd1942016-08-30 22:31:5983 base::FilePath::StringType paths = base::JoinString(
84 load_extensions_, base::FilePath::StringType(1, ','));
Michael Giuffridab158f3f2017-07-17 19:53:4485 command_line->AppendSwitchNative(extensions::switches::kLoadExtension,
86 paths);
[email protected]10f6b142012-04-14 19:22:4387 command_line->AppendSwitch(switches::kDisableExtensionsFileAccessCheck);
88 }
89 }
90
dchengae36a4a2014-10-21 12:36:3691 bool SetUpUserDataDirectory() override {
[email protected]650b2d52013-02-10 03:41:4592 base::FilePath profile_dir;
Avi Drissman9098f9002018-05-04 00:11:5293 base::PathService::Get(chrome::DIR_USER_DATA, &profile_dir);
[email protected]89dbb1772012-07-17 13:47:2594 profile_dir = profile_dir.AppendASCII(TestingProfile::kTestUserProfileDir);
[email protected]426d1c92013-12-03 20:08:5495 base::CreateDirectory(profile_dir);
[email protected]f0488f2f2009-07-01 05:25:2296
[email protected]e96a0602014-02-15 08:27:4297 preferences_file_ = profile_dir.Append(chrome::kPreferencesFilename);
[email protected]f0488f2f2009-07-01 05:25:2298 user_scripts_dir_ = profile_dir.AppendASCII("User Scripts");
99 extensions_dir_ = profile_dir.AppendASCII("Extensions");
100
[email protected]60f7d7a2014-04-03 07:15:11101 if (load_extensions_.empty()) {
[email protected]650b2d52013-02-10 03:41:45102 base::FilePath src_dir;
Avi Drissman9098f9002018-05-04 00:11:52103 base::PathService::Get(chrome::DIR_TEST_DATA, &src_dir);
[email protected]10f6b142012-04-14 19:22:43104 src_dir = src_dir.AppendASCII("extensions").AppendASCII("good");
[email protected]f0488f2f2009-07-01 05:25:22105
[email protected]e96a0602014-02-15 08:27:42106 base::CopyFile(src_dir.Append(chrome::kPreferencesFilename),
107 preferences_file_);
catmullings98cd1942016-08-30 22:31:59108 base::CopyDirectory(src_dir.AppendASCII("Extensions"), profile_dir,
109 true); // recursive
[email protected]f0488f2f2009-07-01 05:25:22110 }
[email protected]10f6b142012-04-14 19:22:43111 return true;
[email protected]f0488f2f2009-07-01 05:25:22112 }
113
gabbcdefd0cc2015-02-17 18:12:40114 void SetUpInProcessBrowserTestFixture() override {
gabbcdefd0cc2015-02-17 18:12:40115 // Bots are on a domain, turn off the domain check for settings hardening in
116 // order to be able to test all SettingsEnforcement groups.
117 chrome_prefs::DisableDomainCheckForTesting();
118 }
119
dcheng72191812014-10-28 20:49:56120 void TearDown() override {
[email protected]dd3aa792013-07-16 19:10:23121 EXPECT_TRUE(base::DeleteFile(preferences_file_, false));
[email protected]020f49e2010-04-08 19:51:12122
123 // TODO(phajdan.jr): Check return values of the functions below, carefully.
Lei Zhang7210bfa2019-12-05 16:44:39124 base::DeleteFileRecursively(user_scripts_dir_);
125 base::DeleteFileRecursively(extensions_dir_);
[email protected]36fb2c7c2011-04-04 15:49:08126
127 InProcessBrowserTest::TearDown();
[email protected]f0488f2f2009-07-01 05:25:22128 }
129
emaxx35e8b822017-04-11 02:04:29130 static int GetNonComponentEnabledExtensionCount(Profile* profile) {
131 extensions::ExtensionRegistry* registry =
132 extensions::ExtensionRegistry::Get(profile);
133 int found_extensions = 0;
134 for (const auto& extension : registry->enabled_extensions()) {
135 if (!extensions::Manifest::IsComponentLocation(extension->location()))
136 ++found_extensions;
137 }
138 return found_extensions;
139 }
140
[email protected]919ddc82009-07-15 04:30:12141 void WaitForServicesToStart(int num_expected_extensions,
142 bool expect_extensions_enabled) {
[email protected]60f7d7a2014-04-03 07:15:11143 if (!unauthenticated_load_allowed_)
144 num_expected_extensions = 0;
emaxx35e8b822017-04-11 02:04:29145 ASSERT_EQ(num_expected_extensions,
146 GetNonComponentEnabledExtensionCount(browser()->profile()));
reillyga3acbc12014-11-11 23:17:12147
Devlin Cronin251bd412018-05-30 00:55:42148 extensions::ExtensionService* service =
catmullings98cd1942016-08-30 22:31:59149 extensions::ExtensionSystem::Get(browser()->profile())
150 ->extension_service();
[email protected]919ddc82009-07-15 04:30:12151 ASSERT_EQ(expect_extensions_enabled, service->extensions_enabled());
152
[email protected]a7fe9112012-07-20 02:34:45153 content::WindowedNotificationObserver user_scripts_observer(
[email protected]adf5a102014-07-31 12:44:06154 extensions::NOTIFICATION_USER_SCRIPTS_UPDATED,
[email protected]ad50def52011-10-19 23:17:07155 content::NotificationService::AllSources());
[email protected]15ad2ee2014-08-15 19:15:26156 extensions::SharedUserScriptMaster* master =
catmullings98cd1942016-08-30 22:31:59157 extensions::ExtensionSystem::Get(browser()->profile())
158 ->shared_user_script_master();
Devlin Cronin53d55542018-12-20 22:47:46159 if (!master->script_loader()->initial_load_complete())
[email protected]120abf132011-09-27 21:38:06160 user_scripts_observer.Wait();
Devlin Cronin53d55542018-12-20 22:47:46161 ASSERT_TRUE(master->script_loader()->initial_load_complete());
[email protected]919ddc82009-07-15 04:30:12162 }
163
164 void TestInjection(bool expect_css, bool expect_script) {
[email protected]60f7d7a2014-04-03 07:15:11165 if (!unauthenticated_load_allowed_) {
166 expect_css = false;
167 expect_script = false;
168 }
169
[email protected]919ddc82009-07-15 04:30:12170 // Load a page affected by the content script and test to see the effect.
[email protected]650b2d52013-02-10 03:41:45171 base::FilePath test_file;
Avi Drissman9098f9002018-05-04 00:11:52172 base::PathService::Get(chrome::DIR_TEST_DATA, &test_file);
catmullings98cd1942016-08-30 22:31:59173 test_file =
174 test_file.AppendASCII("extensions").AppendASCII("test_file.html");
[email protected]62771442009-11-22 02:25:04175
176 ui_test_utils::NavigateToURL(browser(), net::FilePathToFileURL(test_file));
[email protected]919ddc82009-07-15 04:30:12177
178 bool result = false;
[email protected]b6987e02013-01-04 18:30:43179 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
[email protected]47ae23372013-01-29 01:50:48180 browser()->tab_strip_model()->GetActiveWebContents(),
[email protected]06bc5d92013-01-02 22:44:13181 "window.domAutomationController.send("
[email protected]b6987e02013-01-04 18:30:43182 " document.defaultView.getComputedStyle(document.body, null)."
183 " getPropertyValue('background-color') == 'rgb(245, 245, 220)')",
[email protected]9fabbf72010-09-30 21:50:05184 &result));
[email protected]919ddc82009-07-15 04:30:12185 EXPECT_EQ(expect_css, result);
186
187 result = false;
[email protected]b6987e02013-01-04 18:30:43188 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
[email protected]47ae23372013-01-29 01:50:48189 browser()->tab_strip_model()->GetActiveWebContents(),
[email protected]06bc5d92013-01-02 22:44:13190 "window.domAutomationController.send(document.title == 'Modified')",
[email protected]9fabbf72010-09-30 21:50:05191 &result));
[email protected]919ddc82009-07-15 04:30:12192 EXPECT_EQ(expect_script, result);
193 }
194
[email protected]650b2d52013-02-10 03:41:45195 base::FilePath preferences_file_;
196 base::FilePath extensions_dir_;
197 base::FilePath user_scripts_dir_;
[email protected]60f7d7a2014-04-03 07:15:11198 // True unless unauthenticated extension settings are not allowed to be
199 // loaded in this configuration.
200 bool unauthenticated_load_allowed_;
[email protected]bfc93562011-12-14 19:40:04201 // Extensions to load from the command line.
[email protected]650b2d52013-02-10 03:41:45202 std::vector<base::FilePath::StringType> load_extensions_;
[email protected]e50013c32010-08-18 21:05:24203
204 int num_expected_extensions_;
[email protected]f0488f2f2009-07-01 05:25:22205};
206
207
208// ExtensionsStartupTest
209// Ensures that we can startup the browser with --enable-extensions and some
210// extensions installed and see them run and do basic things.
[email protected]60f7d7a2014-04-03 07:15:11211typedef ExtensionStartupTestBase ExtensionsStartupTest;
[email protected]f0488f2f2009-07-01 05:25:22212
Nico Weber9ce471d42015-04-13 20:52:39213// Broken in official builds, http://crbug.com/474659
214IN_PROC_BROWSER_TEST_F(ExtensionsStartupTest, DISABLED_Test) {
[email protected]e50013c32010-08-18 21:05:24215 WaitForServicesToStart(num_expected_extensions_, true);
[email protected]919ddc82009-07-15 04:30:12216 TestInjection(true, true);
217}
[email protected]919ddc82009-07-15 04:30:12218
Nico Weber9ce471d42015-04-13 20:52:39219// Broken in official builds, http://crbug.com/474659
[email protected]b2f665f52010-07-02 01:32:09220// Sometimes times out on Mac. http://crbug.com/48151
[email protected]05c82182010-06-24 17:49:08221// Tests that disallowing file access on an extension prevents it from injecting
222// script into a page with a file URL.
Nico Weber9ce471d42015-04-13 20:52:39223IN_PROC_BROWSER_TEST_F(ExtensionsStartupTest, DISABLED_NoFileAccess) {
[email protected]e50013c32010-08-18 21:05:24224 WaitForServicesToStart(num_expected_extensions_, true);
[email protected]05c82182010-06-24 17:49:08225
[email protected]84df8332011-12-06 18:22:46226 // Keep a separate list of extensions for which to disable file access, since
227 // doing so reloads them.
[email protected]1c321ee2012-05-21 03:02:34228 std::vector<const extensions::Extension*> extension_list;
[email protected]84df8332011-12-06 18:22:46229
[email protected]1d5cf4142014-01-24 18:25:22230 extensions::ExtensionRegistry* registry =
231 extensions::ExtensionRegistry::Get(browser()->profile());
[email protected]289c44b2013-12-17 03:26:57232 for (extensions::ExtensionSet::const_iterator it =
[email protected]1d5cf4142014-01-24 18:25:22233 registry->enabled_extensions().begin();
234 it != registry->enabled_extensions().end(); ++it) {
[email protected]1d5e58b2013-01-31 08:41:40235 if ((*it)->location() == extensions::Manifest::COMPONENT)
[email protected]fe13bf62010-08-26 14:33:19236 continue;
[email protected]1d5cf4142014-01-24 18:25:22237 if (extensions::util::AllowFileAccess((*it)->id(), browser()->profile()))
[email protected]cadac622013-06-11 16:46:36238 extension_list.push_back(it->get());
[email protected]84df8332011-12-06 18:22:46239 }
240
241 for (size_t i = 0; i < extension_list.size(); ++i) {
[email protected]a7fe9112012-07-20 02:34:45242 content::WindowedNotificationObserver user_scripts_observer(
[email protected]adf5a102014-07-31 12:44:06243 extensions::NOTIFICATION_USER_SCRIPTS_UPDATED,
[email protected]84df8332011-12-06 18:22:46244 content::NotificationService::AllSources());
catmullings98cd1942016-08-30 22:31:59245 extensions::util::SetAllowFileAccess(extension_list[i]->id(),
246 browser()->profile(), false);
[email protected]84df8332011-12-06 18:22:46247 user_scripts_observer.Wait();
[email protected]05c82182010-06-24 17:49:08248 }
249
250 TestInjection(false, false);
251}
252
[email protected]919ddc82009-07-15 04:30:12253// ExtensionsLoadTest
254// Ensures that we can startup the browser with --load-extension and see them
255// run.
[email protected]919ddc82009-07-15 04:30:12256class ExtensionsLoadTest : public ExtensionStartupTestBase {
257 public:
258 ExtensionsLoadTest() {
[email protected]650b2d52013-02-10 03:41:45259 base::FilePath one_extension_path;
Avi Drissman9098f9002018-05-04 00:11:52260 base::PathService::Get(chrome::DIR_TEST_DATA, &one_extension_path);
catmullings98cd1942016-08-30 22:31:59261 one_extension_path = one_extension_path.AppendASCII("extensions")
262 .AppendASCII("good")
263 .AppendASCII("Extensions")
264 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
265 .AppendASCII("1.0.0.0");
[email protected]bfc93562011-12-14 19:40:04266 load_extensions_.push_back(one_extension_path.value());
[email protected]f0488f2f2009-07-01 05:25:22267 }
[email protected]919ddc82009-07-15 04:30:12268};
[email protected]f0488f2f2009-07-01 05:25:22269
[email protected]dc128022012-02-17 23:14:58270IN_PROC_BROWSER_TEST_F(ExtensionsLoadTest, Test) {
[email protected]d728e002010-12-08 04:46:23271 WaitForServicesToStart(1, true);
[email protected]919ddc82009-07-15 04:30:12272 TestInjection(true, true);
[email protected]f0488f2f2009-07-01 05:25:22273}
[email protected]bfc93562011-12-14 19:40:04274
emaxx35e8b822017-04-11 02:04:29275#if defined(OS_CHROMEOS)
276
emaxxb4c388b2017-05-11 18:11:24277IN_PROC_BROWSER_TEST_F(ExtensionsLoadTest,
Maksim Ivanov8646d4392017-05-11 20:18:54278 SigninProfileCommandLineExtensionsDontLoad) {
emaxx35e8b822017-04-11 02:04:29279 // The --load-extension command line flag should not be applied to the sign-in
280 // profile.
281 EXPECT_EQ(0, GetNonComponentEnabledExtensionCount(
282 chromeos::ProfileHelper::GetSigninProfile()));
283}
284
285#endif // defined(OS_CHROMEOS)
286
[email protected]bfc93562011-12-14 19:40:04287// ExtensionsLoadMultipleTest
288// Ensures that we can startup the browser with multiple extensions
289// via --load-extension=X1,X2,X3.
290class ExtensionsLoadMultipleTest : public ExtensionStartupTestBase {
291 public:
292 ExtensionsLoadMultipleTest() {
[email protected]650b2d52013-02-10 03:41:45293 base::FilePath one_extension_path;
Avi Drissman9098f9002018-05-04 00:11:52294 base::PathService::Get(chrome::DIR_TEST_DATA, &one_extension_path);
catmullings98cd1942016-08-30 22:31:59295 one_extension_path = one_extension_path.AppendASCII("extensions")
296 .AppendASCII("good")
297 .AppendASCII("Extensions")
298 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
299 .AppendASCII("1.0.0.0");
[email protected]bfc93562011-12-14 19:40:04300 load_extensions_.push_back(one_extension_path.value());
301
[email protected]650b2d52013-02-10 03:41:45302 base::FilePath second_extension_path;
Avi Drissman9098f9002018-05-04 00:11:52303 base::PathService::Get(chrome::DIR_TEST_DATA, &second_extension_path);
catmullings98cd1942016-08-30 22:31:59304 second_extension_path =
305 second_extension_path.AppendASCII("extensions").AppendASCII("app");
[email protected]bfc93562011-12-14 19:40:04306 load_extensions_.push_back(second_extension_path.value());
307
[email protected]650b2d52013-02-10 03:41:45308 base::FilePath third_extension_path;
Avi Drissman9098f9002018-05-04 00:11:52309 base::PathService::Get(chrome::DIR_TEST_DATA, &third_extension_path);
catmullings98cd1942016-08-30 22:31:59310 third_extension_path =
311 third_extension_path.AppendASCII("extensions").AppendASCII("app1");
[email protected]bfc93562011-12-14 19:40:04312 load_extensions_.push_back(third_extension_path.value());
313
[email protected]650b2d52013-02-10 03:41:45314 base::FilePath fourth_extension_path;
Avi Drissman9098f9002018-05-04 00:11:52315 base::PathService::Get(chrome::DIR_TEST_DATA, &fourth_extension_path);
catmullings98cd1942016-08-30 22:31:59316 fourth_extension_path =
317 fourth_extension_path.AppendASCII("extensions").AppendASCII("app2");
[email protected]bfc93562011-12-14 19:40:04318 load_extensions_.push_back(fourth_extension_path.value());
319 }
320};
321
322IN_PROC_BROWSER_TEST_F(ExtensionsLoadMultipleTest, Test) {
323 WaitForServicesToStart(4, true);
324 TestInjection(true, true);
325}
catmullings98cd1942016-08-30 22:31:59326
catmullings1cc8fc72016-12-05 23:39:23327// TODO(catmullings): Remove test in future chrome release, perhaps M59.
328class DeprecatedLoadComponentExtensionSwitchBrowserTest
Devlin Cronin836f545d2018-05-09 00:25:05329 : public extensions::ExtensionBrowserTest {
catmullings1cc8fc72016-12-05 23:39:23330 public:
331 DeprecatedLoadComponentExtensionSwitchBrowserTest() {}
332
333 void SetUpCommandLine(base::CommandLine* command_line) override;
334
335 ExtensionRegistry* GetExtensionRegistry() {
336 return ExtensionRegistry::Get(browser()->profile());
337 }
338};
339
340void DeprecatedLoadComponentExtensionSwitchBrowserTest::SetUpCommandLine(
341 base::CommandLine* command_line) {
Devlin Cronin836f545d2018-05-09 00:25:05342 extensions::ExtensionBrowserTest::SetUpCommandLine(command_line);
catmullings1cc8fc72016-12-05 23:39:23343 base::FilePath fp1(test_data_dir_.AppendASCII("app_dot_com_app/"));
344 base::FilePath fp2(test_data_dir_.AppendASCII("app/"));
345
346 command_line->AppendSwitchASCII(
347 "load-component-extension",
348 fp1.AsUTF8Unsafe() + "," + fp2.AsUTF8Unsafe());
349}
350
351// Tests that the --load-component-extension flag is not supported.
352IN_PROC_BROWSER_TEST_F(DeprecatedLoadComponentExtensionSwitchBrowserTest,
353 DefunctLoadComponentExtensionFlag) {
354 EXPECT_TRUE(extension_service()->extensions_enabled());
355
356 // Checks that the extensions loaded with the --load-component-extension flag
357 // are not installed.
358 bool is_app_dot_com_extension_installed = false;
359 bool is_app_test_extension_installed = false;
360 for (const scoped_refptr<const extensions::Extension>& extension :
361 GetExtensionRegistry()->enabled_extensions()) {
362 if (extension->name() == "App Dot Com: The App") {
363 is_app_dot_com_extension_installed = true;
364 } else if (extension->name() == "App Test") {
365 is_app_test_extension_installed = true;
366 } else {
367 EXPECT_TRUE(
368 extensions::Manifest::IsComponentLocation(extension->location()));
369 }
370 }
371 EXPECT_FALSE(is_app_dot_com_extension_installed);
372 EXPECT_FALSE(is_app_test_extension_installed);
373}
374
Devlin Cronin836f545d2018-05-09 00:25:05375class DisableExtensionsExceptBrowserTest
376 : public extensions::ExtensionBrowserTest {
catmullings98cd1942016-08-30 22:31:59377 public:
378 DisableExtensionsExceptBrowserTest() {}
379
380 void SetUpCommandLine(base::CommandLine* command_line) override;
381
382 ExtensionRegistry* GetExtensionRegistry() {
383 return ExtensionRegistry::Get(browser()->profile());
384 }
385};
386
387void DisableExtensionsExceptBrowserTest::SetUpCommandLine(
388 base::CommandLine* command_line) {
Devlin Cronin836f545d2018-05-09 00:25:05389 extensions::ExtensionBrowserTest::SetUpCommandLine(command_line);
catmullings98cd1942016-08-30 22:31:59390 base::FilePath fp1(test_data_dir_.AppendASCII("app_dot_com_app/"));
391 base::FilePath fp2(test_data_dir_.AppendASCII("app/"));
392
393 command_line->AppendSwitchASCII(
394 switches::kDisableExtensionsExcept,
395 fp1.AsUTF8Unsafe() + "," + fp2.AsUTF8Unsafe());
antrim58769562016-11-14 14:48:41396
397 command_line->AppendSwitch(switches::kNoErrorDialogs);
catmullings98cd1942016-08-30 22:31:59398}
399
400// Tests disabling all extensions except those listed
401// (--disable-extensions-except).
402IN_PROC_BROWSER_TEST_F(DisableExtensionsExceptBrowserTest,
403 DisableExtensionsExceptFlag) {
404 EXPECT_FALSE(extension_service()->extensions_enabled());
405
406 // Checks that the extensions loaded with the --disable-extensions-except flag
407 // are enabled.
408 bool is_app_dot_com_extension_enabled = false;
409 bool is_app_test_extension_enabled = false;
410 for (const scoped_refptr<const extensions::Extension>& extension :
411 GetExtensionRegistry()->enabled_extensions()) {
412 if (extension->name() == "App Dot Com: The App") {
413 is_app_dot_com_extension_enabled = true;
414 } else if (extension->name() == "App Test") {
415 is_app_test_extension_enabled = true;
416 } else {
417 EXPECT_TRUE(
418 extensions::Manifest::IsComponentLocation(extension->location()));
419 }
420 }
421 EXPECT_TRUE(is_app_dot_com_extension_enabled);
422 EXPECT_TRUE(is_app_test_extension_enabled);
423}