| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <set> | 5 #include <set> |
| 6 #include <string> | 6 #include <string> |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/strings/string16.h" | 12 #include "base/strings/string16.h" |
| 13 #include "base/strings/string_split.h" | 13 #include "base/strings/string_split.h" |
| 14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 16 #include "content/browser/accessibility/accessibility_test_utils.h" |
| 16 #include "content/browser/accessibility/accessibility_tree_formatter.h" | 17 #include "content/browser/accessibility/accessibility_tree_formatter.h" |
| 17 #include "content/browser/accessibility/browser_accessibility.h" | 18 #include "content/browser/accessibility/browser_accessibility.h" |
| 18 #include "content/browser/accessibility/browser_accessibility_manager.h" | 19 #include "content/browser/accessibility/browser_accessibility_manager.h" |
| 19 #include "content/browser/web_contents/web_contents_impl.h" | 20 #include "content/browser/web_contents/web_contents_impl.h" |
| 20 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
| 21 #include "content/public/common/content_paths.h" | 22 #include "content/public/common/content_paths.h" |
| 22 #include "content/public/common/content_switches.h" | 23 #include "content/public/common/content_switches.h" |
| 23 #include "content/public/common/url_constants.h" | 24 #include "content/public/common/url_constants.h" |
| 24 #include "content/public/test/content_browser_test.h" | 25 #include "content/public/test/content_browser_test.h" |
| 25 #include "content/public/test/content_browser_test_utils.h" | 26 #include "content/public/test/content_browser_test_utils.h" |
| 26 #include "content/shell/browser/shell.h" | 27 #include "content/shell/browser/shell.h" |
| 27 #include "content/test/accessibility_browser_test_utils.h" | 28 #include "content/test/accessibility_browser_test_utils.h" |
| 28 #include "net/dns/mock_host_resolver.h" | 29 #include "net/dns/mock_host_resolver.h" |
| 29 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
| 30 | 31 |
| 31 namespace content { | 32 namespace content { |
| 32 | 33 |
| 33 namespace { | |
| 34 | |
| 35 bool AXTreeContainsNodeWithName(BrowserAccessibility* node, | |
| 36 const std::string& name) { | |
| 37 if (node->GetStringAttribute(ui::AX_ATTR_NAME) == name) | |
| 38 return true; | |
| 39 | |
| 40 for (unsigned i = 0; i < node->PlatformChildCount(); i++) { | |
| 41 if (AXTreeContainsNodeWithName(node->PlatformGetChild(i), name)) | |
| 42 return true; | |
| 43 } | |
| 44 | |
| 45 return false; | |
| 46 } | |
| 47 | |
| 48 } // namespace | |
| 49 | |
| 50 class AccessibilityHitTestingBrowserTest : public ContentBrowserTest { | 34 class AccessibilityHitTestingBrowserTest : public ContentBrowserTest { |
| 51 public: | 35 public: |
| 52 AccessibilityHitTestingBrowserTest() {} | 36 AccessibilityHitTestingBrowserTest() {} |
| 53 ~AccessibilityHitTestingBrowserTest() override {} | 37 ~AccessibilityHitTestingBrowserTest() override {} |
| 54 | 38 |
| 55 protected: | 39 protected: |
| 56 BrowserAccessibility* HitTestAndWaitForResult(const gfx::Point& point) { | 40 BrowserAccessibility* HitTestAndWaitForResult(const gfx::Point& point) { |
| 57 WebContentsImpl* web_contents = | 41 WebContentsImpl* web_contents = |
| 58 static_cast<WebContentsImpl*>(shell()->web_contents()); | 42 static_cast<WebContentsImpl*>(shell()->web_contents()); |
| 59 FrameTree* frame_tree = web_contents->GetFrameTree(); | 43 FrameTree* frame_tree = web_contents->GetFrameTree(); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 | 94 |
| 111 NavigateToURL(shell(), GURL(url::kAboutBlankURL)); | 95 NavigateToURL(shell(), GURL(url::kAboutBlankURL)); |
| 112 | 96 |
| 113 AccessibilityNotificationWaiter waiter(shell(), AccessibilityModeComplete, | 97 AccessibilityNotificationWaiter waiter(shell(), AccessibilityModeComplete, |
| 114 ui::AX_EVENT_LOAD_COMPLETE); | 98 ui::AX_EVENT_LOAD_COMPLETE); |
| 115 GURL url(embedded_test_server()->GetURL( | 99 GURL url(embedded_test_server()->GetURL( |
| 116 "/accessibility/html/iframe-coordinates.html")); | 100 "/accessibility/html/iframe-coordinates.html")); |
| 117 NavigateToURL(shell(), url); | 101 NavigateToURL(shell(), url); |
| 118 waiter.WaitForNotification(); | 102 waiter.WaitForNotification(); |
| 119 | 103 |
| 120 WebContentsImpl* web_contents = | 104 WaitForAccessibilityTreeToContainNodeWithName( |
| 121 static_cast<WebContentsImpl*>(shell()->web_contents()); | 105 shell()->web_contents(), "Ordinary Button"); |
| 122 FrameTree* frame_tree = web_contents->GetFrameTree(); | 106 WaitForAccessibilityTreeToContainNodeWithName( |
| 123 BrowserAccessibilityManager* manager = | 107 shell()->web_contents(), "Scrolled Button"); |
| 124 web_contents->GetRootBrowserAccessibilityManager(); | |
| 125 BrowserAccessibility* root = manager->GetRoot(); | |
| 126 while (!AXTreeContainsNodeWithName(root, "Ordinary Button") || | |
| 127 !AXTreeContainsNodeWithName(root, "Scrolled Button")) { | |
| 128 AccessibilityNotificationWaiter waiter(shell(), AccessibilityModeComplete, | |
| 129 ui::AX_EVENT_NONE); | |
| 130 for (FrameTreeNode* node : frame_tree->Nodes()) | |
| 131 waiter.ListenToAdditionalFrame(node->current_frame_host()); | |
| 132 waiter.WaitForNotification(); | |
| 133 } | |
| 134 | 108 |
| 135 // Send a series of hit test requests, and for each one | 109 // Send a series of hit test requests, and for each one |
| 136 // wait for the hover event in response, verifying we hit the | 110 // wait for the hover event in response, verifying we hit the |
| 137 // correct object. | 111 // correct object. |
| 138 | 112 |
| 139 // (50, 50) -> "Button" | 113 // (50, 50) -> "Button" |
| 140 BrowserAccessibility* hovered_node; | 114 BrowserAccessibility* hovered_node; |
| 141 hovered_node = HitTestAndWaitForResult(gfx::Point(50, 50)); | 115 hovered_node = HitTestAndWaitForResult(gfx::Point(50, 50)); |
| 142 ASSERT_TRUE(hovered_node != NULL); | 116 ASSERT_TRUE(hovered_node != NULL); |
| 143 ASSERT_EQ(ui::AX_ROLE_BUTTON, hovered_node->GetRole()); | 117 ASSERT_EQ(ui::AX_ROLE_BUTTON, hovered_node->GetRole()); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 162 ASSERT_EQ("Scrolled Button", | 136 ASSERT_EQ("Scrolled Button", |
| 163 hovered_node->GetStringAttribute(ui::AX_ATTR_NAME)); | 137 hovered_node->GetStringAttribute(ui::AX_ATTR_NAME)); |
| 164 | 138 |
| 165 // (50, 505) -> div in second iframe | 139 // (50, 505) -> div in second iframe |
| 166 hovered_node = HitTestAndWaitForResult(gfx::Point(50, 505)); | 140 hovered_node = HitTestAndWaitForResult(gfx::Point(50, 505)); |
| 167 ASSERT_TRUE(hovered_node != NULL); | 141 ASSERT_TRUE(hovered_node != NULL); |
| 168 ASSERT_EQ(ui::AX_ROLE_DIV, hovered_node->GetRole()); | 142 ASSERT_EQ(ui::AX_ROLE_DIV, hovered_node->GetRole()); |
| 169 } | 143 } |
| 170 | 144 |
| 171 } // namespace content | 145 } // namespace content |
| OLD | NEW |