| 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/base/ui_test_utils.h" | 5 #include "chrome/test/base/ui_test_utils.h" |
| 6 | 6 |
| 7 #if defined(OS_WIN) |
| 8 #include <windows.h> |
| 9 #endif |
| 10 |
| 7 #include <vector> | 11 #include <vector> |
| 8 | 12 |
| 9 #include "base/bind.h" | 13 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 14 #include "base/bind_helpers.h" |
| 11 #include "base/callback.h" | 15 #include "base/callback.h" |
| 12 #include "base/command_line.h" | 16 #include "base/command_line.h" |
| 13 #include "base/file_path.h" | 17 #include "base/file_path.h" |
| 14 #include "base/json/json_reader.h" | 18 #include "base/json/json_reader.h" |
| 15 #include "base/memory/scoped_ptr.h" | 19 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/message_loop.h" | 20 #include "base/message_loop.h" |
| 17 #include "base/path_service.h" | 21 #include "base/path_service.h" |
| 18 #include "base/process_util.h" | 22 #include "base/process_util.h" |
| 23 #include "base/string_number_conversions.h" |
| 19 #include "base/utf_string_conversions.h" | 24 #include "base/utf_string_conversions.h" |
| 20 #include "base/values.h" | 25 #include "base/values.h" |
| 21 #include "chrome/browser/automation/ui_controls.h" | 26 #include "chrome/browser/automation/ui_controls.h" |
| 22 #include "chrome/browser/bookmarks/bookmark_model.h" | 27 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 23 #include "chrome/browser/browser_process.h" | 28 #include "chrome/browser/browser_process.h" |
| 24 #include "chrome/browser/dom_operation_notification_details.h" | 29 #include "chrome/browser/dom_operation_notification_details.h" |
| 25 #include "chrome/browser/profiles/profile.h" | 30 #include "chrome/browser/profiles/profile.h" |
| 26 #include "chrome/browser/search_engines/template_url_service.h" | 31 #include "chrome/browser/search_engines/template_url_service.h" |
| 27 #include "chrome/browser/search_engines/template_url_service_test_util.h" | 32 #include "chrome/browser/search_engines/template_url_service_test_util.h" |
| 28 #include "chrome/browser/tab_contents/thumbnail_generator.h" | 33 #include "chrome/browser/tab_contents/thumbnail_generator.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 55 #include "ui/gfx/size.h" | 60 #include "ui/gfx/size.h" |
| 56 | 61 |
| 57 #if defined(TOOLKIT_VIEWS) | 62 #if defined(TOOLKIT_VIEWS) |
| 58 #include "ui/views/focus/accelerator_handler.h" | 63 #include "ui/views/focus/accelerator_handler.h" |
| 59 #endif | 64 #endif |
| 60 | 65 |
| 61 #if defined(USE_AURA) | 66 #if defined(USE_AURA) |
| 62 #include "ui/aura/desktop.h" | 67 #include "ui/aura/desktop.h" |
| 63 #endif | 68 #endif |
| 64 | 69 |
| 70 static const int kDefaultWsPort = 8880; |
| 71 |
| 65 namespace ui_test_utils { | 72 namespace ui_test_utils { |
| 66 | 73 |
| 67 namespace { | 74 namespace { |
| 68 | 75 |
| 69 class DOMOperationObserver : public content::NotificationObserver { | 76 class DOMOperationObserver : public content::NotificationObserver { |
| 70 public: | 77 public: |
| 71 explicit DOMOperationObserver(RenderViewHost* render_view_host) | 78 explicit DOMOperationObserver(RenderViewHost* render_view_host) |
| 72 : did_respond_(false) { | 79 : did_respond_(false) { |
| 73 registrar_.Add(this, chrome::NOTIFICATION_DOM_OPERATION_RESPONSE, | 80 registrar_.Add(this, chrome::NOTIFICATION_DOM_OPERATION_RESPONSE, |
| 74 content::Source<RenderViewHost>(render_view_host)); | 81 content::Source<RenderViewHost>(render_view_host)); |
| (...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 720 std::string newpath(oldpath); | 727 std::string newpath(oldpath); |
| 721 newpath.append(":"); | 728 newpath.append(":"); |
| 722 newpath.append(dir.value()); | 729 newpath.append(dir.value()); |
| 723 setenv(kPythonPath, newpath.c_str(), 1); | 730 setenv(kPythonPath, newpath.c_str(), 1); |
| 724 } | 731 } |
| 725 #endif | 732 #endif |
| 726 } | 733 } |
| 727 | 734 |
| 728 } // anonymous namespace | 735 } // anonymous namespace |
| 729 | 736 |
| 730 TestWebSocketServer::TestWebSocketServer() : started_(false) { | 737 TestWebSocketServer::TestWebSocketServer() |
| 738 : started_(false) { |
| 739 #if defined(OS_POSIX) |
| 740 process_handle_ = base::kNullProcessHandle; |
| 741 #endif |
| 731 } | 742 } |
| 732 | 743 |
| 733 bool TestWebSocketServer::Start(const FilePath& root_directory) { | 744 bool TestWebSocketServer::Start(const FilePath& root_directory) { |
| 734 if (started_) | 745 if (started_) |
| 735 return true; | 746 return true; |
| 736 // Append CommandLine arguments after the server script, switches won't work. | 747 // Append CommandLine arguments after the server script, switches won't work. |
| 737 scoped_ptr<CommandLine> cmd_line(CreateWebSocketServerCommandLine()); | 748 scoped_ptr<CommandLine> cmd_line(CreateWebSocketServerCommandLine()); |
| 738 cmd_line->AppendArg("--server=start"); | 749 cmd_line->AppendArg("--server=start"); |
| 739 cmd_line->AppendArg("--chromium"); | 750 cmd_line->AppendArg("--chromium"); |
| 740 cmd_line->AppendArg("--register_cygwin"); | 751 cmd_line->AppendArg("--register_cygwin"); |
| 741 cmd_line->AppendArgNative(FILE_PATH_LITERAL("--root=") + | 752 cmd_line->AppendArgNative(FILE_PATH_LITERAL("--root=") + |
| 742 root_directory.value()); | 753 root_directory.value()); |
| 754 cmd_line->AppendArg("--port=" + base::IntToString(kDefaultWsPort)); |
| 743 if (!temp_dir_.CreateUniqueTempDir()) { | 755 if (!temp_dir_.CreateUniqueTempDir()) { |
| 744 LOG(ERROR) << "Unable to create a temporary directory."; | 756 LOG(ERROR) << "Unable to create a temporary directory."; |
| 745 return false; | 757 return false; |
| 746 } | 758 } |
| 747 websocket_pid_file_ = temp_dir_.path().AppendASCII("websocket.pid"); | 759 websocket_pid_file_ = temp_dir_.path().AppendASCII("websocket.pid"); |
| 748 cmd_line->AppendArgNative(FILE_PATH_LITERAL("--pidfile=") + | 760 cmd_line->AppendArgNative(FILE_PATH_LITERAL("--pidfile=") + |
| 749 websocket_pid_file_.value()); | 761 websocket_pid_file_.value()); |
| 750 SetPythonPath(); | 762 SetPythonPath(); |
| 763 |
| 751 base::LaunchOptions options; | 764 base::LaunchOptions options; |
| 765 base::ProcessHandle* process_handle = NULL; |
| 766 |
| 767 #if defined(OS_POSIX) |
| 768 options.new_process_group = true; |
| 769 process_handle = &process_handle_; |
| 770 #elif defined(OS_WIN) |
| 771 job_handle_.Set(CreateJobObject(NULL, NULL)); |
| 772 if (!job_handle_.IsValid()) { |
| 773 LOG(ERROR) << "Could not create JobObject."; |
| 774 return false; |
| 775 } |
| 776 |
| 777 if (!base::SetJobObjectAsKillOnJobClose(job_handle_.Get())) { |
| 778 LOG(ERROR) << "Could not SetInformationJobObject."; |
| 779 return false; |
| 780 } |
| 781 |
| 782 options.inherit_handles = true; |
| 783 options.job_handle = job_handle_.Get(); |
| 784 #endif |
| 785 |
| 786 // Launch a new WebSocket server process. |
| 752 options.wait = true; | 787 options.wait = true; |
| 753 if (!base::LaunchProcess(*cmd_line.get(), options, NULL)) { | 788 if (!base::LaunchProcess(*cmd_line.get(), options, process_handle)) { |
| 754 LOG(ERROR) << "Unable to launch websocket server."; | 789 LOG(ERROR) << "Unable to launch websocket server."; |
| 755 return false; | 790 return false; |
| 756 } | 791 } |
| 757 started_ = true; | 792 started_ = true; |
| 758 return true; | 793 return true; |
| 759 } | 794 } |
| 760 | 795 |
| 761 CommandLine* TestWebSocketServer::CreatePythonCommandLine() { | 796 CommandLine* TestWebSocketServer::CreatePythonCommandLine() { |
| 762 // Note: Python's first argument must be the script; do not append CommandLine | 797 // Note: Python's first argument must be the script; do not append CommandLine |
| 763 // switches, as they would precede the script path and break this CommandLine. | 798 // switches, as they would precede the script path and break this CommandLine. |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 798 return; | 833 return; |
| 799 // Append CommandLine arguments after the server script, switches won't work. | 834 // Append CommandLine arguments after the server script, switches won't work. |
| 800 scoped_ptr<CommandLine> cmd_line(CreateWebSocketServerCommandLine()); | 835 scoped_ptr<CommandLine> cmd_line(CreateWebSocketServerCommandLine()); |
| 801 cmd_line->AppendArg("--server=stop"); | 836 cmd_line->AppendArg("--server=stop"); |
| 802 cmd_line->AppendArg("--chromium"); | 837 cmd_line->AppendArg("--chromium"); |
| 803 cmd_line->AppendArgNative(FILE_PATH_LITERAL("--pidfile=") + | 838 cmd_line->AppendArgNative(FILE_PATH_LITERAL("--pidfile=") + |
| 804 websocket_pid_file_.value()); | 839 websocket_pid_file_.value()); |
| 805 base::LaunchOptions options; | 840 base::LaunchOptions options; |
| 806 options.wait = true; | 841 options.wait = true; |
| 807 base::LaunchProcess(*cmd_line.get(), options, NULL); | 842 base::LaunchProcess(*cmd_line.get(), options, NULL); |
| 843 |
| 844 #if defined(OS_POSIX) |
| 845 // Just to make sure that the server process terminates certainly. |
| 846 base::KillProcessGroup(process_handle_); |
| 847 #endif |
| 808 } | 848 } |
| 809 | 849 |
| 810 TestNotificationObserver::TestNotificationObserver() | 850 TestNotificationObserver::TestNotificationObserver() |
| 811 : source_(content::NotificationService::AllSources()) { | 851 : source_(content::NotificationService::AllSources()) { |
| 812 } | 852 } |
| 813 | 853 |
| 814 TestNotificationObserver::~TestNotificationObserver() {} | 854 TestNotificationObserver::~TestNotificationObserver() {} |
| 815 | 855 |
| 816 void TestNotificationObserver::Observe( | 856 void TestNotificationObserver::Observe( |
| 817 int type, | 857 int type, |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1025 return taker.TakeRenderWidgetSnapshot(rwh, page_size, page_size, bitmap); | 1065 return taker.TakeRenderWidgetSnapshot(rwh, page_size, page_size, bitmap); |
| 1026 } | 1066 } |
| 1027 | 1067 |
| 1028 bool TakeEntirePageSnapshot(RenderViewHost* rvh, SkBitmap* bitmap) { | 1068 bool TakeEntirePageSnapshot(RenderViewHost* rvh, SkBitmap* bitmap) { |
| 1029 DCHECK(bitmap); | 1069 DCHECK(bitmap); |
| 1030 SnapshotTaker taker; | 1070 SnapshotTaker taker; |
| 1031 return taker.TakeEntirePageSnapshot(rvh, bitmap); | 1071 return taker.TakeEntirePageSnapshot(rvh, bitmap); |
| 1032 } | 1072 } |
| 1033 | 1073 |
| 1034 } // namespace ui_test_utils | 1074 } // namespace ui_test_utils |
| OLD | NEW |