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" |
(...skipping 12 matching lines...) Expand all Loading... | |
23 ~AccessibilityHitTestingBrowserTest() override {} | 23 ~AccessibilityHitTestingBrowserTest() override {} |
24 | 24 |
25 protected: | 25 protected: |
26 BrowserAccessibility* HitTestAndWaitForResult(const gfx::Point& point) { | 26 BrowserAccessibility* HitTestAndWaitForResult(const gfx::Point& point) { |
27 WebContentsImpl* web_contents = | 27 WebContentsImpl* web_contents = |
28 static_cast<WebContentsImpl*>(shell()->web_contents()); | 28 static_cast<WebContentsImpl*>(shell()->web_contents()); |
29 FrameTree* frame_tree = web_contents->GetFrameTree(); | 29 FrameTree* frame_tree = web_contents->GetFrameTree(); |
30 BrowserAccessibilityManager* manager = | 30 BrowserAccessibilityManager* manager = |
31 web_contents->GetRootBrowserAccessibilityManager(); | 31 web_contents->GetRootBrowserAccessibilityManager(); |
32 | 32 |
33 AccessibilityNotificationWaiter hover_waiter( | 33 AccessibilityNotificationWaiter hover_waiter(shell()->web_contents(), |
34 shell()->web_contents(), ACCESSIBILITY_MODE_COMPLETE, | 34 AccessibilityMode::kComplete, |
dmazzoni
2017/02/23 17:08:21
This function must be taking an int, but it should
| |
35 ui::AX_EVENT_HOVER); | 35 ui::AX_EVENT_HOVER); |
36 for (FrameTreeNode* node : frame_tree->Nodes()) | 36 for (FrameTreeNode* node : frame_tree->Nodes()) |
37 hover_waiter.ListenToAdditionalFrame(node->current_frame_host()); | 37 hover_waiter.ListenToAdditionalFrame(node->current_frame_host()); |
38 manager->HitTest(point); | 38 manager->HitTest(point); |
39 hover_waiter.WaitForNotification(); | 39 hover_waiter.WaitForNotification(); |
40 | 40 |
41 RenderFrameHostImpl* target_frame = hover_waiter.event_render_frame_host(); | 41 RenderFrameHostImpl* target_frame = hover_waiter.event_render_frame_host(); |
42 BrowserAccessibilityManager* target_manager = | 42 BrowserAccessibilityManager* target_manager = |
43 target_frame->browser_accessibility_manager(); | 43 target_frame->browser_accessibility_manager(); |
44 int hover_target_id = hover_waiter.event_target_id(); | 44 int hover_target_id = hover_waiter.event_target_id(); |
45 BrowserAccessibility* hovered_node = | 45 BrowserAccessibility* hovered_node = |
46 target_manager->GetFromID(hover_target_id); | 46 target_manager->GetFromID(hover_target_id); |
47 return hovered_node; | 47 return hovered_node; |
48 } | 48 } |
49 | 49 |
50 BrowserAccessibility* CallCachingAsyncHitTest(const gfx::Point& point) { | 50 BrowserAccessibility* CallCachingAsyncHitTest(const gfx::Point& point) { |
51 WebContentsImpl* web_contents = | 51 WebContentsImpl* web_contents = |
52 static_cast<WebContentsImpl*>(shell()->web_contents()); | 52 static_cast<WebContentsImpl*>(shell()->web_contents()); |
53 FrameTree* frame_tree = web_contents->GetFrameTree(); | 53 FrameTree* frame_tree = web_contents->GetFrameTree(); |
54 BrowserAccessibilityManager* manager = | 54 BrowserAccessibilityManager* manager = |
55 web_contents->GetRootBrowserAccessibilityManager(); | 55 web_contents->GetRootBrowserAccessibilityManager(); |
56 gfx::Point screen_point = | 56 gfx::Point screen_point = |
57 point + manager->GetViewBounds().OffsetFromOrigin(); | 57 point + manager->GetViewBounds().OffsetFromOrigin(); |
58 | 58 |
59 // Each call to CachingAsyncHitTest results in at least one HOVER | 59 // Each call to CachingAsyncHitTest results in at least one HOVER |
60 // event received. Block until we receive it. | 60 // event received. Block until we receive it. |
61 AccessibilityNotificationWaiter hover_waiter( | 61 AccessibilityNotificationWaiter hover_waiter(shell()->web_contents(), |
62 shell()->web_contents(), ACCESSIBILITY_MODE_COMPLETE, | 62 AccessibilityMode::kComplete, |
63 ui::AX_EVENT_HOVER); | 63 ui::AX_EVENT_HOVER); |
64 for (FrameTreeNode* node : frame_tree->Nodes()) | 64 for (FrameTreeNode* node : frame_tree->Nodes()) |
65 hover_waiter.ListenToAdditionalFrame(node->current_frame_host()); | 65 hover_waiter.ListenToAdditionalFrame(node->current_frame_host()); |
66 BrowserAccessibility* result = manager->CachingAsyncHitTest(screen_point); | 66 BrowserAccessibility* result = manager->CachingAsyncHitTest(screen_point); |
67 hover_waiter.WaitForNotification(); | 67 hover_waiter.WaitForNotification(); |
68 return result; | 68 return result; |
69 } | 69 } |
70 }; | 70 }; |
71 | 71 |
72 IN_PROC_BROWSER_TEST_F(AccessibilityHitTestingBrowserTest, | 72 IN_PROC_BROWSER_TEST_F(AccessibilityHitTestingBrowserTest, |
73 HitTestOutsideDocumentBoundsReturnsRoot) { | 73 HitTestOutsideDocumentBoundsReturnsRoot) { |
74 NavigateToURL(shell(), GURL(url::kAboutBlankURL)); | 74 NavigateToURL(shell(), GURL(url::kAboutBlankURL)); |
75 | 75 |
76 // Load the page. | 76 // Load the page. |
77 AccessibilityNotificationWaiter waiter(shell()->web_contents(), | 77 AccessibilityNotificationWaiter waiter(shell()->web_contents(), |
78 ACCESSIBILITY_MODE_COMPLETE, | 78 AccessibilityMode::kComplete, |
79 ui::AX_EVENT_LOAD_COMPLETE); | 79 ui::AX_EVENT_LOAD_COMPLETE); |
80 const char url_str[] = | 80 const char url_str[] = |
81 "data:text/html," | 81 "data:text/html," |
82 "<!doctype html>" | 82 "<!doctype html>" |
83 "<html><head><title>Accessibility Test</title></head>" | 83 "<html><head><title>Accessibility Test</title></head>" |
84 "<body>" | 84 "<body>" |
85 "<a href='#'>" | 85 "<a href='#'>" |
86 "This is some text in a link" | 86 "This is some text in a link" |
87 "</a>" | 87 "</a>" |
88 "</body></html>"; | 88 "</body></html>"; |
89 GURL url(url_str); | 89 GURL url(url_str); |
90 NavigateToURL(shell(), url); | 90 NavigateToURL(shell(), url); |
91 waiter.WaitForNotification(); | 91 waiter.WaitForNotification(); |
92 | 92 |
93 BrowserAccessibility* hovered_node = | 93 BrowserAccessibility* hovered_node = |
94 HitTestAndWaitForResult(gfx::Point(-1, -1)); | 94 HitTestAndWaitForResult(gfx::Point(-1, -1)); |
95 ASSERT_TRUE(hovered_node != NULL); | 95 ASSERT_TRUE(hovered_node != NULL); |
96 ASSERT_EQ(ui::AX_ROLE_ROOT_WEB_AREA, hovered_node->GetRole()); | 96 ASSERT_EQ(ui::AX_ROLE_ROOT_WEB_AREA, hovered_node->GetRole()); |
97 } | 97 } |
98 | 98 |
99 IN_PROC_BROWSER_TEST_F(AccessibilityHitTestingBrowserTest, | 99 IN_PROC_BROWSER_TEST_F(AccessibilityHitTestingBrowserTest, |
100 HitTestingInIframes) { | 100 HitTestingInIframes) { |
101 host_resolver()->AddRule("*", "127.0.0.1"); | 101 host_resolver()->AddRule("*", "127.0.0.1"); |
102 ASSERT_TRUE(embedded_test_server()->Start()); | 102 ASSERT_TRUE(embedded_test_server()->Start()); |
103 | 103 |
104 NavigateToURL(shell(), GURL(url::kAboutBlankURL)); | 104 NavigateToURL(shell(), GURL(url::kAboutBlankURL)); |
105 | 105 |
106 AccessibilityNotificationWaiter waiter(shell()->web_contents(), | 106 AccessibilityNotificationWaiter waiter(shell()->web_contents(), |
107 ACCESSIBILITY_MODE_COMPLETE, | 107 AccessibilityMode::kComplete, |
108 ui::AX_EVENT_LOAD_COMPLETE); | 108 ui::AX_EVENT_LOAD_COMPLETE); |
109 GURL url(embedded_test_server()->GetURL( | 109 GURL url(embedded_test_server()->GetURL( |
110 "/accessibility/html/iframe-coordinates.html")); | 110 "/accessibility/html/iframe-coordinates.html")); |
111 NavigateToURL(shell(), url); | 111 NavigateToURL(shell(), url); |
112 waiter.WaitForNotification(); | 112 waiter.WaitForNotification(); |
113 | 113 |
114 WaitForAccessibilityTreeToContainNodeWithName( | 114 WaitForAccessibilityTreeToContainNodeWithName( |
115 shell()->web_contents(), "Ordinary Button"); | 115 shell()->web_contents(), "Ordinary Button"); |
116 WaitForAccessibilityTreeToContainNodeWithName( | 116 WaitForAccessibilityTreeToContainNodeWithName( |
117 shell()->web_contents(), "Scrolled Button"); | 117 shell()->web_contents(), "Scrolled Button"); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
153 } | 153 } |
154 | 154 |
155 IN_PROC_BROWSER_TEST_F(AccessibilityHitTestingBrowserTest, | 155 IN_PROC_BROWSER_TEST_F(AccessibilityHitTestingBrowserTest, |
156 CachingAsyncHitTestingInIframes) { | 156 CachingAsyncHitTestingInIframes) { |
157 host_resolver()->AddRule("*", "127.0.0.1"); | 157 host_resolver()->AddRule("*", "127.0.0.1"); |
158 ASSERT_TRUE(embedded_test_server()->Start()); | 158 ASSERT_TRUE(embedded_test_server()->Start()); |
159 | 159 |
160 NavigateToURL(shell(), GURL(url::kAboutBlankURL)); | 160 NavigateToURL(shell(), GURL(url::kAboutBlankURL)); |
161 | 161 |
162 AccessibilityNotificationWaiter waiter(shell()->web_contents(), | 162 AccessibilityNotificationWaiter waiter(shell()->web_contents(), |
163 ACCESSIBILITY_MODE_COMPLETE, | 163 AccessibilityMode::kComplete, |
164 ui::AX_EVENT_LOAD_COMPLETE); | 164 ui::AX_EVENT_LOAD_COMPLETE); |
165 GURL url(embedded_test_server()->GetURL( | 165 GURL url(embedded_test_server()->GetURL( |
166 "/accessibility/hit_testing/hit_testing.html")); | 166 "/accessibility/hit_testing/hit_testing.html")); |
167 NavigateToURL(shell(), url); | 167 NavigateToURL(shell(), url); |
168 waiter.WaitForNotification(); | 168 waiter.WaitForNotification(); |
169 | 169 |
170 WaitForAccessibilityTreeToContainNodeWithName( | 170 WaitForAccessibilityTreeToContainNodeWithName( |
171 shell()->web_contents(), "Ordinary Button"); | 171 shell()->web_contents(), "Ordinary Button"); |
172 WaitForAccessibilityTreeToContainNodeWithName( | 172 WaitForAccessibilityTreeToContainNodeWithName( |
173 shell()->web_contents(), "Scrolled Button"); | 173 shell()->web_contents(), "Scrolled Button"); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
214 | 214 |
215 // (50, 505) -> div in second iframe | 215 // (50, 505) -> div in second iframe |
216 hovered_node = CallCachingAsyncHitTest(gfx::Point(50, 505)); | 216 hovered_node = CallCachingAsyncHitTest(gfx::Point(50, 505)); |
217 ASSERT_TRUE(hovered_node != NULL); | 217 ASSERT_TRUE(hovered_node != NULL); |
218 ASSERT_NE(ui::AX_ROLE_DIV, hovered_node->GetRole()); | 218 ASSERT_NE(ui::AX_ROLE_DIV, hovered_node->GetRole()); |
219 hovered_node = CallCachingAsyncHitTest(gfx::Point(50, 505)); | 219 hovered_node = CallCachingAsyncHitTest(gfx::Point(50, 505)); |
220 ASSERT_EQ(ui::AX_ROLE_DIV, hovered_node->GetRole()); | 220 ASSERT_EQ(ui::AX_ROLE_DIV, hovered_node->GetRole()); |
221 } | 221 } |
222 | 222 |
223 } // namespace content | 223 } // namespace content |
OLD | NEW |