| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "win8/test/ui_automation_client.h" | 5 #include "win8/test/ui_automation_client.h" |
| 6 | 6 |
| 7 #include <atlbase.h> | 7 #include <atlbase.h> |
| 8 #include <atlcom.h> | 8 #include <atlcom.h> |
| 9 #include <oleauto.h> | 9 #include <oleauto.h> |
| 10 #include <uiautomation.h> | 10 #include <uiautomation.h> |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 HRESULT hr = S_OK; | 308 HRESULT hr = S_OK; |
| 309 base::win::ScopedVariant var; | 309 base::win::ScopedVariant var; |
| 310 | 310 |
| 311 hr = window->GetCachedPropertyValueEx(UIA_ClassNamePropertyId, TRUE, | 311 hr = window->GetCachedPropertyValueEx(UIA_ClassNamePropertyId, TRUE, |
| 312 var.Receive()); | 312 var.Receive()); |
| 313 if (FAILED(hr)) { | 313 if (FAILED(hr)) { |
| 314 LOG(ERROR) << std::hex << hr; | 314 LOG(ERROR) << std::hex << hr; |
| 315 return; | 315 return; |
| 316 } | 316 } |
| 317 | 317 |
| 318 if (V_VT(&var) != VT_BSTR) { | 318 if (V_VT(var.ptr()) != VT_BSTR) { |
| 319 LOG(ERROR) << __FUNCTION__ << " class name is not a BSTR: " << V_VT(&var); | 319 LOG(ERROR) << __FUNCTION__ |
| 320 << " class name is not a BSTR: " << V_VT(var.ptr()); |
| 320 return; | 321 return; |
| 321 } | 322 } |
| 322 | 323 |
| 323 base::string16 class_name(V_BSTR(&var)); | 324 base::string16 class_name(V_BSTR(var.ptr())); |
| 324 | 325 |
| 325 // Window class names are atoms, which are case-insensitive. | 326 // Window class names are atoms, which are case-insensitive. |
| 326 if (class_name.size() == class_name_.size() && | 327 if (class_name.size() == class_name_.size() && |
| 327 std::equal(class_name.begin(), class_name.end(), class_name_.begin(), | 328 std::equal(class_name.begin(), class_name.end(), class_name_.begin(), |
| 328 base::CaseInsensitiveCompare<wchar_t>())) { | 329 base::CaseInsensitiveCompare<wchar_t>())) { |
| 329 RemoveWindowObserver(); | 330 RemoveWindowObserver(); |
| 330 ProcessWindow(window); | 331 ProcessWindow(window); |
| 331 } | 332 } |
| 332 } | 333 } |
| 333 | 334 |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 if (FAILED(result)) { | 527 if (FAILED(result)) { |
| 527 LOG(ERROR) << std::hex << result; | 528 LOG(ERROR) << std::hex << result; |
| 528 continue; | 529 continue; |
| 529 } | 530 } |
| 530 result = child_element->GetCachedPropertyValueEx(UIA_NamePropertyId, TRUE, | 531 result = child_element->GetCachedPropertyValueEx(UIA_NamePropertyId, TRUE, |
| 531 var.Receive()); | 532 var.Receive()); |
| 532 if (FAILED(result)) { | 533 if (FAILED(result)) { |
| 533 LOG(ERROR) << std::hex << result; | 534 LOG(ERROR) << std::hex << result; |
| 534 continue; | 535 continue; |
| 535 } | 536 } |
| 536 if (V_VT(&var) != VT_BSTR) { | 537 if (V_VT(var.ptr()) != VT_BSTR) { |
| 537 LOG(ERROR) << __FUNCTION__ << " name is not a BSTR: " << V_VT(&var); | 538 LOG(ERROR) << __FUNCTION__ << " name is not a BSTR: " << V_VT(var.ptr()); |
| 538 continue; | 539 continue; |
| 539 } | 540 } |
| 540 choices->push_back(base::string16(V_BSTR(&var))); | 541 choices->push_back(base::string16(V_BSTR(var.ptr()))); |
| 541 var.Reset(); | 542 var.Reset(); |
| 542 } | 543 } |
| 543 | 544 |
| 544 return result; | 545 return result; |
| 545 } | 546 } |
| 546 | 547 |
| 547 // Closes the element |window| by sending it an escape key. | 548 // Closes the element |window| by sending it an escape key. |
| 548 void UIAutomationClient::Context::CloseWindow( | 549 void UIAutomationClient::Context::CloseWindow( |
| 549 const base::win::ScopedComPtr<IUIAutomationElement>& window) { | 550 const base::win::ScopedComPtr<IUIAutomationElement>& window) { |
| 550 DCHECK(thread_checker_.CalledOnValidThread()); | 551 DCHECK(thread_checker_.CalledOnValidThread()); |
| 551 | 552 |
| 552 // It's tempting to get the Window pattern from |window| and invoke its Close | 553 // It's tempting to get the Window pattern from |window| and invoke its Close |
| 553 // method. Unfortunately, this doesn't work. Sending an escape key does the | 554 // method. Unfortunately, this doesn't work. Sending an escape key does the |
| 554 // trick, though. | 555 // trick, though. |
| 555 HRESULT result = S_OK; | 556 HRESULT result = S_OK; |
| 556 base::win::ScopedVariant var; | 557 base::win::ScopedVariant var; |
| 557 | 558 |
| 558 result = window->GetCachedPropertyValueEx( | 559 result = window->GetCachedPropertyValueEx( |
| 559 UIA_NativeWindowHandlePropertyId, | 560 UIA_NativeWindowHandlePropertyId, |
| 560 TRUE, | 561 TRUE, |
| 561 var.Receive()); | 562 var.Receive()); |
| 562 if (FAILED(result)) { | 563 if (FAILED(result)) { |
| 563 LOG(ERROR) << std::hex << result; | 564 LOG(ERROR) << std::hex << result; |
| 564 return; | 565 return; |
| 565 } | 566 } |
| 566 | 567 |
| 567 if (V_VT(&var) != VT_I4) { | 568 if (V_VT(var.ptr()) != VT_I4) { |
| 568 LOG(ERROR) << __FUNCTION__ | 569 LOG(ERROR) << __FUNCTION__ |
| 569 << " window handle is not an int: " << V_VT(&var); | 570 << " window handle is not an int: " << V_VT(var.ptr()); |
| 570 return; | 571 return; |
| 571 } | 572 } |
| 572 | 573 |
| 573 HWND handle = reinterpret_cast<HWND>(V_I4(&var)); | 574 HWND handle = reinterpret_cast<HWND>(V_I4(var.ptr())); |
| 574 | 575 |
| 575 uint32 scan_code = MapVirtualKey(VK_ESCAPE, MAPVK_VK_TO_VSC); | 576 uint32 scan_code = MapVirtualKey(VK_ESCAPE, MAPVK_VK_TO_VSC); |
| 576 PostMessage(handle, WM_KEYDOWN, VK_ESCAPE, | 577 PostMessage(handle, WM_KEYDOWN, VK_ESCAPE, |
| 577 MAKELPARAM(1, scan_code)); | 578 MAKELPARAM(1, scan_code)); |
| 578 PostMessage(handle, WM_KEYUP, VK_ESCAPE, | 579 PostMessage(handle, WM_KEYUP, VK_ESCAPE, |
| 579 MAKELPARAM(1, scan_code | KF_REPEAT | KF_UP)); | 580 MAKELPARAM(1, scan_code | KF_REPEAT | KF_UP)); |
| 580 } | 581 } |
| 581 | 582 |
| 582 UIAutomationClient::UIAutomationClient() | 583 UIAutomationClient::UIAutomationClient() |
| 583 : automation_thread_("UIAutomation") {} | 584 : automation_thread_("UIAutomation") {} |
| (...skipping 27 matching lines...) Expand all Loading... |
| 611 context_, | 612 context_, |
| 612 base::ThreadTaskRunnerHandle::Get(), | 613 base::ThreadTaskRunnerHandle::Get(), |
| 613 base::string16(class_name), | 614 base::string16(class_name), |
| 614 item_name, | 615 item_name, |
| 615 init_callback, | 616 init_callback, |
| 616 result_callback)); | 617 result_callback)); |
| 617 } | 618 } |
| 618 | 619 |
| 619 } // namespace internal | 620 } // namespace internal |
| 620 } // namespace win8 | 621 } // namespace win8 |
| OLD | NEW |