| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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_FRAME_TEST_CHROME_FRAME_TEST_UTILS_H_ | 5 #ifndef CHROME_FRAME_TEST_CHROME_FRAME_TEST_UTILS_H_ |
| 6 #define CHROME_FRAME_TEST_CHROME_FRAME_TEST_UTILS_H_ | 6 #define CHROME_FRAME_TEST_CHROME_FRAME_TEST_UTILS_H_ |
| 7 | 7 |
| 8 #include <atlbase.h> | 8 #include <atlbase.h> |
| 9 #include <atlcom.h> | 9 #include <atlcom.h> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <exdisp.h> | 11 #include <exdisp.h> |
| 12 #include <exdispid.h> | 12 #include <exdispid.h> |
| 13 #include <mshtml.h> | 13 #include <mshtml.h> |
| 14 #include <shlguid.h> | 14 #include <shlguid.h> |
| 15 #include <shobjidl.h> | 15 #include <shobjidl.h> |
| 16 #include <windows.h> | 16 #include <windows.h> |
| 17 | 17 |
| 18 #include "base/basictypes.h" | 18 #include "base/basictypes.h" |
| 19 #include "base/message_loop.h" | 19 #include "base/message_loop.h" |
| 20 #include "base/process_util.h" | 20 #include "base/process_util.h" |
| 21 #include "base/scoped_comptr_win.h" | 21 #include "base/scoped_comptr_win.h" |
| 22 #include "base/scoped_variant_win.h" | 22 #include "base/scoped_variant_win.h" |
| 23 | 23 |
| 24 #include "chrome_frame/test_utils.h" | 24 #include "chrome_frame/test_utils.h" |
| 25 #include "chrome_frame/test/simulate_input.h" |
| 25 // Include without path to make GYP build see it. | 26 // Include without path to make GYP build see it. |
| 26 #include "chrome_tab.h" // NOLINT | 27 #include "chrome_tab.h" // NOLINT |
| 27 | 28 |
| 28 namespace chrome_frame_test { | 29 namespace chrome_frame_test { |
| 29 | 30 |
| 30 bool IsTopLevelWindow(HWND window); | |
| 31 int CloseVisibleWindowsOnAllThreads(HANDLE process); | 31 int CloseVisibleWindowsOnAllThreads(HANDLE process); |
| 32 bool ForceSetForegroundWindow(HWND window); | |
| 33 bool EnsureProcessInForeground(base::ProcessId process_id); | |
| 34 | |
| 35 // Iterates through all the characters in the string and simulates | |
| 36 // keyboard input. The input goes to the currently active application. | |
| 37 bool SendString(const wchar_t* s); | |
| 38 | |
| 39 // Sends a virtual key such as VK_TAB, VK_RETURN or a character that has been | |
| 40 // translated to a virtual key. | |
| 41 // The extended flag indicates if this is an extended key | |
| 42 void SendVirtualKey(int16 key, bool extended); | |
| 43 | |
| 44 // Translates a single char to a virtual key and calls SendVirtualKey. | |
| 45 void SendChar(char c); | |
| 46 | |
| 47 // Sends an ascii string, char by char (calls SendChar for each). | |
| 48 void SendString(const char* s); | |
| 49 | |
| 50 // Sends a keystroke to the currently active application with optional | |
| 51 // modifiers set. | |
| 52 bool SendMnemonic(WORD mnemonic_char, bool shift_pressed, bool control_pressed, | |
| 53 bool alt_pressed); | |
| 54 | 32 |
| 55 base::ProcessHandle LaunchFirefox(const std::wstring& url); | 33 base::ProcessHandle LaunchFirefox(const std::wstring& url); |
| 56 base::ProcessHandle LaunchOpera(const std::wstring& url); | 34 base::ProcessHandle LaunchOpera(const std::wstring& url); |
| 57 base::ProcessHandle LaunchIE(const std::wstring& url); | 35 base::ProcessHandle LaunchIE(const std::wstring& url); |
| 58 base::ProcessHandle LaunchSafari(const std::wstring& url); | 36 base::ProcessHandle LaunchSafari(const std::wstring& url); |
| 59 base::ProcessHandle LaunchChrome(const std::wstring& url); | 37 base::ProcessHandle LaunchChrome(const std::wstring& url); |
| 60 | 38 |
| 61 // Attempts to close all open IE windows. | 39 // Attempts to close all open IE windows. |
| 62 // The return value is the number of windows closed. | 40 // The return value is the number of windows closed. |
| 63 // @note: this function requires COM to be initialized on the calling thread. | 41 // @note: this function requires COM to be initialized on the calling thread. |
| 64 // Since the caller might be running in either MTA or STA, the function does | 42 // Since the caller might be running in either MTA or STA, the function does |
| 65 // not perform this initialization itself. | 43 // not perform this initialization itself. |
| 66 int CloseAllIEWindows(); | 44 int CloseAllIEWindows(); |
| 67 | 45 |
| 68 extern const wchar_t kIEImageName[]; | 46 extern const wchar_t kIEImageName[]; |
| 69 extern const wchar_t kIEBrokerImageName[]; | 47 extern const wchar_t kIEBrokerImageName[]; |
| 70 extern const wchar_t kFirefoxImageName[]; | 48 extern const wchar_t kFirefoxImageName[]; |
| 71 extern const wchar_t kOperaImageName[]; | 49 extern const wchar_t kOperaImageName[]; |
| 72 extern const wchar_t kSafariImageName[]; | 50 extern const wchar_t kSafariImageName[]; |
| 73 extern const wchar_t kChromeImageName[]; | 51 extern const wchar_t kChromeImageName[]; |
| 74 | 52 |
| 75 // Displays the chrome frame context menu by posting mouse move messages to | |
| 76 // Chrome | |
| 77 void ShowChromeFrameContextMenu(); | |
| 78 | |
| 79 // Sends keyboard messages to the chrome frame context menu to select the About | |
| 80 // Chrome frame option. | |
| 81 void SelectAboutChromeFrame(); | |
| 82 | |
| 83 // Returns a handle to the chrome frame render widget child window. | |
| 84 // Returns NULL on failure. | |
| 85 HWND GetChromeRendererWindow(); | |
| 86 | |
| 87 // Sends the specified input to the window passed in. | |
| 88 void SendInputToWindow(HWND window, const std::string& input_string); | |
| 89 | |
| 90 // Helper function to set keyboard focus to a window. This is achieved by | |
| 91 // sending a mouse move followed by a mouse down/mouse up combination to the | |
| 92 // window. | |
| 93 void SetKeyboardFocusToWindow(HWND window, int x, int y); | |
| 94 | |
| 95 // Temporarily impersonate the current thread to low integrity for the lifetime | 53 // Temporarily impersonate the current thread to low integrity for the lifetime |
| 96 // of the object. Destructor will automatically revert integrity level. | 54 // of the object. Destructor will automatically revert integrity level. |
| 97 class LowIntegrityToken { | 55 class LowIntegrityToken { |
| 98 public: | 56 public: |
| 99 LowIntegrityToken(); | 57 LowIntegrityToken(); |
| 100 ~LowIntegrityToken(); | 58 ~LowIntegrityToken(); |
| 101 BOOL Impersonate(); | 59 BOOL Impersonate(); |
| 102 BOOL RevertToSelf(); | 60 BOOL RevertToSelf(); |
| 103 protected: | 61 protected: |
| 104 static bool IsImpersonated(); | 62 static bool IsImpersonated(); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 // errors on failure. | 143 // errors on failure. |
| 186 HRESULT LaunchIEAndNavigate(const std::wstring& navigate_url); | 144 HRESULT LaunchIEAndNavigate(const std::wstring& navigate_url); |
| 187 | 145 |
| 188 virtual HRESULT Navigate(const std::wstring& navigate_url); | 146 virtual HRESULT Navigate(const std::wstring& navigate_url); |
| 189 | 147 |
| 190 // Set input focus to chrome frame window. | 148 // Set input focus to chrome frame window. |
| 191 void SetFocusToChrome(); | 149 void SetFocusToChrome(); |
| 192 | 150 |
| 193 // Send keyboard input to the renderer window hosted in chrome using | 151 // Send keyboard input to the renderer window hosted in chrome using |
| 194 // SendInput API | 152 // SendInput API |
| 195 void SendInputToChrome(const std::string& input_string); | 153 void SendKeys(const wchar_t* input_string); |
| 154 |
| 155 // Send mouse click to the renderer window hosted in chrome using |
| 156 // SendInput API |
| 157 void SendMouseClick(int x, int y, simulate_input::MouseButton button); |
| 158 |
| 159 void Exec(const GUID* cmd_group_guid, DWORD command_id, |
| 160 DWORD cmd_exec_opt, VARIANT* in_args, VARIANT* out_args); |
| 196 | 161 |
| 197 BEGIN_COM_MAP(WebBrowserEventSink) | 162 BEGIN_COM_MAP(WebBrowserEventSink) |
| 198 END_COM_MAP() | 163 END_COM_MAP() |
| 199 | 164 |
| 200 BEGIN_SINK_MAP(WebBrowserEventSink) | 165 BEGIN_SINK_MAP(WebBrowserEventSink) |
| 201 SINK_ENTRY_INFO(0, DIID_DWebBrowserEvents2, DISPID_BEFORENAVIGATE2, | 166 SINK_ENTRY_INFO(0, DIID_DWebBrowserEvents2, DISPID_BEFORENAVIGATE2, |
| 202 OnBeforeNavigate2Internal, &kBeforeNavigate2Info) | 167 OnBeforeNavigate2Internal, &kBeforeNavigate2Info) |
| 203 SINK_ENTRY_INFO(0, DIID_DWebBrowserEvents2, DISPID_DOWNLOADBEGIN, | 168 SINK_ENTRY_INFO(0, DIID_DWebBrowserEvents2, DISPID_DOWNLOADBEGIN, |
| 204 OnDownloadBegin, &kVoidMethodInfo) | 169 OnDownloadBegin, &kVoidMethodInfo) |
| 205 SINK_ENTRY_INFO(0, DIID_DWebBrowserEvents2, DISPID_NAVIGATECOMPLETE2, | 170 SINK_ENTRY_INFO(0, DIID_DWebBrowserEvents2, DISPID_NAVIGATECOMPLETE2, |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 EXCEPINFO* except_info, UINT* arg_error) { | 205 EXCEPINFO* except_info, UINT* arg_error) { |
| 241 DLOG(INFO) << __FUNCTION__ << L" disp id :" << dispid; | 206 DLOG(INFO) << __FUNCTION__ << L" disp id :" << dispid; |
| 242 return DispEventsImpl::Invoke(dispid, riid, lcid, flags, params, result, | 207 return DispEventsImpl::Invoke(dispid, riid, lcid, flags, params, result, |
| 243 except_info, arg_error); | 208 except_info, arg_error); |
| 244 } | 209 } |
| 245 #endif // _DEBUG | 210 #endif // _DEBUG |
| 246 | 211 |
| 247 // Chrome frame callbacks | 212 // Chrome frame callbacks |
| 248 virtual void OnLoad(const wchar_t* url) {} | 213 virtual void OnLoad(const wchar_t* url) {} |
| 249 virtual void OnLoadError(const wchar_t* url) {} | 214 virtual void OnLoadError(const wchar_t* url) {} |
| 250 virtual void OnMessage(const wchar_t* message) {} | 215 virtual void OnMessage(const wchar_t* message, const wchar_t* origin, |
| 216 const wchar_t* source) {} |
| 251 | 217 |
| 252 IWebBrowser2* web_browser2() { | 218 IWebBrowser2* web_browser2() { |
| 253 return web_browser2_.get(); | 219 return web_browser2_.get(); |
| 254 } | 220 } |
| 255 | 221 |
| 256 virtual void OnNewBrowserWindow(IDispatch* new_window, const wchar_t* url) {} | 222 virtual void OnNewBrowserWindow(IDispatch* new_window, const wchar_t* url) {} |
| 257 | 223 |
| 258 HRESULT SetWebBrowser(IWebBrowser2* web_browser2); | 224 HRESULT SetWebBrowser(IWebBrowser2* web_browser2); |
| 225 void ExpectRendererWindowHasfocus(); |
| 259 | 226 |
| 260 protected: | 227 protected: |
| 261 STDMETHOD(OnBeforeNavigate2Internal)(IDispatch* dispatch, VARIANT* url, | 228 STDMETHOD(OnBeforeNavigate2Internal)(IDispatch* dispatch, VARIANT* url, |
| 262 VARIANT* flags, | 229 VARIANT* flags, |
| 263 VARIANT* target_frame_name, | 230 VARIANT* target_frame_name, |
| 264 VARIANT* post_data, VARIANT* headers, | 231 VARIANT* post_data, VARIANT* headers, |
| 265 VARIANT_BOOL* cancel); | 232 VARIANT_BOOL* cancel); |
| 266 STDMETHOD_(void, OnNavigateComplete2Internal)(IDispatch* dispatch, | 233 STDMETHOD_(void, OnNavigateComplete2Internal)(IDispatch* dispatch, |
| 267 VARIANT* url); | 234 VARIANT* url); |
| 268 STDMETHOD_(void, OnDocumentCompleteInternal)(IDispatch* dispatch, | 235 STDMETHOD_(void, OnDocumentCompleteInternal)(IDispatch* dispatch, |
| 269 VARIANT* url); | 236 VARIANT* url); |
| 270 STDMETHOD_(void, OnNewWindow3Internal)(IDispatch** dispatch, | 237 STDMETHOD_(void, OnNewWindow3Internal)(IDispatch** dispatch, |
| 271 VARIANT_BOOL* Cancel, DWORD flags, | 238 VARIANT_BOOL* Cancel, DWORD flags, |
| 272 BSTR url_context, BSTR url); | 239 BSTR url_context, BSTR url); |
| 273 | 240 |
| 274 // IChromeFrame callbacks | 241 // IChromeFrame callbacks |
| 275 HRESULT OnLoadInternal(const VARIANT* param); | 242 HRESULT OnLoadInternal(const VARIANT* param); |
| 276 HRESULT OnLoadErrorInternal(const VARIANT* param); | 243 HRESULT OnLoadErrorInternal(const VARIANT* param); |
| 277 HRESULT OnMessageInternal(const VARIANT* param); | 244 HRESULT OnMessageInternal(const VARIANT* param); |
| 278 | 245 |
| 279 void ConnectToChromeFrame(); | 246 void ConnectToChromeFrame(); |
| 280 void DisconnectFromChromeFrame(); | 247 void DisconnectFromChromeFrame(); |
| 281 HWND GetTabWindow(); | 248 HWND GetRendererWindow(); |
| 282 | 249 |
| 283 public: | 250 public: |
| 284 ScopedComPtr<IWebBrowser2> web_browser2_; | 251 ScopedComPtr<IWebBrowser2> web_browser2_; |
| 285 ScopedComPtr<IChromeFrame> chrome_frame_; | 252 ScopedComPtr<IChromeFrame> chrome_frame_; |
| 286 DispCallback<WebBrowserEventSink> onmessage_; | 253 DispCallback<WebBrowserEventSink> onmessage_; |
| 287 DispCallback<WebBrowserEventSink> onloaderror_; | 254 DispCallback<WebBrowserEventSink> onloaderror_; |
| 288 DispCallback<WebBrowserEventSink> onload_; | 255 DispCallback<WebBrowserEventSink> onload_; |
| 289 | 256 |
| 290 protected: | 257 protected: |
| 291 static _ATL_FUNC_INFO kBeforeNavigate2Info; | 258 static _ATL_FUNC_INFO kBeforeNavigate2Info; |
| 292 static _ATL_FUNC_INFO kNavigateComplete2Info; | 259 static _ATL_FUNC_INFO kNavigateComplete2Info; |
| 293 static _ATL_FUNC_INFO kNavigateErrorInfo; | 260 static _ATL_FUNC_INFO kNavigateErrorInfo; |
| 294 static _ATL_FUNC_INFO kNewWindow2Info; | 261 static _ATL_FUNC_INFO kNewWindow2Info; |
| 295 static _ATL_FUNC_INFO kNewWindow3Info; | 262 static _ATL_FUNC_INFO kNewWindow3Info; |
| 296 static _ATL_FUNC_INFO kVoidMethodInfo; | 263 static _ATL_FUNC_INFO kVoidMethodInfo; |
| 297 static _ATL_FUNC_INFO kDocumentCompleteInfo; | 264 static _ATL_FUNC_INFO kDocumentCompleteInfo; |
| 298 }; | 265 }; |
| 299 | 266 |
| 300 } // namespace chrome_frame_test | 267 } // namespace chrome_frame_test |
| 301 | 268 |
| 302 #endif // CHROME_FRAME_TEST_CHROME_FRAME_TEST_UTILS_H_ | 269 #endif // CHROME_FRAME_TEST_CHROME_FRAME_TEST_UTILS_H_ |
| OLD | NEW |