blob: 9d75c92a557b16d2bf56476ac431e7b2bd2995fa [file] [log] [blame]
[email protected]29af2012012-01-02 16:28:101// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]25fd1b2e2009-08-17 20:57:142// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "chrome/browser/extensions/extension_apitest.h"
6
avia2f4804a2015-12-24 23:11:137#include <stddef.h>
dcheng1fc00f12015-12-26 22:18:038#include <utility>
avia2f4804a2015-12-24 23:11:139
shrike8fbe9d32015-06-02 19:53:5710#include "base/base_switches.h"
Sebastien Marchandf1349f52019-01-25 03:16:4111#include "base/bind.h"
Devlin Croninb15f7f02018-01-31 19:37:3212#include "base/feature_list.h"
Michael Giuffrida352663b2017-08-04 01:48:5113#include "base/files/file_path.h"
14#include "base/path_service.h"
[email protected]c1dffe82013-06-26 20:59:0515#include "base/strings/string_split.h"
[email protected]00e7bef2013-06-10 20:35:1716#include "base/strings/string_util.h"
17#include "base/strings/stringprintf.h"
avia2f4804a2015-12-24 23:11:1318#include "build/build_config.h"
[email protected]06bdd2b2012-11-30 18:47:1319#include "chrome/browser/extensions/extension_service.h"
[email protected]bbcde9102012-03-25 22:40:4920#include "chrome/browser/extensions/unpacked_installer.h"
21#include "chrome/browser/profiles/profile.h"
[email protected]7b5dc002010-11-16 23:08:1022#include "chrome/browser/ui/browser.h"
cylee49e02a92014-12-01 19:03:3923#include "chrome/browser/ui/extensions/app_launch_params.h"
[email protected]bd507a92012-05-23 08:32:0524#include "chrome/browser/ui/extensions/application_launch.h"
[email protected]af44e7fb2011-07-29 18:32:3225#include "chrome/test/base/ui_test_utils.h"
shrike8fbe9d32015-06-02 19:53:5726#include "content/public/common/content_switches.h"
[email protected]09186d832014-04-04 01:33:3327#include "extensions/browser/api/test/test_api.h"
reillyga3acbc12014-11-11 23:17:1228#include "extensions/browser/extension_registry.h"
[email protected]59b0e602014-01-30 00:41:2429#include "extensions/browser/extension_system.h"
cylee49e02a92014-12-01 19:03:3930#include "extensions/common/constants.h"
[email protected]e4452d32013-11-15 23:07:4131#include "extensions/common/extension.h"
Michael Giuffrida352663b2017-08-04 01:48:5132#include "extensions/common/extension_paths.h"
[email protected]289c44b2013-12-17 03:26:5733#include "extensions/common/extension_set.h"
Devlin Croninb15f7f02018-01-31 19:37:3234#include "extensions/common/feature_switch.h"
alexmos9d656a82015-12-02 02:03:0935#include "extensions/common/switches.h"
yoze8dc2f12014-09-09 23:16:3236#include "extensions/test/result_catcher.h"
[email protected]c1dffe82013-06-26 20:59:0537#include "net/base/escape.h"
[email protected]d96cf752014-04-09 04:05:2838#include "net/base/filename_util.h"
Karandeep Bhatia785b3db8d2019-03-05 05:37:5739#include "net/test/embedded_test_server/default_handlers.h"
[email protected]c1dffe82013-06-26 20:59:0540#include "net/test/embedded_test_server/embedded_test_server.h"
[email protected]c1dffe82013-06-26 20:59:0541#include "net/test/embedded_test_server/http_request.h"
[email protected]e4452d32013-11-15 23:07:4142#include "net/test/embedded_test_server/http_response.h"
Matt Falkenhagen29950eb2019-02-28 23:07:1343#include "net/test/embedded_test_server/request_handler_util.h"
[email protected]89b32522013-05-07 20:04:2144#include "net/test/spawned_test_server/spawned_test_server.h"
[email protected]25fd1b2e2009-08-17 20:57:1445
Devlin Croninef3e37e2018-05-14 23:47:2446namespace extensions {
[email protected]761e7162010-10-18 19:26:3947
Devlin Croninef3e37e2018-05-14 23:47:2448namespace {
Devlin Cronin836f545d2018-05-09 00:25:0549
[email protected]c1d9b2b2013-06-13 19:46:5950const char kTestCustomArg[] = "customArg";
[email protected]8f063362011-11-18 00:32:5351const char kTestDataDirectory[] = "testDataDirectory";
[email protected]8913c612012-03-20 01:04:1552const char kTestWebSocketPort[] = "testWebSocketPort";
[email protected]a0e75792014-03-13 13:12:1753const char kFtpServerPort[] = "ftpServer.port";
svaldeza01f7d92015-11-18 17:47:5654const char kEmbeddedTestServerPort[] = "testServer.port";
[email protected]761e7162010-10-18 19:26:3955
Nico Weber42c88d62019-02-11 03:09:2556} // namespace
[email protected]761e7162010-10-18 19:26:3957
[email protected]c1dffe82013-06-26 20:59:0558ExtensionApiTest::ExtensionApiTest() {
Karandeep Bhatia785b3db8d2019-03-05 05:37:5759 net::test_server::RegisterDefaultHandlers(embedded_test_server());
[email protected]c1dffe82013-06-26 20:59:0560}
[email protected]5322a7f2011-02-11 20:44:4261
Karandeep Bhatia785b3db8d2019-03-05 05:37:5762ExtensionApiTest::~ExtensionApiTest() = default;
[email protected]5322a7f2011-02-11 20:44:4263
naskod81f57c52017-02-15 22:46:4964void ExtensionApiTest::SetUpOnMainThread() {
65 ExtensionBrowserTest::SetUpOnMainThread();
[email protected]761e7162010-10-18 19:26:3966 DCHECK(!test_config_.get()) << "Previous test did not clear config state.";
[email protected]023b3d12013-12-23 18:46:4967 test_config_.reset(new base::DictionaryValue());
[email protected]8f063362011-11-18 00:32:5368 test_config_->SetString(kTestDataDirectory,
69 net::FilePathToFileURL(test_data_dir_).spec());
Karandeep Bhatia785b3db8d2019-03-05 05:37:5770
Rob Wu2649de12018-01-09 22:54:4771 if (embedded_test_server()->Started()) {
72 // InitializeEmbeddedTestServer was called before |test_config_| was set.
73 // Set the missing port key.
74 test_config_->SetInteger(kEmbeddedTestServerPort,
75 embedded_test_server()->port());
76 }
Devlin Cronin242d19d22019-03-12 18:08:4877
Devlin Croninef3e37e2018-05-14 23:47:2478 TestGetConfigFunction::set_test_config_state(test_config_.get());
[email protected]761e7162010-10-18 19:26:3979}
80
naskod81f57c52017-02-15 22:46:4981void ExtensionApiTest::TearDownOnMainThread() {
82 ExtensionBrowserTest::TearDownOnMainThread();
Devlin Croninef3e37e2018-05-14 23:47:2483 TestGetConfigFunction::set_test_config_state(NULL);
[email protected]761e7162010-10-18 19:26:3984 test_config_.reset(NULL);
85}
86
[email protected]41547162013-09-24 04:26:5087bool ExtensionApiTest::RunExtensionTest(const std::string& extension_name) {
[email protected]007b3f82013-04-09 08:46:4588 return RunExtensionTestImpl(
[email protected]c1d9b2b2013-06-13 19:46:5989 extension_name, std::string(), NULL, kFlagEnableFileAccess);
[email protected]a320e512010-09-21 09:58:0190}
91
Michael Giuffrida352663b2017-08-04 01:48:5192bool ExtensionApiTest::RunExtensionTestWithFlags(
93 const std::string& extension_name,
94 int flags) {
95 return RunExtensionTestImpl(extension_name, std::string(), nullptr, flags);
96}
97
dcheng7a9e8362016-04-01 19:09:3198bool ExtensionApiTest::RunExtensionTestWithArg(
99 const std::string& extension_name,
100 const char* custom_arg) {
101 return RunExtensionTestImpl(extension_name, std::string(), custom_arg,
102 kFlagEnableFileAccess);
103}
104
Bettina0660e0872018-12-10 21:03:02105bool ExtensionApiTest::RunExtensionTestWithFlagsAndArg(
106 const std::string& extension_name,
107 const char* custom_arg,
108 int flag) {
109 return RunExtensionTestImpl(extension_name, std::string(), custom_arg, flag);
110}
111
[email protected]41547162013-09-24 04:26:50112bool ExtensionApiTest::RunExtensionTestIncognito(
113 const std::string& extension_name) {
[email protected]007b3f82013-04-09 08:46:45114 return RunExtensionTestImpl(extension_name,
115 std::string(),
[email protected]c1d9b2b2013-06-13 19:46:59116 NULL,
[email protected]007b3f82013-04-09 08:46:45117 kFlagEnableIncognito | kFlagEnableFileAccess);
[email protected]61b55b62011-03-24 09:03:10118}
119
[email protected]24e04292012-08-10 21:08:08120bool ExtensionApiTest::RunExtensionTestIgnoreManifestWarnings(
[email protected]41547162013-09-24 04:26:50121 const std::string& extension_name) {
[email protected]24e04292012-08-10 21:08:08122 return RunExtensionTestImpl(
[email protected]c1d9b2b2013-06-13 19:46:59123 extension_name, std::string(), NULL, kFlagIgnoreManifestWarnings);
[email protected]b7462f32012-09-02 15:18:12124}
125
126bool ExtensionApiTest::RunExtensionTestAllowOldManifestVersion(
[email protected]41547162013-09-24 04:26:50127 const std::string& extension_name) {
[email protected]b7462f32012-09-02 15:18:12128 return RunExtensionTestImpl(
129 extension_name,
[email protected]007b3f82013-04-09 08:46:45130 std::string(),
[email protected]c1d9b2b2013-06-13 19:46:59131 NULL,
[email protected]b7462f32012-09-02 15:18:12132 kFlagEnableFileAccess | kFlagAllowOldManifestVersions);
[email protected]24e04292012-08-10 21:08:08133}
134
[email protected]41547162013-09-24 04:26:50135bool ExtensionApiTest::RunComponentExtensionTest(
136 const std::string& extension_name) {
[email protected]007b3f82013-04-09 08:46:45137 return RunExtensionTestImpl(extension_name,
138 std::string(),
[email protected]c1d9b2b2013-06-13 19:46:59139 NULL,
[email protected]007b3f82013-04-09 08:46:45140 kFlagEnableFileAccess | kFlagLoadAsComponent);
[email protected]ff651392010-07-23 20:21:08141}
[email protected]80d6a4422009-10-15 06:59:22142
[email protected]d84d10b0b2018-11-16 22:17:26143bool ExtensionApiTest::RunComponentExtensionTestWithArg(
144 const std::string& extension_name,
145 const char* custom_arg) {
146 return RunExtensionTestImpl(extension_name, std::string(), custom_arg,
147 kFlagEnableFileAccess | kFlagLoadAsComponent);
148}
149
[email protected]c7c401d2011-03-16 10:20:01150bool ExtensionApiTest::RunExtensionTestNoFileAccess(
[email protected]41547162013-09-24 04:26:50151 const std::string& extension_name) {
[email protected]c1d9b2b2013-06-13 19:46:59152 return RunExtensionTestImpl(extension_name, std::string(), NULL, kFlagNone);
[email protected]c7c401d2011-03-16 10:20:01153}
154
155bool ExtensionApiTest::RunExtensionTestIncognitoNoFileAccess(
[email protected]41547162013-09-24 04:26:50156 const std::string& extension_name) {
[email protected]007b3f82013-04-09 08:46:45157 return RunExtensionTestImpl(
[email protected]c1d9b2b2013-06-13 19:46:59158 extension_name, std::string(), NULL, kFlagEnableIncognito);
[email protected]c7c401d2011-03-16 10:20:01159}
[email protected]d10f4602011-06-16 15:44:50160
[email protected]41547162013-09-24 04:26:50161bool ExtensionApiTest::RunExtensionSubtest(const std::string& extension_name,
[email protected]dd9d6272010-09-09 17:33:18162 const std::string& page_url) {
Ken Rockot0cf16c32018-03-01 16:50:49163 return RunExtensionSubtestWithArgAndFlags(extension_name, page_url, nullptr,
164 kFlagEnableFileAccess);
[email protected]ff651392010-07-23 20:21:08165}
166
[email protected]41547162013-09-24 04:26:50167bool ExtensionApiTest::RunExtensionSubtest(const std::string& extension_name,
[email protected]728a6602012-03-23 19:55:29168 const std::string& page_url,
169 int flags) {
Ken Rockot0cf16c32018-03-01 16:50:49170 return RunExtensionSubtestWithArgAndFlags(extension_name, page_url, nullptr,
171 flags);
172}
173
174bool ExtensionApiTest::RunExtensionSubtestWithArg(
175 const std::string& extension_name,
176 const std::string& page_url,
177 const char* custom_arg) {
178 return RunExtensionSubtestWithArgAndFlags(extension_name, page_url,
179 custom_arg, kFlagEnableFileAccess);
180}
181
182bool ExtensionApiTest::RunExtensionSubtestWithArgAndFlags(
183 const std::string& extension_name,
184 const std::string& page_url,
185 const char* custom_arg,
186 int flags) {
[email protected]22121e32012-03-01 05:24:59187 DCHECK(!page_url.empty()) << "Argument page_url is required.";
Ken Rockot0cf16c32018-03-01 16:50:49188 return RunExtensionTestImpl(extension_name, page_url, custom_arg, flags);
[email protected]22121e32012-03-01 05:24:59189}
190
[email protected]dd9d6272010-09-09 17:33:18191bool ExtensionApiTest::RunPageTest(const std::string& page_url) {
[email protected]41547162013-09-24 04:26:50192 return RunExtensionSubtest(std::string(), page_url);
[email protected]dd9d6272010-09-09 17:33:18193}
[email protected]ff651392010-07-23 20:21:08194
[email protected]95879f12012-04-06 23:59:49195bool ExtensionApiTest::RunPageTest(const std::string& page_url,
196 int flags) {
[email protected]41547162013-09-24 04:26:50197 return RunExtensionSubtest(std::string(), page_url, flags);
[email protected]95879f12012-04-06 23:59:49198}
199
[email protected]41547162013-09-24 04:26:50200bool ExtensionApiTest::RunPlatformAppTest(const std::string& extension_name) {
[email protected]007b3f82013-04-09 08:46:45201 return RunExtensionTestImpl(
[email protected]c1d9b2b2013-06-13 19:46:59202 extension_name, std::string(), NULL, kFlagLaunchPlatformApp);
203}
204
205bool ExtensionApiTest::RunPlatformAppTestWithArg(
[email protected]41547162013-09-24 04:26:50206 const std::string& extension_name, const char* custom_arg) {
lazyboy7d3240ef2016-05-26 03:06:47207 return RunPlatformAppTestWithFlags(extension_name, custom_arg, kFlagNone);
[email protected]863e6472012-01-24 19:33:58208}
209
[email protected]c89ab532013-12-06 12:58:32210bool ExtensionApiTest::RunPlatformAppTestWithFlags(
211 const std::string& extension_name, int flags) {
212 return RunExtensionTestImpl(
213 extension_name, std::string(), NULL, flags | kFlagLaunchPlatformApp);
214}
215
lazyboy7d3240ef2016-05-26 03:06:47216bool ExtensionApiTest::RunPlatformAppTestWithFlags(
217 const std::string& extension_name,
218 const char* custom_arg,
219 int flags) {
220 return RunExtensionTestImpl(extension_name, std::string(), custom_arg,
221 flags | kFlagLaunchPlatformApp);
222}
223
224
[email protected]dd9d6272010-09-09 17:33:18225// Load |extension_name| extension and/or |page_url| and wait for
226// PASSED or FAILED notification.
[email protected]41547162013-09-24 04:26:50227bool ExtensionApiTest::RunExtensionTestImpl(const std::string& extension_name,
[email protected]a320e512010-09-21 09:58:01228 const std::string& page_url,
[email protected]c1d9b2b2013-06-13 19:46:59229 const char* custom_arg,
[email protected]863e6472012-01-24 19:33:58230 int flags) {
[email protected]863e6472012-01-24 19:33:58231 bool load_as_component = (flags & kFlagLoadAsComponent) != 0;
[email protected]dc37b002012-04-23 23:02:26232 bool launch_platform_app = (flags & kFlagLaunchPlatformApp) != 0;
[email protected]728a6602012-03-23 19:55:29233 bool use_incognito = (flags & kFlagUseIncognito) != 0;
Michael Giuffrida352663b2017-08-04 01:48:51234 bool use_root_extensions_dir = (flags & kFlagUseRootExtensionsDir) != 0;
[email protected]863e6472012-01-24 19:33:58235
[email protected]41547162013-09-24 04:26:50236 if (custom_arg && custom_arg[0])
Pavol Markocad963db2018-02-15 11:02:49237 SetCustomArg(custom_arg);
[email protected]c1d9b2b2013-06-13 19:46:59238
Devlin Croninef3e37e2018-05-14 23:47:24239 ResultCatcher catcher;
[email protected]41547162013-09-24 04:26:50240 DCHECK(!extension_name.empty() || !page_url.empty()) <<
[email protected]dd9d6272010-09-09 17:33:18241 "extension_name and page_url cannot both be empty";
[email protected]dd9d6272010-09-09 17:33:18242
Devlin Croninef3e37e2018-05-14 23:47:24243 const Extension* extension = NULL;
[email protected]41547162013-09-24 04:26:50244 if (!extension_name.empty()) {
Michael Giuffrida352663b2017-08-04 01:48:51245 const base::FilePath& root_path =
246 use_root_extensions_dir ? shared_test_data_dir_ : test_data_dir_;
247 base::FilePath extension_path = root_path.AppendASCII(extension_name);
[email protected]61b55b62011-03-24 09:03:10248 if (load_as_component) {
[email protected]863e6472012-01-24 19:33:58249 extension = LoadExtensionAsComponent(extension_path);
[email protected]c7c401d2011-03-16 10:20:01250 } else {
[email protected]24e04292012-08-10 21:08:08251 int browser_test_flags = ExtensionBrowserTest::kFlagNone;
252 if (flags & kFlagEnableIncognito)
253 browser_test_flags |= ExtensionBrowserTest::kFlagEnableIncognito;
254 if (flags & kFlagEnableFileAccess)
255 browser_test_flags |= ExtensionBrowserTest::kFlagEnableFileAccess;
256 if (flags & kFlagIgnoreManifestWarnings)
257 browser_test_flags |= ExtensionBrowserTest::kFlagIgnoreManifestWarnings;
[email protected]b7462f32012-09-02 15:18:12258 if (flags & kFlagAllowOldManifestVersions) {
259 browser_test_flags |=
260 ExtensionBrowserTest::kFlagAllowOldManifestVersions;
261 }
Alexander Hendrich5f6d6a2c2019-05-30 00:45:11262 if (flags & kFlagLoadForLoginScreen)
263 browser_test_flags |= ExtensionBrowserTest::kFlagLoadForLoginScreen;
[email protected]24e04292012-08-10 21:08:08264 extension = LoadExtensionWithFlags(extension_path, browser_test_flags);
[email protected]c7c401d2011-03-16 10:20:01265 }
[email protected]863e6472012-01-24 19:33:58266 if (!extension) {
[email protected]dd9d6272010-09-09 17:33:18267 message_ = "Failed to load extension.";
268 return false;
269 }
[email protected]80d6a4422009-10-15 06:59:22270 }
271
[email protected]dd9d6272010-09-09 17:33:18272 // If there is a page_url to load, navigate it.
273 if (!page_url.empty()) {
274 GURL url = GURL(page_url);
[email protected]ff651392010-07-23 20:21:08275
[email protected]dd9d6272010-09-09 17:33:18276 // Note: We use is_valid() here in the expectation that the provided url
277 // may lack a scheme & host and thus be a relative url within the loaded
278 // extension.
279 if (!url.is_valid()) {
[email protected]41547162013-09-24 04:26:50280 DCHECK(!extension_name.empty()) <<
[email protected]dd9d6272010-09-09 17:33:18281 "Relative page_url given with no extension_name";
282
[email protected]dd9d6272010-09-09 17:33:18283 url = extension->GetResourceURL(page_url);
284 }
285
[email protected]728a6602012-03-23 19:55:29286 if (use_incognito)
erikchenff8b5c7a2015-07-13 23:41:20287 OpenURLOffTheRecord(browser()->profile(), url);
[email protected]728a6602012-03-23 19:55:29288 else
289 ui_test_utils::NavigateToURL(browser(), url);
[email protected]dc37b002012-04-23 23:02:26290 } else if (launch_platform_app) {
Devlin Croninef3e37e2018-05-14 23:47:24291 AppLaunchParams params(browser()->profile(), extension,
292 LAUNCH_CONTAINER_NONE,
293 WindowOpenDisposition::NEW_WINDOW, SOURCE_TEST);
avi3ef9ec9e2014-12-22 22:50:17294 params.command_line = *base::CommandLine::ForCurrentProcess();
[email protected]74b221102013-09-27 12:10:27295 OpenApplication(params);
[email protected]ff651392010-07-23 20:21:08296 }
297
[email protected]80d6a4422009-10-15 06:59:22298 if (!catcher.GetNextResult()) {
299 message_ = catcher.message();
300 return false;
[email protected]80d6a4422009-10-15 06:59:22301 }
[email protected]41547162013-09-24 04:26:50302
303 return true;
[email protected]80d6a4422009-10-15 06:59:22304}
305
[email protected]84df8332011-12-06 18:22:46306// Test that exactly one extension is loaded, and return it.
Devlin Croninef3e37e2018-05-14 23:47:24307const Extension* ExtensionApiTest::GetSingleLoadedExtension() {
308 ExtensionRegistry* registry = ExtensionRegistry::Get(browser()->profile());
[email protected]1952c7d2010-03-04 23:48:34309
Devlin Croninef3e37e2018-05-14 23:47:24310 const Extension* result = NULL;
311 for (const scoped_refptr<const Extension>& extension :
reillyga3acbc12014-11-11 23:17:12312 registry->enabled_extensions()) {
[email protected]1952c7d2010-03-04 23:48:34313 // Ignore any component extensions. They are automatically loaded into all
314 // profiles and aren't the extension we're looking for here.
Devlin Croninef3e37e2018-05-14 23:47:24315 if (extension->location() == Manifest::COMPONENT)
[email protected]1952c7d2010-03-04 23:48:34316 continue;
317
reillyga3acbc12014-11-11 23:17:12318 if (result != NULL) {
[email protected]84df8332011-12-06 18:22:46319 // TODO(yoz): this is misleading; it counts component extensions.
[email protected]18d4b6c2010-09-21 03:21:04320 message_ = base::StringPrintf(
[email protected]1952c7d2010-03-04 23:48:34321 "Expected only one extension to be present. Found %u.",
reillyga3acbc12014-11-11 23:17:12322 static_cast<unsigned>(registry->enabled_extensions().size()));
[email protected]1952c7d2010-03-04 23:48:34323 return NULL;
324 }
325
reillyga3acbc12014-11-11 23:17:12326 result = extension.get();
[email protected]5f9c2492010-02-02 21:37:45327 }
[email protected]1952c7d2010-03-04 23:48:34328
reillyga3acbc12014-11-11 23:17:12329 if (!result) {
[email protected]5f9c2492010-02-02 21:37:45330 message_ = "extension pointer is NULL.";
331 return NULL;
332 }
reillyga3acbc12014-11-11 23:17:12333 return result;
[email protected]5f9c2492010-02-02 21:37:45334}
335
[email protected]c1dffe82013-06-26 20:59:05336bool ExtensionApiTest::StartEmbeddedTestServer() {
martijnf9b885b72016-11-22 22:03:47337 if (!InitializeEmbeddedTestServer())
338 return false;
339
340 EmbeddedTestServerAcceptConnections();
341 return true;
342}
343
344bool ExtensionApiTest::InitializeEmbeddedTestServer() {
345 if (!embedded_test_server()->InitializeAndListen())
[email protected]761e7162010-10-18 19:26:39346 return false;
347
348 // Build a dictionary of values that tests can use to build URLs that
[email protected]8f063362011-11-18 00:32:53349 // access the test server and local file system. Tests can see these values
350 // using the extension API function chrome.test.getConfig().
Rob Wu2649de12018-01-09 22:54:47351 if (test_config_) {
352 test_config_->SetInteger(kEmbeddedTestServerPort,
353 embedded_test_server()->port());
354 }
355 // else SetUpOnMainThread has not been called yet. Possibly because the
356 // caller needs a valid port in an overridden SetUpCommandLine method.
[email protected]761e7162010-10-18 19:26:39357
358 return true;
359}
360
martijnf9b885b72016-11-22 22:03:47361void ExtensionApiTest::EmbeddedTestServerAcceptConnections() {
362 embedded_test_server()->StartAcceptingConnections();
363}
364
[email protected]650b2d52013-02-10 03:41:45365bool ExtensionApiTest::StartWebSocketServer(
pkalinnikov0f198df2017-02-22 11:11:24366 const base::FilePath& root_directory,
367 bool enable_basic_auth) {
[email protected]ce7d0cbc2013-05-03 18:57:22368 websocket_server_.reset(new net::SpawnedTestServer(
Sergey Ulanov9e8d6f32017-08-14 22:12:58369 net::SpawnedTestServer::TYPE_WS, root_directory));
pkalinnikov0f198df2017-02-22 11:11:24370 websocket_server_->set_websocket_basic_auth(enable_basic_auth);
[email protected]0987024782012-10-13 20:52:19371
372 if (!websocket_server_->Start())
[email protected]8913c612012-03-20 01:04:15373 return false;
374
[email protected]0987024782012-10-13 20:52:19375 test_config_->SetInteger(kTestWebSocketPort,
376 websocket_server_->host_port_pair().port());
377
[email protected]8913c612012-03-20 01:04:15378 return true;
379}
380
[email protected]a0e75792014-03-13 13:12:17381bool ExtensionApiTest::StartFTPServer(const base::FilePath& root_directory) {
Sergey Ulanov9e8d6f32017-08-14 22:12:58382 ftp_server_.reset(new net::SpawnedTestServer(net::SpawnedTestServer::TYPE_FTP,
383 root_directory));
[email protected]a0e75792014-03-13 13:12:17384
385 if (!ftp_server_->Start())
386 return false;
387
388 test_config_->SetInteger(kFtpServerPort,
389 ftp_server_->host_port_pair().port());
390
391 return true;
392}
393
Pavol Markocad963db2018-02-15 11:02:49394void ExtensionApiTest::SetCustomArg(base::StringPiece custom_arg) {
395 test_config_->SetKey(kTestCustomArg, base::Value(custom_arg));
396}
397
avi3ef9ec9e2014-12-22 22:50:17398void ExtensionApiTest::SetUpCommandLine(base::CommandLine* command_line) {
[email protected]80d6a4422009-10-15 06:59:22399 ExtensionBrowserTest::SetUpCommandLine(command_line);
Michael Giuffrida352663b2017-08-04 01:48:51400
[email protected]80d6a4422009-10-15 06:59:22401 test_data_dir_ = test_data_dir_.AppendASCII("api_test");
Michael Giuffrida352663b2017-08-04 01:48:51402
Devlin Croninef3e37e2018-05-14 23:47:24403 RegisterPathProvider();
404 base::PathService::Get(DIR_TEST_DATA, &shared_test_data_dir_);
Michael Giuffrida352663b2017-08-04 01:48:51405 shared_test_data_dir_ = shared_test_data_dir_.AppendASCII("api_test");
406
shrike8fbe9d32015-06-02 19:53:57407 // Backgrounded renderer processes run at a lower priority, causing the
408 // tests to take more time to complete. Disable backgrounding so that the
409 // tests don't time out.
Devlin Croninef3e37e2018-05-14 23:47:24410 command_line->AppendSwitch(::switches::kDisableRendererBackgrounding);
[email protected]80d6a4422009-10-15 06:59:22411}
Devlin Croninef3e37e2018-05-14 23:47:24412
413} // namespace extensions