[Storage] Blob Storage Refactoring pt 1:
[chromium-blink-merge.git] / content / browser / accessibility / site_per_process_accessibility_browsertest.cc
blob6daf5abbeb5007ed4610f08043f3367698e9ce80
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.
5 #include "base/command_line.h"
6 #include "base/strings/stringprintf.h"
7 #include "content/browser/accessibility/browser_accessibility.h"
8 #include "content/browser/accessibility/browser_accessibility_manager.h"
9 #include "content/browser/accessibility/browser_accessibility_state_impl.h"
10 #include "content/browser/frame_host/cross_process_frame_connector.h"
11 #include "content/browser/frame_host/frame_tree.h"
12 #include "content/browser/frame_host/render_frame_proxy_host.h"
13 #include "content/browser/frame_host/render_widget_host_view_child_frame.h"
14 #include "content/browser/renderer_host/render_view_host_impl.h"
15 #include "content/browser/site_per_process_browsertest.h"
16 #include "content/browser/web_contents/web_contents_impl.h"
17 #include "content/public/browser/notification_observer.h"
18 #include "content/public/browser/notification_service.h"
19 #include "content/public/browser/notification_types.h"
20 #include "content/public/browser/web_contents_observer.h"
21 #include "content/public/common/content_switches.h"
22 #include "content/public/test/browser_test_utils.h"
23 #include "content/public/test/content_browser_test.h"
24 #include "content/public/test/content_browser_test_utils.h"
25 #include "content/public/test/test_utils.h"
26 #include "content/shell/browser/shell.h"
27 #include "content/test/accessibility_browser_test_utils.h"
28 #include "content/test/content_browser_test_utils_internal.h"
29 #include "net/dns/mock_host_resolver.h"
30 #include "url/gurl.h"
31 #include "url/url_constants.h"
33 namespace content {
35 class SitePerProcessAccessibilityBrowserTest
36 : public SitePerProcessBrowserTest {
37 public:
38 SitePerProcessAccessibilityBrowserTest() {}
41 // Utility function to determine if an accessibility tree has finished loading
42 // or if the tree represents a page that hasn't finished loading yet.
43 bool AccessibilityTreeIsLoaded(BrowserAccessibilityManager* manager) {
44 BrowserAccessibility* root = manager->GetRoot();
45 return (root->GetFloatAttribute(ui::AX_ATTR_DOC_LOADING_PROGRESS) == 1.0 &&
46 root->GetStringAttribute(ui::AX_ATTR_DOC_URL) != url::kAboutBlankURL);
49 // TODO(nasko): try enabling this test on more platforms once
50 // SitePerProcessBrowserTest.CrossSiteIframe is enabled everywhere.
51 // http://crbug.com/399775
52 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
53 #define MAYBE_CrossSiteIframeAccessibility CrossSiteIframeAccessibility
54 #else
55 #define MAYBE_CrossSiteIframeAccessibility DISABLED_CrossSiteIframeAccessibility
56 #endif
57 IN_PROC_BROWSER_TEST_F(SitePerProcessAccessibilityBrowserTest,
58 MAYBE_CrossSiteIframeAccessibility) {
59 // Enable full accessibility for all current and future WebContents.
60 BrowserAccessibilityState::GetInstance()->EnableAccessibility();
62 AccessibilityNotificationWaiter main_frame_accessibility_waiter(
63 shell(), AccessibilityModeComplete,
64 ui::AX_EVENT_LOAD_COMPLETE);
66 host_resolver()->AddRule("*", "127.0.0.1");
67 ASSERT_TRUE(test_server()->Start());
68 GURL main_url(test_server()->GetURL("files/site_per_process_main.html"));
69 NavigateToURL(shell(), main_url);
71 // It is safe to obtain the root frame tree node here, as it doesn't change.
72 FrameTreeNode* root =
73 static_cast<WebContentsImpl*>(shell()->web_contents())->
74 GetFrameTree()->root();
76 // Load same-site page into iframe.
77 FrameTreeNode* child = root->child_at(0);
78 GURL http_url(test_server()->GetURL("files/title1.html"));
79 NavigateFrameToURL(child, http_url);
81 // These must stay in scope with replace_host.
82 GURL::Replacements replace_host;
83 std::string foo_com("foo.com");
85 // Load cross-site page into iframe.
86 GURL cross_site_url(test_server()->GetURL("files/title2.html"));
87 replace_host.SetHostStr(foo_com);
88 cross_site_url = cross_site_url.ReplaceComponents(replace_host);
89 NavigateFrameToURL(root->child_at(0), cross_site_url);
91 // Ensure that we have created a new process for the subframe.
92 ASSERT_EQ(2U, root->child_count());
93 SiteInstance* site_instance = child->current_frame_host()->GetSiteInstance();
94 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), site_instance);
96 // Wait for the accessibility tree from the main frame to load.
97 // Because we created the AccessibilityNotificationWaiter before accessibility
98 // was enabled, we're guaranteed to get a LOAD_COMPLETE event.
99 main_frame_accessibility_waiter.WaitForNotification();
101 RenderFrameHostImpl* main_frame = static_cast<RenderFrameHostImpl*>(
102 shell()->web_contents()->GetMainFrame());
103 BrowserAccessibilityManager* main_frame_manager =
104 main_frame->browser_accessibility_manager();
105 VLOG(1) << "Main frame accessibility tree:\n"
106 << main_frame_manager->SnapshotAXTreeForTesting().ToString();
107 EXPECT_TRUE(AccessibilityTreeIsLoaded(main_frame_manager));
109 // Next, wait for the accessibility tree from the cross-process iframe
110 // to load. Since accessibility was enabled at the time this frame was
111 // created, we need to check to see if it's already loaded first, and
112 // only create an AccessibilityNotificationWaiter if it's not.
113 RenderFrameHostImpl* child_frame = static_cast<RenderFrameHostImpl*>(
114 child->current_frame_host());
115 BrowserAccessibilityManager* child_frame_manager =
116 child_frame->browser_accessibility_manager();
117 if (!AccessibilityTreeIsLoaded(child_frame_manager)) {
118 VLOG(1) << "Child frame accessibility tree is not loaded, waiting...";
119 AccessibilityNotificationWaiter child_frame_accessibility_waiter(
120 child_frame, ui::AX_EVENT_LOAD_COMPLETE);
121 child_frame_accessibility_waiter.WaitForNotification();
123 EXPECT_TRUE(AccessibilityTreeIsLoaded(child_frame_manager));
124 VLOG(1) << "Child frame accessibility tree:\n"
125 << child_frame_manager->SnapshotAXTreeForTesting().ToString();
127 // Assert that we can walk from the main frame down into the child frame
128 // directly, getting correct roles and data along the way.
129 BrowserAccessibility* ax_root = main_frame_manager->GetRoot();
130 EXPECT_EQ(ui::AX_ROLE_ROOT_WEB_AREA, ax_root->GetRole());
131 ASSERT_EQ(1U, ax_root->PlatformChildCount());
133 BrowserAccessibility* ax_group = ax_root->PlatformGetChild(0);
134 EXPECT_EQ(ui::AX_ROLE_GROUP, ax_group->GetRole());
135 ASSERT_EQ(2U, ax_group->PlatformChildCount());
137 BrowserAccessibility* ax_iframe = ax_group->PlatformGetChild(0);
138 EXPECT_EQ(ui::AX_ROLE_IFRAME, ax_iframe->GetRole());
139 ASSERT_EQ(1U, ax_iframe->PlatformChildCount());
141 BrowserAccessibility* ax_scroll_area = ax_iframe->PlatformGetChild(0);
142 EXPECT_EQ(ui::AX_ROLE_SCROLL_AREA, ax_scroll_area->GetRole());
143 ASSERT_EQ(1U, ax_scroll_area->PlatformChildCount());
145 BrowserAccessibility* ax_child_frame_root =
146 ax_scroll_area->PlatformGetChild(0);
147 EXPECT_EQ(ui::AX_ROLE_ROOT_WEB_AREA, ax_child_frame_root->GetRole());
148 ASSERT_EQ(1U, ax_child_frame_root->PlatformChildCount());
149 EXPECT_EQ("Title Of Awesomeness", ax_child_frame_root->name());
151 BrowserAccessibility* ax_child_frame_group =
152 ax_child_frame_root->PlatformGetChild(0);
153 EXPECT_EQ(ui::AX_ROLE_GROUP, ax_child_frame_group->GetRole());
154 ASSERT_EQ(1U, ax_child_frame_group->PlatformChildCount());
156 BrowserAccessibility* ax_child_frame_static_text =
157 ax_child_frame_group->PlatformGetChild(0);
158 EXPECT_EQ(ui::AX_ROLE_STATIC_TEXT, ax_child_frame_static_text->GetRole());
159 ASSERT_EQ(0U, ax_child_frame_static_text->PlatformChildCount());
161 // Last, check that the parent of the child frame root is correct.
162 EXPECT_EQ(ax_child_frame_root->GetParent(), ax_scroll_area);
165 } // namespace content