1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
|
// Copyright 2008, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef CHROME_TEST_AUTOMATION_AUTOCOMPLETE_EDIT_PROXY_H__
#define CHROME_TEST_AUTOMATION_AUTOCOMPLETE_EDIT_PROXY_H__
#include <string>
#include <vector>
#include "chrome/browser/autocomplete/autocomplete.h"
#include "chrome/common/ipc_message.h"
#include "chrome/common/ipc_message_utils.h"
#include "chrome/test/automation/automation_handle_tracker.h"
// The purpose of this class is to act as a searializable version of
// AutocompleteMatch. The reason for this class is because we don't want to
// searialize all elements of AutocompleteMatch and we want some data from the
// autocomplete provider without the hassle of serializing it.
struct AutocompleteMatchData {
public:
AutocompleteMatchData() {}
explicit AutocompleteMatchData(const AutocompleteMatch& match)
: contents(match.contents),
deletable(match.deletable),
description(match.description),
destination_url(match.destination_url),
fill_into_edit(match.fill_into_edit),
inline_autocomplete_offset(match.inline_autocomplete_offset),
is_history_what_you_typed_match(match.is_history_what_you_typed_match),
provider_name(match.provider->name()),
relevance(match.relevance),
starred(match.starred) {
switch (match.type) {
case AutocompleteMatch::URL:
str_type = L"URL";
break;
case AutocompleteMatch::KEYWORD:
str_type = L"KEYWORD";
break;
case AutocompleteMatch::SEARCH:
str_type = L"SEARCH";
break;
case AutocompleteMatch::HISTORY_SEARCH:
str_type = L"HISTORY";
break;
default:
NOTREACHED();
}
}
std::wstring contents;
bool deletable;
std::wstring description;
std::wstring destination_url;
std::wstring fill_into_edit;
size_t inline_autocomplete_offset;
bool is_history_what_you_typed_match;
std::string provider_name;
int relevance;
bool starred;
std::wstring str_type;
};
typedef std::vector<AutocompleteMatchData> Matches;
namespace IPC {
template <>
struct ParamTraits<AutocompleteMatchData> {
typedef AutocompleteMatchData param_type;
static void Write(Message* m, const param_type& p) {
m->WriteWString(p.contents);
m->WriteBool(p.deletable);
m->WriteWString(p.description);
m->WriteWString(p.destination_url);
m->WriteWString(p.fill_into_edit);
m->WriteSize(p.inline_autocomplete_offset);
m->WriteBool(p.is_history_what_you_typed_match);
m->WriteString(p.provider_name);
m->WriteInt(p.relevance);
m->WriteBool(p.starred);
m->WriteWString(p.str_type);
}
static bool Read(const Message* m, void** iter, param_type* r) {
return m->ReadWString(iter, &r->contents) &&
m->ReadBool(iter, &r->deletable) &&
m->ReadWString(iter, &r->description) &&
m->ReadWString(iter, &r->destination_url) &&
m->ReadWString(iter, &r->fill_into_edit) &&
m->ReadSize(iter, &r->inline_autocomplete_offset) &&
m->ReadBool(iter, &r->is_history_what_you_typed_match) &&
m->ReadString(iter, &r->provider_name) &&
m->ReadInt(iter, &r->relevance) &&
m->ReadBool(iter, &r->starred) &&
m->ReadWString(iter, &r->str_type);
}
static void Log(const param_type& p, std::wstring* l) {
l->append(StringPrintf(L"[%S %s %S %S %S %d %s %s %d %s %S]",
p.contents, p.deletable ? "true" : "false", p.description,
p.destination_url, p.fill_into_edit, p.inline_autocomplete_offset,
p.is_history_what_you_typed_match ? "true" : "false", p.provider_name,
p.relevance, p.starred ? "true" : "false", p.str_type));
}
};
} // namespace IPC
class AutocompleteEditProxy : public AutomationResourceProxy {
public:
AutocompleteEditProxy(AutomationMessageSender* sender,
AutomationHandleTracker* tracker,
int handle)
: AutomationResourceProxy(tracker, sender, handle) {}
virtual ~AutocompleteEditProxy() {}
// All these functions return true if the autocomplete edit is valid and
// there are no IPC errors.
// Gets the text visible in the omnibox.
bool GetText(std::wstring* text) const;
// Sets the text visible in the omnibox.
bool SetText(const std::wstring& text);
// Determines if a query to an autocomplete provider is still in progress.
// NOTE: No autocomplete queries will be made if the omnibox doesn't have
// focus. This can be achieved by sending a IDC_FOCUS_LOCATION accelerator
// to the browser.
bool IsQueryInProgress(bool* query_in_progress) const;
// Gets a list of autocomplete matches that have been gathered so far.
bool GetAutocompleteMatches(Matches* matches) const;
// Waits for all queries to autocomplete providers to complete.
// |wait_timeout_ms| gives the number of milliseconds to wait for the query
// to finish. Returns false if IPC call failed or if the function times out.
bool WaitForQuery(int wait_timeout_ms) const;
private:
DISALLOW_EVIL_CONSTRUCTORS(AutocompleteEditProxy);
};
#endif // #define CHROME_TEST_AUTOMATION_AUTOCOMPLETE_EDIT_PROXY_H__
|