| 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_FRAME_TEST_CHROME_FRAME_AUTOMATION_MOCK_H_ | 5 #ifndef CHROME_FRAME_TEST_CHROME_FRAME_AUTOMATION_MOCK_H_ |
| 6 #define CHROME_FRAME_TEST_CHROME_FRAME_AUTOMATION_MOCK_H_ | 6 #define CHROME_FRAME_TEST_CHROME_FRAME_AUTOMATION_MOCK_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| 11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "chrome/common/chrome_switches.h" | 13 #include "chrome/common/chrome_switches.h" |
| 14 #include "chrome_frame/chrome_frame_automation.h" | 14 #include "chrome_frame/chrome_frame_automation.h" |
| 15 #include "chrome_frame/chrome_frame_plugin.h" | 15 #include "chrome_frame/chrome_frame_plugin.h" |
| 16 #include "chrome_frame/navigation_constraints.h" | 16 #include "chrome_frame/navigation_constraints.h" |
| 17 #include "chrome_frame/test/chrome_frame_test_utils.h" | 17 #include "chrome_frame/test/chrome_frame_test_utils.h" |
| 18 #include "chrome_frame/test/test_with_web_server.h" | 18 #include "chrome_frame/test/test_with_web_server.h" |
| 19 #include "chrome_frame/utils.h" | 19 #include "chrome_frame/utils.h" |
| 20 | 20 |
| 21 template <typename T> | 21 template <typename T> |
| 22 class AutomationMockDelegate | 22 class AutomationMockDelegate |
| 23 : public CWindowImpl<T>, | 23 : public CWindowImpl<T>, |
| 24 public ChromeFramePlugin<T> { | 24 public ChromeFramePlugin<T> { |
| 25 public: | 25 public: |
| 26 AutomationMockDelegate(MessageLoop* caller_message_loop, | 26 AutomationMockDelegate(MessageLoop* caller_message_loop, |
| 27 int launch_timeout, bool perform_version_check, | 27 int launch_timeout, bool perform_version_check, |
| 28 const std::wstring& profile_name, | 28 const std::wstring& profile_name, |
| 29 const std::wstring& language, | 29 const std::wstring& language, |
| 30 const std::wstring& extra_chrome_arguments, bool incognito, | 30 bool incognito, bool is_widget_mode) |
| 31 bool is_widget_mode) | |
| 32 : caller_message_loop_(caller_message_loop), is_connected_(false), | 31 : caller_message_loop_(caller_message_loop), is_connected_(false), |
| 33 navigation_result_(false), | 32 navigation_result_(false), |
| 34 mock_server_(1337, L"127.0.0.1", | 33 mock_server_(1337, L"127.0.0.1", |
| 35 chrome_frame_test::GetTestDataFolder()) { | 34 chrome_frame_test::GetTestDataFolder()) { |
| 36 | 35 |
| 37 // Endeavour to only kill off Chrome Frame derived Chrome processes. | 36 // Endeavour to only kill off Chrome Frame derived Chrome processes. |
| 38 KillAllNamedProcessesWithArgument( | 37 KillAllNamedProcessesWithArgument( |
| 39 UTF8ToWide(chrome_frame_test::kChromeImageName), | 38 UTF8ToWide(chrome_frame_test::kChromeImageName), |
| 40 UTF8ToWide(switches::kChromeFrame)); | 39 UTF8ToWide(switches::kChromeFrame)); |
| 41 | 40 |
| 42 mock_server_.ExpectAndServeAnyRequests(CFInvocation(CFInvocation::NONE)); | 41 mock_server_.ExpectAndServeAnyRequests(CFInvocation(CFInvocation::NONE)); |
| 43 | 42 |
| 44 FilePath profile_path( | 43 FilePath profile_path( |
| 45 chrome_frame_test::GetProfilePath(profile_name)); | 44 chrome_frame_test::GetProfilePath(profile_name)); |
| 46 | 45 |
| 47 automation_client_ = new ChromeFrameAutomationClient; | 46 automation_client_ = new ChromeFrameAutomationClient; |
| 48 GURL empty; | 47 GURL empty; |
| 49 scoped_refptr<ChromeFrameLaunchParams> clp( | 48 scoped_refptr<ChromeFrameLaunchParams> clp( |
| 50 new ChromeFrameLaunchParams(empty, empty, profile_path, profile_name, | 49 new ChromeFrameLaunchParams(empty, empty, profile_path, profile_name, |
| 51 language, extra_chrome_arguments, incognito, is_widget_mode, | 50 language, incognito, is_widget_mode, false)); |
| 52 false)); | |
| 53 clp->set_launch_timeout(launch_timeout); | 51 clp->set_launch_timeout(launch_timeout); |
| 54 clp->set_version_check(perform_version_check); | 52 clp->set_version_check(perform_version_check); |
| 55 automation_client_->Initialize(this, clp); | 53 automation_client_->Initialize(this, clp); |
| 56 } | 54 } |
| 57 ~AutomationMockDelegate() { | 55 ~AutomationMockDelegate() { |
| 58 if (automation_client_.get()) { | 56 if (automation_client_.get()) { |
| 59 automation_client_->Uninitialize(); | 57 automation_client_->Uninitialize(); |
| 60 automation_client_ = NULL; | 58 automation_client_ = NULL; |
| 61 } | 59 } |
| 62 if (IsWindow()) | 60 if (IsWindow()) |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 bool is_connected_; | 145 bool is_connected_; |
| 148 bool navigation_result_; | 146 bool navigation_result_; |
| 149 }; | 147 }; |
| 150 | 148 |
| 151 class AutomationMockLaunch | 149 class AutomationMockLaunch |
| 152 : public AutomationMockDelegate<AutomationMockLaunch> { | 150 : public AutomationMockDelegate<AutomationMockLaunch> { |
| 153 public: | 151 public: |
| 154 typedef AutomationMockDelegate<AutomationMockLaunch> Base; | 152 typedef AutomationMockDelegate<AutomationMockLaunch> Base; |
| 155 AutomationMockLaunch(MessageLoop* caller_message_loop, | 153 AutomationMockLaunch(MessageLoop* caller_message_loop, |
| 156 int launch_timeout) | 154 int launch_timeout) |
| 157 : Base(caller_message_loop, launch_timeout, true, L"", L"", L"", false, | 155 : Base(caller_message_loop, launch_timeout, true, L"", L"", false, |
| 158 false) { | 156 false) { |
| 159 } | 157 } |
| 160 virtual void OnAutomationServerReady() { | 158 virtual void OnAutomationServerReady() { |
| 161 Base::OnAutomationServerReady(); | 159 Base::OnAutomationServerReady(); |
| 162 QuitMessageLoop(); | 160 QuitMessageLoop(); |
| 163 } | 161 } |
| 164 bool launch_result() const { | 162 bool launch_result() const { |
| 165 return is_connected(); | 163 return is_connected(); |
| 166 } | 164 } |
| 167 }; | 165 }; |
| 168 | 166 |
| 169 class AutomationMockNavigate | 167 class AutomationMockNavigate |
| 170 : public AutomationMockDelegate<AutomationMockNavigate> { | 168 : public AutomationMockDelegate<AutomationMockNavigate> { |
| 171 public: | 169 public: |
| 172 typedef AutomationMockDelegate<AutomationMockNavigate> Base; | 170 typedef AutomationMockDelegate<AutomationMockNavigate> Base; |
| 173 AutomationMockNavigate(MessageLoop* caller_message_loop, | 171 AutomationMockNavigate(MessageLoop* caller_message_loop, |
| 174 int launch_timeout) | 172 int launch_timeout) |
| 175 : Base(caller_message_loop, launch_timeout, true, L"", L"", L"", false, | 173 : Base(caller_message_loop, launch_timeout, true, L"", L"", false, |
| 176 false) { | 174 false) { |
| 177 } | 175 } |
| 178 virtual void OnLoad(const GURL& url) { | 176 virtual void OnLoad(const GURL& url) { |
| 179 Base::OnLoad(url); | 177 Base::OnLoad(url); |
| 180 QuitMessageLoop(); | 178 QuitMessageLoop(); |
| 181 } | 179 } |
| 182 }; | 180 }; |
| 183 | 181 |
| 184 class AutomationMockPostMessage | 182 class AutomationMockPostMessage |
| 185 : public AutomationMockDelegate<AutomationMockPostMessage> { | 183 : public AutomationMockDelegate<AutomationMockPostMessage> { |
| 186 public: | 184 public: |
| 187 typedef AutomationMockDelegate<AutomationMockPostMessage> Base; | 185 typedef AutomationMockDelegate<AutomationMockPostMessage> Base; |
| 188 AutomationMockPostMessage(MessageLoop* caller_message_loop, | 186 AutomationMockPostMessage(MessageLoop* caller_message_loop, |
| 189 int launch_timeout) | 187 int launch_timeout) |
| 190 : Base(caller_message_loop, launch_timeout, true, L"", L"", L"", false, | 188 : Base(caller_message_loop, launch_timeout, true, L"", L"", false, |
| 191 false), | 189 false), |
| 192 postmessage_result_(false) {} | 190 postmessage_result_(false) {} |
| 193 bool postmessage_result() const { | 191 bool postmessage_result() const { |
| 194 return postmessage_result_; | 192 return postmessage_result_; |
| 195 } | 193 } |
| 196 virtual void OnLoad(const GURL& url) { | 194 virtual void OnLoad(const GURL& url) { |
| 197 Base::OnLoad(url); | 195 Base::OnLoad(url); |
| 198 if (navigation_result()) { | 196 if (navigation_result()) { |
| 199 automation()->ForwardMessageFromExternalHost("Test", "null", "*"); | 197 automation()->ForwardMessageFromExternalHost("Test", "null", "*"); |
| 200 } | 198 } |
| 201 } | 199 } |
| 202 virtual void OnMessageFromChromeFrame(const std::string& message, | 200 virtual void OnMessageFromChromeFrame(const std::string& message, |
| 203 const std::string& origin, | 201 const std::string& origin, |
| 204 const std::string& target) { | 202 const std::string& target) { |
| 205 postmessage_result_ = true; | 203 postmessage_result_ = true; |
| 206 QuitMessageLoop(); | 204 QuitMessageLoop(); |
| 207 } | 205 } |
| 208 private: | 206 private: |
| 209 bool postmessage_result_; | 207 bool postmessage_result_; |
| 210 }; | 208 }; |
| 211 | 209 |
| 212 class AutomationMockHostNetworkRequestStart | 210 class AutomationMockHostNetworkRequestStart |
| 213 : public AutomationMockDelegate<AutomationMockHostNetworkRequestStart> { | 211 : public AutomationMockDelegate<AutomationMockHostNetworkRequestStart> { |
| 214 public: | 212 public: |
| 215 typedef AutomationMockDelegate<AutomationMockHostNetworkRequestStart> Base; | 213 typedef AutomationMockDelegate<AutomationMockHostNetworkRequestStart> Base; |
| 216 AutomationMockHostNetworkRequestStart(MessageLoop* caller_message_loop, | 214 AutomationMockHostNetworkRequestStart(MessageLoop* caller_message_loop, |
| 217 int launch_timeout) | 215 int launch_timeout) |
| 218 : Base(caller_message_loop, launch_timeout, true, L"", L"", L"", false, | 216 : Base(caller_message_loop, launch_timeout, true, L"", L"", false, |
| 219 false), | 217 false), |
| 220 request_start_result_(false) { | 218 request_start_result_(false) { |
| 221 if (automation()) { | 219 if (automation()) { |
| 222 automation()->set_use_chrome_network(false); | 220 automation()->set_use_chrome_network(false); |
| 223 } | 221 } |
| 224 } | 222 } |
| 225 bool request_start_result() const { | 223 bool request_start_result() const { |
| 226 return request_start_result_; | 224 return request_start_result_; |
| 227 } | 225 } |
| 228 virtual void OnRequestStart(int request_id, | 226 virtual void OnRequestStart(int request_id, |
| 229 const AutomationURLRequest& request) { | 227 const AutomationURLRequest& request) { |
| 230 request_start_result_ = true; | 228 request_start_result_ = true; |
| 231 QuitMessageLoop(); | 229 QuitMessageLoop(); |
| 232 } | 230 } |
| 233 virtual void OnLoad(const GURL& url) { | 231 virtual void OnLoad(const GURL& url) { |
| 234 Base::OnLoad(url); | 232 Base::OnLoad(url); |
| 235 } | 233 } |
| 236 private: | 234 private: |
| 237 bool request_start_result_; | 235 bool request_start_result_; |
| 238 }; | 236 }; |
| 239 | 237 |
| 240 #endif // CHROME_FRAME_TEST_CHROME_FRAME_AUTOMATION_MOCK_H_ | 238 #endif // CHROME_FRAME_TEST_CHROME_FRAME_AUTOMATION_MOCK_H_ |
| OLD | NEW |