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 | 4 |
5 #include "chrome/test/automation/browser_proxy.h" | 5 #include "chrome/test/automation/browser_proxy.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/platform_thread.h" |
10 #include "base/time.h" | 11 #include "base/time.h" |
11 #include "chrome/test/automation/autocomplete_edit_proxy.h" | 12 #include "chrome/test/automation/autocomplete_edit_proxy.h" |
12 #include "chrome/test/automation/automation_constants.h" | 13 #include "chrome/test/automation/automation_constants.h" |
13 #include "chrome/test/automation/automation_messages.h" | 14 #include "chrome/test/automation/automation_messages.h" |
14 #include "chrome/test/automation/automation_proxy.h" | 15 #include "chrome/test/automation/automation_proxy.h" |
15 #include "chrome/test/automation/tab_proxy.h" | 16 #include "chrome/test/automation/tab_proxy.h" |
16 #include "chrome/test/automation/window_proxy.h" | 17 #include "chrome/test/automation/window_proxy.h" |
17 | 18 |
18 using base::TimeDelta; | 19 using base::TimeDelta; |
19 using base::TimeTicks; | 20 using base::TimeTicks; |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 } | 165 } |
165 | 166 |
166 bool BrowserProxy::ApplyAccelerator(int id) { | 167 bool BrowserProxy::ApplyAccelerator(int id) { |
167 if (!is_valid()) | 168 if (!is_valid()) |
168 return false; | 169 return false; |
169 | 170 |
170 return sender_->Send( | 171 return sender_->Send( |
171 new AutomationMsg_ApplyAccelerator(0, handle_, id)); | 172 new AutomationMsg_ApplyAccelerator(0, handle_, id)); |
172 } | 173 } |
173 | 174 |
| 175 #if defined(OS_WIN) |
| 176 // TODO(port): Replace POINT. |
174 bool BrowserProxy::SimulateDrag(const POINT& start, | 177 bool BrowserProxy::SimulateDrag(const POINT& start, |
175 const POINT& end, | 178 const POINT& end, |
176 int flags, | 179 int flags, |
177 bool press_escape_en_route) { | 180 bool press_escape_en_route) { |
178 return SimulateDragWithTimeout(start, end, flags, base::kNoTimeout, NULL, | 181 return SimulateDragWithTimeout(start, end, flags, base::kNoTimeout, NULL, |
179 press_escape_en_route); | 182 press_escape_en_route); |
180 } | 183 } |
181 | 184 |
182 bool BrowserProxy::SimulateDragWithTimeout(const POINT& start, | 185 bool BrowserProxy::SimulateDragWithTimeout(const POINT& start, |
183 const POINT& end, | 186 const POINT& end, |
184 int flags, | 187 int flags, |
185 uint32 timeout_ms, | 188 uint32 timeout_ms, |
186 bool* is_timeout, | 189 bool* is_timeout, |
187 bool press_escape_en_route) { | 190 bool press_escape_en_route) { |
188 if (!is_valid()) | 191 if (!is_valid()) |
189 return false; | 192 return false; |
190 | 193 |
191 std::vector<POINT> drag_path; | 194 std::vector<POINT> drag_path; |
192 drag_path.push_back(start); | 195 drag_path.push_back(start); |
193 drag_path.push_back(end); | 196 drag_path.push_back(end); |
194 | 197 |
195 bool result = false; | 198 bool result = false; |
196 | 199 |
197 sender_->SendWithTimeout(new AutomationMsg_WindowDrag( | 200 sender_->SendWithTimeout(new AutomationMsg_WindowDrag( |
198 0, handle_, drag_path, flags, press_escape_en_route, &result), | 201 0, handle_, drag_path, flags, press_escape_en_route, &result), |
199 timeout_ms, is_timeout); | 202 timeout_ms, is_timeout); |
200 | 203 |
201 return result; | 204 return result; |
202 } | 205 } |
| 206 #endif // defined(OS_WIN) |
203 | 207 |
204 bool BrowserProxy::WaitForTabCountToChange(int count, int* new_count, | 208 bool BrowserProxy::WaitForTabCountToChange(int count, int* new_count, |
205 int wait_timeout) { | 209 int wait_timeout) { |
206 const TimeTicks start = TimeTicks::Now(); | 210 const TimeTicks start = TimeTicks::Now(); |
207 const TimeDelta timeout = TimeDelta::FromMilliseconds(wait_timeout); | 211 const TimeDelta timeout = TimeDelta::FromMilliseconds(wait_timeout); |
208 while (TimeTicks::Now() - start < timeout) { | 212 while (TimeTicks::Now() - start < timeout) { |
209 Sleep(automation::kSleepTime); | 213 PlatformThread::Sleep(automation::kSleepTime); |
210 bool is_timeout; | 214 bool is_timeout; |
211 bool succeeded = GetTabCountWithTimeout(new_count, wait_timeout, | 215 bool succeeded = GetTabCountWithTimeout(new_count, wait_timeout, |
212 &is_timeout); | 216 &is_timeout); |
213 if (!succeeded) | 217 if (!succeeded) |
214 return false; | 218 return false; |
215 if (count != *new_count) | 219 if (count != *new_count) |
216 return true; | 220 return true; |
217 } | 221 } |
218 // If we get here, the tab count hasn't changed. | 222 // If we get here, the tab count hasn't changed. |
219 return false; | 223 return false; |
220 } | 224 } |
221 | 225 |
222 bool BrowserProxy::WaitForTabCountToBecome(int count, int wait_timeout) { | 226 bool BrowserProxy::WaitForTabCountToBecome(int count, int wait_timeout) { |
223 const TimeTicks start = TimeTicks::Now(); | 227 const TimeTicks start = TimeTicks::Now(); |
224 const TimeDelta timeout = TimeDelta::FromMilliseconds(wait_timeout); | 228 const TimeDelta timeout = TimeDelta::FromMilliseconds(wait_timeout); |
225 while (TimeTicks::Now() - start < timeout) { | 229 while (TimeTicks::Now() - start < timeout) { |
226 Sleep(automation::kSleepTime); | 230 PlatformThread::Sleep(automation::kSleepTime); |
227 bool is_timeout; | 231 bool is_timeout; |
228 int new_count; | 232 int new_count; |
229 bool succeeded = GetTabCountWithTimeout(&new_count, wait_timeout, | 233 bool succeeded = GetTabCountWithTimeout(&new_count, wait_timeout, |
230 &is_timeout); | 234 &is_timeout); |
231 if (!succeeded) | 235 if (!succeeded) |
232 return false; | 236 return false; |
233 if (count == new_count) | 237 if (count == new_count) |
234 return true; | 238 return true; |
235 } | 239 } |
236 // If we get here, the tab count doesn't match. | 240 // If we get here, the tab count doesn't match. |
237 return false; | 241 return false; |
238 } | 242 } |
239 | 243 |
240 bool BrowserProxy::WaitForTabToBecomeActive(int tab, | 244 bool BrowserProxy::WaitForTabToBecomeActive(int tab, |
241 int wait_timeout) { | 245 int wait_timeout) { |
242 const TimeTicks start = TimeTicks::Now(); | 246 const TimeTicks start = TimeTicks::Now(); |
243 const TimeDelta timeout = TimeDelta::FromMilliseconds(wait_timeout); | 247 const TimeDelta timeout = TimeDelta::FromMilliseconds(wait_timeout); |
244 while (TimeTicks::Now() - start < timeout) { | 248 while (TimeTicks::Now() - start < timeout) { |
245 Sleep(automation::kSleepTime); | 249 PlatformThread::Sleep(automation::kSleepTime); |
246 int active_tab; | 250 int active_tab; |
247 if (GetActiveTabIndex(&active_tab) && active_tab == tab) | 251 if (GetActiveTabIndex(&active_tab) && active_tab == tab) |
248 return true; | 252 return true; |
249 } | 253 } |
250 // If we get here, the active tab hasn't changed. | 254 // If we get here, the active tab hasn't changed. |
251 return false; | 255 return false; |
252 } | 256 } |
253 | 257 |
254 bool BrowserProxy::OpenFindInPage() { | 258 bool BrowserProxy::OpenFindInPage() { |
255 if (!is_valid()) | 259 if (!is_valid()) |
(...skipping 17 matching lines...) Expand all Loading... |
273 | 277 |
274 if (!is_visible) { | 278 if (!is_visible) { |
275 NOTREACHED(); | 279 NOTREACHED(); |
276 return false; | 280 return false; |
277 } | 281 } |
278 | 282 |
279 return sender_->Send( | 283 return sender_->Send( |
280 new AutomationMsg_FindWindowVisibility(0, handle_, is_visible)); | 284 new AutomationMsg_FindWindowVisibility(0, handle_, is_visible)); |
281 } | 285 } |
282 | 286 |
| 287 #if defined(OS_WIN) |
| 288 // TODO(port): Replace HWND. |
283 bool BrowserProxy::GetHWND(HWND* handle) const { | 289 bool BrowserProxy::GetHWND(HWND* handle) const { |
284 if (!is_valid()) | 290 if (!is_valid()) |
285 return false; | 291 return false; |
286 | 292 |
287 if (!handle) { | 293 if (!handle) { |
288 NOTREACHED(); | 294 NOTREACHED(); |
289 return false; | 295 return false; |
290 } | 296 } |
291 | 297 |
292 return sender_->Send(new AutomationMsg_WindowHWND(0, handle_, handle)); | 298 return sender_->Send(new AutomationMsg_WindowHWND(0, handle_, handle)); |
293 } | 299 } |
| 300 #endif // defined(OS_WIN) |
294 | 301 |
295 bool BrowserProxy::RunCommand(int browser_command) const { | 302 bool BrowserProxy::RunCommand(int browser_command) const { |
296 if (!is_valid()) | 303 if (!is_valid()) |
297 return false; | 304 return false; |
298 | 305 |
299 bool result = false; | 306 bool result = false; |
300 | 307 |
301 sender_->Send(new AutomationMsg_WindowExecuteCommand(0, handle_, | 308 sender_->Send(new AutomationMsg_WindowExecuteCommand(0, handle_, |
302 browser_command, | 309 browser_command, |
303 &result)); | 310 &result)); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 int autocomplete_edit_handle = 0; | 396 int autocomplete_edit_handle = 0; |
390 | 397 |
391 sender_->Send(new AutomationMsg_AutocompleteEditForBrowser( | 398 sender_->Send(new AutomationMsg_AutocompleteEditForBrowser( |
392 0, handle_, &handle_ok, &autocomplete_edit_handle)); | 399 0, handle_, &handle_ok, &autocomplete_edit_handle)); |
393 | 400 |
394 if (!handle_ok) | 401 if (!handle_ok) |
395 return NULL; | 402 return NULL; |
396 | 403 |
397 return new AutocompleteEditProxy(sender_, tracker_, autocomplete_edit_handle); | 404 return new AutocompleteEditProxy(sender_, tracker_, autocomplete_edit_handle); |
398 } | 405 } |
OLD | NEW |