| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 #ifndef CHROME_TEST_AUTOMATION_AUTOMATION_PROXY_H__ | 5 #ifndef CHROME_TEST_AUTOMATION_AUTOMATION_PROXY_H__ |
| 6 #define CHROME_TEST_AUTOMATION_AUTOMATION_PROXY_H__ | 6 #define CHROME_TEST_AUTOMATION_AUTOMATION_PROXY_H__ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/scoped_ptr.h" | 11 #include "base/scoped_ptr.h" |
| 12 #include "base/time.h" |
| 12 #include "base/thread.h" | 13 #include "base/thread.h" |
| 14 #include "base/waitable_event.h" |
| 13 #include "chrome/common/ipc_channel_proxy.h" | 15 #include "chrome/common/ipc_channel_proxy.h" |
| 14 #include "chrome/common/ipc_message.h" | 16 #include "chrome/common/ipc_message.h" |
| 15 #include "chrome/common/ipc_sync_channel.h" | 17 #include "chrome/common/ipc_sync_channel.h" |
| 16 #include "chrome/test/automation/automation_handle_tracker.h" | 18 #include "chrome/test/automation/automation_handle_tracker.h" |
| 17 #include "chrome/test/automation/automation_messages.h" | 19 #include "chrome/test/automation/automation_messages.h" |
| 20 |
| 21 #if defined(OS_WIN) |
| 22 // TODO(port): Enable this or equivalent. |
| 18 #include "chrome/views/dialog_delegate.h" | 23 #include "chrome/views/dialog_delegate.h" |
| 24 #endif |
| 19 | 25 |
| 20 class AutomationRequest; | 26 class AutomationRequest; |
| 21 class BrowserProxy; | 27 class BrowserProxy; |
| 22 class TabProxy; | 28 class TabProxy; |
| 23 class WindowProxy; | 29 class WindowProxy; |
| 24 | 30 |
| 25 // This is an interface that AutomationProxy-related objects can use to | 31 // This is an interface that AutomationProxy-related objects can use to |
| 26 // access the message-sending abilities of the Proxy. | 32 // access the message-sending abilities of the Proxy. |
| 27 class AutomationMessageSender : public IPC::Message::Sender { | 33 class AutomationMessageSender : public IPC::Message::Sender { |
| 28 public: | 34 public: |
| 29 // Sends a message synchronously; it doesn't return until a response has been | 35 // Sends a message synchronously; it doesn't return until a response has been |
| 30 // received or a timeout has expired. | 36 // received or a timeout has expired. |
| 37 // |
| 38 // Use base::kNoTimeout for no timeout. |
| 39 // |
| 31 // The function returns true if a response is received, and returns false if | 40 // The function returns true if a response is received, and returns false if |
| 32 // there is a failure or timeout (in milliseconds). If return after timeout, | 41 // there is a failure or timeout (in milliseconds). If return after timeout, |
| 33 // is_timeout is set to true. | 42 // is_timeout is set to true. |
| 34 // NOTE: When timeout occurs, the connection between proxy provider may be | 43 // NOTE: When timeout occurs, the connection between proxy provider may be |
| 35 // in transit state. Specifically, there might be pending IPC messages, | 44 // in transit state. Specifically, there might be pending IPC messages, |
| 36 // and the proxy provider might be still working on the previous | 45 // and the proxy provider might be still working on the previous |
| 37 // request. | 46 // request. |
| 38 virtual bool SendWithTimeout(IPC::Message* message, int timeout, | 47 virtual bool SendWithTimeout(IPC::Message* message, int timeout, |
| 39 bool* is_timeout) = 0; | 48 bool* is_timeout) = 0; |
| 40 }; | 49 }; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 // Returns false if the window count does not change before time out. | 95 // Returns false if the window count does not change before time out. |
| 87 // TODO(evanm): this function has a confusing name and semantics; it should | 96 // TODO(evanm): this function has a confusing name and semantics; it should |
| 88 // be deprecated for WaitForWindowCountToBecome. | 97 // be deprecated for WaitForWindowCountToBecome. |
| 89 bool WaitForWindowCountToChange(int count, int* new_counter, | 98 bool WaitForWindowCountToChange(int count, int* new_counter, |
| 90 int wait_timeout); | 99 int wait_timeout); |
| 91 | 100 |
| 92 // Block the thread until the window count becomes the provided value. | 101 // Block the thread until the window count becomes the provided value. |
| 93 // Returns true on success. | 102 // Returns true on success. |
| 94 bool WaitForWindowCountToBecome(int target_count, int wait_timeout); | 103 bool WaitForWindowCountToBecome(int target_count, int wait_timeout); |
| 95 | 104 |
| 105 #if defined(OS_WIN) |
| 106 // TODO(port): Enable when we have portable DialogDelegate. |
| 107 |
| 96 // Returns whether an app modal dialog window is showing right now (i.e., a | 108 // Returns whether an app modal dialog window is showing right now (i.e., a |
| 97 // javascript alert), and what buttons it contains. | 109 // javascript alert), and what buttons it contains. |
| 98 bool GetShowingAppModalDialog(bool* showing_app_modal_dialog, | 110 bool GetShowingAppModalDialog(bool* showing_app_modal_dialog, |
| 99 views::DialogDelegate::DialogButton* button); | 111 views::DialogDelegate::DialogButton* button); |
| 100 | 112 |
| 101 // Simulates a click on a dialog button. | 113 // Simulates a click on a dialog button. |
| 102 bool ClickAppModalDialogButton(views::DialogDelegate::DialogButton button); | 114 bool ClickAppModalDialogButton(views::DialogDelegate::DialogButton button); |
| 115 #endif // defined(OS_WIN) |
| 103 | 116 |
| 104 // Block the thread until a modal dialog is displayed. Returns true on | 117 // Block the thread until a modal dialog is displayed. Returns true on |
| 105 // success. | 118 // success. |
| 106 bool WaitForAppModalDialog(int wait_timeout); | 119 bool WaitForAppModalDialog(int wait_timeout); |
| 107 | 120 |
| 108 // Returns the BrowserProxy for the browser window at the given index, | 121 // Returns the BrowserProxy for the browser window at the given index, |
| 109 // transferring ownership of the pointer to the caller. | 122 // transferring ownership of the pointer to the caller. |
| 110 // On failure, returns NULL. | 123 // On failure, returns NULL. |
| 111 // | 124 // |
| 112 // Use GetBrowserWindowCount to see how many browser windows you can ask for. | 125 // Use GetBrowserWindowCount to see how many browser windows you can ask for. |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 // Returns the current AutomationRequest object. | 167 // Returns the current AutomationRequest object. |
| 155 AutomationRequest* current_request() { return current_request_; } | 168 AutomationRequest* current_request() { return current_request_; } |
| 156 // Clears the current AutomationRequest object. | 169 // Clears the current AutomationRequest object. |
| 157 void clear_current_request() { current_request_ = NULL; } | 170 void clear_current_request() { current_request_ = NULL; } |
| 158 | 171 |
| 159 // Wrapper over AutomationHandleTracker::InvalidateHandle. Receives the | 172 // Wrapper over AutomationHandleTracker::InvalidateHandle. Receives the |
| 160 // message from AutomationProxy, unpacks the messages and routes that call to | 173 // message from AutomationProxy, unpacks the messages and routes that call to |
| 161 // the tracker. | 174 // the tracker. |
| 162 void InvalidateHandle(const IPC::Message& message); | 175 void InvalidateHandle(const IPC::Message& message); |
| 163 | 176 |
| 177 #if defined(OS_WIN) |
| 178 // TODO(port): Enable when we can replace HWND. |
| 179 |
| 164 // Creates a tab that can hosted in an external process. The function | 180 // Creates a tab that can hosted in an external process. The function |
| 165 // returns a TabProxy representing the tab as well as a window handle | 181 // returns a TabProxy representing the tab as well as a window handle |
| 166 // that can be reparented in another process. | 182 // that can be reparented in another process. |
| 167 TabProxy* CreateExternalTab(HWND parent, const gfx::Rect& dimensions, | 183 TabProxy* CreateExternalTab(HWND parent, const gfx::Rect& dimensions, |
| 168 unsigned int style, HWND* external_tab_container); | 184 unsigned int style, HWND* external_tab_container); |
| 185 #endif // defined(OS_WIN) |
| 169 | 186 |
| 170 int command_execution_timeout_ms() const { | 187 int command_execution_timeout_ms() const { |
| 171 return command_execution_timeout_ms_; | 188 return static_cast<int>(command_execution_timeout_.InMilliseconds()); |
| 172 } | 189 } |
| 173 | 190 |
| 174 private: | 191 private: |
| 175 void InitializeEvents(); | |
| 176 void InitializeChannelID(); | 192 void InitializeChannelID(); |
| 177 void InitializeThread(); | 193 void InitializeThread(); |
| 178 void InitializeChannel(); | 194 void InitializeChannel(); |
| 179 void InitializeHandleTracker(); | 195 void InitializeHandleTracker(); |
| 180 | 196 |
| 181 std::wstring channel_id_; | 197 std::wstring channel_id_; |
| 182 scoped_ptr<base::Thread> thread_; | 198 scoped_ptr<base::Thread> thread_; |
| 183 scoped_ptr<IPC::SyncChannel> channel_; | 199 scoped_ptr<IPC::SyncChannel> channel_; |
| 184 scoped_ptr<AutomationHandleTracker> tracker_; | 200 scoped_ptr<AutomationHandleTracker> tracker_; |
| 185 | 201 |
| 186 HANDLE app_launched_; | 202 base::WaitableEvent app_launched_; |
| 187 HANDLE initial_loads_complete_; | 203 base::WaitableEvent initial_loads_complete_; |
| 188 HANDLE new_tab_ui_load_complete_; | 204 base::WaitableEvent new_tab_ui_load_complete_; |
| 189 int new_tab_ui_load_time_; | 205 int new_tab_ui_load_time_; |
| 190 | 206 |
| 191 // An event that notifies when we are shutting-down. | 207 // An event that notifies when we are shutting-down. |
| 192 scoped_ptr<base::WaitableEvent> shutdown_event_; | 208 scoped_ptr<base::WaitableEvent> shutdown_event_; |
| 193 | 209 |
| 194 AutomationRequest* current_request_; | 210 AutomationRequest* current_request_; |
| 195 | 211 |
| 196 // Delay to let the browser execute the command. | 212 // Delay to let the browser execute the command. |
| 197 int command_execution_timeout_ms_; | 213 base::TimeDelta command_execution_timeout_; |
| 198 | 214 |
| 199 DISALLOW_COPY_AND_ASSIGN(AutomationProxy); | 215 DISALLOW_COPY_AND_ASSIGN(AutomationProxy); |
| 200 }; | 216 }; |
| 201 | 217 |
| 202 #endif // CHROME_TEST_AUTOMATION_AUTOMATION_PROXY_H__ | 218 #endif // CHROME_TEST_AUTOMATION_AUTOMATION_PROXY_H__ |
| OLD | NEW |