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

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

Issue 2393123002: Implement caching asynchronous accessibility hit testing. (Closed)
Patch Set: Created 4 years, 2 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 <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
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 BrowserAccessibilityManager* manager =
53 web_contents->GetRootBrowserAccessibilityManager();
54 gfx::Point screen_point =
55 point + manager->GetViewBounds().OffsetFromOrigin();
56 return manager->CachingAsyncHitTest(screen_point);
57 }
62 }; 58 };
63 59
64 IN_PROC_BROWSER_TEST_F(AccessibilityHitTestingBrowserTest, 60 IN_PROC_BROWSER_TEST_F(AccessibilityHitTestingBrowserTest,
65 HitTestOutsideDocumentBoundsReturnsRoot) { 61 HitTestOutsideDocumentBoundsReturnsRoot) {
66 NavigateToURL(shell(), GURL(url::kAboutBlankURL)); 62 NavigateToURL(shell(), GURL(url::kAboutBlankURL));
67 63
68 // Load the page. 64 // Load the page.
69 AccessibilityNotificationWaiter waiter(shell()->web_contents(), 65 AccessibilityNotificationWaiter waiter(shell()->web_contents(),
70 AccessibilityModeComplete, 66 AccessibilityModeComplete,
71 ui::AX_EVENT_LOAD_COMPLETE); 67 ui::AX_EVENT_LOAD_COMPLETE);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 ASSERT_EQ(ui::AX_ROLE_BUTTON, hovered_node->GetRole()); 133 ASSERT_EQ(ui::AX_ROLE_BUTTON, hovered_node->GetRole());
138 ASSERT_EQ("Scrolled Button", 134 ASSERT_EQ("Scrolled Button",
139 hovered_node->GetStringAttribute(ui::AX_ATTR_NAME)); 135 hovered_node->GetStringAttribute(ui::AX_ATTR_NAME));
140 136
141 // (50, 505) -> div in second iframe 137 // (50, 505) -> div in second iframe
142 hovered_node = HitTestAndWaitForResult(gfx::Point(50, 505)); 138 hovered_node = HitTestAndWaitForResult(gfx::Point(50, 505));
143 ASSERT_TRUE(hovered_node != NULL); 139 ASSERT_TRUE(hovered_node != NULL);
144 ASSERT_EQ(ui::AX_ROLE_DIV, hovered_node->GetRole()); 140 ASSERT_EQ(ui::AX_ROLE_DIV, hovered_node->GetRole());
145 } 141 }
146 142
143 IN_PROC_BROWSER_TEST_F(AccessibilityHitTestingBrowserTest,
144 CachingAsyncHitTestingInIframes) {
145 host_resolver()->AddRule("*", "127.0.0.1");
146 ASSERT_TRUE(embedded_test_server()->Start());
147
148 NavigateToURL(shell(), GURL(url::kAboutBlankURL));
149
150 AccessibilityNotificationWaiter waiter(shell()->web_contents(),
151 AccessibilityModeComplete,
152 ui::AX_EVENT_LOAD_COMPLETE);
153 GURL url(embedded_test_server()->GetURL(
154 "/accessibility/hit_testing/hit_testing.html"));
155 NavigateToURL(shell(), url);
156 waiter.WaitForNotification();
157
158 WaitForAccessibilityTreeToContainNodeWithName(
159 shell()->web_contents(), "Ordinary Button");
160 WaitForAccessibilityTreeToContainNodeWithName(
161 shell()->web_contents(), "Scrolled Button");
162
163 // For each point we try, the first time we call CachingAsyncHitTest it
164 // should FAIL and return the wrong object, because this test page has
165 // been designed to confound local synchronous hit testing using
166 // z-indexes. However, calling CachingAsyncHitTest repeatedly should
167 // soon return the correct result.
168
169 // (50, 50) -> "Button"
170 BrowserAccessibility* hovered_node;
171 hovered_node = CallCachingAsyncHitTest(gfx::Point(50, 50));
172 ASSERT_TRUE(hovered_node != NULL);
173 ASSERT_NE(ui::AX_ROLE_BUTTON, hovered_node->GetRole());
174 while (hovered_node->GetRole() != ui::AX_ROLE_BUTTON) {
175 RunAllPendingInMessageLoop();
176 hovered_node = CallCachingAsyncHitTest(gfx::Point(50, 50));
177 }
178 ASSERT_EQ("Button", hovered_node->GetStringAttribute(ui::AX_ATTR_NAME));
179
180 // (50, 305) -> div in first iframe
181 hovered_node = CallCachingAsyncHitTest(gfx::Point(50, 305));
182 ASSERT_TRUE(hovered_node != NULL);
183 ASSERT_NE(ui::AX_ROLE_DIV, hovered_node->GetRole());
184 while (hovered_node->GetRole() != ui::AX_ROLE_DIV) {
185 RunAllPendingInMessageLoop();
186 hovered_node = CallCachingAsyncHitTest(gfx::Point(50, 305));
187 }
188
189 // (50, 350) -> "Ordinary Button"
190 hovered_node = CallCachingAsyncHitTest(gfx::Point(50, 350));
191 ASSERT_TRUE(hovered_node != NULL);
192 ASSERT_NE(ui::AX_ROLE_BUTTON, hovered_node->GetRole());
193 while (hovered_node->GetRole() != ui::AX_ROLE_BUTTON) {
194 RunAllPendingInMessageLoop();
195 hovered_node = CallCachingAsyncHitTest(gfx::Point(50, 350));
196 }
197 ASSERT_EQ("Ordinary Button",
198 hovered_node->GetStringAttribute(ui::AX_ATTR_NAME));
199
200 // (50, 455) -> "Scrolled Button"
201 hovered_node = CallCachingAsyncHitTest(gfx::Point(50, 455));
202 ASSERT_TRUE(hovered_node != NULL);
203 ASSERT_NE(ui::AX_ROLE_BUTTON, hovered_node->GetRole());
204 while (hovered_node->GetRole() != ui::AX_ROLE_BUTTON) {
205 RunAllPendingInMessageLoop();
206 hovered_node = CallCachingAsyncHitTest(gfx::Point(50, 455));
207 }
208 ASSERT_EQ("Scrolled Button",
209 hovered_node->GetStringAttribute(ui::AX_ATTR_NAME));
210
211 // (50, 505) -> div in second iframe
212 hovered_node = CallCachingAsyncHitTest(gfx::Point(50, 505));
213 ASSERT_TRUE(hovered_node != NULL);
214 ASSERT_NE(ui::AX_ROLE_DIV, hovered_node->GetRole());
215 while (hovered_node->GetRole() != ui::AX_ROLE_DIV) {
216 RunAllPendingInMessageLoop();
217 hovered_node = CallCachingAsyncHitTest(gfx::Point(50, 505));
218 }
219 }
220
147 } // namespace content 221 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698