Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(46)

Side by Side Diff: content/browser/accessibility/hit_testing_browsertest.cc

Issue 2748463003: Generalize the HIT_TEST accessibility action so that it can send any event. (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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( 35 AccessibilityNotificationWaiter event_waiter(
34 shell()->web_contents(), ACCESSIBILITY_MODE_COMPLETE, 36 shell()->web_contents(), ACCESSIBILITY_MODE_COMPLETE, 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* hovered_node =
David Tseng 2017/03/13 21:43:47 nit: hit_node
dmazzoni 2017/03/20 05:40:39 Done.
46 target_manager->GetFromID(hover_target_id); 51 target_manager->GetFromID(event_target_id);
47 return hovered_node; 52 return hovered_node;
48 } 53 }
49 54
55 BrowserAccessibility* HitTestAndWaitForResult(const gfx::Point& point) {
56 return HitTestAndWaitForResultWithEvent(point, ui::AX_EVENT_HOVER);
57 }
58
50 BrowserAccessibility* CallCachingAsyncHitTest(const gfx::Point& point) { 59 BrowserAccessibility* CallCachingAsyncHitTest(const gfx::Point& point) {
51 WebContentsImpl* web_contents = 60 WebContentsImpl* web_contents =
52 static_cast<WebContentsImpl*>(shell()->web_contents()); 61 static_cast<WebContentsImpl*>(shell()->web_contents());
53 FrameTree* frame_tree = web_contents->GetFrameTree(); 62 FrameTree* frame_tree = web_contents->GetFrameTree();
54 BrowserAccessibilityManager* manager = 63 BrowserAccessibilityManager* manager =
55 web_contents->GetRootBrowserAccessibilityManager(); 64 web_contents->GetRootBrowserAccessibilityManager();
56 gfx::Point screen_point = 65 gfx::Point screen_point =
57 point + manager->GetViewBounds().OffsetFromOrigin(); 66 point + manager->GetViewBounds().OffsetFromOrigin();
58 67
59 // Each call to CachingAsyncHitTest results in at least one HOVER 68 // Each call to CachingAsyncHitTest results in at least one HOVER
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 hovered_node = HitTestAndWaitForResult(gfx::Point(50, 455)); 152 hovered_node = HitTestAndWaitForResult(gfx::Point(50, 455));
144 ASSERT_TRUE(hovered_node != NULL); 153 ASSERT_TRUE(hovered_node != NULL);
145 ASSERT_EQ(ui::AX_ROLE_BUTTON, hovered_node->GetRole()); 154 ASSERT_EQ(ui::AX_ROLE_BUTTON, hovered_node->GetRole());
146 ASSERT_EQ("Scrolled Button", 155 ASSERT_EQ("Scrolled Button",
147 hovered_node->GetStringAttribute(ui::AX_ATTR_NAME)); 156 hovered_node->GetStringAttribute(ui::AX_ATTR_NAME));
148 157
149 // (50, 505) -> div in second iframe 158 // (50, 505) -> div in second iframe
150 hovered_node = HitTestAndWaitForResult(gfx::Point(50, 505)); 159 hovered_node = HitTestAndWaitForResult(gfx::Point(50, 505));
151 ASSERT_TRUE(hovered_node != NULL); 160 ASSERT_TRUE(hovered_node != NULL);
152 ASSERT_EQ(ui::AX_ROLE_DIV, hovered_node->GetRole()); 161 ASSERT_EQ(ui::AX_ROLE_DIV, hovered_node->GetRole());
162
163 // (50, 505) -> div in second iframe
164 // but with a different event
165 hovered_node =
166 HitTestAndWaitForResultWithEvent(gfx::Point(50, 505), ui::AX_EVENT_ALERT);
167 ASSERT_TRUE(hovered_node != NULL);
David Tseng 2017/03/13 21:43:47 nit: ASSERT_NE
dmazzoni 2017/03/20 05:40:39 Done.
168 ASSERT_EQ(ui::AX_ROLE_DIV, hovered_node->GetRole());
153 } 169 }
154 170
155 IN_PROC_BROWSER_TEST_F(AccessibilityHitTestingBrowserTest, 171 IN_PROC_BROWSER_TEST_F(AccessibilityHitTestingBrowserTest,
156 CachingAsyncHitTestingInIframes) { 172 CachingAsyncHitTestingInIframes) {
157 host_resolver()->AddRule("*", "127.0.0.1"); 173 host_resolver()->AddRule("*", "127.0.0.1");
158 ASSERT_TRUE(embedded_test_server()->Start()); 174 ASSERT_TRUE(embedded_test_server()->Start());
159 175
160 NavigateToURL(shell(), GURL(url::kAboutBlankURL)); 176 NavigateToURL(shell(), GURL(url::kAboutBlankURL));
161 177
162 AccessibilityNotificationWaiter waiter(shell()->web_contents(), 178 AccessibilityNotificationWaiter waiter(shell()->web_contents(),
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 230
215 // (50, 505) -> div in second iframe 231 // (50, 505) -> div in second iframe
216 hovered_node = CallCachingAsyncHitTest(gfx::Point(50, 505)); 232 hovered_node = CallCachingAsyncHitTest(gfx::Point(50, 505));
217 ASSERT_TRUE(hovered_node != NULL); 233 ASSERT_TRUE(hovered_node != NULL);
218 ASSERT_NE(ui::AX_ROLE_DIV, hovered_node->GetRole()); 234 ASSERT_NE(ui::AX_ROLE_DIV, hovered_node->GetRole());
219 hovered_node = CallCachingAsyncHitTest(gfx::Point(50, 505)); 235 hovered_node = CallCachingAsyncHitTest(gfx::Point(50, 505));
220 ASSERT_EQ(ui::AX_ROLE_DIV, hovered_node->GetRole()); 236 ASSERT_EQ(ui::AX_ROLE_DIV, hovered_node->GetRole());
221 } 237 }
222 238
223 } // namespace content 239 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698