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

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

Issue 1375703002: Fire accessibility hover events when the touch exploration flag is set. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Offset by root window, not by screen Created 5 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
« no previous file with comments | « components/test_runner/web_test_proxy.cc ('k') | content/content_tests.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/strings/string_number_conversions.h"
6 #include "content/browser/accessibility/browser_accessibility.h"
7 #include "content/browser/web_contents/web_contents_impl.h"
8 #include "content/public/test/browser_test_utils.h"
9 #include "content/public/test/content_browser_test.h"
10 #include "content/public/test/content_browser_test_utils.h"
11 #include "content/shell/browser/shell.h"
12 #include "content/test/accessibility_browser_test_utils.h"
13 #include "ui/accessibility/ax_node_data.h"
14 #include "ui/aura/window.h"
15 #include "ui/aura/window_tree_host.h"
16 #include "ui/events/event.h"
17 #include "ui/events/event_processor.h"
18 #include "ui/events/event_utils.h"
19
20 namespace content {
21
22 class TouchAccessibilityBrowserTest : public ContentBrowserTest {
23 public:
24 TouchAccessibilityBrowserTest() {}
25
26 DISALLOW_COPY_AND_ASSIGN(TouchAccessibilityBrowserTest);
27 };
28
29 IN_PROC_BROWSER_TEST_F(TouchAccessibilityBrowserTest,
30 TouchExplorationSendsHoverEvents) {
31 // Create HTML with a 7 x 5 table, each exactly 50 x 50 pixels.
32 std::string html_url =
33 "data:text/html,"
34 "<style>"
35 " body { margin: 0; }"
36 " table { border-spacing: 0; border-collapse: collapse; }"
37 " td { width: 50px; height: 50px; padding: 0; }"
38 "</style>"
39 "<body>"
40 "<table>";
41 int cell = 0;
42 for (int row = 0; row < 5; ++row) {
43 html_url += "<tr>";
44 for (int col = 0; col < 7; ++col) {
45 html_url += "<td>" + base::IntToString(cell) + "</td>";
46 ++cell;
47 }
48 html_url += "</tr>";
49 }
50 html_url += "</table></body>";
51
52 // Navigate to the url and load the accessibility tree.
53 AccessibilityNotificationWaiter waiter(
54 shell(), AccessibilityModeComplete, ui::AX_EVENT_LOAD_COMPLETE);
55 GURL url(html_url);
56 NavigateToURL(shell(), url);
57 waiter.WaitForNotification();
58
59 // Get the BrowserAccessibilityManager.
60 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>(
61 shell()->web_contents());
62 BrowserAccessibilityManager* manager =
63 web_contents->GetRootBrowserAccessibilityManager();
64 CHECK(manager);
Peter Lundblad 2015/09/29 09:48:14 nit: use ASSERT* in tests.
dmazzoni 2015/09/29 17:11:28 Done.
65
66 // Loop over all of the cells in the table. For each one, send a simulated
67 // touch exploration event in the center of that cell, and assert that we
68 // get an accessibility hover event fired in the correct cell.
69 AccessibilityNotificationWaiter waiter2(
70 shell(), AccessibilityModeComplete, ui::AX_EVENT_HOVER);
71 aura::Window* window = web_contents->GetContentNativeView();
72 ui::EventProcessor* dispatcher = window->GetHost()->event_processor();
73 for (int row = 0; row < 5; ++row) {
74 for (int col = 0; col < 7; ++col) {
75 std::string expected_cell_text = base::IntToString(row * 7 + col);
76 VLOG(1) << "Sending event in row " << row << " col " << col
77 << " with text " << expected_cell_text;
78
79 // Send a touch exploration event to the center of the particular grid
80 // cell. A touch exploration event is just a mouse move event with
81 // the ui::EF_TOUCH_ACCESSIBILITY flag set.
82 gfx::Rect bounds = window->GetBoundsInRootWindow();
83 gfx::PointF location(bounds.x() + 50 * col + 25,
84 bounds.y() + 50 * row + 25);
85 int flags = ui::EF_TOUCH_ACCESSIBILITY;
86 scoped_ptr<ui::Event> mouse_move_event(new ui::MouseEvent(
87 ui::ET_MOUSE_MOVED, location, location, ui::EventTimeForNow(),
88 flags, 0));
89 ignore_result(dispatcher->OnEventFromSource(mouse_move_event.get()));
90
91 // Wait until we get a hover event in the expected grid cell.
92 // Tolerate additional events, keep looping until we get the expected one.
93 std::string cell_text;
94 do {
95 waiter2.WaitForNotification();
96 int target_id = waiter2.event_target_id();
97 BrowserAccessibility* hit = manager->GetFromID(target_id);
98 BrowserAccessibility* child = hit->PlatformGetChild(0);
99 CHECK(child);
Peter Lundblad 2015/09/29 09:48:14 nit: use ASSERT/EXPECT in tests?
dmazzoni 2015/09/29 17:11:28 Done.
100 cell_text = child->GetData().GetStringAttribute(ui::AX_ATTR_VALUE);
101 VLOG(1) << "Got hover event in cell with text: " << cell_text;
102 } while (cell_text != expected_cell_text);
103 }
104 }
105 }
106
107 } // namespace content
OLDNEW
« no previous file with comments | « components/test_runner/web_test_proxy.cc ('k') | content/content_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698