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 #ifndef CHROME_FRAME_TEST_CHROME_FRAME_UNITTESTS_H_ | 4 #ifndef CHROME_FRAME_TEST_CHROME_FRAME_UNITTESTS_H_ |
5 #define CHROME_FRAME_TEST_CHROME_FRAME_UNITTESTS_H_ | 5 #define CHROME_FRAME_TEST_CHROME_FRAME_UNITTESTS_H_ |
6 | 6 |
7 #include <atlbase.h> | 7 #include <atlbase.h> |
8 #include <atlcom.h> | 8 #include <atlcom.h> |
9 #include <string> | 9 #include <string> |
10 #include <exdisp.h> | 10 #include <exdisp.h> |
11 #include <exdispid.h> | 11 #include <exdispid.h> |
12 | 12 |
13 #include "base/ref_counted.h" | 13 #include "base/ref_counted.h" |
| 14 #include "base/scoped_comptr_win.h" |
14 #include "base/scoped_handle_win.h" | 15 #include "base/scoped_handle_win.h" |
15 #include "googleurl/src/gurl.h" | 16 #include "googleurl/src/gurl.h" |
16 #include "chrome_frame/test/http_server.h" | 17 #include "chrome_frame/test/http_server.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
18 | 19 |
19 // Class that: | 20 // Class that: |
20 // 1) Starts the local webserver, | 21 // 1) Starts the local webserver, |
21 // 2) Supports launching browsers - Internet Explorer and Firefox with local url | 22 // 2) Supports launching browsers - Internet Explorer and Firefox with local url |
22 // 3) Wait the webserver to finish. It is supposed the test webpage to shutdown | 23 // 3) Wait the webserver to finish. It is supposed the test webpage to shutdown |
23 // the server by navigating to "kill" page | 24 // the server by navigating to "kill" page |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 BrowserKind browser_; | 88 BrowserKind browser_; |
88 std::wstring results_dir_; | 89 std::wstring results_dir_; |
89 ScopedHandle browser_handle_; | 90 ScopedHandle browser_handle_; |
90 ChromeFrameHTTPServer server_; | 91 ChromeFrameHTTPServer server_; |
91 }; | 92 }; |
92 | 93 |
93 // This class sets up event sinks to the IWebBrowser interface. Currently it | 94 // This class sets up event sinks to the IWebBrowser interface. Currently it |
94 // subscribes to the following events:- | 95 // subscribes to the following events:- |
95 // 1. DISPID_BEFORENAVIGATE2 | 96 // 1. DISPID_BEFORENAVIGATE2 |
96 // 2. DISPID_NAVIGATEERROR | 97 // 2. DISPID_NAVIGATEERROR |
97 // 3. DISPID_NAVIGATECOMPLETE2 | 98 // 3. DISPID_NAVIGATECOMPLETE2 |
| 99 // 4. DISPID_NEWWINDOW3 |
98 // Other events can be subscribed to on an if needed basis. | 100 // Other events can be subscribed to on an if needed basis. |
99 class WebBrowserEventSink | 101 class WebBrowserEventSink |
100 : public CComObjectRootEx<CComSingleThreadModel>, | 102 : public CComObjectRootEx<CComSingleThreadModel>, |
101 public IDispEventSimpleImpl<0, WebBrowserEventSink, | 103 public IDispEventSimpleImpl<0, WebBrowserEventSink, |
102 &DIID_DWebBrowserEvents2> { | 104 &DIID_DWebBrowserEvents2> { |
103 public: | 105 public: |
104 WebBrowserEventSink() | 106 typedef IDispEventSimpleImpl<0, WebBrowserEventSink, |
105 : navigation_failed_(false), | 107 &DIID_DWebBrowserEvents2> DispEventsImpl; |
106 main_thread_id_(0) { | 108 WebBrowserEventSink() {} |
| 109 ~WebBrowserEventSink() { |
| 110 Uninitialize(); |
107 } | 111 } |
108 | 112 |
| 113 void Uninitialize() { |
| 114 if (web_browser2_.get()) { |
| 115 DispEventUnadvise(web_browser2_); |
| 116 web_browser2_.Release(); |
| 117 } |
| 118 } |
| 119 |
| 120 // Helper function to launch IE and navigate to a URL. |
| 121 // Returns S_OK on success, S_FALSE if the test was not run, other |
| 122 // errors on failure. |
| 123 HRESULT LaunchIEAndNavigate(const std::wstring& navigate_url, |
| 124 _IDispEvent* sink); |
| 125 |
109 BEGIN_COM_MAP(WebBrowserEventSink) | 126 BEGIN_COM_MAP(WebBrowserEventSink) |
110 END_COM_MAP() | 127 END_COM_MAP() |
111 | 128 |
112 BEGIN_SINK_MAP(WebBrowserEventSink) | 129 BEGIN_SINK_MAP(WebBrowserEventSink) |
113 SINK_ENTRY_INFO(0, DIID_DWebBrowserEvents2, DISPID_BEFORENAVIGATE2, | 130 SINK_ENTRY_INFO(0, DIID_DWebBrowserEvents2, DISPID_BEFORENAVIGATE2, |
114 OnBeforeNavigate2, &kBeforeNavigate2Info) | 131 OnBeforeNavigate2, &kBeforeNavigate2Info) |
115 SINK_ENTRY_INFO(0, DIID_DWebBrowserEvents2, DISPID_NAVIGATECOMPLETE2, | 132 SINK_ENTRY_INFO(0, DIID_DWebBrowserEvents2, DISPID_NAVIGATECOMPLETE2, |
116 OnNavigateComplete2, &kNavigateComplete2Info) | 133 OnNavigateComplete2, &kNavigateComplete2Info) |
117 SINK_ENTRY_INFO(0, DIID_DWebBrowserEvents2, DISPID_NAVIGATEERROR, | 134 SINK_ENTRY_INFO(0, DIID_DWebBrowserEvents2, DISPID_NAVIGATEERROR, |
118 OnNavigateError, &kNavigateErrorInfo) | 135 OnNavigateError, &kNavigateErrorInfo) |
| 136 SINK_ENTRY_INFO(0, DIID_DWebBrowserEvents2, DISPID_NEWWINDOW3, |
| 137 OnNewWindow3, &kNewWindow3Info) |
119 END_SINK_MAP() | 138 END_SINK_MAP() |
120 | 139 |
121 STDMETHOD_(void, OnNavigateError)(IDispatch* dispatch, VARIANT* url, | 140 STDMETHOD_(void, OnNavigateError)(IDispatch* dispatch, VARIANT* url, |
122 VARIANT* frame_name, VARIANT* status_code, | 141 VARIANT* frame_name, VARIANT* status_code, |
123 VARIANT* cancel) { | 142 VARIANT* cancel) { |
124 navigation_failed_ = true; | 143 DLOG(INFO) << __FUNCTION__; |
125 } | 144 } |
126 | 145 |
127 STDMETHOD(OnBeforeNavigate2)(IDispatch* dispatch, VARIANT* url, VARIANT* | 146 STDMETHOD(OnBeforeNavigate2)(IDispatch* dispatch, VARIANT* url, VARIANT* |
128 flags, VARIANT* target_frame_name, | 147 flags, VARIANT* target_frame_name, |
129 VARIANT* post_data, VARIANT* headers, | 148 VARIANT* post_data, VARIANT* headers, |
130 VARIANT_BOOL* cancel) { | 149 VARIANT_BOOL* cancel) { |
131 DLOG(INFO) << __FUNCTION__; | 150 DLOG(INFO) << __FUNCTION__; |
132 // If a navigation fails then IE issues a navigation to an interstitial | |
133 // page. Catch this to track navigation errors as the NavigateError | |
134 // notification does not seem to fire reliably. | |
135 GURL crack_url(url->bstrVal); | |
136 if (crack_url.scheme() == "res") { | |
137 navigation_failed_ = true; | |
138 } | |
139 return S_OK; | 151 return S_OK; |
140 } | 152 } |
141 | 153 |
142 STDMETHOD_(void, OnNavigateComplete2)(IDispatch* dispatch, VARIANT* url) { | 154 STDMETHOD_(void, OnNavigateComplete2)(IDispatch* dispatch, VARIANT* url) { |
143 DLOG(INFO) << __FUNCTION__; | 155 DLOG(INFO) << __FUNCTION__; |
144 } | 156 } |
145 | 157 |
146 bool navigation_failed() const { | 158 STDMETHOD_(void, OnNewWindow3)(IDispatch** dispatch, VARIANT_BOOL* Cancel, |
147 return navigation_failed_; | 159 DWORD flags, BSTR url_context, BSTR url) { |
| 160 DLOG(INFO) << __FUNCTION__; |
148 } | 161 } |
149 | 162 |
150 void set_main_thread_id(DWORD thread_id) { | 163 #ifdef _DEBUG |
151 main_thread_id_ = thread_id; | 164 STDMETHOD(Invoke)(DISPID dispid, REFIID riid, |
| 165 LCID lcid, WORD flags, DISPPARAMS* params, VARIANT* result, |
| 166 EXCEPINFO* except_info, UINT* arg_error) { |
| 167 DLOG(INFO) << __FUNCTION__ << L" disp id :" << dispid; |
| 168 return DispEventsImpl::Invoke(dispid, riid, lcid, flags, params, result, |
| 169 except_info, arg_error); |
| 170 } |
| 171 #endif // _DEBUG |
| 172 |
| 173 IWebBrowser2* web_browser2() { |
| 174 return web_browser2_.get(); |
152 } | 175 } |
153 | 176 |
154 protected: | 177 protected: |
155 bool navigation_failed_; | |
156 | |
157 static _ATL_FUNC_INFO kBeforeNavigate2Info; | 178 static _ATL_FUNC_INFO kBeforeNavigate2Info; |
158 static _ATL_FUNC_INFO kNavigateComplete2Info; | 179 static _ATL_FUNC_INFO kNavigateComplete2Info; |
159 static _ATL_FUNC_INFO kNavigateErrorInfo; | 180 static _ATL_FUNC_INFO kNavigateErrorInfo; |
160 DWORD main_thread_id_; | 181 static _ATL_FUNC_INFO kNewWindow3Info; |
| 182 ScopedComPtr<IWebBrowser2> web_browser2_; |
161 }; | 183 }; |
162 | 184 |
163 #endif // CHROME_FRAME_TEST_CHROME_FRAME_UNITTESTS_H_ | 185 #endif // CHROME_FRAME_TEST_CHROME_FRAME_UNITTESTS_H_ |
164 | 186 |
OLD | NEW |