OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_frame/test/chrome_frame_ui_test_utils.h" | 5 #include "chrome_frame/test/chrome_frame_ui_test_utils.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 | 8 |
9 #include <sstream> | 9 #include <sstream> |
10 #include <stack> | 10 #include <stack> |
11 | 11 |
12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
13 #include "base/scoped_bstr_win.h" | 13 #include "base/scoped_bstr_win.h" |
14 #include "base/scoped_ptr.h" | 14 #include "base/scoped_ptr.h" |
15 #include "base/string_util.h" | 15 #include "base/string_util.h" |
| 16 #include "base/utf_string_conversions.h" |
16 #include "gfx/rect.h" | 17 #include "gfx/rect.h" |
17 #include "chrome_frame/test/win_event_receiver.h" | 18 #include "chrome_frame/test/win_event_receiver.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
19 | 20 |
20 namespace chrome_frame_test { | 21 namespace chrome_frame_test { |
21 | 22 |
22 // Timeout for waiting on Chrome to create the accessibility tree for the DOM. | 23 // Timeout for waiting on Chrome to create the accessibility tree for the DOM. |
23 const int kChromeDOMAccessibilityTreeTimeoutMs = 10 * 1000; | 24 const int kChromeDOMAccessibilityTreeTimeoutMs = 10 * 1000; |
24 | 25 |
25 // Timeout for waiting on a menu to popup. | 26 // Timeout for waiting on a menu to popup. |
(...skipping 20 matching lines...) Expand all Loading... |
46 AccObject* AccObject::CreateFromWindow(HWND hwnd) { | 47 AccObject* AccObject::CreateFromWindow(HWND hwnd) { |
47 ScopedComPtr<IAccessible> accessible; | 48 ScopedComPtr<IAccessible> accessible; |
48 AccessibleObjectFromWindow(hwnd, OBJID_CLIENT, | 49 AccessibleObjectFromWindow(hwnd, OBJID_CLIENT, |
49 IID_IAccessible, reinterpret_cast<void**>(accessible.Receive())); | 50 IID_IAccessible, reinterpret_cast<void**>(accessible.Receive())); |
50 if (accessible) | 51 if (accessible) |
51 return new AccObject(accessible); | 52 return new AccObject(accessible); |
52 return NULL; | 53 return NULL; |
53 } | 54 } |
54 | 55 |
55 // static | 56 // static |
| 57 AccObject* AccObject::CreateFromEvent(HWND hwnd, LONG object_id, |
| 58 LONG child_id) { |
| 59 ScopedComPtr<IAccessible> accessible; |
| 60 ScopedVariant acc_child_id; |
| 61 AccessibleObjectFromEvent(hwnd, object_id, child_id, accessible.Receive(), |
| 62 acc_child_id.Receive()); |
| 63 if (accessible && acc_child_id.type() == VT_I4) |
| 64 return new AccObject(accessible, V_I4(&acc_child_id)); |
| 65 return NULL; |
| 66 } |
| 67 |
| 68 // static |
56 AccObject* AccObject::CreateFromDispatch(IDispatch* dispatch) { | 69 AccObject* AccObject::CreateFromDispatch(IDispatch* dispatch) { |
57 if (dispatch) { | 70 if (dispatch) { |
58 ScopedComPtr<IAccessible> accessible; | 71 ScopedComPtr<IAccessible> accessible; |
59 accessible.QueryFrom(dispatch); | 72 accessible.QueryFrom(dispatch); |
60 if (accessible) | 73 if (accessible) |
61 return new AccObject(accessible); | 74 return new AccObject(accessible); |
62 } | 75 } |
63 return NULL; | 76 return NULL; |
64 } | 77 } |
65 | 78 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 bool did_select = false; | 120 bool did_select = false; |
108 ScopedVariant selected; | 121 ScopedVariant selected; |
109 if (SUCCEEDED(accessible_->get_accSelection(selected.Receive()))) { | 122 if (SUCCEEDED(accessible_->get_accSelection(selected.Receive()))) { |
110 if (selected.type() != VT_EMPTY) | 123 if (selected.type() != VT_EMPTY) |
111 did_select = true; | 124 did_select = true; |
112 } | 125 } |
113 EXPECT_TRUE(did_select) << "Could not select AccObject: " << GetDescription(); | 126 EXPECT_TRUE(did_select) << "Could not select AccObject: " << GetDescription(); |
114 return did_select; | 127 return did_select; |
115 } | 128 } |
116 | 129 |
| 130 bool AccObject::SetValue(const std::wstring& value) { |
| 131 ScopedBstr value_bstr(value.c_str()); |
| 132 EXPECT_HRESULT_SUCCEEDED(accessible_->put_accValue(child_id_, value_bstr)); |
| 133 |
| 134 // Double check that the object's value has actually changed. Some objects' |
| 135 // values can not be changed. |
| 136 bool did_set_value = false; |
| 137 std::wstring actual_value = L"-"; |
| 138 if (GetValue(&actual_value) && value == actual_value) { |
| 139 did_set_value = true; |
| 140 } |
| 141 EXPECT_TRUE(did_set_value) << "Could not set value for AccObject: " |
| 142 << GetDescription(); |
| 143 return did_set_value; |
| 144 } |
| 145 |
117 bool AccObject::GetName(std::wstring* name) { | 146 bool AccObject::GetName(std::wstring* name) { |
118 DCHECK(name); | 147 DCHECK(name); |
119 ScopedBstr name_bstr; | 148 ScopedBstr name_bstr; |
120 HRESULT result = accessible_->get_accName(child_id_, name_bstr.Receive()); | 149 HRESULT result = accessible_->get_accName(child_id_, name_bstr.Receive()); |
121 if (SUCCEEDED(result)) | 150 if (SUCCEEDED(result)) |
122 name->assign(name_bstr, name_bstr.Length()); | 151 name->assign(name_bstr, name_bstr.Length()); |
123 return SUCCEEDED(result); | 152 return SUCCEEDED(result); |
124 } | 153 } |
125 | 154 |
126 bool AccObject::GetRoleText(std::wstring* role_text) { | 155 bool AccObject::GetRoleText(std::wstring* role_text) { |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 // possible, since this class operates under the assumption that if the | 255 // possible, since this class operates under the assumption that if the |
227 // child id is not CHILDID_SELF, the object is a simple element. See the | 256 // child id is not CHILDID_SELF, the object is a simple element. See the |
228 // DCHECK in the constructor. | 257 // DCHECK in the constructor. |
229 HRESULT result = accessible_->get_accChild(children[i], | 258 HRESULT result = accessible_->get_accChild(children[i], |
230 dispatch.Receive()); | 259 dispatch.Receive()); |
231 if (result == S_FALSE || result == E_NOINTERFACE) { | 260 if (result == S_FALSE || result == E_NOINTERFACE) { |
232 // The object in question really is a simple element. Add it. | 261 // The object in question really is a simple element. Add it. |
233 objects.push_back(new AccObject(accessible_, V_I4(&children[i]))); | 262 objects.push_back(new AccObject(accessible_, V_I4(&children[i]))); |
234 continue; | 263 continue; |
235 } else if (FAILED(result)) { | 264 } else if (FAILED(result)) { |
236 LOG(ERROR) << "Failed to determine if child id refers to a full " | 265 DLOG(WARNING) << "Failed to determine if child id refers to a full " |
237 << "object. Error: " << result; | 266 << "object. Error: " << result << std::endl |
238 return false; | 267 << "Parent object: " << WideToUTF8(GetDescription()) |
| 268 << std::endl << "Child ID: " << V_I4(&children[i]); |
| 269 // Disregard this object. |
| 270 continue; |
239 } | 271 } |
240 // The object in question was actually a full object. It is saved in the | 272 // The object in question was actually a full object. It is saved in the |
241 // |dispatch| arg and will be added down below. | 273 // |dispatch| arg and will be added down below. |
242 } else if (children[i].type() == VT_DISPATCH) { | 274 } else if (children[i].type() == VT_DISPATCH) { |
243 dispatch.Attach(V_DISPATCH(&children[i].Release())); | 275 dispatch.Attach(V_DISPATCH(&children[i].Release())); |
244 } else { | 276 } else { |
245 DLOG(WARNING) << "Unrecognizable child type, omitting from children"; | 277 DLOG(WARNING) << "Unrecognizable child type, omitting from children"; |
246 continue; | 278 continue; |
247 } | 279 } |
248 | 280 |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 ss << L"Value: '" << value_ << L"'"; | 425 ss << L"Value: '" << value_ << L"'"; |
394 ss << L"]"; | 426 ss << L"]"; |
395 return ss.str(); | 427 return ss.str(); |
396 } | 428 } |
397 | 429 |
398 // Other methods | 430 // Other methods |
399 bool FindAccObjectInWindow(HWND hwnd, const AccObjectMatcher& matcher, | 431 bool FindAccObjectInWindow(HWND hwnd, const AccObjectMatcher& matcher, |
400 scoped_refptr<AccObject>* object) { | 432 scoped_refptr<AccObject>* object) { |
401 DCHECK(object); | 433 DCHECK(object); |
402 EXPECT_TRUE(matcher.FindInWindow(hwnd, object)); | 434 EXPECT_TRUE(matcher.FindInWindow(hwnd, object)); |
403 EXPECT_TRUE(object) << "Element not found for matcher: " | 435 EXPECT_TRUE(*object) << "Element not found for matcher: " |
404 << matcher.GetDescription(); | 436 << matcher.GetDescription(); |
405 if (!object) | 437 if (!*object) |
406 DumpAccessibilityTreeForWindow(hwnd); | 438 DumpAccessibilityTreeForWindow(hwnd); |
407 return *object; | 439 return *object; |
408 } | 440 } |
409 | 441 |
410 void DumpAccessibilityTreeForWindow(HWND hwnd) { | 442 void DumpAccessibilityTreeForWindow(HWND hwnd) { |
411 scoped_refptr<AccObject> object(AccObject::CreateFromWindow(hwnd)); | 443 scoped_refptr<AccObject> object(AccObject::CreateFromWindow(hwnd)); |
412 if (object) | 444 if (object) |
413 std::wcout << object->GetTree(); | 445 std::wcout << object->GetTree(); |
414 else | 446 else |
415 std::cout << "Could not get IAccessible for window" << std::endl; | 447 std::cout << "Could not get IAccessible for window" << std::endl; |
416 } | 448 } |
417 | 449 |
418 bool IsDesktopUnlocked() { | 450 bool IsDesktopUnlocked() { |
419 HDESK desk = ::OpenInputDesktop(0, FALSE, DESKTOP_SWITCHDESKTOP); | 451 HDESK desk = ::OpenInputDesktop(0, FALSE, DESKTOP_SWITCHDESKTOP); |
420 if (desk) | 452 if (desk) |
421 ::CloseDesktop(desk); | 453 ::CloseDesktop(desk); |
422 return desk; | 454 return desk; |
423 } | 455 } |
424 | 456 |
425 } // namespace chrome_frame_test | 457 } // namespace chrome_frame_test |
OLD | NEW |