Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / chromeos / accessibility / spoken_feedback_browsertest.cc
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.
4
5 #include <queue>
6
7 #include "base/command_line.h"
8 #include "base/strings/string_util.h"
9 #include "chrome/app/chrome_command_ids.h"
10 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h"
11 #include "chrome/browser/chromeos/accessibility/speech_monitor.h"
12 #include "chrome/browser/chromeos/login/login_display_host.h"
13 #include "chrome/browser/chromeos/login/login_display_host_impl.h"
14 #include "chrome/browser/chromeos/login/user_manager.h"
15 #include "chrome/browser/chromeos/login/webui_login_view.h"
16 #include "chrome/browser/chromeos/profiles/profile_helper.h"
17 #include "chrome/browser/extensions/api/braille_display_private/stub_braille_controller.h"
18 #include "chrome/browser/speech/tts_controller.h"
19 #include "chrome/browser/speech/tts_platform.h"
20 #include "chrome/browser/ui/browser.h"
21 #include "chrome/browser/ui/browser_commands.h"
22 #include "chrome/browser/ui/browser_window.h"
23 #include "chrome/test/base/in_process_browser_test.h"
24 #include "chrome/test/base/testing_profile.h"
25 #include "chrome/test/base/ui_test_utils.h"
26 #include "chromeos/chromeos_switches.h"
27 #include "content/public/common/url_constants.h"
28 #include "content/public/test/test_utils.h"
29 #include "testing/gtest/include/gtest/gtest.h"
30 #include "ui/base/test/ui_controls.h"
31 #include "ui/views/widget/widget.h"
32
33 using extensions::api::braille_display_private::StubBrailleController;
34
35 namespace chromeos {
36
37 //
38 // Spoken feedback tests in a normal browser window.
39 //
40
41 class SpokenFeedbackTest : public InProcessBrowserTest {
42  protected:
43   SpokenFeedbackTest() {}
44   virtual ~SpokenFeedbackTest() {}
45
46   virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
47     AccessibilityManager::SetBrailleControllerForTest(&braille_controller_);
48   }
49
50   virtual void CleanUpOnMainThread() OVERRIDE {
51     AccessibilityManager::SetBrailleControllerForTest(NULL);
52   }
53
54  private:
55   StubBrailleController braille_controller_;
56   DISALLOW_COPY_AND_ASSIGN(SpokenFeedbackTest);
57 };
58
59 IN_PROC_BROWSER_TEST_F(SpokenFeedbackTest, EnableSpokenFeedback) {
60   EXPECT_FALSE(AccessibilityManager::Get()->IsSpokenFeedbackEnabled());
61
62   SpeechMonitor monitor;
63   AccessibilityManager::Get()->EnableSpokenFeedback(
64       true, ash::A11Y_NOTIFICATION_NONE);
65   EXPECT_TRUE(monitor.SkipChromeVoxEnabledMessage());
66 }
67
68 IN_PROC_BROWSER_TEST_F(SpokenFeedbackTest, FocusToolbar) {
69   EXPECT_FALSE(AccessibilityManager::Get()->IsSpokenFeedbackEnabled());
70
71   SpeechMonitor monitor;
72   AccessibilityManager::Get()->EnableSpokenFeedback(
73       true, ash::A11Y_NOTIFICATION_NONE);
74   EXPECT_TRUE(monitor.SkipChromeVoxEnabledMessage());
75
76   chrome::ExecuteCommand(browser(), IDC_FOCUS_TOOLBAR);
77   // Might be "Google Chrome Toolbar" or "Chromium Toolbar".
78   EXPECT_TRUE(MatchPattern(monitor.GetNextUtterance(), "*oolbar*"));
79   EXPECT_EQ("Reload,", monitor.GetNextUtterance());
80   EXPECT_EQ("button", monitor.GetNextUtterance());
81 }
82
83 //
84 // Spoken feedback tests of the out-of-box experience.
85 //
86
87 class OobeSpokenFeedbackTest : public InProcessBrowserTest {
88  protected:
89   OobeSpokenFeedbackTest() {}
90   virtual ~OobeSpokenFeedbackTest() {}
91
92   virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
93     command_line->AppendSwitch(chromeos::switches::kLoginManager);
94     command_line->AppendSwitch(chromeos::switches::kForceLoginManagerInTests);
95     command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, "user");
96   }
97
98   virtual void SetUpOnMainThread() OVERRIDE {
99     AccessibilityManager::Get()->
100         SetProfileForTest(ProfileHelper::GetSigninProfile());
101   }
102
103  private:
104   DISALLOW_COPY_AND_ASSIGN(OobeSpokenFeedbackTest);
105 };
106
107 IN_PROC_BROWSER_TEST_F(OobeSpokenFeedbackTest, SpokenFeedbackInOobe) {
108   ui_controls::EnableUIControls();
109   EXPECT_FALSE(AccessibilityManager::Get()->IsSpokenFeedbackEnabled());
110
111   LoginDisplayHost* login_display_host = LoginDisplayHostImpl::default_host();
112   WebUILoginView* web_ui_login_view = login_display_host->GetWebUILoginView();
113   views::Widget* widget = web_ui_login_view->GetWidget();
114   gfx::NativeWindow window = widget->GetNativeWindow();
115
116   SpeechMonitor monitor;
117   AccessibilityManager::Get()->EnableSpokenFeedback(
118       true, ash::A11Y_NOTIFICATION_NONE);
119   EXPECT_TRUE(monitor.SkipChromeVoxEnabledMessage());
120
121   EXPECT_EQ("Select your language:", monitor.GetNextUtterance());
122   EXPECT_EQ("English ( United States)", monitor.GetNextUtterance());
123   EXPECT_TRUE(MatchPattern(monitor.GetNextUtterance(), "Combo box * of *"));
124   ui_controls::SendKeyPress(window, ui::VKEY_TAB, false, false, false, false);
125   EXPECT_EQ("Select your keyboard:", monitor.GetNextUtterance());
126 }
127
128 }  // namespace chromeos