| 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> | |
| 6 #include <string> | |
| 7 #include <vector> | |
| 8 | |
| 9 #include "base/command_line.h" | |
| 10 #include "base/files/file_util.h" | |
| 11 #include "base/logging.h" | 5 #include "base/logging.h" |
| 12 #include "base/strings/string16.h" | |
| 13 #include "base/strings/string_split.h" | |
| 14 #include "base/strings/string_util.h" | |
| 15 #include "base/strings/utf_string_conversions.h" | |
| 16 #include "content/browser/accessibility/accessibility_tree_formatter.h" | |
| 17 #include "content/browser/accessibility/browser_accessibility.h" | 6 #include "content/browser/accessibility/browser_accessibility.h" |
| 18 #include "content/browser/accessibility/browser_accessibility_manager.h" | 7 #include "content/browser/accessibility/browser_accessibility_manager.h" |
| 19 #include "content/browser/web_contents/web_contents_impl.h" | 8 #include "content/browser/web_contents/web_contents_impl.h" |
| 20 #include "content/public/browser/web_contents.h" | |
| 21 #include "content/public/common/content_paths.h" | |
| 22 #include "content/public/common/content_switches.h" | |
| 23 #include "content/public/common/url_constants.h" | |
| 24 #include "content/public/test/browser_test_utils.h" | 9 #include "content/public/test/browser_test_utils.h" |
| 25 #include "content/public/test/content_browser_test.h" | 10 #include "content/public/test/content_browser_test.h" |
| 26 #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" |
| 27 #include "content/shell/browser/shell.h" | 13 #include "content/shell/browser/shell.h" |
| 28 #include "content/test/accessibility_browser_test_utils.h" | 14 #include "content/test/accessibility_browser_test_utils.h" |
| 29 #include "net/dns/mock_host_resolver.h" | 15 #include "net/dns/mock_host_resolver.h" |
| 30 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 31 | 17 |
| 32 namespace content { | 18 namespace content { |
| 33 | 19 |
| 34 class AccessibilityHitTestingBrowserTest : public ContentBrowserTest { | 20 class AccessibilityHitTestingBrowserTest : public ContentBrowserTest { |
| 35 public: | 21 public: |
| 36 AccessibilityHitTestingBrowserTest() {} | 22 AccessibilityHitTestingBrowserTest() {} |
| (...skipping 15 matching lines...) Expand all Loading... |
| 52 hover_waiter.WaitForNotification(); | 38 hover_waiter.WaitForNotification(); |
| 53 | 39 |
| 54 RenderFrameHostImpl* target_frame = hover_waiter.event_render_frame_host(); | 40 RenderFrameHostImpl* target_frame = hover_waiter.event_render_frame_host(); |
| 55 BrowserAccessibilityManager* target_manager = | 41 BrowserAccessibilityManager* target_manager = |
| 56 target_frame->browser_accessibility_manager(); | 42 target_frame->browser_accessibility_manager(); |
| 57 int hover_target_id = hover_waiter.event_target_id(); | 43 int hover_target_id = hover_waiter.event_target_id(); |
| 58 BrowserAccessibility* hovered_node = | 44 BrowserAccessibility* hovered_node = |
| 59 target_manager->GetFromID(hover_target_id); | 45 target_manager->GetFromID(hover_target_id); |
| 60 return hovered_node; | 46 return hovered_node; |
| 61 } | 47 } |
| 48 |
| 49 BrowserAccessibility* CallCachingAsyncHitTest(const gfx::Point& point) { |
| 50 WebContentsImpl* web_contents = |
| 51 static_cast<WebContentsImpl*>(shell()->web_contents()); |
| 52 FrameTree* frame_tree = web_contents->GetFrameTree(); |
| 53 BrowserAccessibilityManager* manager = |
| 54 web_contents->GetRootBrowserAccessibilityManager(); |
| 55 gfx::Point screen_point = |
| 56 point + manager->GetViewBounds().OffsetFromOrigin(); |
| 57 |
| 58 // Each call to CachingAsyncHitTest results in at least one HOVER |
| 59 // event received. Block until we receive it. |
| 60 AccessibilityNotificationWaiter hover_waiter( |
| 61 shell()->web_contents(), AccessibilityModeComplete, ui::AX_EVENT_HOVER); |
| 62 for (FrameTreeNode* node : frame_tree->Nodes()) |
| 63 hover_waiter.ListenToAdditionalFrame(node->current_frame_host()); |
| 64 BrowserAccessibility* result = manager->CachingAsyncHitTest(screen_point); |
| 65 hover_waiter.WaitForNotification(); |
| 66 return result; |
| 67 } |
| 62 }; | 68 }; |
| 63 | 69 |
| 64 IN_PROC_BROWSER_TEST_F(AccessibilityHitTestingBrowserTest, | 70 IN_PROC_BROWSER_TEST_F(AccessibilityHitTestingBrowserTest, |
| 65 HitTestOutsideDocumentBoundsReturnsRoot) { | 71 HitTestOutsideDocumentBoundsReturnsRoot) { |
| 66 NavigateToURL(shell(), GURL(url::kAboutBlankURL)); | 72 NavigateToURL(shell(), GURL(url::kAboutBlankURL)); |
| 67 | 73 |
| 68 // Load the page. | 74 // Load the page. |
| 69 AccessibilityNotificationWaiter waiter(shell()->web_contents(), | 75 AccessibilityNotificationWaiter waiter(shell()->web_contents(), |
| 70 AccessibilityModeComplete, | 76 AccessibilityModeComplete, |
| 71 ui::AX_EVENT_LOAD_COMPLETE); | 77 ui::AX_EVENT_LOAD_COMPLETE); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 ASSERT_EQ(ui::AX_ROLE_BUTTON, hovered_node->GetRole()); | 143 ASSERT_EQ(ui::AX_ROLE_BUTTON, hovered_node->GetRole()); |
| 138 ASSERT_EQ("Scrolled Button", | 144 ASSERT_EQ("Scrolled Button", |
| 139 hovered_node->GetStringAttribute(ui::AX_ATTR_NAME)); | 145 hovered_node->GetStringAttribute(ui::AX_ATTR_NAME)); |
| 140 | 146 |
| 141 // (50, 505) -> div in second iframe | 147 // (50, 505) -> div in second iframe |
| 142 hovered_node = HitTestAndWaitForResult(gfx::Point(50, 505)); | 148 hovered_node = HitTestAndWaitForResult(gfx::Point(50, 505)); |
| 143 ASSERT_TRUE(hovered_node != NULL); | 149 ASSERT_TRUE(hovered_node != NULL); |
| 144 ASSERT_EQ(ui::AX_ROLE_DIV, hovered_node->GetRole()); | 150 ASSERT_EQ(ui::AX_ROLE_DIV, hovered_node->GetRole()); |
| 145 } | 151 } |
| 146 | 152 |
| 153 IN_PROC_BROWSER_TEST_F(AccessibilityHitTestingBrowserTest, |
| 154 CachingAsyncHitTestingInIframes) { |
| 155 host_resolver()->AddRule("*", "127.0.0.1"); |
| 156 ASSERT_TRUE(embedded_test_server()->Start()); |
| 157 |
| 158 NavigateToURL(shell(), GURL(url::kAboutBlankURL)); |
| 159 |
| 160 AccessibilityNotificationWaiter waiter(shell()->web_contents(), |
| 161 AccessibilityModeComplete, |
| 162 ui::AX_EVENT_LOAD_COMPLETE); |
| 163 GURL url(embedded_test_server()->GetURL( |
| 164 "/accessibility/hit_testing/hit_testing.html")); |
| 165 NavigateToURL(shell(), url); |
| 166 waiter.WaitForNotification(); |
| 167 |
| 168 WaitForAccessibilityTreeToContainNodeWithName( |
| 169 shell()->web_contents(), "Ordinary Button"); |
| 170 WaitForAccessibilityTreeToContainNodeWithName( |
| 171 shell()->web_contents(), "Scrolled Button"); |
| 172 |
| 173 // For each point we try, the first time we call CachingAsyncHitTest it |
| 174 // should FAIL and return the wrong object, because this test page has |
| 175 // been designed to confound local synchronous hit testing using |
| 176 // z-indexes. However, calling CachingAsyncHitTest a second time should |
| 177 // return the correct result (since CallCachingAsyncHitTest waits for the |
| 178 // HOVER event to be received). |
| 179 |
| 180 // (50, 50) -> "Button" |
| 181 BrowserAccessibility* hovered_node; |
| 182 hovered_node = CallCachingAsyncHitTest(gfx::Point(50, 50)); |
| 183 ASSERT_TRUE(hovered_node != NULL); |
| 184 ASSERT_NE(ui::AX_ROLE_BUTTON, hovered_node->GetRole()); |
| 185 hovered_node = CallCachingAsyncHitTest(gfx::Point(50, 50)); |
| 186 ASSERT_EQ("Button", hovered_node->GetStringAttribute(ui::AX_ATTR_NAME)); |
| 187 |
| 188 // (50, 305) -> div in first iframe |
| 189 hovered_node = CallCachingAsyncHitTest(gfx::Point(50, 305)); |
| 190 ASSERT_TRUE(hovered_node != NULL); |
| 191 ASSERT_NE(ui::AX_ROLE_DIV, hovered_node->GetRole()); |
| 192 hovered_node = CallCachingAsyncHitTest(gfx::Point(50, 305)); |
| 193 ASSERT_EQ(ui::AX_ROLE_DIV, hovered_node->GetRole()); |
| 194 |
| 195 // (50, 350) -> "Ordinary Button" |
| 196 hovered_node = CallCachingAsyncHitTest(gfx::Point(50, 350)); |
| 197 ASSERT_TRUE(hovered_node != NULL); |
| 198 ASSERT_NE(ui::AX_ROLE_BUTTON, hovered_node->GetRole()); |
| 199 hovered_node = CallCachingAsyncHitTest(gfx::Point(50, 350)); |
| 200 ASSERT_EQ(ui::AX_ROLE_BUTTON, hovered_node->GetRole()); |
| 201 ASSERT_EQ("Ordinary Button", |
| 202 hovered_node->GetStringAttribute(ui::AX_ATTR_NAME)); |
| 203 |
| 204 // (50, 455) -> "Scrolled Button" |
| 205 hovered_node = CallCachingAsyncHitTest(gfx::Point(50, 455)); |
| 206 ASSERT_TRUE(hovered_node != NULL); |
| 207 ASSERT_NE(ui::AX_ROLE_BUTTON, hovered_node->GetRole()); |
| 208 hovered_node = CallCachingAsyncHitTest(gfx::Point(50, 455)); |
| 209 ASSERT_EQ(ui::AX_ROLE_BUTTON, hovered_node->GetRole()); |
| 210 ASSERT_EQ("Scrolled Button", |
| 211 hovered_node->GetStringAttribute(ui::AX_ATTR_NAME)); |
| 212 |
| 213 // (50, 505) -> div in second iframe |
| 214 hovered_node = CallCachingAsyncHitTest(gfx::Point(50, 505)); |
| 215 ASSERT_TRUE(hovered_node != NULL); |
| 216 ASSERT_NE(ui::AX_ROLE_DIV, hovered_node->GetRole()); |
| 217 hovered_node = CallCachingAsyncHitTest(gfx::Point(50, 505)); |
| 218 ASSERT_EQ(ui::AX_ROLE_DIV, hovered_node->GetRole()); |
| 219 } |
| 220 |
| 147 } // namespace content | 221 } // namespace content |
| OLD | NEW |