OLD | NEW |
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-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 #ifndef CHROME_FRAME_TEST_CHROME_FRAME_AUTOMATION_MOCK_H_ | 4 #ifndef CHROME_FRAME_TEST_CHROME_FRAME_AUTOMATION_MOCK_H_ |
5 #define CHROME_FRAME_TEST_CHROME_FRAME_AUTOMATION_MOCK_H_ | 5 #define CHROME_FRAME_TEST_CHROME_FRAME_AUTOMATION_MOCK_H_ |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
11 #include "chrome_frame/chrome_frame_automation.h" | 11 #include "chrome_frame/chrome_frame_automation.h" |
12 #include "chrome_frame/chrome_frame_plugin.h" | 12 #include "chrome_frame/chrome_frame_plugin.h" |
13 #include "chrome_frame/test/http_server.h" | 13 #include "chrome_frame/test/http_server.h" |
14 | 14 |
15 template <typename T> | 15 template <typename T> |
16 class AutomationMockDelegate | 16 class AutomationMockDelegate |
17 : public CWindowImpl<T>, | 17 : public CWindowImpl<T>, |
18 public ChromeFramePlugin<T> { | 18 public ChromeFramePlugin<T> { |
19 public: | 19 public: |
20 AutomationMockDelegate(MessageLoop* caller_message_loop, | 20 AutomationMockDelegate(MessageLoop* caller_message_loop, |
21 int launch_timeout, bool perform_version_check, | 21 int launch_timeout, bool perform_version_check, |
22 const std::wstring& profile_name, | 22 const std::wstring& profile_name, |
23 const std::wstring& extra_chrome_arguments, bool incognito, | 23 const std::wstring& extra_chrome_arguments, bool incognito) |
24 bool is_widget_mode) | |
25 : caller_message_loop_(caller_message_loop), is_connected_(false), | 24 : caller_message_loop_(caller_message_loop), is_connected_(false), |
26 navigation_result_(false) { | 25 navigation_result_(false) { |
27 test_server_.SetUp(); | 26 test_server_.SetUp(); |
28 automation_client_ = new ChromeFrameAutomationClient; | 27 automation_client_ = new ChromeFrameAutomationClient; |
29 ChromeFrameLaunchParams cfp = { | 28 automation_client_->Initialize(this, launch_timeout, perform_version_check, |
30 launch_timeout, | 29 profile_name, extra_chrome_arguments, incognito); |
31 GURL(), | |
32 GURL(), | |
33 profile_name, | |
34 extra_chrome_arguments, | |
35 perform_version_check, | |
36 incognito, | |
37 is_widget_mode | |
38 }; | |
39 automation_client_->Initialize(this, cfp); | |
40 } | 30 } |
41 ~AutomationMockDelegate() { | 31 ~AutomationMockDelegate() { |
42 if (automation_client_.get()) { | 32 if (automation_client_.get()) { |
43 automation_client_->Uninitialize(); | 33 automation_client_->Uninitialize(); |
44 automation_client_ = NULL; | 34 automation_client_ = NULL; |
45 } | 35 } |
46 if (IsWindow()) | 36 if (IsWindow()) |
47 DestroyWindow(); | 37 DestroyWindow(); |
48 | 38 |
49 test_server_.TearDown(); | 39 test_server_.TearDown(); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 bool is_connected_; | 123 bool is_connected_; |
134 bool navigation_result_; | 124 bool navigation_result_; |
135 }; | 125 }; |
136 | 126 |
137 class AutomationMockLaunch | 127 class AutomationMockLaunch |
138 : public AutomationMockDelegate<AutomationMockLaunch> { | 128 : public AutomationMockDelegate<AutomationMockLaunch> { |
139 public: | 129 public: |
140 typedef AutomationMockDelegate<AutomationMockLaunch> Base; | 130 typedef AutomationMockDelegate<AutomationMockLaunch> Base; |
141 AutomationMockLaunch(MessageLoop* caller_message_loop, | 131 AutomationMockLaunch(MessageLoop* caller_message_loop, |
142 int launch_timeout) | 132 int launch_timeout) |
143 : Base(caller_message_loop, launch_timeout, true, L"", L"", false, | 133 : Base(caller_message_loop, launch_timeout, true, L"", L"", false) { |
144 false) { | |
145 } | 134 } |
146 virtual void OnAutomationServerReady() { | 135 virtual void OnAutomationServerReady() { |
147 Base::OnAutomationServerReady(); | 136 Base::OnAutomationServerReady(); |
148 QuitMessageLoop(); | 137 QuitMessageLoop(); |
149 } | 138 } |
150 bool launch_result() const { | 139 bool launch_result() const { |
151 return is_connected(); | 140 return is_connected(); |
152 } | 141 } |
153 }; | 142 }; |
154 | 143 |
155 class AutomationMockNavigate | 144 class AutomationMockNavigate |
156 : public AutomationMockDelegate<AutomationMockNavigate> { | 145 : public AutomationMockDelegate<AutomationMockNavigate> { |
157 public: | 146 public: |
158 typedef AutomationMockDelegate<AutomationMockNavigate> Base; | 147 typedef AutomationMockDelegate<AutomationMockNavigate> Base; |
159 AutomationMockNavigate(MessageLoop* caller_message_loop, | 148 AutomationMockNavigate(MessageLoop* caller_message_loop, |
160 int launch_timeout) | 149 int launch_timeout) |
161 : Base(caller_message_loop, launch_timeout, true, L"", L"", false, | 150 : Base(caller_message_loop, launch_timeout, true, L"", L"", false) { |
162 false) { | |
163 } | 151 } |
164 virtual void OnLoad(int tab_handle, const GURL& url) { | 152 virtual void OnLoad(int tab_handle, const GURL& url) { |
165 Base::OnLoad(tab_handle, url); | 153 Base::OnLoad(tab_handle, url); |
166 QuitMessageLoop(); | 154 QuitMessageLoop(); |
167 } | 155 } |
168 }; | 156 }; |
169 | 157 |
170 class AutomationMockPostMessage | 158 class AutomationMockPostMessage |
171 : public AutomationMockDelegate<AutomationMockPostMessage> { | 159 : public AutomationMockDelegate<AutomationMockPostMessage> { |
172 public: | 160 public: |
173 typedef AutomationMockDelegate<AutomationMockPostMessage> Base; | 161 typedef AutomationMockDelegate<AutomationMockPostMessage> Base; |
174 AutomationMockPostMessage(MessageLoop* caller_message_loop, | 162 AutomationMockPostMessage(MessageLoop* caller_message_loop, |
175 int launch_timeout) | 163 int launch_timeout) |
176 : Base(caller_message_loop, launch_timeout, true, L"", L"", false, false), | 164 : Base(caller_message_loop, launch_timeout, true, L"", L"", false), |
177 postmessage_result_(false) {} | 165 postmessage_result_(false) {} |
178 bool postmessage_result() const { | 166 bool postmessage_result() const { |
179 return postmessage_result_; | 167 return postmessage_result_; |
180 } | 168 } |
181 virtual void OnLoad(int tab_handle, const GURL& url) { | 169 virtual void OnLoad(int tab_handle, const GURL& url) { |
182 Base::OnLoad(tab_handle, url); | 170 Base::OnLoad(tab_handle, url); |
183 if (navigation_result()) { | 171 if (navigation_result()) { |
184 automation()->ForwardMessageFromExternalHost("Test", "null", "*"); | 172 automation()->ForwardMessageFromExternalHost("Test", "null", "*"); |
185 } | 173 } |
186 } | 174 } |
187 virtual void OnMessageFromChromeFrame(int tab_handle, | 175 virtual void OnMessageFromChromeFrame(int tab_handle, |
188 const std::string& message, | 176 const std::string& message, |
189 const std::string& origin, | 177 const std::string& origin, |
190 const std::string& target) { | 178 const std::string& target) { |
191 postmessage_result_ = true; | 179 postmessage_result_ = true; |
192 QuitMessageLoop(); | 180 QuitMessageLoop(); |
193 } | 181 } |
194 private: | 182 private: |
195 bool postmessage_result_; | 183 bool postmessage_result_; |
196 }; | 184 }; |
197 | 185 |
198 class AutomationMockHostNetworkRequestStart | 186 class AutomationMockHostNetworkRequestStart |
199 : public AutomationMockDelegate<AutomationMockHostNetworkRequestStart> { | 187 : public AutomationMockDelegate<AutomationMockHostNetworkRequestStart> { |
200 public: | 188 public: |
201 typedef AutomationMockDelegate<AutomationMockHostNetworkRequestStart> Base; | 189 typedef AutomationMockDelegate<AutomationMockHostNetworkRequestStart> Base; |
202 AutomationMockHostNetworkRequestStart(MessageLoop* caller_message_loop, | 190 AutomationMockHostNetworkRequestStart(MessageLoop* caller_message_loop, |
203 int launch_timeout) | 191 int launch_timeout) |
204 : Base(caller_message_loop, launch_timeout, true, L"", L"", false, false), | 192 : Base(caller_message_loop, launch_timeout, true, L"", L"", false), |
205 request_start_result_(false) { | 193 request_start_result_(false) { |
206 if (automation()) { | 194 if (automation()) { |
207 automation()->set_use_chrome_network(false); | 195 automation()->set_use_chrome_network(false); |
208 } | 196 } |
209 } | 197 } |
210 bool request_start_result() const { | 198 bool request_start_result() const { |
211 return request_start_result_; | 199 return request_start_result_; |
212 } | 200 } |
213 virtual void OnRequestStart(int tab_handle, int request_id, | 201 virtual void OnRequestStart(int tab_handle, int request_id, |
214 const IPC::AutomationURLRequest& request) { | 202 const IPC::AutomationURLRequest& request) { |
215 request_start_result_ = true; | 203 request_start_result_ = true; |
216 QuitMessageLoop(); | 204 QuitMessageLoop(); |
217 } | 205 } |
218 virtual void OnLoad(int tab_handle, const GURL& url) { | 206 virtual void OnLoad(int tab_handle, const GURL& url) { |
219 Base::OnLoad(tab_handle, url); | 207 Base::OnLoad(tab_handle, url); |
220 } | 208 } |
221 private: | 209 private: |
222 bool request_start_result_; | 210 bool request_start_result_; |
223 }; | 211 }; |
224 | 212 |
225 | 213 |
226 #endif // CHROME_FRAME_TEST_CHROME_FRAME_AUTOMATION_MOCK_H_ | 214 #endif // CHROME_FRAME_TEST_CHROME_FRAME_AUTOMATION_MOCK_H_ |
227 | 215 |
OLD | NEW |