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

Side by Side Diff: chrome/test/ui/ui_test.cc

Issue 6526040: CommandLine refactoring and cleanup. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Nix program_path_, add and update comments. Created 9 years, 7 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/test/ui/ui_test.h" 5 #include "chrome/test/ui/ui_test.h"
6 6
7 #if defined(OS_POSIX) 7 #if defined(OS_POSIX)
8 #include <signal.h> 8 #include <signal.h>
9 #include <sys/types.h> 9 #include <sys/types.h>
10 #endif 10 #endif
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 } 515 }
516 516
517 ProxyLauncher* UITest::CreateProxyLauncher() { 517 ProxyLauncher* UITest::CreateProxyLauncher() {
518 // Make the AutomationProxy disconnect the channel on the first error, 518 // Make the AutomationProxy disconnect the channel on the first error,
519 // so that we avoid spending a lot of time in timeouts. The browser is likely 519 // so that we avoid spending a lot of time in timeouts. The browser is likely
520 // hosed if we hit those errors. 520 // hosed if we hit those errors.
521 return new AnonymousProxyLauncher(true); 521 return new AnonymousProxyLauncher(true);
522 } 522 }
523 523
524 static CommandLine* CreatePythonCommandLine() { 524 static CommandLine* CreatePythonCommandLine() {
525 // Note: Python's first argument must be the script; do not append CommandLine
526 // switches, as they would precede the script path and break this CommandLine.
525 return new CommandLine(FilePath(FILE_PATH_LITERAL("python"))); 527 return new CommandLine(FilePath(FILE_PATH_LITERAL("python")));
526 } 528 }
527 529
528 static CommandLine* CreateHttpServerCommandLine() { 530 static CommandLine* CreateHttpServerCommandLine() {
529 FilePath src_path; 531 FilePath src_path;
530 // Get to 'src' dir. 532 // Get to 'src' dir.
531 PathService::Get(base::DIR_SOURCE_ROOT, &src_path); 533 PathService::Get(base::DIR_SOURCE_ROOT, &src_path);
532 534
533 FilePath script_path(src_path); 535 FilePath script_path(src_path);
534 script_path = script_path.AppendASCII("third_party"); 536 script_path = script_path.AppendASCII("third_party");
535 script_path = script_path.AppendASCII("WebKit"); 537 script_path = script_path.AppendASCII("WebKit");
536 script_path = script_path.AppendASCII("Tools"); 538 script_path = script_path.AppendASCII("Tools");
537 script_path = script_path.AppendASCII("Scripts"); 539 script_path = script_path.AppendASCII("Scripts");
538 script_path = script_path.AppendASCII("new-run-webkit-httpd"); 540 script_path = script_path.AppendASCII("new-run-webkit-httpd");
539 541
540 CommandLine* cmd_line = CreatePythonCommandLine(); 542 CommandLine* cmd_line = CreatePythonCommandLine();
541 cmd_line->AppendArgPath(script_path); 543 cmd_line->AppendArgPath(script_path);
542 return cmd_line; 544 return cmd_line;
543 } 545 }
544 546
545 void UITest::StartHttpServer(const FilePath& root_directory) { 547 void UITest::StartHttpServer(const FilePath& root_directory) {
546 StartHttpServerWithPort(root_directory, 0); 548 StartHttpServerWithPort(root_directory, 0);
547 } 549 }
548 550
549 void UITest::StartHttpServerWithPort(const FilePath& root_directory, 551 void UITest::StartHttpServerWithPort(const FilePath& root_directory,
550 int port) { 552 int port) {
553 // Append CommandLine arguments after the server script, switches won't work.
551 scoped_ptr<CommandLine> cmd_line(CreateHttpServerCommandLine()); 554 scoped_ptr<CommandLine> cmd_line(CreateHttpServerCommandLine());
552 ASSERT_TRUE(cmd_line.get()); 555 ASSERT_TRUE(cmd_line.get());
553 cmd_line->AppendSwitchASCII("server", "start"); 556 cmd_line->AppendArg("--server=start");
554 cmd_line->AppendSwitch("register_cygwin"); 557 cmd_line->AppendArg("--register_cygwin");
555 cmd_line->AppendSwitchPath("root", root_directory); 558 cmd_line->AppendArgNative(FILE_PATH_LITERAL("--root=") +
559 root_directory.value());
556 560
557 FilePath layout_tests_dir; 561 FilePath layout_tests_dir;
558 PathService::Get(base::DIR_SOURCE_ROOT, &layout_tests_dir); 562 PathService::Get(base::DIR_SOURCE_ROOT, &layout_tests_dir);
559 layout_tests_dir = layout_tests_dir.AppendASCII("chrome") 563 layout_tests_dir = layout_tests_dir.AppendASCII("chrome")
560 .AppendASCII("test") 564 .AppendASCII("test")
561 .AppendASCII("data") 565 .AppendASCII("data")
562 .AppendASCII("layout_tests") 566 .AppendASCII("layout_tests")
563 .AppendASCII("LayoutTests"); 567 .AppendASCII("LayoutTests");
564 cmd_line->AppendSwitchPath("layout_tests_dir", layout_tests_dir); 568 cmd_line->AppendArgNative(FILE_PATH_LITERAL("--layout_tests_dir=") +
569 layout_tests_dir.value());
565 570
566 // For Windows 7, if we start the lighttpd server on the foreground mode, 571 // For Windows 7, if we start the lighttpd server on the foreground mode,
567 // it will mess up with the command window and cause conhost.exe to crash. To 572 // it will mess up with the command window and cause conhost.exe to crash. To
568 // work around this, we start the http server on the background mode. 573 // work around this, we start the http server on the background mode.
569 #if defined(OS_WIN) 574 #if defined(OS_WIN)
570 if (base::win::GetVersion() >= base::win::VERSION_WIN7) 575 if (base::win::GetVersion() >= base::win::VERSION_WIN7)
571 cmd_line->AppendSwitch("run_background"); 576 cmd_line->AppendArg("--run_background");
572 #endif 577 #endif
573 578
574 if (port) 579 if (port)
575 cmd_line->AppendSwitchASCII("port", base::IntToString(port)); 580 cmd_line->AppendArg("--port=" + base::IntToString(port));
576 581
577 #if defined(OS_WIN) 582 #if defined(OS_WIN)
578 // TODO(phajdan.jr): is this needed? 583 // TODO(phajdan.jr): is this needed?
579 base::LaunchAppWithHandleInheritance(cmd_line->command_line_string(), 584 base::LaunchAppWithHandleInheritance(cmd_line->command_line_string(),
580 true, 585 true,
581 false, 586 false,
582 NULL); 587 NULL);
583 #else 588 #else
584 base::LaunchApp(*cmd_line.get(), true, false, NULL); 589 base::LaunchApp(*cmd_line.get(), true, false, NULL);
585 #endif 590 #endif
586 } 591 }
587 592
588 void UITest::StopHttpServer() { 593 void UITest::StopHttpServer() {
594 // Append CommandLine arguments after the server script, switches won't work.
589 scoped_ptr<CommandLine> cmd_line(CreateHttpServerCommandLine()); 595 scoped_ptr<CommandLine> cmd_line(CreateHttpServerCommandLine());
590 ASSERT_TRUE(cmd_line.get()); 596 ASSERT_TRUE(cmd_line.get());
591 cmd_line->AppendSwitchASCII("server", "stop"); 597 cmd_line->AppendArg("--server=stop");
592 598
593 #if defined(OS_WIN) 599 #if defined(OS_WIN)
594 // TODO(phajdan.jr): is this needed? 600 // TODO(phajdan.jr): is this needed?
595 base::LaunchAppWithHandleInheritance(cmd_line->command_line_string(), 601 base::LaunchAppWithHandleInheritance(cmd_line->command_line_string(),
596 true, 602 true,
597 false, 603 false,
598 NULL); 604 NULL);
599 #else 605 #else
600 base::LaunchApp(*cmd_line.get(), true, false, NULL); 606 base::LaunchApp(*cmd_line.get(), true, false, NULL);
601 #endif 607 #endif
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
839 base::PlatformThread::Sleep(TestTimeouts::action_timeout_ms() / kCycles); 845 base::PlatformThread::Sleep(TestTimeouts::action_timeout_ms() / kCycles);
840 } 846 }
841 847
842 LOG(INFO) << "Elapsed time: " << (base::Time::Now() - start).InSecondsF() 848 LOG(INFO) << "Elapsed time: " << (base::Time::Now() - start).InSecondsF()
843 << " seconds" 849 << " seconds"
844 << " call failed " << fail_count << " times" 850 << " call failed " << fail_count << " times"
845 << " state was incorrect " << incorrect_state_count << " times"; 851 << " state was incorrect " << incorrect_state_count << " times";
846 ADD_FAILURE() << "Timeout reached in " << __FUNCTION__; 852 ADD_FAILURE() << "Timeout reached in " << __FUNCTION__;
847 return false; 853 return false;
848 } 854 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698