diff options
author | kkania@chromium.org <kkania@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-17 17:04:24 +0000 |
---|---|---|
committer | kkania@chromium.org <kkania@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-17 17:04:24 +0000 |
commit | 39f7f17f35ec7f78a2b5b413d4b0b02fc216da61 (patch) | |
tree | 08ce71d716ee7cf4106e035f78cf2a877933ea6f /chrome_frame/test/chrome_frame_test_utils.cc | |
parent | 4aad7cc13daa4baa068a8e138ba2b5c3596cbeb4 (diff) | |
download | chromium_src-39f7f17f35ec7f78a2b5b413d4b0b02fc216da61.zip chromium_src-39f7f17f35ec7f78a2b5b413d4b0b02fc216da61.tar.gz chromium_src-39f7f17f35ec7f78a2b5b413d4b0b02fc216da61.tar.bz2 |
[chrome_frame] Add utils for using MSAA for working with menus and for selecting/focusing elements. Change context menu tests to use this approach.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/3115002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@56373 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome_frame/test/chrome_frame_test_utils.cc')
-rw-r--r-- | chrome_frame/test/chrome_frame_test_utils.cc | 280 |
1 files changed, 0 insertions, 280 deletions
diff --git a/chrome_frame/test/chrome_frame_test_utils.cc b/chrome_frame/test/chrome_frame_test_utils.cc index 9c43cb2..b9ea02a 100644 --- a/chrome_frame/test/chrome_frame_test_utils.cc +++ b/chrome_frame/test/chrome_frame_test_utils.cc @@ -7,7 +7,6 @@ #include <atlbase.h> #include <atlwin.h> #include <iepmapi.h> -#include <oleacc.h> #include <oleauto.h> #include <sddl.h> @@ -34,7 +33,6 @@ #include "chrome_frame/utils.h" #include "testing/gtest/include/gtest/gtest.h" -#include "third_party/xulrunner-sdk/win/include/accessibility/AccessibleEventId.h" namespace chrome_frame_test { @@ -49,7 +47,6 @@ const char kChromeImageName[] = "chrome.exe"; const wchar_t kIEProfileName[] = L"iexplore"; const wchar_t kChromeLauncher[] = L"chrome_launcher.exe"; const int kChromeFrameLongNavigationTimeoutInSeconds = 10; -const int kChromeDOMAccessibilityTreeTimeoutMs = 10 * 1000; // Callback function for EnumThreadWindows. BOOL CALLBACK CloseWindowsThreadCallback(HWND hwnd, LPARAM param) { @@ -955,283 +952,6 @@ void DelaySendExtendedKeysEnter(TimedMsgLoop* loop, int delay, char c, simulate_input::SendCharA, VK_RETURN, simulate_input::NONE), next_delay); } -UIObjectMatcher::UIObjectMatcher(const std::wstring& name, - const std::wstring& role, - const std::wstring& value) - : name_(name), role_(role), value_(value) { -} - -bool UIObjectMatcher::Find(IAccessible* object, IAccessible** match) const { - DCHECK(object); - DCHECK(match); - ScopedVariant self_id(CHILDID_SELF); - - // Determine if |object| is a match. - bool does_match = true; - if (name_.length()) { - ScopedBstr name; - object->get_accName(self_id, name.Receive()); - std::wstring name_string; - name_string.assign(name, name.Length()); - does_match = MatchPatternWide(name_string, name_); - } - if (does_match && role_.length()) { - ScopedVariant role; - object->get_accRole(self_id, role.Receive()); - does_match = false; - if (role.type() == VT_I4) { - wchar_t role_text[50]; - if (GetRoleText(V_I4(&role), role_text, arraysize(role_text))) { - does_match = MatchPatternWide(role_text, role_); - } - } - } - if (does_match && value_.length()) { - ScopedBstr value; - object->get_accValue(self_id, value.Receive()); - std::wstring value_string; - value_string.assign(value, value.Length()); - does_match = MatchPatternWide(value_string, value_); - } - - if (does_match) { - *match = object; - object->AddRef(); - } else { - // Get the accessible children of |object|. - long child_count, actual_child_count; // NOLINT - if (FAILED(object->get_accChildCount(&child_count))) { - LOG(ERROR) << "Failed to get child count of accessible object"; - return false; - } - scoped_array<VARIANT> children(new VARIANT[child_count]); - if (FAILED(AccessibleChildren(object, 0L, child_count, children.get(), - &actual_child_count))) { - LOG(ERROR) << "Failed to get children of accessible object"; - return false; - } - - // Try each descendant. - for (int i = 0; i < actual_child_count; i++) { - if (children[i].vt == VT_DISPATCH) { - ScopedComPtr<IAccessible> accessible_child; - accessible_child.QueryFrom(V_DISPATCH(&children[i])); - if (accessible_child.get()) { - if (FAILED(Find(accessible_child.get(), match))) - return false; - if (*match) - break; - } - } - } - } - return true; -} - -bool UIObjectMatcher::FindInWindow(HWND hwnd, IAccessible** match) const { - ScopedComPtr<IAccessible> accessible; - HRESULT result = AccessibleObjectFromWindow(hwnd, OBJID_CLIENT, - IID_IAccessible, reinterpret_cast<void**>(accessible.Receive())); - if (FAILED(result) || !accessible.get()) { - LOG(INFO) << "Failed to get accessible object from window"; - return false; - } - return Find(accessible.get(), match); -} - -std::wstring UIObjectMatcher::GetDescription() const { - std::wostringstream ss; - ss << L"("; - if (name_.length()) - ss << L"Name: \"" << name_ << L"\" "; - if (role_.length()) - ss << L"Role: \"" << role_ << L"\" "; - if (value_.length()) - ss << L"Value: \"" << value_ << L"\""; - ss << L")"; - return ss.str(); -} - -void DoDefaultUIAction(HWND hwnd, const UIObjectMatcher& matcher) { - ScopedComPtr<IAccessible> object; - EXPECT_TRUE(matcher.FindInWindow(hwnd, object.Receive())); - EXPECT_TRUE(object.get()); - if (object.get()) { - ScopedVariant self_id(CHILDID_SELF); - EXPECT_HRESULT_SUCCEEDED(object->accDoDefaultAction(self_id)); - } else { - EXPECT_TRUE(object.get()) << "Element not found for matcher: " - << matcher.GetDescription(); - DumpAccessibilityTreeForWindow(hwnd); - } -} - -// Used to ensure a message loop is quit at most one time. -class OneTimeLoopQuitter : public base::RefCounted<OneTimeLoopQuitter> { - public: - OneTimeLoopQuitter() : did_quit_(false), should_quit_(true) {} - - void Quit() { - if (should_quit_ && !did_quit_) - MessageLoop::current()->Quit(); - did_quit_ = true; - } - - void Cancel() { - should_quit_ = false; - } - - bool did_quit() const { return did_quit_; } - - private: - bool did_quit_; - bool should_quit_; - - DISALLOW_COPY_AND_ASSIGN(OneTimeLoopQuitter); -}; - -// Used to wait for an accessibility document load event. Starts listening -// on creation. -class AccessibilityDocumentLoadObserver : public WinEventListener { - public: - explicit AccessibilityDocumentLoadObserver(HWND hwnd) - : did_receive_load_(false), - hwnd_to_watch_(hwnd) { - event_receiver_.SetListenerForEvent(this, IA2_EVENT_DOCUMENT_LOAD_COMPLETE); - } - - // Waits for the document load event to be received or the timeout to occur. - // This assumes there is a MessageLoop for the current thread. - bool WaitForDocumentLoad(int timeoutInMs) { - DCHECK(MessageLoop::current() != NULL); - if (!did_receive_load_) { - quitter = new OneTimeLoopQuitter(); - MessageLoop::current()->PostDelayedTask( - FROM_HERE, - NewRunnableMethod(quitter.get(), &OneTimeLoopQuitter::Quit), - timeoutInMs); - DLOG(INFO) << "Waiting for document load event"; - MessageLoop::current()->Run(); - - DLOG_IF(WARNING, !quitter->did_quit()) - << "Message loop was quit externally."; - quitter->Quit(); - quitter.release(); - } - return did_receive_load_; - } - - private: - virtual void OnEventReceived(DWORD event, HWND hwnd) { - if (hwnd == hwnd_to_watch_) { - DLOG(INFO) << "Received document load event"; - did_receive_load_ = true; - if (quitter.get()) - quitter->Quit(); - } - } - - bool did_receive_load_; - HWND hwnd_to_watch_; - scoped_refptr<OneTimeLoopQuitter> quitter; - WinEventReceiver event_receiver_; - - DISALLOW_COPY_AND_ASSIGN(AccessibilityDocumentLoadObserver); -}; - -bool WaitForChromeDOMAccessibilityTree(HWND hwnd) { - bool tree_is_ready = true; - // Create this here so it can watch for events that are processed when - // fetching IAccessible. - AccessibilityDocumentLoadObserver load_observer(hwnd); - - // Get the first object in the current accessibility tree. The state of this - // object will be busy if Chrome is still processing the tree. - ScopedComPtr<IAccessible> first_object; - UIObjectMatcher first_object_matcher; - if (first_object_matcher.FindInWindow(hwnd, first_object.Receive()) && - first_object.get()) { - ScopedVariant self_id(CHILDID_SELF); - ScopedVariant state; - if (SUCCEEDED(first_object->get_accState(self_id, state.Receive()))) { - if (state.type() == VT_I4 && V_I4(&state) & STATE_SYSTEM_BUSY) { - tree_is_ready = load_observer.WaitForDocumentLoad( - kChromeDOMAccessibilityTreeTimeoutMs); - } - } - } - DLOG_IF(ERROR, !tree_is_ready) - << "Gave up waiting for accessibility document load event"; - return tree_is_ready; -} - -namespace { - -void DumpAccessibilityTreeHelper(IAccessible* object, int depth) { - ScopedVariant self_id(CHILDID_SELF); - ScopedBstr name; - object->get_accName(self_id, name.Receive()); - std::wstring name_string; - name_string.assign(name, name.Length()); - for (int i = 0; i < depth; ++i) { - std::wcout << L"---"; - } - std::wcout << L"\"" << name_string << L"\", "; - - ScopedVariant role; - object->get_accRole(self_id, role.Receive()); - if (role.type() == VT_I4) { - wchar_t role_text[50]; - if (GetRoleText(V_I4(&role), role_text, arraysize(role_text))) - std::wcout << L"\"" << role_text << "\""; - } - std::wcout << ", "; - - ScopedBstr value; - object->get_accValue(self_id, value.Receive()); - std::wstring value_string; - value_string.assign(value, value.Length()); - std::wcout << L"\"" << value_string << L"\"" << std::endl; - - // Get the accessible children of |root|. - HRESULT result = S_OK; - long child_count, actual_child_count; // NOLINT - if (FAILED(object->get_accChildCount(&child_count))) - return; - scoped_array<VARIANT> children(new VARIANT[child_count]); - if (FAILED(AccessibleChildren(object, 0L, child_count, children.get(), - &actual_child_count))) - return; - - for (int i = 0; i < actual_child_count; i++) { - if (children[i].vt == VT_DISPATCH) { - ScopedComPtr<IAccessible> accessible_child; - accessible_child.QueryFrom(V_DISPATCH(&children[i])); - if (accessible_child.get()) { - DumpAccessibilityTreeHelper(accessible_child.get(), depth + 1); - } - } - } -} - -} // namespace - -void DumpAccessibilityTree(IAccessible* object) { - std::cout << "Accessibility object tree:" << std::endl; - std::cout << "NAME, ROLE, VALUE" << std::endl; - DumpAccessibilityTreeHelper(object, 0); -} - -void DumpAccessibilityTreeForWindow(HWND hwnd) { - ScopedComPtr<IAccessible> accessible; - AccessibleObjectFromWindow(hwnd, OBJID_CLIENT, - IID_IAccessible, reinterpret_cast<void**>(accessible.Receive())); - if (accessible.get()) - DumpAccessibilityTree(accessible); - else - std::cout << "Could not get IAccessible for window" << std::endl; -} - CloseIeAtEndOfScope::~CloseIeAtEndOfScope() { int closed = CloseAllIEWindows(); DLOG_IF(ERROR, closed != 0) << "Closed " << closed << " windows forcefully"; |