| 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 "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/strings/stringprintf.h" | 6 #include "base/strings/stringprintf.h" |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
| 9 #include "content/browser/accessibility/accessibility_test_utils.h" |
| 9 #include "content/browser/accessibility/browser_accessibility.h" | 10 #include "content/browser/accessibility/browser_accessibility.h" |
| 10 #include "content/browser/accessibility/browser_accessibility_manager.h" | 11 #include "content/browser/accessibility/browser_accessibility_manager.h" |
| 11 #include "content/browser/accessibility/browser_accessibility_state_impl.h" | 12 #include "content/browser/accessibility/browser_accessibility_state_impl.h" |
| 12 #include "content/browser/frame_host/cross_process_frame_connector.h" | 13 #include "content/browser/frame_host/cross_process_frame_connector.h" |
| 13 #include "content/browser/frame_host/frame_tree.h" | 14 #include "content/browser/frame_host/frame_tree.h" |
| 14 #include "content/browser/frame_host/render_frame_proxy_host.h" | 15 #include "content/browser/frame_host/render_frame_proxy_host.h" |
| 15 #include "content/browser/frame_host/render_widget_host_view_child_frame.h" | 16 #include "content/browser/frame_host/render_widget_host_view_child_frame.h" |
| 16 #include "content/browser/renderer_host/render_view_host_impl.h" | 17 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 17 #include "content/browser/site_per_process_browsertest.h" | 18 #include "content/browser/site_per_process_browsertest.h" |
| 18 #include "content/browser/web_contents/web_contents_impl.h" | 19 #include "content/browser/web_contents/web_contents_impl.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 36 #if defined(OS_ANDROID) | 37 #if defined(OS_ANDROID) |
| 37 #define MAYBE_SitePerProcessAccessibilityBrowserTest \ | 38 #define MAYBE_SitePerProcessAccessibilityBrowserTest \ |
| 38 DISABLED_SitePerProcessAccessibilityBrowserTest | 39 DISABLED_SitePerProcessAccessibilityBrowserTest |
| 39 #else | 40 #else |
| 40 #define MAYBE_SitePerProcessAccessibilityBrowserTest \ | 41 #define MAYBE_SitePerProcessAccessibilityBrowserTest \ |
| 41 SitePerProcessAccessibilityBrowserTest | 42 SitePerProcessAccessibilityBrowserTest |
| 42 #endif | 43 #endif |
| 43 | 44 |
| 44 namespace content { | 45 namespace content { |
| 45 | 46 |
| 46 namespace { | |
| 47 | |
| 48 // Searches recursively and returns true if any node's accessible name | |
| 49 // is equal to the given text. | |
| 50 bool AccessibilityTreeContainsText(BrowserAccessibility* node, | |
| 51 const std::string& text) { | |
| 52 if (node->GetStringAttribute(ui::AX_ATTR_NAME) == text) | |
| 53 return true; | |
| 54 for (unsigned i = 0; i < node->PlatformChildCount(); i++) { | |
| 55 if (AccessibilityTreeContainsText(node->PlatformGetChild(i), text)) | |
| 56 return true; | |
| 57 } | |
| 58 return false; | |
| 59 } | |
| 60 | |
| 61 } // namespace | |
| 62 | |
| 63 class MAYBE_SitePerProcessAccessibilityBrowserTest | 47 class MAYBE_SitePerProcessAccessibilityBrowserTest |
| 64 : public SitePerProcessBrowserTest { | 48 : public SitePerProcessBrowserTest { |
| 65 public: | 49 public: |
| 66 MAYBE_SitePerProcessAccessibilityBrowserTest() {} | 50 MAYBE_SitePerProcessAccessibilityBrowserTest() {} |
| 67 | 51 |
| 68 void LoadCrossSitePageIntoFrame(FrameTreeNode* frame_tree_node, | 52 void LoadCrossSitePageIntoFrame(FrameTreeNode* frame_tree_node, |
| 69 const std::string& relative_url, | 53 const std::string& relative_url, |
| 70 const std::string& host) { | 54 const std::string& host) { |
| 71 // Load cross-site page into iframe. | 55 // Load cross-site page into iframe. |
| 72 RenderFrameHostImpl* child_rfh = | 56 RenderFrameHostImpl* child_rfh = |
| 73 frame_tree_node->render_manager()->current_frame_host(); | 57 frame_tree_node->render_manager()->current_frame_host(); |
| 74 RenderFrameDeletedObserver deleted_observer(child_rfh); | 58 RenderFrameDeletedObserver deleted_observer(child_rfh); |
| 75 GURL cross_site_url(embedded_test_server()->GetURL(host, relative_url)); | 59 GURL cross_site_url(embedded_test_server()->GetURL(host, relative_url)); |
| 76 NavigateFrameToURL(frame_tree_node, cross_site_url); | 60 NavigateFrameToURL(frame_tree_node, cross_site_url); |
| 77 | 61 |
| 78 // Ensure that we have created a new process for the subframe. | 62 // Ensure that we have created a new process for the subframe. |
| 79 SiteInstance* site_instance = | 63 SiteInstance* site_instance = |
| 80 frame_tree_node->current_frame_host()->GetSiteInstance(); | 64 frame_tree_node->current_frame_host()->GetSiteInstance(); |
| 81 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), site_instance); | 65 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), site_instance); |
| 82 | 66 |
| 83 // Wait until the iframe completes the swap. | 67 // Wait until the iframe completes the swap. |
| 84 deleted_observer.WaitUntilDeleted(); | 68 deleted_observer.WaitUntilDeleted(); |
| 85 } | 69 } |
| 86 | |
| 87 // This is intended to be a robust way to assert that the accessibility | |
| 88 // tree eventually gets into the correct state, without worrying about | |
| 89 // the exact ordering of events received while getting there. | |
| 90 // | |
| 91 // Searches the accessibility tree to see if any node's accessible name | |
| 92 // is equal to the given text. If not, sets up a notification waiter | |
| 93 // that listens for any accessibility event in any frame, and checks again | |
| 94 // after each event. Keeps looping until the text is found (or the | |
| 95 // test times out). | |
| 96 void WaitForAccessibilityTreeToContainText(const std::string& text) { | |
| 97 RenderFrameHostImpl* main_frame = static_cast<RenderFrameHostImpl*>( | |
| 98 shell()->web_contents()->GetMainFrame()); | |
| 99 BrowserAccessibilityManager* main_frame_manager = | |
| 100 main_frame->browser_accessibility_manager(); | |
| 101 FrameTree* frame_tree = | |
| 102 static_cast<WebContentsImpl*>(shell()->web_contents())->GetFrameTree(); | |
| 103 while (!AccessibilityTreeContainsText( | |
| 104 main_frame_manager->GetRoot(), text)) { | |
| 105 AccessibilityNotificationWaiter accessibility_waiter(main_frame, | |
| 106 ui::AX_EVENT_NONE); | |
| 107 for (FrameTreeNode* node : frame_tree->Nodes()) | |
| 108 accessibility_waiter.ListenToAdditionalFrame( | |
| 109 node->current_frame_host()); | |
| 110 | |
| 111 accessibility_waiter.WaitForNotification(); | |
| 112 } | |
| 113 } | |
| 114 }; | 70 }; |
| 115 | 71 |
| 116 IN_PROC_BROWSER_TEST_F(MAYBE_SitePerProcessAccessibilityBrowserTest, | 72 IN_PROC_BROWSER_TEST_F(MAYBE_SitePerProcessAccessibilityBrowserTest, |
| 117 CrossSiteIframeAccessibility) { | 73 CrossSiteIframeAccessibility) { |
| 118 // Enable full accessibility for all current and future WebContents. | 74 // Enable full accessibility for all current and future WebContents. |
| 119 BrowserAccessibilityState::GetInstance()->EnableAccessibility(); | 75 BrowserAccessibilityState::GetInstance()->EnableAccessibility(); |
| 120 | 76 |
| 121 GURL main_url(embedded_test_server()->GetURL("/site_per_process_main.html")); | 77 GURL main_url(embedded_test_server()->GetURL("/site_per_process_main.html")); |
| 122 NavigateToURL(shell(), main_url); | 78 NavigateToURL(shell(), main_url); |
| 123 | 79 |
| 124 // It is safe to obtain the root frame tree node here, as it doesn't change. | 80 // It is safe to obtain the root frame tree node here, as it doesn't change. |
| 125 FrameTreeNode* root = | 81 FrameTreeNode* root = |
| 126 static_cast<WebContentsImpl*>(shell()->web_contents())-> | 82 static_cast<WebContentsImpl*>(shell()->web_contents())-> |
| 127 GetFrameTree()->root(); | 83 GetFrameTree()->root(); |
| 128 | 84 |
| 129 // Load same-site page into iframe. | 85 // Load same-site page into iframe. |
| 130 FrameTreeNode* child = root->child_at(0); | 86 FrameTreeNode* child = root->child_at(0); |
| 131 GURL http_url(embedded_test_server()->GetURL("/title1.html")); | 87 GURL http_url(embedded_test_server()->GetURL("/title1.html")); |
| 132 NavigateFrameToURL(child, http_url); | 88 NavigateFrameToURL(child, http_url); |
| 133 | 89 |
| 134 // Load cross-site page into iframe and wait for text from that | 90 // Load cross-site page into iframe and wait for text from that |
| 135 // page to appear in the accessibility tree. | 91 // page to appear in the accessibility tree. |
| 136 LoadCrossSitePageIntoFrame(child, "/title2.html", "foo.com"); | 92 LoadCrossSitePageIntoFrame(child, "/title2.html", "foo.com"); |
| 137 WaitForAccessibilityTreeToContainText("Title Of Awesomeness"); | 93 WaitForAccessibilityTreeToContainNodeWithName( |
| 94 shell()->web_contents(), |
| 95 "Title Of Awesomeness"); |
| 138 | 96 |
| 139 RenderFrameHostImpl* main_frame = static_cast<RenderFrameHostImpl*>( | 97 RenderFrameHostImpl* main_frame = static_cast<RenderFrameHostImpl*>( |
| 140 shell()->web_contents()->GetMainFrame()); | 98 shell()->web_contents()->GetMainFrame()); |
| 141 BrowserAccessibilityManager* main_frame_manager = | 99 BrowserAccessibilityManager* main_frame_manager = |
| 142 main_frame->browser_accessibility_manager(); | 100 main_frame->browser_accessibility_manager(); |
| 143 VLOG(1) << "Main frame accessibility tree:\n" | 101 VLOG(1) << "Main frame accessibility tree:\n" |
| 144 << main_frame_manager->SnapshotAXTreeForTesting().ToString(); | 102 << main_frame_manager->SnapshotAXTreeForTesting().ToString(); |
| 145 | 103 |
| 146 // Assert that we can walk from the main frame down into the child frame | 104 // Assert that we can walk from the main frame down into the child frame |
| 147 // directly, getting correct roles and data along the way. | 105 // directly, getting correct roles and data along the way. |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 | 145 |
| 188 // It is safe to obtain the root frame tree node here, as it doesn't change. | 146 // It is safe to obtain the root frame tree node here, as it doesn't change. |
| 189 FrameTreeNode* root = | 147 FrameTreeNode* root = |
| 190 static_cast<WebContentsImpl*>(shell()->web_contents())-> | 148 static_cast<WebContentsImpl*>(shell()->web_contents())-> |
| 191 GetFrameTree()->root(); | 149 GetFrameTree()->root(); |
| 192 | 150 |
| 193 // Load first cross-site page into iframe and wait for text from that | 151 // Load first cross-site page into iframe and wait for text from that |
| 194 // page to appear in the accessibility tree. | 152 // page to appear in the accessibility tree. |
| 195 FrameTreeNode* child = root->child_at(0); | 153 FrameTreeNode* child = root->child_at(0); |
| 196 LoadCrossSitePageIntoFrame(child, "/title1.html", "foo.com"); | 154 LoadCrossSitePageIntoFrame(child, "/title1.html", "foo.com"); |
| 197 WaitForAccessibilityTreeToContainText("This page has no title."); | 155 WaitForAccessibilityTreeToContainNodeWithName( |
| 156 shell()->web_contents(), |
| 157 "This page has no title."); |
| 198 | 158 |
| 199 // Load second cross-site page into iframe and wait for text from that | 159 // Load second cross-site page into iframe and wait for text from that |
| 200 // page to appear in the accessibility tree. If this succeeds and doesn't | 160 // page to appear in the accessibility tree. If this succeeds and doesn't |
| 201 // time out, the test passes. | 161 // time out, the test passes. |
| 202 LoadCrossSitePageIntoFrame(child, "/title2.html", "bar.com"); | 162 LoadCrossSitePageIntoFrame(child, "/title2.html", "bar.com"); |
| 203 WaitForAccessibilityTreeToContainText("Title Of Awesomeness"); | 163 WaitForAccessibilityTreeToContainNodeWithName( |
| 164 shell()->web_contents(), |
| 165 "Title Of Awesomeness"); |
| 204 } | 166 } |
| 205 | 167 |
| 206 } // namespace content | 168 } // namespace content |
| OLD | NEW |