Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(606)

Side by Side Diff: chrome/browser/extensions/extension_apitest.cc

Issue 11087027: WebSocket test server migration on ExtensionApiTest.WebSocket (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add default value for testWebSocketPort Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
22 #include "net/base/net_util.h" 21 #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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 default: 96 default:
97 NOTREACHED(); 97 NOTREACHED();
98 } 98 }
99 } 99 }
100 100
101 void ExtensionApiTest::SetUpInProcessBrowserTestFixture() { 101 void ExtensionApiTest::SetUpInProcessBrowserTestFixture() {
102 DCHECK(!test_config_.get()) << "Previous test did not clear config state."; 102 DCHECK(!test_config_.get()) << "Previous test did not clear config state.";
103 test_config_.reset(new DictionaryValue()); 103 test_config_.reset(new DictionaryValue());
104 test_config_->SetString(kTestDataDirectory, 104 test_config_->SetString(kTestDataDirectory,
105 net::FilePathToFileURL(test_data_dir_).spec()); 105 net::FilePathToFileURL(test_data_dir_).spec());
106 test_config_->SetInteger(kTestWebSocketPort, 0);
106 extensions::TestGetConfigFunction::set_test_config_state( 107 extensions::TestGetConfigFunction::set_test_config_state(
107 test_config_.get()); 108 test_config_.get());
108 } 109 }
109 110
110 void ExtensionApiTest::TearDownInProcessBrowserTestFixture() { 111 void ExtensionApiTest::TearDownInProcessBrowserTestFixture() {
111 extensions::TestGetConfigFunction::set_test_config_state(NULL); 112 extensions::TestGetConfigFunction::set_test_config_state(NULL);
112 test_config_.reset(NULL); 113 test_config_.reset(NULL);
113 } 114 }
114 115
115 bool ExtensionApiTest::RunExtensionTest(const char* extension_name) { 116 bool ExtensionApiTest::RunExtensionTest(const char* extension_name) {
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 // Build a dictionary of values that tests can use to build URLs that 287 // 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 288 // access the test server and local file system. Tests can see these values
288 // using the extension API function chrome.test.getConfig(). 289 // using the extension API function chrome.test.getConfig().
289 test_config_->SetInteger(kTestServerPort, 290 test_config_->SetInteger(kTestServerPort,
290 test_server()->host_port_pair().port()); 291 test_server()->host_port_pair().port());
291 292
292 return true; 293 return true;
293 } 294 }
294 295
295 bool ExtensionApiTest::StartWebSocketServer(const FilePath& root_directory) { 296 bool ExtensionApiTest::StartWebSocketServer(const FilePath& root_directory) {
296 websocket_server_.reset(new content::TestWebSocketServer()); 297 websocket_server_.reset(new net::TestServer(
297 int port = websocket_server_->UseRandomPort(); 298 net::TestServer::TYPE_WS,
298 if (!websocket_server_->Start(root_directory)) 299 net::TestServer::kLocalhost,
300 root_directory));
301
302 if (!websocket_server_->Start())
299 return false; 303 return false;
300 304
301 test_config_->SetInteger(kTestWebSocketPort, port); 305 test_config_->SetInteger(kTestWebSocketPort,
306 websocket_server_->host_port_pair().port());
307
302 return true; 308 return true;
303 } 309 }
304 310
305 void ExtensionApiTest::SetUpCommandLine(CommandLine* command_line) { 311 void ExtensionApiTest::SetUpCommandLine(CommandLine* command_line) {
306 ExtensionBrowserTest::SetUpCommandLine(command_line); 312 ExtensionBrowserTest::SetUpCommandLine(command_line);
307 test_data_dir_ = test_data_dir_.AppendASCII("api_test"); 313 test_data_dir_ = test_data_dir_.AppendASCII("api_test");
308 } 314 }
309 315
310 PlatformAppApiTest::PlatformAppApiTest() {} 316 PlatformAppApiTest::PlatformAppApiTest() {}
311 317
312 PlatformAppApiTest::~PlatformAppApiTest() {} 318 PlatformAppApiTest::~PlatformAppApiTest() {}
313 319
314 void PlatformAppApiTest::SetUpCommandLine(CommandLine* command_line) { 320 void PlatformAppApiTest::SetUpCommandLine(CommandLine* command_line) {
315 ExtensionApiTest::SetUpCommandLine(command_line); 321 ExtensionApiTest::SetUpCommandLine(command_line);
316 322
317 // If someone is using this class, we're going to insist on management of the 323 // If someone is using this class, we're going to insist on management of the
318 // relevant flags. If these flags are already set, die. 324 // relevant flags. If these flags are already set, die.
319 DCHECK(!command_line->HasSwitch(switches::kEnableExperimentalExtensionApis)); 325 DCHECK(!command_line->HasSwitch(switches::kEnableExperimentalExtensionApis));
320 326
321 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis); 327 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis);
322 } 328 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_apitest.h ('k') | chrome/browser/extensions/extension_websocket_apitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698