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