Chromium Code Reviews| Index: content/browser/accessibility/frame_tree_accessibility_browsertest.cc |
| diff --git a/content/browser/accessibility/frame_tree_accessibility_browsertest.cc b/content/browser/accessibility/frame_tree_accessibility_browsertest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..40a482a6b986e215de61fba1d60fa844564ddfca |
| --- /dev/null |
| +++ b/content/browser/accessibility/frame_tree_accessibility_browsertest.cc |
| @@ -0,0 +1,246 @@ |
| +// Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "base/command_line.h" |
| +#include "base/logging.h" |
| +#include "content/browser/accessibility/browser_accessibility.h" |
| +#include "content/browser/accessibility/browser_accessibility_manager.h" |
| +#include "content/browser/frame_host/frame_tree.h" |
| +#include "content/browser/renderer_host/render_view_host_impl.h" |
| +#include "content/browser/web_contents/web_contents_impl.h" |
| +#include "content/port/browser/render_widget_host_view_port.h" |
| +#include "content/public/browser/browser_accessibility_state.h" |
| +#include "content/public/browser/notification_observer.h" |
| +#include "content/public/browser/notification_service.h" |
| +#include "content/public/browser/notification_types.h" |
| +#include "content/public/browser/web_contents.h" |
| +#include "content/public/browser/web_contents_observer.h" |
| +#include "content/public/common/content_switches.h" |
| +#include "content/public/common/url_constants.h" |
| +#include "content/public/test/browser_test_utils.h" |
| +#include "content/public/test/content_browser_test.h" |
| +#include "content/public/test/content_browser_test_utils.h" |
| +#include "content/public/test/test_utils.h" |
| +#include "content/shell/browser/shell.h" |
| +#include "content/test/accessibility_browser_test_utils.h" |
| +#include "net/dns/mock_host_resolver.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| +#include "url/gurl.h" |
| + |
| +namespace content { |
| + |
| +namespace { |
| + |
| +// TODO: share this with site_per_process_browsertest.cc |
| +class SitePerProcessWebContentsObserver: public WebContentsObserver { |
| + public: |
| + explicit SitePerProcessWebContentsObserver(WebContents* web_contents) |
| + : WebContentsObserver(web_contents), |
| + navigation_succeeded_(false) {} |
| + virtual ~SitePerProcessWebContentsObserver() {} |
| + |
| + virtual void DidStartProvisionalLoadForFrame( |
| + int64 frame_id, |
| + int64 parent_frame_id, |
| + bool is_main_frame, |
| + const GURL& validated_url, |
| + bool is_error_page, |
| + bool is_iframe_srcdoc, |
| + RenderViewHost* render_view_host) OVERRIDE { |
| + navigation_succeeded_ = false; |
| + } |
| + |
| + virtual void DidFailProvisionalLoad( |
| + int64 frame_id, |
| + const base::string16& frame_unique_name, |
| + bool is_main_frame, |
| + const GURL& validated_url, |
| + int error_code, |
| + const base::string16& error_description, |
| + RenderViewHost* render_view_host) OVERRIDE { |
| + navigation_url_ = validated_url; |
| + navigation_succeeded_ = false; |
| + } |
| + |
| + virtual void DidCommitProvisionalLoadForFrame( |
| + int64 frame_id, |
| + const base::string16& frame_unique_name, |
| + bool is_main_frame, |
| + const GURL& url, |
| + PageTransition transition_type, |
| + RenderViewHost* render_view_host) OVERRIDE{ |
| + navigation_url_ = url; |
| + navigation_succeeded_ = true; |
| + } |
| + |
| + const GURL& navigation_url() const { |
| + return navigation_url_; |
| + } |
| + |
| + int navigation_succeeded() const { return navigation_succeeded_; } |
| + |
| + private: |
| + GURL navigation_url_; |
| + bool navigation_succeeded_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(SitePerProcessWebContentsObserver); |
| +}; |
| + |
| +} // namespace. |
| + |
| +class SitePerProcessAccessibilityBrowserTest : public ContentBrowserTest { |
| + public: |
| + SitePerProcessAccessibilityBrowserTest() {} |
| + |
| + protected: |
| + // Start at a data URL so each extra navigation creates a navigation entry. |
| + // (The first navigation will silently be classified as AUTO_SUBFRAME.) |
| + // TODO(creis): This won't be necessary when we can wait for LOAD_STOP. |
| + void StartFrameAtDataURL() { |
| + std::string data_url_script = |
| + "var iframes = document.getElementById('test');iframes.src=" |
| + "'data:text/html,dataurl';"; |
| + ASSERT_TRUE(ExecuteScript(shell()->web_contents(), data_url_script)); |
| + } |
| + |
| + // TODO: share this with site_per_process_browsertest.cc |
| + bool NavigateIframeToURL(Shell* window, |
|
ncarter (slow)
2014/05/02 19:10:02
One OKR we have for this quarter is to try to get
|
| + const GURL& url, |
| + std::string iframe_id) { |
| + // TODO(creis): This should wait for LOAD_STOP, but cross-site subframe |
| + // navigations generate extra DidStartLoading and DidStopLoading messages. |
| + // Until we replace swappedout:// with frame proxies, we need to listen for |
| + // something else. For now, we trigger NEW_SUBFRAME navigations and listen |
| + // for commit. |
| + std::string script = base::StringPrintf( |
| + "setTimeout(\"" |
| + "var iframes = document.getElementById('%s');iframes.src='%s';" |
| + "\",0)", |
| + iframe_id.c_str(), url.spec().c_str()); |
| + WindowedNotificationObserver load_observer( |
| + NOTIFICATION_NAV_ENTRY_COMMITTED, |
| + Source<NavigationController>( |
| + &window->web_contents()->GetController())); |
| + bool result = ExecuteScript(window->web_contents(), script); |
| + load_observer.Wait(); |
| + return result; |
| + } |
| + |
| + virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| + command_line->AppendSwitch(switches::kSitePerProcess); |
| + } |
| +}; |
| + |
| +IN_PROC_BROWSER_TEST_F(SitePerProcessAccessibilityBrowserTest, |
| + CrossSiteIframeAccessibility) { |
| + // Enable full accessibility for all current and future RenderWidgetHosts. |
| + BrowserAccessibilityState::GetInstance()->EnableAccessibility(); |
| + |
| + AccessibilityNotificationWaiter accessibility_waiter( |
| + shell(), AccessibilityModeComplete, |
| + ui::AX_EVENT_LOAD_COMPLETE); |
| + |
| + host_resolver()->AddRule("*", "127.0.0.1"); |
| + ASSERT_TRUE(test_server()->Start()); |
| + GURL main_url(test_server()->GetURL("files/site_per_process_main.html")); |
| + NavigateToURL(shell(), main_url); |
| + |
| + StartFrameAtDataURL(); |
| + |
| + SitePerProcessWebContentsObserver observer(shell()->web_contents()); |
| + |
| + // TODO: share this with site_per_process_browsertest.cc |
| + |
| + // Load same-site page into iframe. |
| + GURL http_url(test_server()->GetURL("files/title1.html")); |
| + EXPECT_TRUE(NavigateIframeToURL(shell(), http_url, "test")); |
| + EXPECT_EQ(http_url, observer.navigation_url()); |
| + EXPECT_TRUE(observer.navigation_succeeded()); |
| + |
| + // These must stay in scope with replace_host. |
| + GURL::Replacements replace_host; |
| + std::string foo_com("foo.com"); |
| + |
| + // Load cross-site page into iframe. |
| + GURL cross_site_url(test_server()->GetURL("files/title2.html")); |
| + replace_host.SetHostStr(foo_com); |
| + cross_site_url = cross_site_url.ReplaceComponents(replace_host); |
| + EXPECT_TRUE(NavigateIframeToURL(shell(), cross_site_url, "test")); |
| + EXPECT_EQ(cross_site_url, observer.navigation_url()); |
| + EXPECT_TRUE(observer.navigation_succeeded()); |
| + |
| + // Ensure that we have created a new process for the subframe. |
| + FrameTreeNode* root = |
| + static_cast<WebContentsImpl*>(shell()->web_contents())-> |
| + GetFrameTree()->root(); |
| + ASSERT_EQ(1U, root->child_count()); |
| + FrameTreeNode* child = root->child_at(0); |
| + EXPECT_NE(shell()->web_contents()->GetRenderViewHost(), |
| + child->current_frame_host()->render_view_host()); |
| + EXPECT_NE(shell()->web_contents()->GetSiteInstance(), |
| + child->current_frame_host()->render_view_host()->GetSiteInstance()); |
| + EXPECT_NE(shell()->web_contents()->GetRenderProcessHost(), |
| + child->current_frame_host()->GetProcess()); |
| + |
| + RenderViewHostImpl* child_rvhi = |
| + child->current_frame_host()->render_view_host(); |
| + |
| + AccessibilityNotificationWaiter accessibility_waiter2( |
| + shell(), AccessibilityModeComplete, ui::AX_EVENT_LOAD_COMPLETE, |
| + child_rvhi); |
| + |
| + accessibility_waiter.WaitForNotification(); |
| + accessibility_waiter2.WaitForNotification(); |
| + |
| + RenderWidgetHostViewPort* host_view = RenderWidgetHostViewPort::FromRWHV( |
| + shell()->web_contents()->GetRenderWidgetHostView()); |
| + |
| + BrowserAccessibilityManager* manager = |
| + host_view->GetBrowserAccessibilityManager(); |
| + LOG(INFO) << "Main frame accessibility tree:\n" |
| + << manager->SnapshotAXTreeForTesting().ToString(); |
| + |
| + BrowserAccessibilityManager* child_frame_manager = |
| + RenderWidgetHostViewPort::FromRWHV(child_rvhi->GetView())-> |
| + GetBrowserAccessibilityManager(); |
| + LOG(INFO) << "Child frame accessibility tree:\n" |
| + << child_frame_manager->SnapshotAXTreeForTesting().ToString(); |
| + |
| + // Assert that we can walk from the main frame down into the child frame |
| + // directly, getting correct roles and data along the way. |
| + |
| + BrowserAccessibility* ax_root = manager->GetRoot(); |
| + ASSERT_EQ(ui::AX_ROLE_ROOT_WEB_AREA, ax_root->GetRole()); |
| + ASSERT_EQ(1U, ax_root->PlatformChildCount()); |
| + |
| + BrowserAccessibility* ax_group = ax_root->PlatformGetChild(0); |
| + ASSERT_EQ(ui::AX_ROLE_GROUP, ax_group->GetRole()); |
| + ASSERT_EQ(1U, ax_group->PlatformChildCount()); |
| + |
| + BrowserAccessibility* ax_iframe = ax_group->PlatformGetChild(0); |
| + ASSERT_EQ(ui::AX_ROLE_IFRAME, ax_iframe->GetRole()); |
| + ASSERT_EQ(1U, ax_iframe->PlatformChildCount()); |
| + |
| + BrowserAccessibility* ax_scroll_area = ax_iframe->PlatformGetChild(0); |
| + ASSERT_EQ(ui::AX_ROLE_SCROLL_AREA, ax_scroll_area->GetRole()); |
| + ASSERT_EQ(1U, ax_scroll_area->PlatformChildCount()); |
| + |
| + BrowserAccessibility* ax_child_frame_root = |
| + ax_scroll_area->PlatformGetChild(0); |
| + ASSERT_EQ(ui::AX_ROLE_ROOT_WEB_AREA, ax_child_frame_root->GetRole()); |
| + ASSERT_EQ(1U, ax_child_frame_root->PlatformChildCount()); |
| + ASSERT_EQ("Title Of Awesomeness", ax_child_frame_root->name()); |
| + |
| + BrowserAccessibility* ax_child_frame_group = |
| + ax_child_frame_root->PlatformGetChild(0); |
| + ASSERT_EQ(ui::AX_ROLE_GROUP, ax_child_frame_group->GetRole()); |
| + ASSERT_EQ(1U, ax_child_frame_group->PlatformChildCount()); |
| + |
| + BrowserAccessibility* ax_child_frame_static_text = |
| + ax_child_frame_group->PlatformGetChild(0); |
| + ASSERT_EQ(ui::AX_ROLE_STATIC_TEXT, ax_child_frame_static_text->GetRole()); |
| + ASSERT_EQ(0U, ax_child_frame_static_text->PlatformChildCount()); |
| +} |
| + |
| +} // namespace content |