| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "content/browser/accessibility/accessibility_test_utils.h" |
| 6 |
| 7 #include "content/browser/accessibility/browser_accessibility.h" |
| 8 #include "content/browser/accessibility/browser_accessibility_manager.h" |
| 9 #include "content/browser/frame_host/frame_tree.h" |
| 10 #include "content/browser/frame_host/render_frame_host_impl.h" |
| 11 #include "content/browser/web_contents/web_contents_impl.h" |
| 12 #include "content/test/accessibility_browser_test_utils.h" |
| 13 |
| 14 namespace content { |
| 15 |
| 16 bool AccessibilityTreeContainsNodeWithName(BrowserAccessibility* node, |
| 17 const std::string& name) { |
| 18 if (node->GetStringAttribute(ui::AX_ATTR_NAME) == name) |
| 19 return true; |
| 20 for (unsigned i = 0; i < node->PlatformChildCount(); i++) { |
| 21 if (AccessibilityTreeContainsNodeWithName(node->PlatformGetChild(i), name)) |
| 22 return true; |
| 23 } |
| 24 return false; |
| 25 } |
| 26 |
| 27 void WaitForAccessibilityTreeToContainNodeWithName(WebContents* web_contents, |
| 28 const std::string& name) { |
| 29 WebContentsImpl* web_contents_impl = static_cast<WebContentsImpl*>( |
| 30 web_contents); |
| 31 RenderFrameHostImpl* main_frame = static_cast<RenderFrameHostImpl*>( |
| 32 web_contents_impl->GetMainFrame()); |
| 33 BrowserAccessibilityManager* main_frame_manager = |
| 34 main_frame->browser_accessibility_manager(); |
| 35 FrameTree* frame_tree = web_contents_impl->GetFrameTree(); |
| 36 while (!AccessibilityTreeContainsNodeWithName( |
| 37 main_frame_manager->GetRoot(), name)) { |
| 38 AccessibilityNotificationWaiter accessibility_waiter(main_frame, |
| 39 ui::AX_EVENT_NONE); |
| 40 for (FrameTreeNode* node : frame_tree->Nodes()) |
| 41 accessibility_waiter.ListenToAdditionalFrame( |
| 42 node->current_frame_host()); |
| 43 |
| 44 accessibility_waiter.WaitForNotification(); |
| 45 } |
| 46 } |
| 47 |
| 48 } // namespace |
| OLD | NEW |