| 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 "base/logging.h" | 5 #include "base/logging.h" |
| 6 #include "content/browser/accessibility/browser_accessibility.h" | 6 #include "content/browser/accessibility/browser_accessibility.h" |
| 7 #include "content/browser/accessibility/browser_accessibility_manager.h" | 7 #include "content/browser/accessibility/browser_accessibility_manager.h" |
| 8 #include "content/browser/web_contents/web_contents_impl.h" | 8 #include "content/browser/web_contents/web_contents_impl.h" |
| 9 #include "content/public/test/browser_test_utils.h" | 9 #include "content/public/test/browser_test_utils.h" |
| 10 #include "content/public/test/content_browser_test.h" | 10 #include "content/public/test/content_browser_test.h" |
| 11 #include "content/public/test/content_browser_test_utils.h" | 11 #include "content/public/test/content_browser_test_utils.h" |
| 12 #include "content/public/test/test_utils.h" | 12 #include "content/public/test/test_utils.h" |
| 13 #include "content/shell/browser/shell.h" | 13 #include "content/shell/browser/shell.h" |
| 14 #include "content/test/accessibility_browser_test_utils.h" | 14 #include "content/test/accessibility_browser_test_utils.h" |
| 15 #include "net/dns/mock_host_resolver.h" | 15 #include "net/dns/mock_host_resolver.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 17 |
| 18 namespace content { | 18 namespace content { |
| 19 | 19 |
| 20 class AccessibilityHitTestingBrowserTest : public ContentBrowserTest { | 20 class AccessibilityHitTestingBrowserTest : public ContentBrowserTest { |
| 21 public: | 21 public: |
| 22 AccessibilityHitTestingBrowserTest() {} | 22 AccessibilityHitTestingBrowserTest() {} |
| 23 ~AccessibilityHitTestingBrowserTest() override {} | 23 ~AccessibilityHitTestingBrowserTest() override {} |
| 24 | 24 |
| 25 protected: | 25 protected: |
| 26 BrowserAccessibility* HitTestAndWaitForResult(const gfx::Point& point) { | 26 BrowserAccessibility* HitTestAndWaitForResultWithEvent( |
| 27 const gfx::Point& point, |
| 28 ui::AXEvent event_to_fire) { |
| 27 WebContentsImpl* web_contents = | 29 WebContentsImpl* web_contents = |
| 28 static_cast<WebContentsImpl*>(shell()->web_contents()); | 30 static_cast<WebContentsImpl*>(shell()->web_contents()); |
| 29 FrameTree* frame_tree = web_contents->GetFrameTree(); | 31 FrameTree* frame_tree = web_contents->GetFrameTree(); |
| 30 BrowserAccessibilityManager* manager = | 32 BrowserAccessibilityManager* manager = |
| 31 web_contents->GetRootBrowserAccessibilityManager(); | 33 web_contents->GetRootBrowserAccessibilityManager(); |
| 32 | 34 |
| 33 AccessibilityNotificationWaiter hover_waiter(shell()->web_contents(), | 35 AccessibilityNotificationWaiter event_waiter( |
| 34 kAccessibilityModeComplete, | 36 shell()->web_contents(), kAccessibilityModeComplete, event_to_fire); |
| 35 ui::AX_EVENT_HOVER); | |
| 36 for (FrameTreeNode* node : frame_tree->Nodes()) | 37 for (FrameTreeNode* node : frame_tree->Nodes()) |
| 37 hover_waiter.ListenToAdditionalFrame(node->current_frame_host()); | 38 event_waiter.ListenToAdditionalFrame(node->current_frame_host()); |
| 38 manager->HitTest(point); | 39 ui::AXActionData action_data; |
| 39 hover_waiter.WaitForNotification(); | 40 action_data.action = ui::AX_ACTION_HIT_TEST; |
| 41 action_data.target_point = point; |
| 42 action_data.hit_test_event_to_fire = event_to_fire; |
| 43 manager->delegate()->AccessibilityPerformAction(action_data); |
| 44 event_waiter.WaitForNotification(); |
| 40 | 45 |
| 41 RenderFrameHostImpl* target_frame = hover_waiter.event_render_frame_host(); | 46 RenderFrameHostImpl* target_frame = event_waiter.event_render_frame_host(); |
| 42 BrowserAccessibilityManager* target_manager = | 47 BrowserAccessibilityManager* target_manager = |
| 43 target_frame->browser_accessibility_manager(); | 48 target_frame->browser_accessibility_manager(); |
| 44 int hover_target_id = hover_waiter.event_target_id(); | 49 int event_target_id = event_waiter.event_target_id(); |
| 45 BrowserAccessibility* hovered_node = | 50 BrowserAccessibility* hit_node = target_manager->GetFromID(event_target_id); |
| 46 target_manager->GetFromID(hover_target_id); | 51 return hit_node; |
| 47 return hovered_node; | 52 } |
| 53 |
| 54 BrowserAccessibility* HitTestAndWaitForResult(const gfx::Point& point) { |
| 55 return HitTestAndWaitForResultWithEvent(point, ui::AX_EVENT_HOVER); |
| 48 } | 56 } |
| 49 | 57 |
| 50 BrowserAccessibility* CallCachingAsyncHitTest(const gfx::Point& point) { | 58 BrowserAccessibility* CallCachingAsyncHitTest(const gfx::Point& point) { |
| 51 WebContentsImpl* web_contents = | 59 WebContentsImpl* web_contents = |
| 52 static_cast<WebContentsImpl*>(shell()->web_contents()); | 60 static_cast<WebContentsImpl*>(shell()->web_contents()); |
| 53 FrameTree* frame_tree = web_contents->GetFrameTree(); | 61 FrameTree* frame_tree = web_contents->GetFrameTree(); |
| 54 BrowserAccessibilityManager* manager = | 62 BrowserAccessibilityManager* manager = |
| 55 web_contents->GetRootBrowserAccessibilityManager(); | 63 web_contents->GetRootBrowserAccessibilityManager(); |
| 56 gfx::Point screen_point = | 64 gfx::Point screen_point = |
| 57 point + manager->GetViewBounds().OffsetFromOrigin(); | 65 point + manager->GetViewBounds().OffsetFromOrigin(); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 83 "<html><head><title>Accessibility Test</title></head>" | 91 "<html><head><title>Accessibility Test</title></head>" |
| 84 "<body>" | 92 "<body>" |
| 85 "<a href='#'>" | 93 "<a href='#'>" |
| 86 "This is some text in a link" | 94 "This is some text in a link" |
| 87 "</a>" | 95 "</a>" |
| 88 "</body></html>"; | 96 "</body></html>"; |
| 89 GURL url(url_str); | 97 GURL url(url_str); |
| 90 NavigateToURL(shell(), url); | 98 NavigateToURL(shell(), url); |
| 91 waiter.WaitForNotification(); | 99 waiter.WaitForNotification(); |
| 92 | 100 |
| 93 BrowserAccessibility* hovered_node = | 101 BrowserAccessibility* hit_node = HitTestAndWaitForResult(gfx::Point(-1, -1)); |
| 94 HitTestAndWaitForResult(gfx::Point(-1, -1)); | 102 ASSERT_TRUE(hit_node != NULL); |
| 95 ASSERT_TRUE(hovered_node != NULL); | 103 ASSERT_EQ(ui::AX_ROLE_ROOT_WEB_AREA, hit_node->GetRole()); |
| 96 ASSERT_EQ(ui::AX_ROLE_ROOT_WEB_AREA, hovered_node->GetRole()); | |
| 97 } | 104 } |
| 98 | 105 |
| 99 IN_PROC_BROWSER_TEST_F(AccessibilityHitTestingBrowserTest, | 106 IN_PROC_BROWSER_TEST_F(AccessibilityHitTestingBrowserTest, |
| 100 HitTestingInIframes) { | 107 HitTestingInIframes) { |
| 101 host_resolver()->AddRule("*", "127.0.0.1"); | 108 host_resolver()->AddRule("*", "127.0.0.1"); |
| 102 ASSERT_TRUE(embedded_test_server()->Start()); | 109 ASSERT_TRUE(embedded_test_server()->Start()); |
| 103 | 110 |
| 104 NavigateToURL(shell(), GURL(url::kAboutBlankURL)); | 111 NavigateToURL(shell(), GURL(url::kAboutBlankURL)); |
| 105 | 112 |
| 106 AccessibilityNotificationWaiter waiter(shell()->web_contents(), | 113 AccessibilityNotificationWaiter waiter(shell()->web_contents(), |
| 107 kAccessibilityModeComplete, | 114 kAccessibilityModeComplete, |
| 108 ui::AX_EVENT_LOAD_COMPLETE); | 115 ui::AX_EVENT_LOAD_COMPLETE); |
| 109 GURL url(embedded_test_server()->GetURL( | 116 GURL url(embedded_test_server()->GetURL( |
| 110 "/accessibility/html/iframe-coordinates.html")); | 117 "/accessibility/html/iframe-coordinates.html")); |
| 111 NavigateToURL(shell(), url); | 118 NavigateToURL(shell(), url); |
| 112 waiter.WaitForNotification(); | 119 waiter.WaitForNotification(); |
| 113 | 120 |
| 114 WaitForAccessibilityTreeToContainNodeWithName( | 121 WaitForAccessibilityTreeToContainNodeWithName( |
| 115 shell()->web_contents(), "Ordinary Button"); | 122 shell()->web_contents(), "Ordinary Button"); |
| 116 WaitForAccessibilityTreeToContainNodeWithName( | 123 WaitForAccessibilityTreeToContainNodeWithName( |
| 117 shell()->web_contents(), "Scrolled Button"); | 124 shell()->web_contents(), "Scrolled Button"); |
| 118 | 125 |
| 119 // Send a series of hit test requests, and for each one | 126 // Send a series of hit test requests, and for each one |
| 120 // wait for the hover event in response, verifying we hit the | 127 // wait for the hover event in response, verifying we hit the |
| 121 // correct object. | 128 // correct object. |
| 122 | 129 |
| 123 // (50, 50) -> "Button" | 130 // (50, 50) -> "Button" |
| 124 BrowserAccessibility* hovered_node; | 131 BrowserAccessibility* hit_node; |
| 125 hovered_node = HitTestAndWaitForResult(gfx::Point(50, 50)); | 132 hit_node = HitTestAndWaitForResult(gfx::Point(50, 50)); |
| 126 ASSERT_TRUE(hovered_node != NULL); | 133 ASSERT_TRUE(hit_node != NULL); |
| 127 ASSERT_EQ(ui::AX_ROLE_BUTTON, hovered_node->GetRole()); | 134 ASSERT_EQ(ui::AX_ROLE_BUTTON, hit_node->GetRole()); |
| 128 ASSERT_EQ("Button", hovered_node->GetStringAttribute(ui::AX_ATTR_NAME)); | 135 ASSERT_EQ("Button", hit_node->GetStringAttribute(ui::AX_ATTR_NAME)); |
| 129 | 136 |
| 130 // (50, 305) -> div in first iframe | 137 // (50, 305) -> div in first iframe |
| 131 hovered_node = HitTestAndWaitForResult(gfx::Point(50, 305)); | 138 hit_node = HitTestAndWaitForResult(gfx::Point(50, 305)); |
| 132 ASSERT_TRUE(hovered_node != NULL); | 139 ASSERT_TRUE(hit_node != NULL); |
| 133 ASSERT_EQ(ui::AX_ROLE_DIV, hovered_node->GetRole()); | 140 ASSERT_EQ(ui::AX_ROLE_DIV, hit_node->GetRole()); |
| 134 | 141 |
| 135 // (50, 350) -> "Ordinary Button" | 142 // (50, 350) -> "Ordinary Button" |
| 136 hovered_node = HitTestAndWaitForResult(gfx::Point(50, 350)); | 143 hit_node = HitTestAndWaitForResult(gfx::Point(50, 350)); |
| 137 ASSERT_TRUE(hovered_node != NULL); | 144 ASSERT_TRUE(hit_node != NULL); |
| 138 ASSERT_EQ(ui::AX_ROLE_BUTTON, hovered_node->GetRole()); | 145 ASSERT_EQ(ui::AX_ROLE_BUTTON, hit_node->GetRole()); |
| 139 ASSERT_EQ("Ordinary Button", | 146 ASSERT_EQ("Ordinary Button", hit_node->GetStringAttribute(ui::AX_ATTR_NAME)); |
| 140 hovered_node->GetStringAttribute(ui::AX_ATTR_NAME)); | |
| 141 | 147 |
| 142 // (50, 455) -> "Scrolled Button" | 148 // (50, 455) -> "Scrolled Button" |
| 143 hovered_node = HitTestAndWaitForResult(gfx::Point(50, 455)); | 149 hit_node = HitTestAndWaitForResult(gfx::Point(50, 455)); |
| 144 ASSERT_TRUE(hovered_node != NULL); | 150 ASSERT_TRUE(hit_node != NULL); |
| 145 ASSERT_EQ(ui::AX_ROLE_BUTTON, hovered_node->GetRole()); | 151 ASSERT_EQ(ui::AX_ROLE_BUTTON, hit_node->GetRole()); |
| 146 ASSERT_EQ("Scrolled Button", | 152 ASSERT_EQ("Scrolled Button", hit_node->GetStringAttribute(ui::AX_ATTR_NAME)); |
| 147 hovered_node->GetStringAttribute(ui::AX_ATTR_NAME)); | |
| 148 | 153 |
| 149 // (50, 505) -> div in second iframe | 154 // (50, 505) -> div in second iframe |
| 150 hovered_node = HitTestAndWaitForResult(gfx::Point(50, 505)); | 155 hit_node = HitTestAndWaitForResult(gfx::Point(50, 505)); |
| 151 ASSERT_TRUE(hovered_node != NULL); | 156 ASSERT_TRUE(hit_node != NULL); |
| 152 ASSERT_EQ(ui::AX_ROLE_DIV, hovered_node->GetRole()); | 157 ASSERT_EQ(ui::AX_ROLE_DIV, hit_node->GetRole()); |
| 158 |
| 159 // (50, 505) -> div in second iframe |
| 160 // but with a different event |
| 161 hit_node = |
| 162 HitTestAndWaitForResultWithEvent(gfx::Point(50, 505), ui::AX_EVENT_ALERT); |
| 163 ASSERT_NE(hit_node, nullptr); |
| 164 ASSERT_EQ(ui::AX_ROLE_DIV, hit_node->GetRole()); |
| 153 } | 165 } |
| 154 | 166 |
| 155 IN_PROC_BROWSER_TEST_F(AccessibilityHitTestingBrowserTest, | 167 IN_PROC_BROWSER_TEST_F(AccessibilityHitTestingBrowserTest, |
| 156 CachingAsyncHitTestingInIframes) { | 168 CachingAsyncHitTestingInIframes) { |
| 157 host_resolver()->AddRule("*", "127.0.0.1"); | 169 host_resolver()->AddRule("*", "127.0.0.1"); |
| 158 ASSERT_TRUE(embedded_test_server()->Start()); | 170 ASSERT_TRUE(embedded_test_server()->Start()); |
| 159 | 171 |
| 160 NavigateToURL(shell(), GURL(url::kAboutBlankURL)); | 172 NavigateToURL(shell(), GURL(url::kAboutBlankURL)); |
| 161 | 173 |
| 162 AccessibilityNotificationWaiter waiter(shell()->web_contents(), | 174 AccessibilityNotificationWaiter waiter(shell()->web_contents(), |
| (...skipping 10 matching lines...) Expand all Loading... |
| 173 shell()->web_contents(), "Scrolled Button"); | 185 shell()->web_contents(), "Scrolled Button"); |
| 174 | 186 |
| 175 // For each point we try, the first time we call CachingAsyncHitTest it | 187 // For each point we try, the first time we call CachingAsyncHitTest it |
| 176 // should FAIL and return the wrong object, because this test page has | 188 // should FAIL and return the wrong object, because this test page has |
| 177 // been designed to confound local synchronous hit testing using | 189 // been designed to confound local synchronous hit testing using |
| 178 // z-indexes. However, calling CachingAsyncHitTest a second time should | 190 // z-indexes. However, calling CachingAsyncHitTest a second time should |
| 179 // return the correct result (since CallCachingAsyncHitTest waits for the | 191 // return the correct result (since CallCachingAsyncHitTest waits for the |
| 180 // HOVER event to be received). | 192 // HOVER event to be received). |
| 181 | 193 |
| 182 // (50, 50) -> "Button" | 194 // (50, 50) -> "Button" |
| 183 BrowserAccessibility* hovered_node; | 195 BrowserAccessibility* hit_node; |
| 184 hovered_node = CallCachingAsyncHitTest(gfx::Point(50, 50)); | 196 hit_node = CallCachingAsyncHitTest(gfx::Point(50, 50)); |
| 185 ASSERT_TRUE(hovered_node != NULL); | 197 ASSERT_TRUE(hit_node != NULL); |
| 186 ASSERT_NE(ui::AX_ROLE_BUTTON, hovered_node->GetRole()); | 198 ASSERT_NE(ui::AX_ROLE_BUTTON, hit_node->GetRole()); |
| 187 hovered_node = CallCachingAsyncHitTest(gfx::Point(50, 50)); | 199 hit_node = CallCachingAsyncHitTest(gfx::Point(50, 50)); |
| 188 ASSERT_EQ("Button", hovered_node->GetStringAttribute(ui::AX_ATTR_NAME)); | 200 ASSERT_EQ("Button", hit_node->GetStringAttribute(ui::AX_ATTR_NAME)); |
| 189 | 201 |
| 190 // (50, 305) -> div in first iframe | 202 // (50, 305) -> div in first iframe |
| 191 hovered_node = CallCachingAsyncHitTest(gfx::Point(50, 305)); | 203 hit_node = CallCachingAsyncHitTest(gfx::Point(50, 305)); |
| 192 ASSERT_TRUE(hovered_node != NULL); | 204 ASSERT_TRUE(hit_node != NULL); |
| 193 ASSERT_NE(ui::AX_ROLE_DIV, hovered_node->GetRole()); | 205 ASSERT_NE(ui::AX_ROLE_DIV, hit_node->GetRole()); |
| 194 hovered_node = CallCachingAsyncHitTest(gfx::Point(50, 305)); | 206 hit_node = CallCachingAsyncHitTest(gfx::Point(50, 305)); |
| 195 ASSERT_EQ(ui::AX_ROLE_DIV, hovered_node->GetRole()); | 207 ASSERT_EQ(ui::AX_ROLE_DIV, hit_node->GetRole()); |
| 196 | 208 |
| 197 // (50, 350) -> "Ordinary Button" | 209 // (50, 350) -> "Ordinary Button" |
| 198 hovered_node = CallCachingAsyncHitTest(gfx::Point(50, 350)); | 210 hit_node = CallCachingAsyncHitTest(gfx::Point(50, 350)); |
| 199 ASSERT_TRUE(hovered_node != NULL); | 211 ASSERT_TRUE(hit_node != NULL); |
| 200 ASSERT_NE(ui::AX_ROLE_BUTTON, hovered_node->GetRole()); | 212 ASSERT_NE(ui::AX_ROLE_BUTTON, hit_node->GetRole()); |
| 201 hovered_node = CallCachingAsyncHitTest(gfx::Point(50, 350)); | 213 hit_node = CallCachingAsyncHitTest(gfx::Point(50, 350)); |
| 202 ASSERT_EQ(ui::AX_ROLE_BUTTON, hovered_node->GetRole()); | 214 ASSERT_EQ(ui::AX_ROLE_BUTTON, hit_node->GetRole()); |
| 203 ASSERT_EQ("Ordinary Button", | 215 ASSERT_EQ("Ordinary Button", hit_node->GetStringAttribute(ui::AX_ATTR_NAME)); |
| 204 hovered_node->GetStringAttribute(ui::AX_ATTR_NAME)); | |
| 205 | 216 |
| 206 // (50, 455) -> "Scrolled Button" | 217 // (50, 455) -> "Scrolled Button" |
| 207 hovered_node = CallCachingAsyncHitTest(gfx::Point(50, 455)); | 218 hit_node = CallCachingAsyncHitTest(gfx::Point(50, 455)); |
| 208 ASSERT_TRUE(hovered_node != NULL); | 219 ASSERT_TRUE(hit_node != NULL); |
| 209 ASSERT_NE(ui::AX_ROLE_BUTTON, hovered_node->GetRole()); | 220 ASSERT_NE(ui::AX_ROLE_BUTTON, hit_node->GetRole()); |
| 210 hovered_node = CallCachingAsyncHitTest(gfx::Point(50, 455)); | 221 hit_node = CallCachingAsyncHitTest(gfx::Point(50, 455)); |
| 211 ASSERT_EQ(ui::AX_ROLE_BUTTON, hovered_node->GetRole()); | 222 ASSERT_EQ(ui::AX_ROLE_BUTTON, hit_node->GetRole()); |
| 212 ASSERT_EQ("Scrolled Button", | 223 ASSERT_EQ("Scrolled Button", hit_node->GetStringAttribute(ui::AX_ATTR_NAME)); |
| 213 hovered_node->GetStringAttribute(ui::AX_ATTR_NAME)); | |
| 214 | 224 |
| 215 // (50, 505) -> div in second iframe | 225 // (50, 505) -> div in second iframe |
| 216 hovered_node = CallCachingAsyncHitTest(gfx::Point(50, 505)); | 226 hit_node = CallCachingAsyncHitTest(gfx::Point(50, 505)); |
| 217 ASSERT_TRUE(hovered_node != NULL); | 227 ASSERT_TRUE(hit_node != NULL); |
| 218 ASSERT_NE(ui::AX_ROLE_DIV, hovered_node->GetRole()); | 228 ASSERT_NE(ui::AX_ROLE_DIV, hit_node->GetRole()); |
| 219 hovered_node = CallCachingAsyncHitTest(gfx::Point(50, 505)); | 229 hit_node = CallCachingAsyncHitTest(gfx::Point(50, 505)); |
| 220 ASSERT_EQ(ui::AX_ROLE_DIV, hovered_node->GetRole()); | 230 ASSERT_EQ(ui::AX_ROLE_DIV, hit_node->GetRole()); |
| 221 } | 231 } |
| 222 | 232 |
| 223 } // namespace content | 233 } // namespace content |
| OLD | NEW |