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