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

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

Issue 2694413006: Scope and clean up uses of AccessibilityMode. (Closed)
Patch Set: merge Created 3 years, 9 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 (c) 2014 The Chromium Authors. All rights reserved. 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 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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "build/build_config.h" 8 #include "build/build_config.h"
9 #include "content/browser/frame_host/render_frame_host_impl.h" 9 #include "content/browser/frame_host/render_frame_host_impl.h"
10 #include "content/browser/web_contents/web_contents_impl.h" 10 #include "content/browser/web_contents/web_contents_impl.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 NavigateToURL(shell(), url); 53 NavigateToURL(shell(), url);
54 54
55 // Simulate a condition where the RFH can't create a 55 // Simulate a condition where the RFH can't create a
56 // BrowserAccessibilityManager - like if there's no view. 56 // BrowserAccessibilityManager - like if there's no view.
57 RenderFrameHostImpl* frame = static_cast<RenderFrameHostImpl*>( 57 RenderFrameHostImpl* frame = static_cast<RenderFrameHostImpl*>(
58 shell()->web_contents()->GetMainFrame()); 58 shell()->web_contents()->GetMainFrame());
59 frame->set_no_create_browser_accessibility_manager_for_testing(true); 59 frame->set_no_create_browser_accessibility_manager_for_testing(true);
60 ASSERT_EQ(nullptr, frame->GetOrCreateBrowserAccessibilityManager()); 60 ASSERT_EQ(nullptr, frame->GetOrCreateBrowserAccessibilityManager());
61 61
62 { 62 {
63 // Enable accessibility (passing ACCESSIBILITY_MODE_COMPLETE to 63 // Enable accessibility (passing kAccessibilityModeComplete to
64 // AccessibilityNotificationWaiter does this automatically) and wait for 64 // AccessibilityNotificationWaiter does this automatically) and wait for
65 // the first event. 65 // the first event.
66 AccessibilityNotificationWaiter waiter( 66 AccessibilityNotificationWaiter waiter(shell()->web_contents(),
67 shell()->web_contents(), 67 kAccessibilityModeComplete,
68 ACCESSIBILITY_MODE_COMPLETE, 68 ui::AX_EVENT_LAYOUT_COMPLETE);
69 ui::AX_EVENT_LAYOUT_COMPLETE);
70 waiter.WaitForNotification(); 69 waiter.WaitForNotification();
71 } 70 }
72 71
73 // Make sure we still didn't create a BrowserAccessibilityManager. 72 // Make sure we still didn't create a BrowserAccessibilityManager.
74 // This means that at least one accessibility IPC was lost. 73 // This means that at least one accessibility IPC was lost.
75 ASSERT_EQ(nullptr, frame->GetOrCreateBrowserAccessibilityManager()); 74 ASSERT_EQ(nullptr, frame->GetOrCreateBrowserAccessibilityManager());
76 75
77 // Now create a BrowserAccessibilityManager, simulating what would happen 76 // Now create a BrowserAccessibilityManager, simulating what would happen
78 // if the RFH's view is created now - but then disallow recreating the 77 // if the RFH's view is created now - but then disallow recreating the
79 // BrowserAccessibilityManager so that we can test that this one gets 78 // BrowserAccessibilityManager so that we can test that this one gets
80 // destroyed. 79 // destroyed.
81 frame->set_no_create_browser_accessibility_manager_for_testing(false); 80 frame->set_no_create_browser_accessibility_manager_for_testing(false);
82 ASSERT_TRUE(frame->GetOrCreateBrowserAccessibilityManager() != nullptr); 81 ASSERT_TRUE(frame->GetOrCreateBrowserAccessibilityManager() != nullptr);
83 frame->set_no_create_browser_accessibility_manager_for_testing(true); 82 frame->set_no_create_browser_accessibility_manager_for_testing(true);
84 83
85 { 84 {
86 // Hide one of the elements on the page, and wait for an accessibility 85 // Hide one of the elements on the page, and wait for an accessibility
87 // notification triggered by the hide. 86 // notification triggered by the hide.
88 AccessibilityNotificationWaiter waiter( 87 AccessibilityNotificationWaiter waiter(shell()->web_contents(),
89 shell()->web_contents(), 88 kAccessibilityModeComplete,
90 ACCESSIBILITY_MODE_COMPLETE, 89 ui::AX_EVENT_LIVE_REGION_CHANGED);
91 ui::AX_EVENT_LIVE_REGION_CHANGED);
92 ASSERT_TRUE(ExecuteScript( 90 ASSERT_TRUE(ExecuteScript(
93 shell(), "document.getElementById('p1').style.display = 'none';")); 91 shell(), "document.getElementById('p1').style.display = 'none';"));
94 waiter.WaitForNotification(); 92 waiter.WaitForNotification();
95 } 93 }
96 94
97 // Show that accessibility was reset because the frame doesn't have a 95 // Show that accessibility was reset because the frame doesn't have a
98 // BrowserAccessibilityManager anymore. 96 // BrowserAccessibilityManager anymore.
99 ASSERT_EQ(nullptr, frame->browser_accessibility_manager()); 97 ASSERT_EQ(nullptr, frame->browser_accessibility_manager());
100 98
101 // Finally, allow creating a new accessibility manager and 99 // Finally, allow creating a new accessibility manager and
102 // ensure that we didn't kill the renderer; we can still send it messages. 100 // ensure that we didn't kill the renderer; we can still send it messages.
103 frame->set_no_create_browser_accessibility_manager_for_testing(false); 101 frame->set_no_create_browser_accessibility_manager_for_testing(false);
104 const ui::AXTree* tree = nullptr; 102 const ui::AXTree* tree = nullptr;
105 { 103 {
106 AccessibilityNotificationWaiter waiter( 104 AccessibilityNotificationWaiter waiter(shell()->web_contents(),
107 shell()->web_contents(), ACCESSIBILITY_MODE_COMPLETE, 105 kAccessibilityModeComplete,
108 ui::AX_EVENT_FOCUS); 106 ui::AX_EVENT_FOCUS);
109 ASSERT_TRUE( 107 ASSERT_TRUE(
110 ExecuteScript(shell(), "document.getElementById('button').focus();")); 108 ExecuteScript(shell(), "document.getElementById('button').focus();"));
111 waiter.WaitForNotification(); 109 waiter.WaitForNotification();
112 tree = &waiter.GetAXTree(); 110 tree = &waiter.GetAXTree();
113 } 111 }
114 112
115 // Get the accessibility tree, ensure it reflects the final state of the 113 // Get the accessibility tree, ensure it reflects the final state of the
116 // document. 114 // document.
117 const ui::AXNode* root = tree->root(); 115 const ui::AXNode* root = tree->root();
118 116
(...skipping 25 matching lines...) Expand all
144 // Create a data url and load it. 142 // Create a data url and load it.
145 const char url_str[] = 143 const char url_str[] =
146 "data:text/html," 144 "data:text/html,"
147 "<button id='button'>Button</button>"; 145 "<button id='button'>Button</button>";
148 GURL url(url_str); 146 GURL url(url_str);
149 NavigateToURL(shell(), url); 147 NavigateToURL(shell(), url);
150 RenderFrameHostImpl* frame = static_cast<RenderFrameHostImpl*>( 148 RenderFrameHostImpl* frame = static_cast<RenderFrameHostImpl*>(
151 shell()->web_contents()->GetMainFrame()); 149 shell()->web_contents()->GetMainFrame());
152 150
153 { 151 {
154 // Enable accessibility (passing ACCESSIBILITY_MODE_COMPLETE to 152 // Enable accessibility (passing kAccessibilityModeComplete to
155 // AccessibilityNotificationWaiter does this automatically) and wait for 153 // AccessibilityNotificationWaiter does this automatically) and wait for
156 // the first event. 154 // the first event.
157 AccessibilityNotificationWaiter waiter( 155 AccessibilityNotificationWaiter waiter(shell()->web_contents(),
158 shell()->web_contents(), 156 kAccessibilityModeComplete,
159 ACCESSIBILITY_MODE_COMPLETE, 157 ui::AX_EVENT_LAYOUT_COMPLETE);
160 ui::AX_EVENT_LAYOUT_COMPLETE);
161 waiter.WaitForNotification(); 158 waiter.WaitForNotification();
162 } 159 }
163 160
164 // Construct a bad accessibility message that BrowserAccessibilityManager 161 // Construct a bad accessibility message that BrowserAccessibilityManager
165 // will reject. 162 // will reject.
166 std::vector<AXEventNotificationDetails> bad_accessibility_event_list; 163 std::vector<AXEventNotificationDetails> bad_accessibility_event_list;
167 bad_accessibility_event_list.push_back(AXEventNotificationDetails()); 164 bad_accessibility_event_list.push_back(AXEventNotificationDetails());
168 bad_accessibility_event_list[0].update.node_id_to_clear = -2; 165 bad_accessibility_event_list[0].update.node_id_to_clear = -2;
169 166
170 // We should be able to reset accessibility |max_iterations-1| times 167 // We should be able to reset accessibility |max_iterations-1| times
171 // (see render_frame_host_impl.cc - kMaxAccessibilityResets), 168 // (see render_frame_host_impl.cc - kMaxAccessibilityResets),
172 // but the subsequent time the renderer should be killed. 169 // but the subsequent time the renderer should be killed.
173 int max_iterations = RenderFrameHostImpl::kMaxAccessibilityResets; 170 int max_iterations = RenderFrameHostImpl::kMaxAccessibilityResets;
174 171
175 for (int iteration = 0; iteration < max_iterations; iteration++) { 172 for (int iteration = 0; iteration < max_iterations; iteration++) {
176 // Send the browser accessibility the bad message. 173 // Send the browser accessibility the bad message.
177 BrowserAccessibilityManager* manager = 174 BrowserAccessibilityManager* manager =
178 frame->GetOrCreateBrowserAccessibilityManager(); 175 frame->GetOrCreateBrowserAccessibilityManager();
179 manager->OnAccessibilityEvents(bad_accessibility_event_list); 176 manager->OnAccessibilityEvents(bad_accessibility_event_list);
180 177
181 // Now the frame should have deleted the BrowserAccessibilityManager. 178 // Now the frame should have deleted the BrowserAccessibilityManager.
182 ASSERT_EQ(nullptr, frame->browser_accessibility_manager()); 179 ASSERT_EQ(nullptr, frame->browser_accessibility_manager());
183 180
184 if (iteration == max_iterations - 1) 181 if (iteration == max_iterations - 1)
185 break; 182 break;
186 183
187 AccessibilityNotificationWaiter waiter( 184 AccessibilityNotificationWaiter waiter(shell()->web_contents(),
188 shell()->web_contents(), 185 kAccessibilityModeComplete,
189 ACCESSIBILITY_MODE_COMPLETE, 186 ui::AX_EVENT_LOAD_COMPLETE);
190 ui::AX_EVENT_LOAD_COMPLETE);
191 waiter.WaitForNotification(); 187 waiter.WaitForNotification();
192 } 188 }
193 189
194 // Wait for the renderer to be killed. 190 // Wait for the renderer to be killed.
195 if (frame->IsRenderFrameLive()) { 191 if (frame->IsRenderFrameLive()) {
196 RenderProcessHostWatcher render_process_watcher( 192 RenderProcessHostWatcher render_process_watcher(
197 frame->GetProcess(), RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT); 193 frame->GetProcess(), RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT);
198 render_process_watcher.Wait(); 194 render_process_watcher.Wait();
199 } 195 }
200 ASSERT_FALSE(frame->IsRenderFrameLive()); 196 ASSERT_FALSE(frame->IsRenderFrameLive());
201 } 197 }
202 198
203 } // namespace content 199 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698