| OLD | NEW |
| (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 | |
| 5 #include "chrome/test/automation/autocomplete_edit_proxy.h" | |
| 6 | |
| 7 #include <vector> | |
| 8 | |
| 9 #include "base/threading/platform_thread.h" | |
| 10 #include "chrome/common/automation_constants.h" | |
| 11 #include "chrome/common/automation_messages.h" | |
| 12 #include "chrome/test/automation/automation_proxy.h" | |
| 13 | |
| 14 using base::TimeDelta; | |
| 15 using base::TimeTicks; | |
| 16 | |
| 17 bool AutocompleteEditProxy::GetText(string16* text) const { | |
| 18 if (!is_valid()) | |
| 19 return false; | |
| 20 if (!text) { | |
| 21 NOTREACHED(); | |
| 22 return false; | |
| 23 } | |
| 24 bool result = false; | |
| 25 sender_->Send(new AutomationMsg_AutocompleteEditGetText( | |
| 26 handle_, &result, text)); | |
| 27 return result; | |
| 28 } | |
| 29 | |
| 30 bool AutocompleteEditProxy::WaitForFocus() const { | |
| 31 if (!is_valid()) | |
| 32 return false; | |
| 33 bool edit_exists = false; | |
| 34 sender_->Send(new AutomationMsg_WaitForAutocompleteEditFocus( | |
| 35 handle_, &edit_exists)); | |
| 36 return edit_exists; | |
| 37 } | |
| 38 | |
| 39 bool AutocompleteEditProxy::SetText(const string16& text) { | |
| 40 if (!is_valid()) | |
| 41 return false; | |
| 42 bool result = false; | |
| 43 sender_->Send(new AutomationMsg_AutocompleteEditSetText( | |
| 44 handle_, text, &result)); | |
| 45 return result; | |
| 46 } | |
| 47 | |
| 48 bool AutocompleteEditProxy::IsQueryInProgress(bool* query_in_progress) const { | |
| 49 if (!is_valid()) | |
| 50 return false; | |
| 51 if (!query_in_progress) { | |
| 52 NOTREACHED(); | |
| 53 return false; | |
| 54 } | |
| 55 bool edit_exists = false; | |
| 56 sender_->Send(new AutomationMsg_AutocompleteEditIsQueryInProgress( | |
| 57 handle_, &edit_exists, query_in_progress)); | |
| 58 return edit_exists; | |
| 59 } | |
| 60 | |
| 61 bool AutocompleteEditProxy::WaitForQuery(int wait_timeout_ms) const { | |
| 62 // TODO(jknotten): use a delayed message / observer instead. | |
| 63 // See, for example, AutocompleteEditProxy::WaitForFocus. | |
| 64 const TimeTicks start = TimeTicks::Now(); | |
| 65 const TimeDelta timeout = TimeDelta::FromMilliseconds(wait_timeout_ms); | |
| 66 bool query_in_progress; | |
| 67 while (TimeTicks::Now() - start < timeout) { | |
| 68 if (IsQueryInProgress(&query_in_progress) && !query_in_progress) | |
| 69 return true; | |
| 70 base::PlatformThread::Sleep(automation::kSleepTime); | |
| 71 } | |
| 72 // If we get here the query is still in progress. | |
| 73 return false; | |
| 74 } | |
| 75 | |
| 76 bool AutocompleteEditProxy::GetAutocompleteMatches(Matches* matches) const { | |
| 77 if (!is_valid()) | |
| 78 return false; | |
| 79 if (!matches) { | |
| 80 NOTREACHED(); | |
| 81 return false; | |
| 82 } | |
| 83 bool edit_exists = false; | |
| 84 sender_->Send(new AutomationMsg_AutocompleteEditGetMatches( | |
| 85 handle_, &edit_exists, matches)); | |
| 86 return edit_exists; | |
| 87 } | |
| OLD | NEW |