Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(185)

Side by Side Diff: chrome_frame/test/chrome_frame_automation_mock.h

Issue 218019: Initial import of the Chrome Frame codebase. Integration in chrome.gyp coming... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 11 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4 #ifndef CHROME_FRAME_TEST_CHROME_FRAME_AUTOMATION_MOCK_H_
5 #define CHROME_FRAME_TEST_CHROME_FRAME_AUTOMATION_MOCK_H_
6
7 #include <string>
8
9 #include "base/file_path.h"
10 #include "base/path_service.h"
11 #include "chrome_frame/chrome_frame_automation.h"
12 #include "chrome_frame/chrome_frame_plugin.h"
13 #include "chrome_frame/test/http_server.h"
14
15 template <typename T>
16 class AutomationMockDelegate
17 : public CWindowImpl<T>,
18 public ChromeFramePlugin<T> {
19 public:
20 AutomationMockDelegate(MessageLoop* caller_message_loop,
21 int launch_timeout, bool perform_version_check,
22 const std::wstring& profile_name,
23 const std::wstring& extra_chrome_arguments, bool incognito)
24 : caller_message_loop_(caller_message_loop), is_connected_(false) {
25 test_server_.SetUp();
26 automation_client_.reset(new ChromeFrameAutomationClient);
27 automation_client_->Initialize(this, launch_timeout, perform_version_check,
28 profile_name, extra_chrome_arguments, incognito);
29 }
30 ~AutomationMockDelegate() {
31 if (automation_client_.get()) {
32 automation_client_->Uninitialize();
33 automation_client_.reset();
34 }
35 if (IsWindow())
36 DestroyWindow();
37
38 test_server_.TearDown();
39 }
40
41 // Navigate external tab to the specified url through automation
42 bool Navigate(const std::string& url) {
43 url_ = GURL(url);
44 return automation_client_->InitiateNavigation(url);
45 }
46
47 // Navigate the external to a 'file://' url for unit test files
48 bool NavigateRelativeFile(const std::wstring& file) {
49 FilePath cf_source_path;
50 PathService::Get(base::DIR_SOURCE_ROOT, &cf_source_path);
51 std::wstring file_url(L"file://");
52 file_url.append(cf_source_path.Append(
53 FILE_PATH_LITERAL("chrome_frame")).Append(
54 FILE_PATH_LITERAL("test")).Append(
55 FILE_PATH_LITERAL("data")).Append(file).value());
56 return Navigate(WideToUTF8(file_url));
57 }
58
59 bool NavigateRelative(const std::wstring& relative_url) {
60 return Navigate(test_server_.Resolve(relative_url.c_str()).spec());
61 }
62
63 virtual void OnAutomationServerReady() {
64 if (automation_client_.get()) {
65 Create(NULL, 0, NULL, WS_OVERLAPPEDWINDOW);
66 DCHECK(IsWindow());
67 is_connected_ = true;
68 } else {
69 NOTREACHED();
70 }
71 }
72
73 virtual void OnAutomationServerLaunchFailed() {
74 QuitMessageLoop();
75 }
76
77 virtual void OnLoad(int tab_handle, const GURL& url) {
78 if (url_ == url) {
79 navigation_result_ = true;
80 } else {
81 QuitMessageLoop();
82 }
83 }
84
85 virtual void OnLoadFailed(int error_code, const std::string& url) {
86 QuitMessageLoop();
87 }
88
89 ChromeFrameAutomationClient* automation() {
90 return automation_client_.get();
91 }
92 const GURL& url() const {
93 return url_;
94 }
95 bool is_connected() const {
96 return is_connected_;
97 }
98 bool navigation_result() const {
99 return navigation_result_;
100 }
101
102 BEGIN_MSG_MAP(AutomationMockDelegate)
103 END_MSG_MAP()
104
105 protected:
106 void QuitMessageLoop() {
107 // Quit on the caller message loop has to be called on the caller
108 // thread.
109 caller_message_loop_->PostTask(FROM_HERE, new MessageLoop::QuitTask);
110 }
111
112 private:
113 ChromeFrameHTTPServer test_server_;
114 MessageLoop* caller_message_loop_;
115 GURL url_;
116 bool is_connected_;
117 bool navigation_result_;
118 };
119
120 class AutomationMockLaunch
121 : public AutomationMockDelegate<AutomationMockLaunch> {
122 public:
123 typedef AutomationMockDelegate<AutomationMockLaunch> Base;
124 AutomationMockLaunch(MessageLoop* caller_message_loop,
125 int launch_timeout)
126 : Base(caller_message_loop, launch_timeout, true, L"", L"", false) {
127 }
128 virtual void OnAutomationServerReady() {
129 Base::OnAutomationServerReady();
130 QuitMessageLoop();
131 }
132 bool launch_result() const {
133 return is_connected();
134 }
135 };
136
137 class AutomationMockNavigate
138 : public AutomationMockDelegate<AutomationMockNavigate> {
139 public:
140 typedef AutomationMockDelegate<AutomationMockNavigate> Base;
141 AutomationMockNavigate(MessageLoop* caller_message_loop,
142 int launch_timeout)
143 : Base(caller_message_loop, launch_timeout, true, L"", L"", false) {
144 }
145 virtual void OnLoad(int tab_handle, const GURL& url) {
146 Base::OnLoad(tab_handle, url);
147 QuitMessageLoop();
148 }
149 };
150
151 class AutomationMockPostMessage
152 : public AutomationMockDelegate<AutomationMockPostMessage> {
153 public:
154 typedef AutomationMockDelegate<AutomationMockPostMessage> Base;
155 AutomationMockPostMessage(MessageLoop* caller_message_loop,
156 int launch_timeout)
157 : Base(caller_message_loop, launch_timeout, true, L"", L"", false),
158 postmessage_result_(false) {}
159 bool postmessage_result() const {
160 return postmessage_result_;
161 }
162 virtual void OnLoad(int tab_handle, const GURL& url) {
163 Base::OnLoad(tab_handle, url);
164 if (navigation_result()) {
165 automation()->ForwardMessageFromExternalHost("Test", "null", "*");
166 }
167 }
168 virtual void OnMessageFromChromeFrame(int tab_handle,
169 const std::string& message,
170 const std::string& origin,
171 const std::string& target) {
172 postmessage_result_ = true;
173 QuitMessageLoop();
174 }
175 private:
176 bool postmessage_result_;
177 };
178
179 class AutomationMockHostNetworkRequestStart
180 : public AutomationMockDelegate<AutomationMockHostNetworkRequestStart> {
181 public:
182 typedef AutomationMockDelegate<AutomationMockHostNetworkRequestStart> Base;
183 AutomationMockHostNetworkRequestStart(MessageLoop* caller_message_loop,
184 int launch_timeout)
185 : Base(caller_message_loop, launch_timeout, true, L"", L"", false),
186 request_start_result_(false) {
187 if (automation()) {
188 automation()->set_use_chrome_network(false);
189 }
190 }
191 bool request_start_result() const {
192 return request_start_result_;
193 }
194 virtual void OnRequestStart(int tab_handle, int request_id,
195 const IPC::AutomationURLRequest& request) {
196 request_start_result_ = true;
197 QuitMessageLoop();
198 }
199 virtual void OnLoad(int tab_handle, const GURL& url) {
200 Base::OnLoad(tab_handle, url);
201 }
202 private:
203 bool request_start_result_;
204 };
205
206
207 #endif // CHROME_FRAME_TEST_CHROME_FRAME_AUTOMATION_MOCK_H_
208
OLDNEW
« no previous file with comments | « chrome_frame/test/ChromeTab_UnitTests.vcproj ('k') | chrome_frame/test/chrome_frame_automation_mock.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698