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

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

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

Powered by Google App Engine
This is Rietveld 408576698