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

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

Issue 1409163006: Migrating tests to use EmbeddedTestServer (/chrome/browser misc) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 5 years, 1 month 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
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/base_switches.h" 7 #include "base/base_switches.h"
8 #include "base/strings/string_split.h" 8 #include "base/strings/string_split.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
(...skipping 15 matching lines...) Expand all
26 #include "net/base/escape.h" 26 #include "net/base/escape.h"
27 #include "net/base/filename_util.h" 27 #include "net/base/filename_util.h"
28 #include "net/test/embedded_test_server/embedded_test_server.h" 28 #include "net/test/embedded_test_server/embedded_test_server.h"
29 #include "net/test/embedded_test_server/http_request.h" 29 #include "net/test/embedded_test_server/http_request.h"
30 #include "net/test/embedded_test_server/http_response.h" 30 #include "net/test/embedded_test_server/http_response.h"
31 #include "net/test/spawned_test_server/spawned_test_server.h" 31 #include "net/test/spawned_test_server/spawned_test_server.h"
32 32
33 namespace { 33 namespace {
34 34
35 const char kTestCustomArg[] = "customArg"; 35 const char kTestCustomArg[] = "customArg";
36 const char kTestServerPort[] = "testServer.port";
37 const char kTestDataDirectory[] = "testDataDirectory"; 36 const char kTestDataDirectory[] = "testDataDirectory";
38 const char kTestWebSocketPort[] = "testWebSocketPort"; 37 const char kTestWebSocketPort[] = "testWebSocketPort";
39 const char kSitePerProcess[] = "sitePerProcess"; 38 const char kSitePerProcess[] = "sitePerProcess";
40 const char kFtpServerPort[] = "ftpServer.port"; 39 const char kFtpServerPort[] = "ftpServer.port";
41 const char kSpawnedTestServerPort[] = "spawnedTestServer.port"; 40 const char kEmbeddedTestServerPort[] = "testServer.port";
42 41
43 scoped_ptr<net::test_server::HttpResponse> HandleServerRedirectRequest( 42 scoped_ptr<net::test_server::HttpResponse> HandleServerRedirectRequest(
44 const net::test_server::HttpRequest& request) { 43 const net::test_server::HttpRequest& request) {
45 if (!base::StartsWith(request.relative_url, "/server-redirect?", 44 if (!base::StartsWith(request.relative_url, "/server-redirect?",
46 base::CompareCase::SENSITIVE)) 45 base::CompareCase::SENSITIVE))
47 return nullptr; 46 return nullptr;
48 47
49 size_t query_string_pos = request.relative_url.find('?'); 48 size_t query_string_pos = request.relative_url.find('?');
50 std::string redirect_target = 49 std::string redirect_target =
51 request.relative_url.substr(query_string_pos + 1); 50 request.relative_url.substr(query_string_pos + 1);
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 } 362 }
364 363
365 if (!result) { 364 if (!result) {
366 message_ = "extension pointer is NULL."; 365 message_ = "extension pointer is NULL.";
367 return NULL; 366 return NULL;
368 } 367 }
369 return result; 368 return result;
370 } 369 }
371 370
372 bool ExtensionApiTest::StartEmbeddedTestServer() { 371 bool ExtensionApiTest::StartEmbeddedTestServer() {
373 if (!embedded_test_server()->InitializeAndWaitUntilReady()) 372 if (!embedded_test_server()->Start())
374 return false; 373 return false;
375 374
376 // Build a dictionary of values that tests can use to build URLs that 375 // Build a dictionary of values that tests can use to build URLs that
377 // access the test server and local file system. Tests can see these values 376 // access the test server and local file system. Tests can see these values
378 // using the extension API function chrome.test.getConfig(). 377 // using the extension API function chrome.test.getConfig().
379 test_config_->SetInteger(kTestServerPort, 378 test_config_->SetInteger(kEmbeddedTestServerPort,
380 embedded_test_server()->port()); 379 embedded_test_server()->port());
381 380
382 return true; 381 return true;
383 } 382 }
384 383
385 bool ExtensionApiTest::StartWebSocketServer( 384 bool ExtensionApiTest::StartWebSocketServer(
386 const base::FilePath& root_directory) { 385 const base::FilePath& root_directory) {
387 websocket_server_.reset(new net::SpawnedTestServer( 386 websocket_server_.reset(new net::SpawnedTestServer(
388 net::SpawnedTestServer::TYPE_WS, 387 net::SpawnedTestServer::TYPE_WS,
389 net::SpawnedTestServer::kLocalhost, 388 net::SpawnedTestServer::kLocalhost,
(...skipping 16 matching lines...) Expand all
406 405
407 if (!ftp_server_->Start()) 406 if (!ftp_server_->Start())
408 return false; 407 return false;
409 408
410 test_config_->SetInteger(kFtpServerPort, 409 test_config_->SetInteger(kFtpServerPort,
411 ftp_server_->host_port_pair().port()); 410 ftp_server_->host_port_pair().port());
412 411
413 return true; 412 return true;
414 } 413 }
415 414
416 bool ExtensionApiTest::StartSpawnedTestServer() {
417 if (!test_server()->Start())
418 return false;
419
420 // Build a dictionary of values that tests can use to build URLs that
421 // access the test server and local file system. Tests can see these values
422 // using the extension API function chrome.test.getConfig().
423 test_config_->SetInteger(kSpawnedTestServerPort,
424 test_server()->host_port_pair().port());
425
426 return true;
427 }
428
429 void ExtensionApiTest::SetUpCommandLine(base::CommandLine* command_line) { 415 void ExtensionApiTest::SetUpCommandLine(base::CommandLine* command_line) {
430 ExtensionBrowserTest::SetUpCommandLine(command_line); 416 ExtensionBrowserTest::SetUpCommandLine(command_line);
431 test_data_dir_ = test_data_dir_.AppendASCII("api_test"); 417 test_data_dir_ = test_data_dir_.AppendASCII("api_test");
432 // Backgrounded renderer processes run at a lower priority, causing the 418 // Backgrounded renderer processes run at a lower priority, causing the
433 // tests to take more time to complete. Disable backgrounding so that the 419 // tests to take more time to complete. Disable backgrounding so that the
434 // tests don't time out. 420 // tests don't time out.
435 command_line->AppendSwitch(switches::kDisableRendererBackgrounding); 421 command_line->AppendSwitch(switches::kDisableRendererBackgrounding);
436 } 422 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_apitest.h ('k') | chrome/browser/extensions/extension_keybinding_apitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698