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

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

Issue 2447013009: Implement Increment and Decrement accessible actions (Closed)
Patch Set: Change to make test pass on Android Created 4 years, 1 month 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
(Empty)
1 // Copyright 2016 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/logging.h"
6 #include "content/browser/accessibility/browser_accessibility.h"
7 #include "content/browser/accessibility/browser_accessibility_manager.h"
8 #include "content/browser/web_contents/web_contents_impl.h"
9 #include "content/public/test/browser_test_utils.h"
10 #include "content/public/test/content_browser_test.h"
11 #include "content/public/test/content_browser_test_utils.h"
12 #include "content/public/test/test_utils.h"
13 #include "content/shell/browser/shell.h"
14 #include "content/test/accessibility_browser_test_utils.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16
17 namespace content {
18
19 namespace {
20
21 class AccessibilityActionBrowserTest : public ContentBrowserTest {
22 public:
23 AccessibilityActionBrowserTest() {}
24 ~AccessibilityActionBrowserTest() override {}
25
26 protected:
27 BrowserAccessibility* FindNode(ui::AXRole role,
28 const std::string& name) {
29 BrowserAccessibility* root = GetManager()->GetRoot();
30 CHECK(root);
31 return FindNodeInSubtree(*root, role, name);
32 }
33
34 BrowserAccessibilityManager* GetManager() {
35 WebContentsImpl* web_contents =
36 static_cast<WebContentsImpl*>(shell()->web_contents());
37 return web_contents->GetRootBrowserAccessibilityManager();
38 }
39
40 private:
41 BrowserAccessibility* FindNodeInSubtree(
42 BrowserAccessibility& node,
43 ui::AXRole role,
44 const std::string& name) {
45 if (node.GetRole() == role &&
46 node.GetStringAttribute(ui::AX_ATTR_NAME) == name)
47 return &node;
48 for (unsigned int i = 0; i < node.PlatformChildCount(); ++i) {
49 BrowserAccessibility* result = FindNodeInSubtree(
50 *node.PlatformGetChild(i), role, name);
51 if (result)
52 return result;
53 }
54 return nullptr;
55 }
56 };
57
58 } // namespace
59
60 IN_PROC_BROWSER_TEST_F(AccessibilityActionBrowserTest, FocusAction) {
61 NavigateToURL(shell(), GURL(url::kAboutBlankURL));
62
63 AccessibilityNotificationWaiter waiter(shell()->web_contents(),
64 AccessibilityModeComplete,
65 ui::AX_EVENT_LOAD_COMPLETE);
66 GURL url("data:text/html,"
67 "<button>One</button>"
68 "<button>Two</button>"
69 "<button>Three</button>");
70 NavigateToURL(shell(), url);
71 waiter.WaitForNotification();
72
73 BrowserAccessibility* target = FindNode(ui::AX_ROLE_BUTTON, "One");
74 ASSERT_NE(nullptr, target);
75
76 AccessibilityNotificationWaiter waiter2(shell()->web_contents(),
77 AccessibilityModeComplete,
78 ui::AX_EVENT_FOCUS);
79 GetManager()->SetFocus(*target);
80 waiter2.WaitForNotification();
81
82 BrowserAccessibility* focus = GetManager()->GetFocus();
83 EXPECT_EQ(focus->GetId(), target->GetId());
84 }
85
86 IN_PROC_BROWSER_TEST_F(AccessibilityActionBrowserTest,
87 IncrementDecrementActions) {
88 NavigateToURL(shell(), GURL(url::kAboutBlankURL));
89
90 AccessibilityNotificationWaiter waiter(shell()->web_contents(),
91 AccessibilityModeComplete,
92 ui::AX_EVENT_LOAD_COMPLETE);
93 GURL url("data:text/html,"
94 "<input type=range min=2 value=8 max=10 step=2>");
95 NavigateToURL(shell(), url);
96 waiter.WaitForNotification();
97
98 BrowserAccessibility* target = FindNode(ui::AX_ROLE_SLIDER, "");
99 ASSERT_NE(nullptr, target);
100 EXPECT_EQ(8.0, target->GetFloatAttribute(ui::AX_ATTR_VALUE_FOR_RANGE));
101
102 // Increment, should result in value changing from 8 to 10.
103 {
104 AccessibilityNotificationWaiter waiter2(shell()->web_contents(),
105 AccessibilityModeComplete,
106 ui::AX_EVENT_VALUE_CHANGED);
107 GetManager()->Increment(*target);
108 waiter2.WaitForNotification();
109 }
110 EXPECT_EQ(10.0, target->GetFloatAttribute(ui::AX_ATTR_VALUE_FOR_RANGE));
111
112 // Increment, should result in value staying the same (max).
113 {
114 AccessibilityNotificationWaiter waiter2(shell()->web_contents(),
115 AccessibilityModeComplete,
116 ui::AX_EVENT_VALUE_CHANGED);
117 GetManager()->Increment(*target);
118 waiter2.WaitForNotification();
119 }
120 EXPECT_EQ(10.0, target->GetFloatAttribute(ui::AX_ATTR_VALUE_FOR_RANGE));
121
122 // Decrement, should result in value changing from 10 to 8.
123 {
124 AccessibilityNotificationWaiter waiter2(shell()->web_contents(),
125 AccessibilityModeComplete,
126 ui::AX_EVENT_VALUE_CHANGED);
127 GetManager()->Decrement(*target);
128 waiter2.WaitForNotification();
129 }
130 EXPECT_EQ(8.0, target->GetFloatAttribute(ui::AX_ATTR_VALUE_FOR_RANGE));
131 }
132
133 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698