Blink roll 25b6bd3a7a131ffe68d809546ad1a20707915cdc:3a503f41ae42e5b79cfcd2ff10e65afde...
[chromium-blink-merge.git] / content / browser / accessibility / accessibility_mode_browsertest.cc
blobaa54862fa3d41a13752fe4c50025dad0973a2693
1 // Copyright 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 "content/browser/accessibility/accessibility_mode_helper.h"
6 #include "content/browser/renderer_host/render_view_host_impl.h"
7 #include "content/browser/renderer_host/render_widget_host_impl.h"
8 #include "content/browser/renderer_host/render_widget_host_view_base.h"
9 #include "content/browser/web_contents/web_contents_impl.h"
10 #include "content/public/browser/render_view_host.h"
11 #include "content/public/browser/render_widget_host.h"
12 #include "content/public/browser/render_widget_host_view.h"
13 #include "content/public/browser/web_contents.h"
14 #include "content/public/common/url_constants.h"
15 #include "content/public/test/content_browser_test.h"
16 #include "content/public/test/content_browser_test_utils.h"
17 #include "content/shell/browser/shell.h"
18 #include "content/test/accessibility_browser_test_utils.h"
19 #include "testing/gtest/include/gtest/gtest.h"
21 namespace content {
23 const char kMinimalPageDataURL[] =
24 "data:text/html,<html><head></head><body>Hello, world</body></html>";
26 class AccessibilityModeTest : public ContentBrowserTest {
27 protected:
28 WebContentsImpl* web_contents() {
29 return static_cast<WebContentsImpl*>(shell()->web_contents());
32 void ExpectBrowserAccessibilityManager(bool expect_bam,
33 std::string message = "") {
34 if (expect_bam) {
35 EXPECT_NE(
36 (BrowserAccessibilityManager*)NULL,
37 web_contents()->GetRootBrowserAccessibilityManager()) << message;
38 } else {
39 EXPECT_EQ(
40 (BrowserAccessibilityManager*)NULL,
41 web_contents()->GetRootBrowserAccessibilityManager()) << message;
45 AccessibilityMode CorrectedAccessibility(AccessibilityMode mode) {
46 return AddAccessibilityModeTo(GetBaseAccessibilityMode(), mode);
49 bool ShouldBeBrowserAccessibilityManager(AccessibilityMode mode) {
50 mode = CorrectedAccessibility(mode);
51 switch (mode) {
52 case AccessibilityModeOff:
53 case AccessibilityModeTreeOnly:
54 return false;
55 case AccessibilityModeComplete:
56 return true;
57 default:
58 NOTREACHED();
60 return false;
64 IN_PROC_BROWSER_TEST_F(AccessibilityModeTest, AccessibilityModeOff) {
65 NavigateToURL(shell(), GURL(kMinimalPageDataURL));
67 EXPECT_EQ(CorrectedAccessibility(AccessibilityModeOff),
68 web_contents()->GetAccessibilityMode());
69 ExpectBrowserAccessibilityManager(
70 ShouldBeBrowserAccessibilityManager(AccessibilityModeOff));
73 IN_PROC_BROWSER_TEST_F(AccessibilityModeTest, AccessibilityModeComplete) {
74 NavigateToURL(shell(), GURL(kMinimalPageDataURL));
75 ASSERT_EQ(CorrectedAccessibility(AccessibilityModeOff),
76 web_contents()->GetAccessibilityMode());
78 AccessibilityNotificationWaiter waiter(shell());
79 web_contents()->AddAccessibilityMode(AccessibilityModeComplete);
80 EXPECT_EQ(AccessibilityModeComplete, web_contents()->GetAccessibilityMode());
81 waiter.WaitForNotification();
82 ExpectBrowserAccessibilityManager(
83 ShouldBeBrowserAccessibilityManager(AccessibilityModeComplete));
86 IN_PROC_BROWSER_TEST_F(AccessibilityModeTest, AccessibilityModeTreeOnly) {
87 NavigateToURL(shell(), GURL(kMinimalPageDataURL));
88 ASSERT_EQ(CorrectedAccessibility(AccessibilityModeOff),
89 web_contents()->GetAccessibilityMode());
91 AccessibilityNotificationWaiter waiter(shell());
92 web_contents()->AddAccessibilityMode(AccessibilityModeTreeOnly);
93 EXPECT_EQ(CorrectedAccessibility(AccessibilityModeTreeOnly),
94 web_contents()->GetAccessibilityMode());
95 waiter.WaitForNotification();
96 // No BrowserAccessibilityManager expected for AccessibilityModeTreeOnly
97 ExpectBrowserAccessibilityManager(
98 ShouldBeBrowserAccessibilityManager(AccessibilityModeTreeOnly));
101 IN_PROC_BROWSER_TEST_F(AccessibilityModeTest, AddingModes) {
102 NavigateToURL(shell(), GURL(kMinimalPageDataURL));
104 AccessibilityNotificationWaiter waiter(shell());
105 web_contents()->AddAccessibilityMode(AccessibilityModeTreeOnly);
106 EXPECT_EQ(CorrectedAccessibility(AccessibilityModeTreeOnly),
107 web_contents()->GetAccessibilityMode());
108 waiter.WaitForNotification();
109 ExpectBrowserAccessibilityManager(ShouldBeBrowserAccessibilityManager(
110 AccessibilityModeTreeOnly),
111 "Should be no BrowserAccessibilityManager "
112 "for AccessibilityModeTreeOnly");
114 AccessibilityNotificationWaiter waiter2(shell());
115 web_contents()->AddAccessibilityMode(AccessibilityModeComplete);
116 EXPECT_EQ(AccessibilityModeComplete, web_contents()->GetAccessibilityMode());
117 waiter2.WaitForNotification();
118 ExpectBrowserAccessibilityManager(ShouldBeBrowserAccessibilityManager(
119 AccessibilityModeComplete),
120 "Should be a BrowserAccessibilityManager "
121 "for AccessibilityModeComplete");
124 } // namespace content