OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/extensions/extension_apitest.h" | 5 #include "chrome/browser/extensions/extension_apitest.h" |
6 | 6 |
7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
8 #include "base/stringprintf.h" | 8 #include "base/stringprintf.h" |
9 #include "chrome/browser/extensions/extension_service.h" | 9 #include "chrome/browser/extensions/extension_service.h" |
10 #include "chrome/browser/extensions/api/test/test_api.h" | 10 #include "chrome/browser/extensions/api/test/test_api.h" |
11 #include "chrome/browser/extensions/unpacked_installer.h" | 11 #include "chrome/browser/extensions/unpacked_installer.h" |
12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
14 #include "chrome/browser/ui/extensions/application_launch.h" | 14 #include "chrome/browser/ui/extensions/application_launch.h" |
15 #include "chrome/common/chrome_notification_types.h" | 15 #include "chrome/common/chrome_notification_types.h" |
16 #include "chrome/common/chrome_switches.h" | 16 #include "chrome/common/chrome_switches.h" |
17 #include "chrome/common/extensions/extension.h" | 17 #include "chrome/common/extensions/extension.h" |
18 #include "chrome/test/base/ui_test_utils.h" | 18 #include "chrome/test/base/ui_test_utils.h" |
19 #include "content/public/browser/notification_registrar.h" | 19 #include "content/public/browser/notification_registrar.h" |
20 #include "content/public/browser/notification_service.h" | 20 #include "content/public/browser/notification_service.h" |
| 21 #include "content/public/test/browser_test_utils.h" |
21 #include "net/base/net_util.h" | 22 #include "net/base/net_util.h" |
22 #include "net/test/test_server.h" | |
23 | 23 |
24 namespace { | 24 namespace { |
25 | 25 |
26 const char kTestServerPort[] = "testServer.port"; | 26 const char kTestServerPort[] = "testServer.port"; |
27 const char kTestDataDirectory[] = "testDataDirectory"; | 27 const char kTestDataDirectory[] = "testDataDirectory"; |
28 const char kTestWebSocketPort[] = "testWebSocketPort"; | 28 const char kTestWebSocketPort[] = "testWebSocketPort"; |
29 | 29 |
30 }; // namespace | 30 }; // namespace |
31 | 31 |
32 ExtensionApiTest::ExtensionApiTest() {} | 32 ExtensionApiTest::ExtensionApiTest() {} |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 // Build a dictionary of values that tests can use to build URLs that | 286 // Build a dictionary of values that tests can use to build URLs that |
287 // access the test server and local file system. Tests can see these values | 287 // access the test server and local file system. Tests can see these values |
288 // using the extension API function chrome.test.getConfig(). | 288 // using the extension API function chrome.test.getConfig(). |
289 test_config_->SetInteger(kTestServerPort, | 289 test_config_->SetInteger(kTestServerPort, |
290 test_server()->host_port_pair().port()); | 290 test_server()->host_port_pair().port()); |
291 | 291 |
292 return true; | 292 return true; |
293 } | 293 } |
294 | 294 |
295 bool ExtensionApiTest::StartWebSocketServer(const FilePath& root_directory) { | 295 bool ExtensionApiTest::StartWebSocketServer(const FilePath& root_directory) { |
296 websocket_server_.reset(new net::TestServer( | 296 websocket_server_.reset(new content::TestWebSocketServer()); |
297 net::TestServer::TYPE_WS, | 297 int port = websocket_server_->UseRandomPort(); |
298 net::TestServer::kLocalhost, | 298 if (!websocket_server_->Start(root_directory)) |
299 root_directory)); | |
300 | |
301 if (!websocket_server_->Start()) | |
302 return false; | 299 return false; |
303 | 300 |
304 test_config_->SetInteger(kTestWebSocketPort, | 301 test_config_->SetInteger(kTestWebSocketPort, port); |
305 websocket_server_->host_port_pair().port()); | |
306 | |
307 return true; | 302 return true; |
308 } | 303 } |
309 | 304 |
310 void ExtensionApiTest::SetUpCommandLine(CommandLine* command_line) { | 305 void ExtensionApiTest::SetUpCommandLine(CommandLine* command_line) { |
311 ExtensionBrowserTest::SetUpCommandLine(command_line); | 306 ExtensionBrowserTest::SetUpCommandLine(command_line); |
312 test_data_dir_ = test_data_dir_.AppendASCII("api_test"); | 307 test_data_dir_ = test_data_dir_.AppendASCII("api_test"); |
313 } | 308 } |
314 | 309 |
315 PlatformAppApiTest::PlatformAppApiTest() {} | 310 PlatformAppApiTest::PlatformAppApiTest() {} |
316 | 311 |
317 PlatformAppApiTest::~PlatformAppApiTest() {} | 312 PlatformAppApiTest::~PlatformAppApiTest() {} |
318 | 313 |
319 void PlatformAppApiTest::SetUpCommandLine(CommandLine* command_line) { | 314 void PlatformAppApiTest::SetUpCommandLine(CommandLine* command_line) { |
320 ExtensionApiTest::SetUpCommandLine(command_line); | 315 ExtensionApiTest::SetUpCommandLine(command_line); |
321 | 316 |
322 // If someone is using this class, we're going to insist on management of the | 317 // If someone is using this class, we're going to insist on management of the |
323 // relevant flags. If these flags are already set, die. | 318 // relevant flags. If these flags are already set, die. |
324 DCHECK(!command_line->HasSwitch(switches::kEnableExperimentalExtensionApis)); | 319 DCHECK(!command_line->HasSwitch(switches::kEnableExperimentalExtensionApis)); |
325 | 320 |
326 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis); | 321 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis); |
327 } | 322 } |
OLD | NEW |