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

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

Issue 1836113002: Fix accessible touch exploration inside of iframes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Make test server url relative Created 4 years, 8 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> 5 #include <set>
6 #include <string> 6 #include <string>
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
(...skipping 11 matching lines...) Expand all
22 #include "content/public/common/content_switches.h" 22 #include "content/public/common/content_switches.h"
23 #include "content/public/common/url_constants.h" 23 #include "content/public/common/url_constants.h"
24 #include "content/public/test/content_browser_test.h" 24 #include "content/public/test/content_browser_test.h"
25 #include "content/public/test/content_browser_test_utils.h" 25 #include "content/public/test/content_browser_test_utils.h"
26 #include "content/shell/browser/shell.h" 26 #include "content/shell/browser/shell.h"
27 #include "content/test/accessibility_browser_test_utils.h" 27 #include "content/test/accessibility_browser_test_utils.h"
28 #include "testing/gtest/include/gtest/gtest.h" 28 #include "testing/gtest/include/gtest/gtest.h"
29 29
30 namespace content { 30 namespace content {
31 31
32 namespace {
33
34 bool AXTreeContainsNodeWithName(BrowserAccessibility* node,
nasko 2016/03/30 21:01:41 style: First param on a new line.
dmazzoni 2016/03/31 16:15:54 Done.
35 const std::string& name) {
36 if (node->GetStringAttribute(ui::AX_ATTR_NAME) == name)
37 return true;
38
39 for (unsigned i = 0; i < node->PlatformChildCount(); i++) {
40 if (AXTreeContainsNodeWithName(node->PlatformGetChild(i), name))
41 return true;
42 }
43
44 return false;
45 }
46
47 } // namespace
48
32 class AndroidHitTestingBrowserTest : public ContentBrowserTest { 49 class AndroidHitTestingBrowserTest : public ContentBrowserTest {
33 public: 50 public:
34 AndroidHitTestingBrowserTest() {} 51 AndroidHitTestingBrowserTest() {}
35 ~AndroidHitTestingBrowserTest() override {} 52 ~AndroidHitTestingBrowserTest() override {}
53
54 protected:
55 BrowserAccessibility* HitTestAndWaitForResult(const gfx::Point& point) {
56 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>(
57 shell()->web_contents());
58 FrameTree* frame_tree = web_contents->GetFrameTree();
59 BrowserAccessibilityManager* manager =
60 web_contents->GetRootBrowserAccessibilityManager();
61
62 AccessibilityNotificationWaiter hover_waiter(
63 shell(), AccessibilityModeComplete,
64 ui::AX_EVENT_HOVER);
65 for (FrameTreeNode* node : frame_tree->Nodes())
66 hover_waiter.ListenToAdditionalFrame(node->current_frame_host());
67 manager->delegate()->AccessibilityHitTest(point);
68 hover_waiter.WaitForNotification();
69
70 RenderFrameHostImpl* target_frame = hover_waiter.event_render_frame_host();
71 BrowserAccessibilityManager* target_manager =
72 target_frame->browser_accessibility_manager();
73 int hover_target_id = hover_waiter.event_target_id();
74 BrowserAccessibility* hovered_node = target_manager->GetFromID(
75 hover_target_id);
76 return hovered_node;
77 }
36 }; 78 };
37 79
38 IN_PROC_BROWSER_TEST_F(AndroidHitTestingBrowserTest, 80 IN_PROC_BROWSER_TEST_F(AndroidHitTestingBrowserTest,
39 HitTestOutsideDocumentBoundsReturnsRoot) { 81 HitTestOutsideDocumentBoundsReturnsRoot) {
40 NavigateToURL(shell(), GURL(url::kAboutBlankURL)); 82 NavigateToURL(shell(), GURL(url::kAboutBlankURL));
41 83
42 // Load the page. 84 // Load the page.
43 AccessibilityNotificationWaiter waiter( 85 AccessibilityNotificationWaiter waiter(
44 shell(), AccessibilityModeComplete, 86 shell(), AccessibilityModeComplete,
45 ui::AX_EVENT_LOAD_COMPLETE); 87 ui::AX_EVENT_LOAD_COMPLETE);
46 const char url_str[] = 88 const char url_str[] =
47 "data:text/html," 89 "data:text/html,"
48 "<!doctype html>" 90 "<!doctype html>"
49 "<html><head><title>Accessibility Test</title></head>" 91 "<html><head><title>Accessibility Test</title></head>"
50 "<body>" 92 "<body>"
51 "<a href='#'>" 93 "<a href='#'>"
52 "This is some text in a link" 94 "This is some text in a link"
53 "</a>" 95 "</a>"
54 "</body></html>"; 96 "</body></html>";
55 GURL url(url_str); 97 GURL url(url_str);
56 NavigateToURL(shell(), url); 98 NavigateToURL(shell(), url);
57 waiter.WaitForNotification(); 99 waiter.WaitForNotification();
58 100
59 // Get the BrowserAccessibilityManager. 101 BrowserAccessibility* hovered_node = HitTestAndWaitForResult(
60 WebContentsImpl* web_contents = 102 gfx::Point(-1, -1));
61 static_cast<WebContentsImpl*>(shell()->web_contents());
62 BrowserAccessibilityManager* manager =
63 web_contents->GetRootBrowserAccessibilityManager();
64
65 // Send a hit test request, and wait for the hover event in response.
66 AccessibilityNotificationWaiter hover_waiter(
67 shell(), AccessibilityModeComplete,
68 ui::AX_EVENT_HOVER);
69 manager->delegate()->AccessibilityHitTest(gfx::Point(-1, -1));
70 hover_waiter.WaitForNotification();
71
72 // Assert that the hover event was fired on the root of the tree.
73 int hover_target_id = hover_waiter.event_target_id();
74 BrowserAccessibility* hovered_node = manager->GetFromID(hover_target_id);
75 ASSERT_TRUE(hovered_node != NULL); 103 ASSERT_TRUE(hovered_node != NULL);
76 ASSERT_EQ(ui::AX_ROLE_ROOT_WEB_AREA, hovered_node->GetRole()); 104 ASSERT_EQ(ui::AX_ROLE_ROOT_WEB_AREA, hovered_node->GetRole());
77 } 105 }
78 106
107 IN_PROC_BROWSER_TEST_F(AndroidHitTestingBrowserTest,
108 HitTestingInIframes) {
109 ASSERT_TRUE(embedded_test_server()->Start());
110
111 AccessibilityNotificationWaiter waiter(
112 shell(), AccessibilityModeComplete,
113 ui::AX_EVENT_LOAD_COMPLETE);
114 GURL url(embedded_test_server()->GetURL(
115 "/accessibility/html/iframe-coordinates.html"));
116 NavigateToURL(shell(), url);
117 waiter.WaitForNotification();
118
119 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>(
120 shell()->web_contents());
121 FrameTree* frame_tree = web_contents->GetFrameTree();
122 BrowserAccessibilityManager* manager =
123 web_contents->GetRootBrowserAccessibilityManager();
124 BrowserAccessibility* root = manager->GetRoot();
125 while (!AXTreeContainsNodeWithName(root, "Ordinary Button") ||
126 !AXTreeContainsNodeWithName(root, "Scrolled Button")) {
127 AccessibilityNotificationWaiter waiter(
128 shell(), AccessibilityModeComplete,
129 ui::AX_EVENT_NONE);
130 for (FrameTreeNode* node : frame_tree->Nodes())
131 waiter.ListenToAdditionalFrame(node->current_frame_host());
132 waiter.WaitForNotification();
133 }
134
135 // Send a series of hit test requests, and for each one
136 // wait for the hover event in response, verifying we hit the
137 // correct object.
138
139 // (50, 50) -> "Button"
140 BrowserAccessibility* hovered_node;
141 hovered_node = HitTestAndWaitForResult(gfx::Point(50, 50));
142 ASSERT_TRUE(hovered_node != NULL);
143 ASSERT_EQ(ui::AX_ROLE_BUTTON, hovered_node->GetRole());
144 ASSERT_EQ("Button", hovered_node->GetStringAttribute(ui::AX_ATTR_NAME));
145
146 // (50, 305) -> div in first iframe
147 hovered_node = HitTestAndWaitForResult(gfx::Point(50, 305));
148 ASSERT_TRUE(hovered_node != NULL);
149 ASSERT_EQ(ui::AX_ROLE_DIV, hovered_node->GetRole());
150
151 // (50, 350) -> "Ordinary Button"
152 hovered_node = HitTestAndWaitForResult(gfx::Point(50, 350));
153 ASSERT_TRUE(hovered_node != NULL);
154 ASSERT_EQ(ui::AX_ROLE_BUTTON, hovered_node->GetRole());
155 ASSERT_EQ("Ordinary Button",
156 hovered_node->GetStringAttribute(ui::AX_ATTR_NAME));
157
158 // (50, 455) -> "Scrolled Button"
159 hovered_node = HitTestAndWaitForResult(gfx::Point(50, 455));
160 ASSERT_TRUE(hovered_node != NULL);
161 ASSERT_EQ(ui::AX_ROLE_BUTTON, hovered_node->GetRole());
162 ASSERT_EQ("Scrolled Button",
163 hovered_node->GetStringAttribute(ui::AX_ATTR_NAME));
164
165 // (50, 505) -> div in second iframe
166 hovered_node = HitTestAndWaitForResult(gfx::Point(50, 505));
167 ASSERT_TRUE(hovered_node != NULL);
168 ASSERT_EQ(ui::AX_ROLE_DIV, hovered_node->GetRole());
169 }
170
79 } // namespace content 171 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698