blob: e2aa865b415e991ecc3319a13b336b9798337da7 [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]15ad2ee2014-08-15 19:15:2622#include "chrome/browser/extensions/shared_user_script_master.h"
[email protected]60f7d7a2014-04-03 07:15:1123#include "chrome/browser/prefs/chrome_pref_service_factory.h"
[email protected]8ecad5e2010-12-02 21:18:3324#include "chrome/browser/profiles/profile.h"
[email protected]7b5dc002010-11-16 23:08:1025#include "chrome/browser/ui/browser.h"
[email protected]47ae23372013-01-29 01:50:4826#include "chrome/browser/ui/tabs/tab_strip_model.h"
[email protected]e96a0602014-02-15 08:27:4227#include "chrome/common/chrome_constants.h"
[email protected]f0488f2f2009-07-01 05:25:2228#include "chrome/common/chrome_paths.h"
29#include "chrome/common/chrome_switches.h"
[email protected]af44e7fb2011-07-29 18:32:3230#include "chrome/test/base/in_process_browser_test.h"
[email protected]89dbb1772012-07-17 13:47:2531#include "chrome/test/base/testing_profile.h"
[email protected]af44e7fb2011-07-29 18:32:3232#include "chrome/test/base/ui_test_utils.h"
[email protected]6c2381d2011-10-19 02:52:5333#include "content/public/browser/notification_details.h"
[email protected]ad50def52011-10-19 23:17:0734#include "content/public/browser/notification_service.h"
[email protected]4ca15302012-01-03 05:53:2035#include "content/public/browser/web_contents.h"
[email protected]60f7d7a2014-04-03 07:15:1136#include "content/public/common/content_switches.h"
[email protected]7d478cb2012-07-24 17:19:4237#include "content/public/test/browser_test_utils.h"
[email protected]1d5cf4142014-01-24 18:25:2238#include "extensions/browser/extension_registry.h"
[email protected]59b0e602014-01-30 00:41:2439#include "extensions/browser/extension_system.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"
[email protected]d96cf752014-04-09 04:05:2843#include "net/base/filename_util.h"
[email protected]f0488f2f2009-07-01 05:25:2244
[email protected]00b5d0a52012-10-30 13:13:5345using extensions::FeatureSwitch;
catmullings98cd1942016-08-30 22:31:5946using extensions::ExtensionRegistry;
[email protected]00b5d0a52012-10-30 13:13:5347
[email protected]17c4f3c2009-07-04 16:36:2548// This file contains high-level startup tests for the extensions system. We've
49// had many silly bugs where command line flags did not get propagated correctly
50// into the services, so we didn't start correctly.
[email protected]f0488f2f2009-07-01 05:25:2251
[email protected]3e59bac2010-04-08 16:16:5552class ExtensionStartupTestBase : public InProcessBrowserTest {
[email protected]f0488f2f2009-07-01 05:25:2253 public:
[email protected]60f7d7a2014-04-03 07:15:1154 ExtensionStartupTestBase() : unauthenticated_load_allowed_(true) {
[email protected]fe13bf62010-08-26 14:33:1955 num_expected_extensions_ = 3;
[email protected]f0488f2f2009-07-01 05:25:2256 }
57
58 protected:
59 // InProcessBrowserTest
avi3ef9ec9e2014-12-22 22:50:1760 void SetUpCommandLine(base::CommandLine* command_line) override {
[email protected]60f7d7a2014-04-03 07:15:1161 if (load_extensions_.empty()) {
62 // If no |load_extensions_| were specified, allow unauthenticated
63 // extension settings to be loaded from Preferences as if they had been
64 // authenticated correctly before they were handed to the ExtensionSystem.
65 command_line->AppendSwitchASCII(
66 switches::kForceFieldTrials,
67 base::StringPrintf(
catmullings98cd1942016-08-30 22:31:5968 "%s/%s/", chrome_prefs::internals::kSettingsEnforcementTrialName,
[email protected]60f7d7a2014-04-03 07:15:1169 chrome_prefs::internals::kSettingsEnforcementGroupNoEnforcement));
[email protected]337695e2014-04-17 03:55:4970#if defined(OFFICIAL_BUILD) && defined(OS_WIN)
71 // In Windows official builds, it is not possible to disable settings
[email protected]60f7d7a2014-04-03 07:15:1172 // authentication.
[email protected]55274dd2014-06-23 21:51:1873 unauthenticated_load_allowed_ = false;
[email protected]60f7d7a2014-04-03 07:15:1174#endif
75 } else {
catmullings98cd1942016-08-30 22:31:5976 base::FilePath::StringType paths = base::JoinString(
77 load_extensions_, base::FilePath::StringType(1, ','));
78 command_line->AppendSwitchNative(switches::kLoadExtension, paths);
[email protected]10f6b142012-04-14 19:22:4379 command_line->AppendSwitch(switches::kDisableExtensionsFileAccessCheck);
80 }
81 }
82
dchengae36a4a2014-10-21 12:36:3683 bool SetUpUserDataDirectory() override {
[email protected]650b2d52013-02-10 03:41:4584 base::FilePath profile_dir;
[email protected]f0488f2f2009-07-01 05:25:2285 PathService::Get(chrome::DIR_USER_DATA, &profile_dir);
[email protected]89dbb1772012-07-17 13:47:2586 profile_dir = profile_dir.AppendASCII(TestingProfile::kTestUserProfileDir);
[email protected]426d1c92013-12-03 20:08:5487 base::CreateDirectory(profile_dir);
[email protected]f0488f2f2009-07-01 05:25:2288
[email protected]e96a0602014-02-15 08:27:4289 preferences_file_ = profile_dir.Append(chrome::kPreferencesFilename);
[email protected]f0488f2f2009-07-01 05:25:2290 user_scripts_dir_ = profile_dir.AppendASCII("User Scripts");
91 extensions_dir_ = profile_dir.AppendASCII("Extensions");
92
[email protected]60f7d7a2014-04-03 07:15:1193 if (load_extensions_.empty()) {
[email protected]650b2d52013-02-10 03:41:4594 base::FilePath src_dir;
[email protected]10f6b142012-04-14 19:22:4395 PathService::Get(chrome::DIR_TEST_DATA, &src_dir);
96 src_dir = src_dir.AppendASCII("extensions").AppendASCII("good");
[email protected]f0488f2f2009-07-01 05:25:2297
[email protected]e96a0602014-02-15 08:27:4298 base::CopyFile(src_dir.Append(chrome::kPreferencesFilename),
99 preferences_file_);
catmullings98cd1942016-08-30 22:31:59100 base::CopyDirectory(src_dir.AppendASCII("Extensions"), profile_dir,
101 true); // recursive
[email protected]f0488f2f2009-07-01 05:25:22102 }
[email protected]10f6b142012-04-14 19:22:43103 return true;
[email protected]f0488f2f2009-07-01 05:25:22104 }
105
gabbcdefd0cc2015-02-17 18:12:40106 void SetUpInProcessBrowserTestFixture() override {
107 InProcessBrowserTest::SetUpInProcessBrowserTestFixture();
108
109 // Bots are on a domain, turn off the domain check for settings hardening in
110 // order to be able to test all SettingsEnforcement groups.
111 chrome_prefs::DisableDomainCheckForTesting();
112 }
113
dcheng72191812014-10-28 20:49:56114 void TearDown() override {
[email protected]dd3aa792013-07-16 19:10:23115 EXPECT_TRUE(base::DeleteFile(preferences_file_, false));
[email protected]020f49e2010-04-08 19:51:12116
117 // TODO(phajdan.jr): Check return values of the functions below, carefully.
[email protected]dd3aa792013-07-16 19:10:23118 base::DeleteFile(user_scripts_dir_, true);
119 base::DeleteFile(extensions_dir_, true);
[email protected]36fb2c7c2011-04-04 15:49:08120
121 InProcessBrowserTest::TearDown();
[email protected]f0488f2f2009-07-01 05:25:22122 }
123
[email protected]919ddc82009-07-15 04:30:12124 void WaitForServicesToStart(int num_expected_extensions,
125 bool expect_extensions_enabled) {
reillyga3acbc12014-11-11 23:17:12126 extensions::ExtensionRegistry* registry =
127 extensions::ExtensionRegistry::Get(browser()->profile());
[email protected]919ddc82009-07-15 04:30:12128
[email protected]fe13bf62010-08-26 14:33:19129 // Count the number of non-component extensions.
130 int found_extensions = 0;
reillyga3acbc12014-11-11 23:17:12131 for (const scoped_refptr<const extensions::Extension>& extension :
132 registry->enabled_extensions()) {
133 if (extension->location() != extensions::Manifest::COMPONENT)
[email protected]fe13bf62010-08-26 14:33:19134 found_extensions++;
[email protected]1d5cf4142014-01-24 18:25:22135 }
[email protected]fe13bf62010-08-26 14:33:19136
[email protected]60f7d7a2014-04-03 07:15:11137 if (!unauthenticated_load_allowed_)
138 num_expected_extensions = 0;
139
avia2f4804a2015-12-24 23:11:13140 ASSERT_EQ(static_cast<uint32_t>(num_expected_extensions),
141 static_cast<uint32_t>(found_extensions));
reillyga3acbc12014-11-11 23:17:12142
catmullings98cd1942016-08-30 22:31:59143 ExtensionService* service =
144 extensions::ExtensionSystem::Get(browser()->profile())
145 ->extension_service();
[email protected]919ddc82009-07-15 04:30:12146 ASSERT_EQ(expect_extensions_enabled, service->extensions_enabled());
147
[email protected]a7fe9112012-07-20 02:34:45148 content::WindowedNotificationObserver user_scripts_observer(
[email protected]adf5a102014-07-31 12:44:06149 extensions::NOTIFICATION_USER_SCRIPTS_UPDATED,
[email protected]ad50def52011-10-19 23:17:07150 content::NotificationService::AllSources());
[email protected]15ad2ee2014-08-15 19:15:26151 extensions::SharedUserScriptMaster* master =
catmullings98cd1942016-08-30 22:31:59152 extensions::ExtensionSystem::Get(browser()->profile())
153 ->shared_user_script_master();
[email protected]15ad2ee2014-08-15 19:15:26154 if (!master->scripts_ready())
[email protected]120abf132011-09-27 21:38:06155 user_scripts_observer.Wait();
[email protected]15ad2ee2014-08-15 19:15:26156 ASSERT_TRUE(master->scripts_ready());
[email protected]919ddc82009-07-15 04:30:12157 }
158
159 void TestInjection(bool expect_css, bool expect_script) {
[email protected]60f7d7a2014-04-03 07:15:11160 if (!unauthenticated_load_allowed_) {
161 expect_css = false;
162 expect_script = false;
163 }
164
[email protected]919ddc82009-07-15 04:30:12165 // Load a page affected by the content script and test to see the effect.
[email protected]650b2d52013-02-10 03:41:45166 base::FilePath test_file;
[email protected]62771442009-11-22 02:25:04167 PathService::Get(chrome::DIR_TEST_DATA, &test_file);
catmullings98cd1942016-08-30 22:31:59168 test_file =
169 test_file.AppendASCII("extensions").AppendASCII("test_file.html");
[email protected]62771442009-11-22 02:25:04170
171 ui_test_utils::NavigateToURL(browser(), net::FilePathToFileURL(test_file));
[email protected]919ddc82009-07-15 04:30:12172
173 bool result = false;
[email protected]b6987e02013-01-04 18:30:43174 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
[email protected]47ae23372013-01-29 01:50:48175 browser()->tab_strip_model()->GetActiveWebContents(),
[email protected]06bc5d92013-01-02 22:44:13176 "window.domAutomationController.send("
[email protected]b6987e02013-01-04 18:30:43177 " document.defaultView.getComputedStyle(document.body, null)."
178 " getPropertyValue('background-color') == 'rgb(245, 245, 220)')",
[email protected]9fabbf72010-09-30 21:50:05179 &result));
[email protected]919ddc82009-07-15 04:30:12180 EXPECT_EQ(expect_css, result);
181
182 result = false;
[email protected]b6987e02013-01-04 18:30:43183 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
[email protected]47ae23372013-01-29 01:50:48184 browser()->tab_strip_model()->GetActiveWebContents(),
[email protected]06bc5d92013-01-02 22:44:13185 "window.domAutomationController.send(document.title == 'Modified')",
[email protected]9fabbf72010-09-30 21:50:05186 &result));
[email protected]919ddc82009-07-15 04:30:12187 EXPECT_EQ(expect_script, result);
188 }
189
[email protected]650b2d52013-02-10 03:41:45190 base::FilePath preferences_file_;
191 base::FilePath extensions_dir_;
192 base::FilePath user_scripts_dir_;
[email protected]60f7d7a2014-04-03 07:15:11193 // True unless unauthenticated extension settings are not allowed to be
194 // loaded in this configuration.
195 bool unauthenticated_load_allowed_;
[email protected]bfc93562011-12-14 19:40:04196 // Extensions to load from the command line.
[email protected]650b2d52013-02-10 03:41:45197 std::vector<base::FilePath::StringType> load_extensions_;
[email protected]e50013c32010-08-18 21:05:24198
199 int num_expected_extensions_;
[email protected]f0488f2f2009-07-01 05:25:22200};
201
202
203// ExtensionsStartupTest
204// Ensures that we can startup the browser with --enable-extensions and some
205// extensions installed and see them run and do basic things.
[email protected]60f7d7a2014-04-03 07:15:11206typedef ExtensionStartupTestBase ExtensionsStartupTest;
[email protected]f0488f2f2009-07-01 05:25:22207
Nico Weber9ce471d42015-04-13 20:52:39208// Broken in official builds, http://crbug.com/474659
209IN_PROC_BROWSER_TEST_F(ExtensionsStartupTest, DISABLED_Test) {
[email protected]e50013c32010-08-18 21:05:24210 WaitForServicesToStart(num_expected_extensions_, true);
[email protected]919ddc82009-07-15 04:30:12211 TestInjection(true, true);
212}
[email protected]919ddc82009-07-15 04:30:12213
Nico Weber9ce471d42015-04-13 20:52:39214// Broken in official builds, http://crbug.com/474659
[email protected]b2f665f52010-07-02 01:32:09215// Sometimes times out on Mac. http://crbug.com/48151
[email protected]05c82182010-06-24 17:49:08216// Tests that disallowing file access on an extension prevents it from injecting
217// script into a page with a file URL.
Nico Weber9ce471d42015-04-13 20:52:39218IN_PROC_BROWSER_TEST_F(ExtensionsStartupTest, DISABLED_NoFileAccess) {
[email protected]e50013c32010-08-18 21:05:24219 WaitForServicesToStart(num_expected_extensions_, true);
[email protected]05c82182010-06-24 17:49:08220
[email protected]84df8332011-12-06 18:22:46221 // Keep a separate list of extensions for which to disable file access, since
222 // doing so reloads them.
[email protected]1c321ee2012-05-21 03:02:34223 std::vector<const extensions::Extension*> extension_list;
[email protected]84df8332011-12-06 18:22:46224
[email protected]1d5cf4142014-01-24 18:25:22225 extensions::ExtensionRegistry* registry =
226 extensions::ExtensionRegistry::Get(browser()->profile());
[email protected]289c44b2013-12-17 03:26:57227 for (extensions::ExtensionSet::const_iterator it =
[email protected]1d5cf4142014-01-24 18:25:22228 registry->enabled_extensions().begin();
229 it != registry->enabled_extensions().end(); ++it) {
[email protected]1d5e58b2013-01-31 08:41:40230 if ((*it)->location() == extensions::Manifest::COMPONENT)
[email protected]fe13bf62010-08-26 14:33:19231 continue;
[email protected]1d5cf4142014-01-24 18:25:22232 if (extensions::util::AllowFileAccess((*it)->id(), browser()->profile()))
[email protected]cadac622013-06-11 16:46:36233 extension_list.push_back(it->get());
[email protected]84df8332011-12-06 18:22:46234 }
235
236 for (size_t i = 0; i < extension_list.size(); ++i) {
[email protected]a7fe9112012-07-20 02:34:45237 content::WindowedNotificationObserver user_scripts_observer(
[email protected]adf5a102014-07-31 12:44:06238 extensions::NOTIFICATION_USER_SCRIPTS_UPDATED,
[email protected]84df8332011-12-06 18:22:46239 content::NotificationService::AllSources());
catmullings98cd1942016-08-30 22:31:59240 extensions::util::SetAllowFileAccess(extension_list[i]->id(),
241 browser()->profile(), false);
[email protected]84df8332011-12-06 18:22:46242 user_scripts_observer.Wait();
[email protected]05c82182010-06-24 17:49:08243 }
244
245 TestInjection(false, false);
246}
247
[email protected]919ddc82009-07-15 04:30:12248// ExtensionsLoadTest
249// Ensures that we can startup the browser with --load-extension and see them
250// run.
[email protected]919ddc82009-07-15 04:30:12251class ExtensionsLoadTest : public ExtensionStartupTestBase {
252 public:
253 ExtensionsLoadTest() {
[email protected]650b2d52013-02-10 03:41:45254 base::FilePath one_extension_path;
[email protected]bfc93562011-12-14 19:40:04255 PathService::Get(chrome::DIR_TEST_DATA, &one_extension_path);
catmullings98cd1942016-08-30 22:31:59256 one_extension_path = one_extension_path.AppendASCII("extensions")
257 .AppendASCII("good")
258 .AppendASCII("Extensions")
259 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
260 .AppendASCII("1.0.0.0");
[email protected]bfc93562011-12-14 19:40:04261 load_extensions_.push_back(one_extension_path.value());
[email protected]f0488f2f2009-07-01 05:25:22262 }
[email protected]919ddc82009-07-15 04:30:12263};
[email protected]f0488f2f2009-07-01 05:25:22264
[email protected]dc128022012-02-17 23:14:58265IN_PROC_BROWSER_TEST_F(ExtensionsLoadTest, Test) {
[email protected]d728e002010-12-08 04:46:23266 WaitForServicesToStart(1, true);
[email protected]919ddc82009-07-15 04:30:12267 TestInjection(true, true);
[email protected]f0488f2f2009-07-01 05:25:22268}
[email protected]bfc93562011-12-14 19:40:04269
270// ExtensionsLoadMultipleTest
271// Ensures that we can startup the browser with multiple extensions
272// via --load-extension=X1,X2,X3.
273class ExtensionsLoadMultipleTest : public ExtensionStartupTestBase {
274 public:
275 ExtensionsLoadMultipleTest() {
[email protected]650b2d52013-02-10 03:41:45276 base::FilePath one_extension_path;
[email protected]bfc93562011-12-14 19:40:04277 PathService::Get(chrome::DIR_TEST_DATA, &one_extension_path);
catmullings98cd1942016-08-30 22:31:59278 one_extension_path = one_extension_path.AppendASCII("extensions")
279 .AppendASCII("good")
280 .AppendASCII("Extensions")
281 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
282 .AppendASCII("1.0.0.0");
[email protected]bfc93562011-12-14 19:40:04283 load_extensions_.push_back(one_extension_path.value());
284
[email protected]650b2d52013-02-10 03:41:45285 base::FilePath second_extension_path;
[email protected]bfc93562011-12-14 19:40:04286 PathService::Get(chrome::DIR_TEST_DATA, &second_extension_path);
catmullings98cd1942016-08-30 22:31:59287 second_extension_path =
288 second_extension_path.AppendASCII("extensions").AppendASCII("app");
[email protected]bfc93562011-12-14 19:40:04289 load_extensions_.push_back(second_extension_path.value());
290
[email protected]650b2d52013-02-10 03:41:45291 base::FilePath third_extension_path;
[email protected]bfc93562011-12-14 19:40:04292 PathService::Get(chrome::DIR_TEST_DATA, &third_extension_path);
catmullings98cd1942016-08-30 22:31:59293 third_extension_path =
294 third_extension_path.AppendASCII("extensions").AppendASCII("app1");
[email protected]bfc93562011-12-14 19:40:04295 load_extensions_.push_back(third_extension_path.value());
296
[email protected]650b2d52013-02-10 03:41:45297 base::FilePath fourth_extension_path;
[email protected]bfc93562011-12-14 19:40:04298 PathService::Get(chrome::DIR_TEST_DATA, &fourth_extension_path);
catmullings98cd1942016-08-30 22:31:59299 fourth_extension_path =
300 fourth_extension_path.AppendASCII("extensions").AppendASCII("app2");
[email protected]bfc93562011-12-14 19:40:04301 load_extensions_.push_back(fourth_extension_path.value());
302 }
303};
304
305IN_PROC_BROWSER_TEST_F(ExtensionsLoadMultipleTest, Test) {
306 WaitForServicesToStart(4, true);
307 TestInjection(true, true);
308}
catmullings98cd1942016-08-30 22:31:59309
catmullings1cc8fc72016-12-05 23:39:23310// TODO(catmullings): Remove test in future chrome release, perhaps M59.
311class DeprecatedLoadComponentExtensionSwitchBrowserTest
312 : public ExtensionBrowserTest {
313 public:
314 DeprecatedLoadComponentExtensionSwitchBrowserTest() {}
315
316 void SetUpCommandLine(base::CommandLine* command_line) override;
317
318 ExtensionRegistry* GetExtensionRegistry() {
319 return ExtensionRegistry::Get(browser()->profile());
320 }
321};
322
323void DeprecatedLoadComponentExtensionSwitchBrowserTest::SetUpCommandLine(
324 base::CommandLine* command_line) {
325 ExtensionBrowserTest::SetUpCommandLine(command_line);
326 base::FilePath fp1(test_data_dir_.AppendASCII("app_dot_com_app/"));
327 base::FilePath fp2(test_data_dir_.AppendASCII("app/"));
328
329 command_line->AppendSwitchASCII(
330 "load-component-extension",
331 fp1.AsUTF8Unsafe() + "," + fp2.AsUTF8Unsafe());
332}
333
334// Tests that the --load-component-extension flag is not supported.
335IN_PROC_BROWSER_TEST_F(DeprecatedLoadComponentExtensionSwitchBrowserTest,
336 DefunctLoadComponentExtensionFlag) {
337 EXPECT_TRUE(extension_service()->extensions_enabled());
338
339 // Checks that the extensions loaded with the --load-component-extension flag
340 // are not installed.
341 bool is_app_dot_com_extension_installed = false;
342 bool is_app_test_extension_installed = false;
343 for (const scoped_refptr<const extensions::Extension>& extension :
344 GetExtensionRegistry()->enabled_extensions()) {
345 if (extension->name() == "App Dot Com: The App") {
346 is_app_dot_com_extension_installed = true;
347 } else if (extension->name() == "App Test") {
348 is_app_test_extension_installed = true;
349 } else {
350 EXPECT_TRUE(
351 extensions::Manifest::IsComponentLocation(extension->location()));
352 }
353 }
354 EXPECT_FALSE(is_app_dot_com_extension_installed);
355 EXPECT_FALSE(is_app_test_extension_installed);
356}
357
catmullings98cd1942016-08-30 22:31:59358class DisableExtensionsExceptBrowserTest : public ExtensionBrowserTest {
359 public:
360 DisableExtensionsExceptBrowserTest() {}
361
362 void SetUpCommandLine(base::CommandLine* command_line) override;
363
364 ExtensionRegistry* GetExtensionRegistry() {
365 return ExtensionRegistry::Get(browser()->profile());
366 }
367};
368
369void DisableExtensionsExceptBrowserTest::SetUpCommandLine(
370 base::CommandLine* command_line) {
371 ExtensionBrowserTest::SetUpCommandLine(command_line);
372 base::FilePath fp1(test_data_dir_.AppendASCII("app_dot_com_app/"));
373 base::FilePath fp2(test_data_dir_.AppendASCII("app/"));
374
375 command_line->AppendSwitchASCII(
376 switches::kDisableExtensionsExcept,
377 fp1.AsUTF8Unsafe() + "," + fp2.AsUTF8Unsafe());
antrim58769562016-11-14 14:48:41378
379 command_line->AppendSwitch(switches::kNoErrorDialogs);
catmullings98cd1942016-08-30 22:31:59380}
381
382// Tests disabling all extensions except those listed
383// (--disable-extensions-except).
384IN_PROC_BROWSER_TEST_F(DisableExtensionsExceptBrowserTest,
385 DisableExtensionsExceptFlag) {
386 EXPECT_FALSE(extension_service()->extensions_enabled());
387
388 // Checks that the extensions loaded with the --disable-extensions-except flag
389 // are enabled.
390 bool is_app_dot_com_extension_enabled = false;
391 bool is_app_test_extension_enabled = false;
392 for (const scoped_refptr<const extensions::Extension>& extension :
393 GetExtensionRegistry()->enabled_extensions()) {
394 if (extension->name() == "App Dot Com: The App") {
395 is_app_dot_com_extension_enabled = true;
396 } else if (extension->name() == "App Test") {
397 is_app_test_extension_enabled = true;
398 } else {
399 EXPECT_TRUE(
400 extensions::Manifest::IsComponentLocation(extension->location()));
401 }
402 }
403 EXPECT_TRUE(is_app_dot_com_extension_enabled);
404 EXPECT_TRUE(is_app_test_extension_enabled);
405}