Chromium Code Reviews| 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 #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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 42 // received or a timeout has expired. | 42 // received or a timeout has expired. |
| 43 // | 43 // |
| 44 // The function returns true if a response is received, and returns false if | 44 // The function returns true if a response is received, and returns false if |
| 45 // there is a failure or timeout (in milliseconds). | 45 // there is a failure or timeout (in milliseconds). |
| 46 // | 46 // |
| 47 // NOTE: When timeout occurs, the connection between proxy provider may be | 47 // NOTE: When timeout occurs, the connection between proxy provider may be |
| 48 // in transit state. Specifically, there might be pending IPC messages, | 48 // in transit state. Specifically, there might be pending IPC messages, |
| 49 // and the proxy provider might be still working on the previous | 49 // and the proxy provider might be still working on the previous |
| 50 // request. | 50 // request. |
| 51 virtual bool Send(IPC::Message* message) = 0; | 51 virtual bool Send(IPC::Message* message) = 0; |
| 52 virtual bool Send(IPC::Message* message, int timeout_ms) = 0; | |
| 52 }; | 53 }; |
| 53 | 54 |
| 54 // This is the interface that external processes can use to interact with | 55 // This is the interface that external processes can use to interact with |
| 55 // a running instance of the app. | 56 // a running instance of the app. |
| 56 class AutomationProxy : public IPC::Channel::Listener, | 57 class AutomationProxy : public IPC::Channel::Listener, |
| 57 public AutomationMessageSender { | 58 public AutomationMessageSender { |
| 58 public: | 59 public: |
| 59 AutomationProxy(int command_execution_timeout_ms, bool disconnect_on_failure); | 60 AutomationProxy(int action_timeout_ms, bool disconnect_on_failure); |
| 60 virtual ~AutomationProxy(); | 61 virtual ~AutomationProxy(); |
| 61 | 62 |
| 62 // Creates a previously unused channel id. | 63 // Creates a previously unused channel id. |
| 63 static std::string GenerateChannelID(); | 64 static std::string GenerateChannelID(); |
| 64 | 65 |
| 65 // Initializes a channel for a connection to an AutomationProvider. | 66 // Initializes a channel for a connection to an AutomationProvider. |
| 66 // If use_named_interface is false, it will act as a client | 67 // If use_named_interface is false, it will act as a client |
| 67 // and connect to the named IPC socket with channel_id as its path. | 68 // and connect to the named IPC socket with channel_id as its path. |
| 68 // If use_named_interface is true, it will act as a server and | 69 // If use_named_interface is true, it will act as a server and |
| 69 // use an anonymous socketpair instead. | 70 // use an anonymous socketpair instead. |
| 70 void InitializeChannel(const std::string& channel_id, | 71 void InitializeChannel(const std::string& channel_id, |
| 71 bool use_named_interface); | 72 bool use_named_interface); |
| 72 | 73 |
| 73 // IPC callback | 74 // IPC callback |
| 74 virtual bool OnMessageReceived(const IPC::Message& msg); | 75 virtual bool OnMessageReceived(const IPC::Message& msg); |
| 75 virtual void OnChannelError(); | 76 virtual void OnChannelError(); |
| 76 | 77 |
| 77 // Close the automation IPC channel. | 78 // Close the automation IPC channel. |
| 78 void Disconnect(); | 79 void Disconnect(); |
| 79 | 80 |
| 80 // Waits for the app to launch and the automation provider to say hello | 81 // Waits for the app to launch and the automation provider to say hello |
| 81 // (the app isn't fully done loading by this point). | 82 // (the app isn't fully done loading by this point). |
| 82 // Returns SUCCESS if the launch is successful. | 83 // Returns SUCCESS if the launch is successful. |
| 83 // Returns TIMEOUT if there was no response by command_execution_timeout_ | 84 // Returns TIMEOUT if there was no response by action_timeout_ |
| 84 // Returns VERSION_MISMATCH if the automation protocol version of the | 85 // Returns VERSION_MISMATCH if the automation protocol version of the |
| 85 // automation provider does not match and if perform_version_check_ is set | 86 // automation provider does not match and if perform_version_check_ is set |
| 86 // to true. Note that perform_version_check_ defaults to false, call | 87 // to true. Note that perform_version_check_ defaults to false, call |
| 87 // set_perform_version_check() to set it. | 88 // set_perform_version_check() to set it. |
| 88 AutomationLaunchResult WaitForAppLaunch(); | 89 AutomationLaunchResult WaitForAppLaunch(); |
| 89 | 90 |
| 90 // See description in AutomationMsg_WaitForProcessLauncherThreadToGoIdle. | 91 // See description in AutomationMsg_WaitForProcessLauncherThreadToGoIdle. |
| 91 bool WaitForProcessLauncherThreadToGoIdle() WARN_UNUSED_RESULT; | 92 bool WaitForProcessLauncherThreadToGoIdle() WARN_UNUSED_RESULT; |
| 92 | 93 |
| 93 // Waits for any initial page loads to complete. | 94 // Waits for any initial page loads to complete. |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 208 | 209 |
| 209 // Gets a list of all enabled extensions' base directories. | 210 // Gets a list of all enabled extensions' base directories. |
| 210 // Returns true on success. | 211 // Returns true on success. |
| 211 bool GetEnabledExtensions(std::vector<FilePath>* extension_directories); | 212 bool GetEnabledExtensions(std::vector<FilePath>* extension_directories); |
| 212 | 213 |
| 213 // Resets to the default theme. Returns true on success. | 214 // Resets to the default theme. Returns true on success. |
| 214 bool ResetToDefaultTheme(); | 215 bool ResetToDefaultTheme(); |
| 215 | 216 |
| 216 // Generic pattern for sending automation requests. | 217 // Generic pattern for sending automation requests. |
| 217 bool SendJSONRequest(const std::string& request, | 218 bool SendJSONRequest(const std::string& request, |
| 219 int timeout_ms, | |
| 218 std::string* response) WARN_UNUSED_RESULT; | 220 std::string* response) WARN_UNUSED_RESULT; |
| 219 | 221 |
| 220 #if defined(OS_CHROMEOS) | 222 #if defined(OS_CHROMEOS) |
| 221 // Logs in through the Chrome OS login wizard with given |username| | 223 // Logs in through the Chrome OS login wizard with given |username| |
| 222 // and |password|. Returns true on success. | 224 // and |password|. Returns true on success. |
| 223 bool LoginWithUserAndPass(const std::string& username, | 225 bool LoginWithUserAndPass(const std::string& username, |
| 224 const std::string& password) WARN_UNUSED_RESULT; | 226 const std::string& password) WARN_UNUSED_RESULT; |
| 225 #endif | 227 #endif |
| 226 | 228 |
| 227 #if defined(OS_POSIX) | 229 #if defined(OS_POSIX) |
| 228 base::file_handle_mapping_vector fds_to_map() const; | 230 base::file_handle_mapping_vector fds_to_map() const; |
| 229 #endif | 231 #endif |
| 230 | 232 |
| 231 // AutomationMessageSender implementation. | 233 // AutomationMessageSender implementation. |
| 232 virtual bool Send(IPC::Message* message) WARN_UNUSED_RESULT; | 234 virtual bool Send(IPC::Message* message) WARN_UNUSED_RESULT; |
| 235 virtual bool Send(IPC::Message* message, int timeout_ms) WARN_UNUSED_RESULT; | |
| 233 | 236 |
| 234 // Wrapper over AutomationHandleTracker::InvalidateHandle. Receives the | 237 // Wrapper over AutomationHandleTracker::InvalidateHandle. Receives the |
| 235 // message from AutomationProxy, unpacks the messages and routes that call to | 238 // message from AutomationProxy, unpacks the messages and routes that call to |
| 236 // the tracker. | 239 // the tracker. |
| 237 virtual void InvalidateHandle(const IPC::Message& message); | 240 virtual void InvalidateHandle(const IPC::Message& message); |
| 238 | 241 |
| 239 // Creates a tab that can hosted in an external process. The function | 242 // Creates a tab that can hosted in an external process. The function |
| 240 // returns a TabProxy representing the tab as well as a window handle | 243 // returns a TabProxy representing the tab as well as a window handle |
| 241 // that can be reparented in another process. | 244 // that can be reparented in another process. |
| 242 scoped_refptr<TabProxy> CreateExternalTab( | 245 scoped_refptr<TabProxy> CreateExternalTab( |
| 243 const ExternalTabSettings& settings, | 246 const ExternalTabSettings& settings, |
| 244 gfx::NativeWindow* external_tab_container, | 247 gfx::NativeWindow* external_tab_container, |
| 245 gfx::NativeWindow* tab); | 248 gfx::NativeWindow* tab); |
| 246 | 249 |
| 247 int command_execution_timeout_ms() const { | 250 int action_timeout_ms() const { |
| 248 return static_cast<int>(command_execution_timeout_.InMilliseconds()); | 251 return static_cast<int>(action_timeout_.InMilliseconds()); |
| 249 } | 252 } |
| 250 | 253 |
| 251 // Sets the timeout for subsequent automation calls. | 254 // Sets the timeout for subsequent automation calls. |
| 252 void set_command_execution_timeout_ms(int timeout_ms) { | 255 void set_action_timeout_ms(int timeout_ms) { |
|
Paweł Hajdan Jr.
2011/03/31 20:11:09
Well, I think this should also be removed.
| |
| 253 DCHECK(timeout_ms <= 10 * 60 * 1000 ) << "10+ min of automation timeout " | 256 DCHECK(timeout_ms <= 10 * 60 * 1000 ) << "10+ min of automation timeout " |
| 254 "can make the test hang and be killed by buildbot"; | 257 "can make the test hang and be killed by buildbot"; |
| 255 command_execution_timeout_ = base::TimeDelta::FromMilliseconds(timeout_ms); | 258 action_timeout_ = base::TimeDelta::FromMilliseconds(timeout_ms); |
| 256 } | 259 } |
| 257 | 260 |
| 258 // Returns the server version of the server connected. You may only call this | 261 // Returns the server version of the server connected. You may only call this |
| 259 // method after WaitForAppLaunch() has returned SUCCESS or VERSION_MISMATCH. | 262 // method after WaitForAppLaunch() has returned SUCCESS or VERSION_MISMATCH. |
| 260 // If you call it before this, the return value is undefined. | 263 // If you call it before this, the return value is undefined. |
| 261 std::string server_version() const { | 264 std::string server_version() const { |
| 262 return server_version_; | 265 return server_version_; |
| 263 } | 266 } |
| 264 | 267 |
| 265 // Call this while passing true to tell the automation proxy to perform | 268 // Call this while passing true to tell the automation proxy to perform |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 300 // the automation provider at connection time. Defaults to false, you can | 303 // the automation provider at connection time. Defaults to false, you can |
| 301 // set this to true if building the automation proxy into a module with | 304 // set this to true if building the automation proxy into a module with |
| 302 // a version resource. | 305 // a version resource. |
| 303 bool perform_version_check_; | 306 bool perform_version_check_; |
| 304 | 307 |
| 305 // If true, the proxy will disconnect the IPC channel on first failure | 308 // If true, the proxy will disconnect the IPC channel on first failure |
| 306 // to send an IPC message. This helps avoid long timeouts in tests. | 309 // to send an IPC message. This helps avoid long timeouts in tests. |
| 307 bool disconnect_on_failure_; | 310 bool disconnect_on_failure_; |
| 308 | 311 |
| 309 // Delay to let the browser execute the command. | 312 // Delay to let the browser execute the command. |
| 310 base::TimeDelta command_execution_timeout_; | 313 base::TimeDelta action_timeout_; |
| 311 | 314 |
| 312 base::PlatformThreadId listener_thread_id_; | 315 base::PlatformThreadId listener_thread_id_; |
| 313 | 316 |
| 314 DISALLOW_COPY_AND_ASSIGN(AutomationProxy); | 317 DISALLOW_COPY_AND_ASSIGN(AutomationProxy); |
| 315 }; | 318 }; |
| 316 | 319 |
| 317 #endif // CHROME_TEST_AUTOMATION_AUTOMATION_PROXY_H_ | 320 #endif // CHROME_TEST_AUTOMATION_AUTOMATION_PROXY_H_ |
| OLD | NEW |