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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
|
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/test/accessibility/tab_impl.h"
#include <oleacc.h>
#include "chrome/test/accessibility/accessibility_util.h"
#include "chrome/test/accessibility/browser_impl.h"
#include "chrome/test/accessibility/keyboard_util.h"
TabImpl::~TabImpl() {
if (tab_) {
SysFreeString(tab_->title_);
delete tab_;
}
}
bool TabImpl::Close(void) {
IAccessible* acc_obj = NULL;
HWND hwnd = GetChromeBrowserWnd(&acc_obj);
if (!acc_obj || !hwnd)
return false;
// Activate main window and operate key Ctrl+F4.
ActivateWnd(acc_obj, hwnd);
ClickKey(hwnd, VK_CONTROL, VK_F4);
CHK_RELEASE(acc_obj);
// Update tab information in browser object.
browser_->CloseTabFromCollection(tab_->index_);
return true;
}
bool TabImpl::GetTitle(BSTR* title) {
// Validation.
if (!title)
return false;
// Read Tab name and store it in local member and return same value.
BSTR tab_title = GetTabName(tab_->index_);
*title = SysAllocString(tab_title);
tab_->title_ = SysAllocString(tab_title);
return true;
}
bool TabImpl::SetAddressBarText(const BSTR text) {
IAccessible* acc_obj = NULL;
HWND hwnd_addr_bar = GetAddressBarWnd(&acc_obj);
if (!acc_obj || !hwnd_addr_bar)
return false;
// Activate address bar.
ActivateWnd(acc_obj, hwnd_addr_bar);
// Set text to address bar.
SendMessage(hwnd_addr_bar, WM_SETTEXT, 0, LPARAM(text));
CHK_RELEASE(acc_obj);
return true;
}
bool TabImpl::NavigateToURL(const BSTR url) {
IAccessible* acc_obj = NULL;
HWND hwnd_addr_bar = GetAddressBarWnd(&acc_obj);
if (!acc_obj || !hwnd_addr_bar)
return false;
// Activate address bar.
ActivateWnd(acc_obj, hwnd_addr_bar);
// Set text to address bar.
SendMessage(hwnd_addr_bar, WM_SETTEXT, 0, LPARAM(url));
// Click Enter. Window is activated above for this.
ClickKey(hwnd_addr_bar, VK_RETURN);
CHK_RELEASE(acc_obj);
return true;
}
bool TabImpl::FindInPage(const BSTR find_text) {
IAccessible* acc_obj = NULL;
HWND hwnd = GetChromeBrowserWnd(&acc_obj);
if (!acc_obj || !hwnd)
return false;
// Activate main window and operate key 'F3' to invoke Find window.
ActivateWnd(acc_obj, hwnd);
ClickKey(hwnd, VK_F3);
CHK_RELEASE(acc_obj);
// If no text is to be searched, return.
if (find_text != NULL) {
// TODO(klink): Once FindWindow is exported through Accessibility.
// Instead of sleep, check if FindWindows exists or not.
Sleep(50);
// Get Find window.
acc_obj = NULL;
hwnd = GetFindTextWnd(&acc_obj);
if (hwnd) {
HWND hwnd_find_edit = FindWindowEx(hwnd, 0, CHROME_VIEWS_TEXT_FIELD_EDIT,
0);
if (hwnd_find_edit) {
ActivateWnd(acc_obj, hwnd);
ActivateWnd(NULL, hwnd_find_edit);
// Set text in Find window edit box.
WCHAR* strTemp =
reinterpret_cast<WCHAR*>(calloc(wcslen(find_text), sizeof(WCHAR)));
wcscpy_s(strTemp, wcslen(find_text), find_text);
for (size_t i = 0; i < wcslen(strTemp); i++) {
SendMessage(hwnd_find_edit, WM_KEYDOWN, strTemp[i], 0);
SendMessage(hwnd_find_edit, WM_CHAR, strTemp[i], 0);
SendMessage(hwnd_find_edit, WM_KEYUP, strTemp[i], 0);
}
}
}
}
CHK_RELEASE(acc_obj);
return true;
}
bool TabImpl::Reload(void) {
IAccessible* acc_obj = NULL;
HWND hwnd = GetChromeBrowserWnd(&acc_obj);
if (!acc_obj || !hwnd)
return false;
// Operate key F5.
ActivateWnd(acc_obj, hwnd);
ClickKey(hwnd, VK_F5);
CHK_RELEASE(acc_obj);
return true;
}
bool TabImpl::Duplicate(TabImpl** tab) {
return true;
}
bool TabImpl::IsAuthDialogVisible() {
IAccessible* acc_obj = NULL;
HWND hwnd = GetChromeBrowserWnd(&acc_obj);
if (!acc_obj || !hwnd)
return false;
// Activate main window.
ActivateWnd(acc_obj, hwnd);
CHK_RELEASE(acc_obj);
// Check for Authentication Window.
acc_obj = NULL;
hwnd = GetAuthWnd(&acc_obj);
if (!hwnd || !acc_obj) {
CHK_RELEASE(acc_obj);
return false;
}
CHK_RELEASE(acc_obj);
return true;
}
bool TabImpl::SetAuthDialog(const BSTR user_name, const BSTR password) {
IAccessible* acc_obj = NULL;
HWND hwnd = GetChromeBrowserWnd(&acc_obj);
if (!acc_obj || !hwnd)
return false;
// Activate main window.
ActivateWnd(acc_obj, hwnd);
CHK_RELEASE(acc_obj);
// Get editbox for user name and password.
acc_obj = NULL;
hwnd = GetAuthWnd(&acc_obj);
if (!hwnd) {
CHK_RELEASE(acc_obj);
return false;
}
// Get handle to password edit box.
HWND hwnd_auth_pwd = FindWindowEx(hwnd, 0, CHROME_VIEWS_TEXT_FIELD_EDIT, 0);
if (!hwnd_auth_pwd) {
CHK_RELEASE(acc_obj);
return false;
}
// Child after password edit box is edit box for name.
HWND hwnd_auth_name = FindWindowEx(hwnd, hwnd_auth_pwd,
CHROME_VIEWS_TEXT_FIELD_EDIT, 0);
if (!hwnd_auth_name) {
CHK_RELEASE(acc_obj);
return false;
}
// Activate Tab.
SetActiveWindow(GetParent(hwnd));
// Activate Authentication window.
ActivateWnd(acc_obj, hwnd);
// Activate edit box for name.
ActivateWnd(NULL, hwnd_auth_name);
// Set user name.
if (user_name != NULL) {
WCHAR* strTemp =
reinterpret_cast<WCHAR*>(calloc(wcslen(user_name), sizeof(WCHAR)));
wcscpy_s(strTemp, wcslen(user_name), user_name);
for (size_t i = 0; i < wcslen(strTemp); i++) {
SendMessage(hwnd_auth_name, WM_KEYDOWN, strTemp[i], 0);
SendMessage(hwnd_auth_name, WM_CHAR, strTemp[i], 0);
SendMessage(hwnd_auth_name, WM_KEYUP, strTemp[i], 0);
}
}
// Activate edit box for password.
ActivateWnd(NULL, hwnd_auth_pwd);
// Set password.
if (password != NULL) {
// set text
WCHAR* strTemp = reinterpret_cast<WCHAR*>(calloc(wcslen(password),
sizeof(WCHAR)));
wcscpy_s(strTemp, wcslen(password), password);
for (size_t i = 0; i < wcslen(strTemp); i++) {
SendMessage(hwnd_auth_pwd, WM_KEYDOWN, strTemp[i], 0);
SendMessage(hwnd_auth_pwd, WM_CHAR, strTemp[i], 0);
SendMessage(hwnd_auth_pwd, WM_KEYUP, strTemp[i], 0);
}
}
CHK_RELEASE(acc_obj);
return true;
}
bool TabImpl::CancelAuthDialog(void) {
IAccessible* acc_obj = NULL;
HWND hwnd = GetChromeBrowserWnd(&acc_obj);
if (!acc_obj || !hwnd)
return false;
// Activate main window.
ActivateWnd(acc_obj, hwnd);
CHK_RELEASE(acc_obj);
// Get editbox for user name which is after password.
acc_obj = NULL;
hwnd = GetAuthWnd(&acc_obj);
if (!hwnd) {
CHK_RELEASE(acc_obj);
return false;
}
// Get Cancel button.
HWND cancel_button_container = FindWindowEx(hwnd, 0,
CHROME_VIEWS_NATIVE_CTRL_CONTNR,
0);
if (!cancel_button_container) {
CHK_RELEASE(acc_obj);
return false;
}
HWND cancel_button = FindWindowEx(cancel_button_container, 0, STD_BUTTON, 0);
if (!cancel_button) {
CHK_RELEASE(acc_obj);
return false;
}
// Click Cancel button.
SetActiveWindow(cancel_button_container);
SetActiveWindow(cancel_button);
SendMessage(cancel_button, BM_CLICK, 0, 0);
CHK_RELEASE(acc_obj);
return true;
}
bool TabImpl::UseAuthDialog(void) {
IAccessible* acc_obj = NULL;
HWND hwnd = GetChromeBrowserWnd(&acc_obj);
if (!acc_obj || !hwnd)
return false;
// Activate main window.
ActivateWnd(acc_obj, hwnd);
CHK_RELEASE(acc_obj);
// Get editbox for user name which is after password.
acc_obj = NULL;
hwnd = GetAuthWnd(&acc_obj);
if (!hwnd) {
CHK_RELEASE(acc_obj);
return false;
}
// Get Ok button.
HWND cancel_button_container = FindWindowEx(hwnd, 0,
CHROME_VIEWS_NATIVE_CTRL_CONTNR,
0);
if (!cancel_button_container) {
CHK_RELEASE(acc_obj);
return false;
}
// Ok button is located after cancel button in window hierarchy.
HWND ok_button_container = FindWindowEx(hwnd, cancel_button_container,
CHROME_VIEWS_NATIVE_CTRL_CONTNR, 0);
if (!ok_button_container) {
CHK_RELEASE(acc_obj);
return false;
}
HWND ok_button = FindWindowEx(ok_button_container, 0, STD_BUTTON, 0);
if (!ok_button) {
CHK_RELEASE(acc_obj);
return false;
}
// Click Ok.
SetActiveWindow(ok_button_container);
SetActiveWindow(ok_button);
SendMessage(ok_button, BM_CLICK, 0, 0);
CHK_RELEASE(acc_obj);
return true;
}
void TabImpl::set_title(BSTR title) {
if (!tab_)
InitTabData();
tab_->title_ = SysAllocString(title);
}
bool TabImpl::Activate(void) {
return true;
}
bool TabImpl::WaitForTabToBecomeActive(const INT64 interval,
const INT64 timeout) {
return true;
}
bool TabImpl::WaitForTabToGetLoaded(const INT64 interval, const INT64 timeout) {
return true;
}
bool TabImpl::IsSSLLockPresent(bool* present) {
return true;
}
bool TabImpl::IsSSLSoftError(bool* soft_err) {
return true;
}
bool TabImpl::OpenPageCertificateDialog(void) {
return true;
}
bool TabImpl::ClosePageCertificateDialog(void) {
return true;
}
bool TabImpl::GoBack(void) {
return true;
}
bool TabImpl::GoForward(void) {
return true;
}
|