Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(365)

Side by Side Diff: content/browser/accessibility/site_per_process_accessibility_browsertest.cc

Issue 268543008: Cross-process iframe accessibility. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: FindByRoutingID Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 "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
32 namespace content {
33
34 class SitePerProcessAccessibilityBrowserTest
35 : public SitePerProcessBrowserTest {
36 public:
37 SitePerProcessAccessibilityBrowserTest() {}
38 };
39
40 IN_PROC_BROWSER_TEST_F(SitePerProcessAccessibilityBrowserTest,
41 CrossSiteIframeAccessibility) {
42 // Enable full accessibility for all current and future WebContents.
43 BrowserAccessibilityState::GetInstance()->EnableAccessibility();
44
45 AccessibilityNotificationWaiter main_frame_accessibility_waiter(
46 shell(), AccessibilityModeComplete,
47 ui::AX_EVENT_LOAD_COMPLETE);
48
49 host_resolver()->AddRule("*", "127.0.0.1");
50 ASSERT_TRUE(test_server()->Start());
51 GURL main_url(test_server()->GetURL("files/site_per_process_main.html"));
52 NavigateToURL(shell(), main_url);
53
54 // It is safe to obtain the root frame tree node here, as it doesn't change.
55 FrameTreeNode* root =
56 static_cast<WebContentsImpl*>(shell()->web_contents())->
57 GetFrameTree()->root();
58
59 // Load same-site page into iframe.
60 FrameTreeNode* child = root->child_at(0);
61 GURL http_url(test_server()->GetURL("files/title1.html"));
62 NavigateFrameToURL(child, http_url);
63
64 // These must stay in scope with replace_host.
65 GURL::Replacements replace_host;
66 std::string foo_com("foo.com");
67
68 // Load cross-site page into iframe.
69 GURL cross_site_url(test_server()->GetURL("files/title2.html"));
70 replace_host.SetHostStr(foo_com);
71 cross_site_url = cross_site_url.ReplaceComponents(replace_host);
72 NavigateFrameToURL(root->child_at(0), cross_site_url);
73
74 // Ensure that we have created a new process for the subframe.
75 ASSERT_EQ(1U, root->child_count());
76 SiteInstance* site_instance = child->current_frame_host()->GetSiteInstance();
77 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), site_instance);
78
79 // Wait until the accessibility tree from both the main frame and
80 // cross-process iframe load.
81 RenderFrameHostImpl* child_frame = static_cast<RenderFrameHostImpl*>(
82 child->current_frame_host());
83 AccessibilityNotificationWaiter child_frame_accessibility_waiter(
84 child_frame, ui::AX_EVENT_NONE);
85 main_frame_accessibility_waiter.WaitForNotification();
86 child_frame_accessibility_waiter.WaitForNotification();
87
88 RenderFrameHostImpl* main_frame = static_cast<RenderFrameHostImpl*>(
89 shell()->web_contents()->GetMainFrame());
90 BrowserAccessibilityManager* main_frame_manager =
91 main_frame->browser_accessibility_manager();
92 VLOG(1) << "Main frame accessibility tree:\n"
93 << main_frame_manager->SnapshotAXTreeForTesting().ToString();
94
95 BrowserAccessibilityManager* child_frame_manager =
96 child_frame->browser_accessibility_manager();
97 VLOG(1) << "Child frame accessibility tree:\n"
98 << child_frame_manager->SnapshotAXTreeForTesting().ToString();
99
100 // Assert that we can walk from the main frame down into the child frame
101 // directly, getting correct roles and data along the way.
102 BrowserAccessibility* ax_root = main_frame_manager->GetRoot();
103 ASSERT_EQ(ui::AX_ROLE_ROOT_WEB_AREA, ax_root->GetRole());
104 ASSERT_EQ(1U, ax_root->PlatformChildCount());
105
106 BrowserAccessibility* ax_group = ax_root->PlatformGetChild(0);
107 ASSERT_EQ(ui::AX_ROLE_GROUP, ax_group->GetRole());
108 ASSERT_EQ(1U, ax_group->PlatformChildCount());
109
110 BrowserAccessibility* ax_iframe = ax_group->PlatformGetChild(0);
111 ASSERT_EQ(ui::AX_ROLE_IFRAME, ax_iframe->GetRole());
112 ASSERT_EQ(1U, ax_iframe->PlatformChildCount());
113
114 BrowserAccessibility* ax_scroll_area = ax_iframe->PlatformGetChild(0);
115 ASSERT_EQ(ui::AX_ROLE_SCROLL_AREA, ax_scroll_area->GetRole());
116 ASSERT_EQ(1U, ax_scroll_area->PlatformChildCount());
117
118 BrowserAccessibility* ax_child_frame_root =
119 ax_scroll_area->PlatformGetChild(0);
120 ASSERT_EQ(ui::AX_ROLE_ROOT_WEB_AREA, ax_child_frame_root->GetRole());
121 ASSERT_EQ(1U, ax_child_frame_root->PlatformChildCount());
122 ASSERT_EQ("Title Of Awesomeness", ax_child_frame_root->name());
123
124 BrowserAccessibility* ax_child_frame_group =
125 ax_child_frame_root->PlatformGetChild(0);
126 ASSERT_EQ(ui::AX_ROLE_GROUP, ax_child_frame_group->GetRole());
127 ASSERT_EQ(1U, ax_child_frame_group->PlatformChildCount());
128
129 BrowserAccessibility* ax_child_frame_static_text =
130 ax_child_frame_group->PlatformGetChild(0);
131 ASSERT_EQ(ui::AX_ROLE_STATIC_TEXT, ax_child_frame_static_text->GetRole());
132 ASSERT_EQ(0U, ax_child_frame_static_text->PlatformChildCount());
133
134 // Last, check that the parent of the child frame root is correct.
135 ASSERT_EQ(ax_child_frame_root->GetParent(), ax_scroll_area);
136 }
137
138 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698