Chromium Code Reviews| OLD | NEW |
|---|---|
| (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/public/test/browser_test_utils.h" | |
| 8 #include "content/public/test/content_browser_test.h" | |
| 9 #include "content/public/test/content_browser_test_utils.h" | |
| 10 #include "content/shell/browser/shell.h" | |
| 11 #include "content/test/accessibility_browser_test_utils.h" | |
| 12 #include "ui/accessibility/ax_node.h" | |
| 13 #include "ui/accessibility/ax_tree.h" | |
| 14 | |
| 15 namespace content { | |
| 16 | |
| 17 class AccessibilityIpcErrorBrowserTest : public ContentBrowserTest { | |
| 18 public: | |
| 19 AccessibilityIpcErrorBrowserTest() {} | |
| 20 | |
| 21 protected: | |
| 22 // Convenience method to get the value of a particular AXNode | |
| 23 // attribute as a UTF-8 string. | |
| 24 std::string GetAttr(const ui::AXNode* node, | |
| 25 const ui::AXStringAttribute attr) { | |
| 26 const ui::AXNodeData& data = node->data(); | |
| 27 for (size_t i = 0; i < data.string_attributes.size(); ++i) { | |
| 28 if (data.string_attributes[i].first == attr) | |
| 29 return data.string_attributes[i].second; | |
| 30 } | |
| 31 return std::string(); | |
| 32 } | |
| 33 | |
| 34 DISALLOW_COPY_AND_ASSIGN(AccessibilityIpcErrorBrowserTest); | |
| 35 }; | |
| 36 | |
| 37 IN_PROC_BROWSER_TEST_F(AccessibilityIpcErrorBrowserTest, | |
| 38 ResetBrowserAccessibilityManager) { | |
| 39 // Create a data url and load it. | |
| 40 const char url_str[] = | |
| 41 "data:text/html," | |
| 42 "<div aria-live='polite'>" | |
| 43 " <p id='p1'>Paragraph One</p>" | |
| 44 " <p id='p2'>Paragraph Two</p>" | |
| 45 "</div>" | |
| 46 "<button id='button'>Button</button>"; | |
| 47 GURL url(url_str); | |
| 48 NavigateToURL(shell(), url); | |
| 49 | |
| 50 // Simulate a condition where the RFH can't create a | |
| 51 // BrowserAccessibilityManager - like if there's no view. | |
| 52 RenderFrameHostImpl* frame = static_cast<RenderFrameHostImpl*>( | |
| 53 shell()->web_contents()->GetMainFrame()); | |
| 54 frame->set_disallow_browser_accessibility_manager_for_testing(true); | |
| 55 ASSERT_EQ(NULL, frame->GetOrCreateBrowserAccessibilityManager()); | |
| 56 | |
| 57 // Enable accessibility (passing AccessibilityModeComplete to | |
| 58 // AccessibilityNotificationWaiter does this automatically) and wait for | |
| 59 // the first event. | |
| 60 AccessibilityNotificationWaiter waiter( | |
| 61 shell(), AccessibilityModeComplete, ui::AX_EVENT_LAYOUT_COMPLETE); | |
| 62 waiter.WaitForNotification(); | |
| 63 | |
| 64 // Make sure we still didn't create a BrowserAccessibilityManager. | |
| 65 // This means that at least one accessibility IPC was lost. | |
| 66 ASSERT_EQ(NULL, frame->GetOrCreateBrowserAccessibilityManager()); | |
| 67 | |
| 68 // Now allow a BrowserAccessibilityManager, simulating what would happen | |
| 69 // if the RFH's view is created now. | |
| 70 frame->set_disallow_browser_accessibility_manager_for_testing(false); | |
| 71 BrowserAccessibilityManager* manager = | |
| 72 frame->GetOrCreateBrowserAccessibilityManager(); | |
| 73 ASSERT_TRUE(manager != NULL); | |
| 74 | |
| 75 // Hide one of the elements on the page, and wait for an accessibility | |
| 76 // notification triggered by the hide. | |
| 77 AccessibilityNotificationWaiter waiter2( | |
|
nasko
2014/10/02 16:38:47
Since you don't preserve any state in each of thos
dmazzoni
2014/10/02 21:51:12
Good idea, done.
| |
| 78 shell(), AccessibilityModeComplete, ui::AX_EVENT_LIVE_REGION_CHANGED); | |
| 79 ASSERT_TRUE(ExecuteScript(shell()->web_contents(), | |
| 80 "document.getElementById('p1').style.display = 'none';")); | |
| 81 waiter2.WaitForNotification(); | |
| 82 | |
| 83 // Show that accessibility was reset because we have a new | |
| 84 // BrowserAccessibilityManager object. | |
| 85 ASSERT_TRUE(manager != frame->GetOrCreateBrowserAccessibilityManager()); | |
| 86 | |
| 87 // Ensure that we didn't kill the renderer; we can still send it messages. | |
|
nasko
2014/10/02 16:38:48
Do you plan to test that the process kill function
dmazzoni
2014/10/02 21:51:12
Sure, makes sense. I added a new test.
| |
| 88 AccessibilityNotificationWaiter waiter3( | |
| 89 shell(), AccessibilityModeComplete, ui::AX_EVENT_FOCUS); | |
| 90 ASSERT_TRUE(ExecuteScript(shell()->web_contents(), | |
| 91 "document.getElementById('button').focus();")); | |
| 92 waiter3.WaitForNotification(); | |
| 93 | |
| 94 // Get the accessibility tree, ensure it reflects the final state of the | |
| 95 // document. | |
| 96 const ui::AXTree& tree = waiter3.GetAXTree(); | |
| 97 const ui::AXNode* root = tree.GetRoot(); | |
| 98 | |
| 99 // Use this for debugging if the test fails. | |
| 100 VLOG(1) << tree.ToString(); | |
| 101 | |
| 102 EXPECT_EQ(ui::AX_ROLE_ROOT_WEB_AREA, root->data().role); | |
| 103 ASSERT_EQ(2, root->child_count()); | |
| 104 | |
| 105 const ui::AXNode* live_region = root->ChildAtIndex(0); | |
| 106 ASSERT_EQ(1, live_region->child_count()); | |
| 107 EXPECT_EQ(ui::AX_ROLE_DIV, live_region->data().role); | |
| 108 | |
| 109 const ui::AXNode* para = live_region->ChildAtIndex(0); | |
| 110 EXPECT_EQ(ui::AX_ROLE_PARAGRAPH, para->data().role); | |
| 111 | |
| 112 const ui::AXNode* button_container = root->ChildAtIndex(1); | |
| 113 EXPECT_EQ(ui::AX_ROLE_GROUP, button_container->data().role); | |
| 114 ASSERT_EQ(1, button_container->child_count()); | |
| 115 | |
| 116 const ui::AXNode* button = button_container->ChildAtIndex(0); | |
| 117 EXPECT_EQ(ui::AX_ROLE_BUTTON, button->data().role); | |
| 118 EXPECT_TRUE(button->data().state >> ui::AX_STATE_FOCUSED & 1); | |
| 119 } | |
| 120 | |
| 121 } // namespace content | |
| OLD | NEW |