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

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

Issue 625443002: Reset accessibility if it gets out of sync. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Replace random accessibility token with sequential Created 6 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
(Empty)
1 // Copyright (c) 2014 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 "content/browser/frame_host/render_frame_host_impl.h"
6 #include "content/browser/web_contents/web_contents_impl.h"
7 #include "content/common/accessibility_messages.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.h"
14 #include "ui/accessibility/ax_tree.h"
15
16 namespace content {
17
18 class AccessibilityIpcErrorBrowserTest : public ContentBrowserTest {
19 public:
20 AccessibilityIpcErrorBrowserTest() {}
21
22 protected:
23 // Convenience method to get the value of a particular AXNode
24 // attribute as a UTF-8 string.
25 std::string GetAttr(const ui::AXNode* node,
26 const ui::AXStringAttribute attr) {
27 const ui::AXNodeData& data = node->data();
28 for (size_t i = 0; i < data.string_attributes.size(); ++i) {
29 if (data.string_attributes[i].first == attr)
30 return data.string_attributes[i].second;
31 }
32 return std::string();
33 }
34
35 DISALLOW_COPY_AND_ASSIGN(AccessibilityIpcErrorBrowserTest);
36 };
37
38 IN_PROC_BROWSER_TEST_F(AccessibilityIpcErrorBrowserTest,
39 ResetBrowserAccessibilityManager) {
40 // Create a data url and load it.
41 const char url_str[] =
42 "data:text/html,"
43 "<div aria-live='polite'>"
44 " <p id='p1'>Paragraph One</p>"
45 " <p id='p2'>Paragraph Two</p>"
46 "</div>"
47 "<button id='button'>Button</button>";
48 GURL url(url_str);
49 NavigateToURL(shell(), url);
50
51 // Simulate a condition where the RFH can't create a
52 // BrowserAccessibilityManager - like if there's no view.
53 RenderFrameHostImpl* frame = static_cast<RenderFrameHostImpl*>(
54 shell()->web_contents()->GetMainFrame());
55 frame->set_disallow_browser_accessibility_manager_for_testing(true);
56 ASSERT_EQ(NULL, frame->GetOrCreateBrowserAccessibilityManager());
57
58 {
59 // Enable accessibility (passing AccessibilityModeComplete to
60 // AccessibilityNotificationWaiter does this automatically) and wait for
61 // the first event.
62 AccessibilityNotificationWaiter waiter(
63 shell(), AccessibilityModeComplete, ui::AX_EVENT_LAYOUT_COMPLETE);
64 waiter.WaitForNotification();
65 }
66
67 // Make sure we still didn't create a BrowserAccessibilityManager.
68 // This means that at least one accessibility IPC was lost.
69 ASSERT_EQ(NULL, frame->GetOrCreateBrowserAccessibilityManager());
70
71 // Now allow a BrowserAccessibilityManager, simulating what would happen
72 // if the RFH's view is created now.
73 frame->set_disallow_browser_accessibility_manager_for_testing(false);
74 BrowserAccessibilityManager* manager =
75 frame->GetOrCreateBrowserAccessibilityManager();
76 ASSERT_TRUE(manager != NULL);
77
78 {
79 // Hide one of the elements on the page, and wait for an accessibility
80 // notification triggered by the hide.
81 AccessibilityNotificationWaiter waiter(
82 shell(), AccessibilityModeComplete, ui::AX_EVENT_LIVE_REGION_CHANGED);
83 ASSERT_TRUE(ExecuteScript(
84 shell()->web_contents(),
85 "document.getElementById('p1').style.display = 'none';"));
86 waiter.WaitForNotification();
87 }
88
89 // Show that accessibility was reset because we have a new
90 // BrowserAccessibilityManager object.
91 ASSERT_TRUE(manager != frame->GetOrCreateBrowserAccessibilityManager());
92 const ui::AXTree* tree = NULL;
93 {
94 // Ensure that we didn't kill the renderer; we can still send it messages.
95 AccessibilityNotificationWaiter waiter(
96 shell(), AccessibilityModeComplete, ui::AX_EVENT_FOCUS);
97 ASSERT_TRUE(ExecuteScript(
98 shell()->web_contents(),
99 "document.getElementById('button').focus();"));
100 waiter.WaitForNotification();
101 tree = &waiter.GetAXTree();
102 }
103
104 // Get the accessibility tree, ensure it reflects the final state of the
105 // document.
106 const ui::AXNode* root = tree->GetRoot();
107
108 // Use this for debugging if the test fails.
109 VLOG(1) << tree->ToString();
110
111 EXPECT_EQ(ui::AX_ROLE_ROOT_WEB_AREA, root->data().role);
112 ASSERT_EQ(2, root->child_count());
113
114 const ui::AXNode* live_region = root->ChildAtIndex(0);
115 ASSERT_EQ(1, live_region->child_count());
116 EXPECT_EQ(ui::AX_ROLE_DIV, live_region->data().role);
117
118 const ui::AXNode* para = live_region->ChildAtIndex(0);
119 EXPECT_EQ(ui::AX_ROLE_PARAGRAPH, para->data().role);
120
121 const ui::AXNode* button_container = root->ChildAtIndex(1);
122 EXPECT_EQ(ui::AX_ROLE_GROUP, button_container->data().role);
123 ASSERT_EQ(1, button_container->child_count());
124
125 const ui::AXNode* button = button_container->ChildAtIndex(0);
126 EXPECT_EQ(ui::AX_ROLE_BUTTON, button->data().role);
127 EXPECT_TRUE(button->data().state >> ui::AX_STATE_FOCUSED & 1);
128 }
129
130 IN_PROC_BROWSER_TEST_F(AccessibilityIpcErrorBrowserTest,
131 MultipleBadAccessibilityIPCsKillsRenderer) {
132 // Create a data url and load it.
133 const char url_str[] =
134 "data:text/html,"
135 "<button id='button'>Button</button>";
136 GURL url(url_str);
137 NavigateToURL(shell(), url);
138 RenderFrameHostImpl* frame = static_cast<RenderFrameHostImpl*>(
139 shell()->web_contents()->GetMainFrame());
140
141 {
142 // Enable accessibility (passing AccessibilityModeComplete to
143 // AccessibilityNotificationWaiter does this automatically) and wait for
144 // the first event.
145 AccessibilityNotificationWaiter waiter(
146 shell(), AccessibilityModeComplete, ui::AX_EVENT_LAYOUT_COMPLETE);
147 waiter.WaitForNotification();
148 }
149
150 // Construct a bad accessibility message that BrowserAccessibilityManager
151 // will reject.
152 std::vector<AccessibilityHostMsg_EventParams> bad_accessibility_event_list;
153 bad_accessibility_event_list.push_back(AccessibilityHostMsg_EventParams());
154 bad_accessibility_event_list[0].update.node_id_to_clear = -2;
155
156 // We should be able to reset accessibility 4 times
157 // (see render_frame_host_impl.cc - kMaxAccessibilityResets),
158 // but the 5th time the renderer should be killed.
159
160 for (int iteration = 0; iteration < 5; iteration++) {
nasko 2014/10/03 15:58:41 Why not define the constant in a header and use it
dmazzoni 2014/10/03 19:08:11 Done.
161 // Send the browser accessibility the bad message.
162 BrowserAccessibilityManager* manager =
163 frame->GetOrCreateBrowserAccessibilityManager();
164 manager->OnAccessibilityEvents(bad_accessibility_event_list);
165
166 // Now the frame should have deleted the BrowserAccessibilityManager.
167 ASSERT_EQ(NULL, frame->browser_accessibility_manager());
168
169 if (iteration == 4)
170 break;
171
172 AccessibilityNotificationWaiter waiter(
173 shell(), AccessibilityModeComplete, ui::AX_EVENT_LAYOUT_COMPLETE);
174 waiter.WaitForNotification();
175 }
176
177 // The 5th time, the renderer will be killed, so attempting to execute
178 // a script in the page will fail, and after ExecuteScript returns (it's
179 // blocking), the frame host should know that its frame is dead.
180 ASSERT_FALSE(ExecuteScript(
nasko 2014/10/03 15:58:41 Is this extra step needed? There is RenderProcessH
dmazzoni 2014/10/03 19:08:12 Done.
181 shell()->web_contents(),
182 "document.getElementById('button').focus();"));
183 ASSERT_FALSE(frame->IsRenderFrameLive());
184 }
185
186 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698