OLD | NEW |
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_test_utils.h" | 5 #include "chrome/test/ui_test_utils.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
743 } | 743 } |
744 | 744 |
745 } // anonymous namespace | 745 } // anonymous namespace |
746 | 746 |
747 TestWebSocketServer::TestWebSocketServer() : started_(false) { | 747 TestWebSocketServer::TestWebSocketServer() : started_(false) { |
748 } | 748 } |
749 | 749 |
750 bool TestWebSocketServer::Start(const FilePath& root_directory) { | 750 bool TestWebSocketServer::Start(const FilePath& root_directory) { |
751 if (started_) | 751 if (started_) |
752 return true; | 752 return true; |
| 753 // Append CommandLine arguments after the server script, switches won't work. |
753 scoped_ptr<CommandLine> cmd_line(CreateWebSocketServerCommandLine()); | 754 scoped_ptr<CommandLine> cmd_line(CreateWebSocketServerCommandLine()); |
754 cmd_line->AppendSwitchASCII("server", "start"); | 755 cmd_line->AppendArg("--server=start"); |
755 cmd_line->AppendSwitch("chromium"); | 756 cmd_line->AppendArg("--chromium"); |
756 cmd_line->AppendSwitch("register_cygwin"); | 757 cmd_line->AppendArg("--register_cygwin"); |
757 cmd_line->AppendSwitchPath("root", root_directory); | 758 cmd_line->AppendArgNative(FILE_PATH_LITERAL("--root=") + |
| 759 root_directory.value()); |
758 if (!temp_dir_.CreateUniqueTempDir()) { | 760 if (!temp_dir_.CreateUniqueTempDir()) { |
759 LOG(ERROR) << "Unable to create a temporary directory."; | 761 LOG(ERROR) << "Unable to create a temporary directory."; |
760 return false; | 762 return false; |
761 } | 763 } |
762 websocket_pid_file_ = temp_dir_.path().AppendASCII("websocket.pid"); | 764 websocket_pid_file_ = temp_dir_.path().AppendASCII("websocket.pid"); |
763 cmd_line->AppendSwitchPath("pidfile", websocket_pid_file_); | 765 cmd_line->AppendArgNative(FILE_PATH_LITERAL("--pidfile=") + |
| 766 websocket_pid_file_.value()); |
764 SetPythonPath(); | 767 SetPythonPath(); |
765 if (!base::LaunchApp(*cmd_line.get(), true, false, NULL)) { | 768 if (!base::LaunchApp(*cmd_line.get(), true, false, NULL)) { |
766 LOG(ERROR) << "Unable to launch websocket server."; | 769 LOG(ERROR) << "Unable to launch websocket server."; |
767 return false; | 770 return false; |
768 } | 771 } |
769 started_ = true; | 772 started_ = true; |
770 return true; | 773 return true; |
771 } | 774 } |
772 | 775 |
773 CommandLine* TestWebSocketServer::CreatePythonCommandLine() { | 776 CommandLine* TestWebSocketServer::CreatePythonCommandLine() { |
| 777 // Note: Python's first argument must be the script; do not append CommandLine |
| 778 // switches, as they would precede the script path and break this CommandLine. |
774 return new CommandLine(FilePath(FILE_PATH_LITERAL("python"))); | 779 return new CommandLine(FilePath(FILE_PATH_LITERAL("python"))); |
775 } | 780 } |
776 | 781 |
777 void TestWebSocketServer::SetPythonPath() { | 782 void TestWebSocketServer::SetPythonPath() { |
778 FilePath scripts_path; | 783 FilePath scripts_path; |
779 PathService::Get(base::DIR_SOURCE_ROOT, &scripts_path); | 784 PathService::Get(base::DIR_SOURCE_ROOT, &scripts_path); |
780 | 785 |
781 scripts_path = scripts_path | 786 scripts_path = scripts_path |
782 .Append(FILE_PATH_LITERAL("third_party")) | 787 .Append(FILE_PATH_LITERAL("third_party")) |
783 .Append(FILE_PATH_LITERAL("WebKit")) | 788 .Append(FILE_PATH_LITERAL("WebKit")) |
(...skipping 15 matching lines...) Expand all Loading... |
799 script_path = script_path.AppendASCII("new-run-webkit-websocketserver"); | 804 script_path = script_path.AppendASCII("new-run-webkit-websocketserver"); |
800 | 805 |
801 CommandLine* cmd_line = CreatePythonCommandLine(); | 806 CommandLine* cmd_line = CreatePythonCommandLine(); |
802 cmd_line->AppendArgPath(script_path); | 807 cmd_line->AppendArgPath(script_path); |
803 return cmd_line; | 808 return cmd_line; |
804 } | 809 } |
805 | 810 |
806 TestWebSocketServer::~TestWebSocketServer() { | 811 TestWebSocketServer::~TestWebSocketServer() { |
807 if (!started_) | 812 if (!started_) |
808 return; | 813 return; |
| 814 // Append CommandLine arguments after the server script, switches won't work. |
809 scoped_ptr<CommandLine> cmd_line(CreateWebSocketServerCommandLine()); | 815 scoped_ptr<CommandLine> cmd_line(CreateWebSocketServerCommandLine()); |
810 cmd_line->AppendSwitchASCII("server", "stop"); | 816 cmd_line->AppendArg("--server=stop"); |
811 cmd_line->AppendSwitch("chromium"); | 817 cmd_line->AppendArg("--chromium"); |
812 cmd_line->AppendSwitchPath("pidfile", websocket_pid_file_); | 818 cmd_line->AppendArgNative(FILE_PATH_LITERAL("--pidfile=") + |
| 819 websocket_pid_file_.value()); |
813 base::LaunchApp(*cmd_line.get(), true, false, NULL); | 820 base::LaunchApp(*cmd_line.get(), true, false, NULL); |
814 } | 821 } |
815 | 822 |
816 TestNotificationObserver::TestNotificationObserver() | 823 TestNotificationObserver::TestNotificationObserver() |
817 : source_(NotificationService::AllSources()) { | 824 : source_(NotificationService::AllSources()) { |
818 } | 825 } |
819 | 826 |
820 TestNotificationObserver::~TestNotificationObserver() {} | 827 TestNotificationObserver::~TestNotificationObserver() {} |
821 | 828 |
822 void TestNotificationObserver::Observe(NotificationType type, | 829 void TestNotificationObserver::Observe(NotificationType type, |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
980 return taker.TakeRenderWidgetSnapshot(rwh, page_size, page_size, bitmap); | 987 return taker.TakeRenderWidgetSnapshot(rwh, page_size, page_size, bitmap); |
981 } | 988 } |
982 | 989 |
983 bool TakeEntirePageSnapshot(RenderViewHost* rvh, SkBitmap* bitmap) { | 990 bool TakeEntirePageSnapshot(RenderViewHost* rvh, SkBitmap* bitmap) { |
984 DCHECK(bitmap); | 991 DCHECK(bitmap); |
985 SnapshotTaker taker; | 992 SnapshotTaker taker; |
986 return taker.TakeEntirePageSnapshot(rvh, bitmap); | 993 return taker.TakeEntirePageSnapshot(rvh, bitmap); |
987 } | 994 } |
988 | 995 |
989 } // namespace ui_test_utils | 996 } // namespace ui_test_utils |
OLD | NEW |