• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2010 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 "chrome/browser/accessibility_events.h"
6 #include "chrome/browser/chromeos/login/wizard_accessibility_handler.h"
7 #include "testing/gtest/include/gtest/gtest.h"
8 
9 using chromeos::EarconType;
10 using chromeos::WizardAccessibilityHandler;
11 
12 namespace chromeos {
13 
14 class WizardAccessibilityHandlerTest : public testing::Test {
15  protected:
ChangeText(WizardAccessibilityHandler * handler,AccessibilityTextBoxInfo * textbox_info,const std::string & value,int selection_start,int selection_end,std::string * description)16   void ChangeText(WizardAccessibilityHandler* handler,
17                   AccessibilityTextBoxInfo* textbox_info,
18                   const std::string& value,
19                   int selection_start,
20                   int selection_end,
21                   std::string* description) {
22     textbox_info->SetValue(value, selection_start, selection_end);
23     EarconType earcon = chromeos::NO_EARCON;
24     handler->DescribeAccessibilityEvent(
25         NotificationType::ACCESSIBILITY_TEXT_CHANGED,
26         textbox_info,
27         description,
28         &earcon);
29   }
30 };
31 
TEST_F(WizardAccessibilityHandlerTest,TestFocusEvents)32 TEST_F(WizardAccessibilityHandlerTest, TestFocusEvents) {
33   WizardAccessibilityHandler handler;
34 
35   std::string description;
36   EarconType earcon;
37 
38   // No need to test every possible control, but test several types
39   // to exercise different types of string concatenation.
40 
41   // NOTE: unittests are forced to run under the en-US locale, so it's
42   // safe to do these string comparisons without using l10n_util.
43 
44   // Test a simple control.
45   std::string button_name = "Save";
46   AccessibilityButtonInfo button_info(NULL, button_name);
47   handler.DescribeAccessibilityEvent(
48       NotificationType::ACCESSIBILITY_CONTROL_FOCUSED,
49       &button_info,
50       &description,
51       &earcon);
52   EXPECT_EQ(chromeos::EARCON_BUTTON, earcon);
53   EXPECT_EQ("Save Button", description);
54 
55   // Test a control with multiple states.
56   std::string checkbox_name = "Accessibility";
57   AccessibilityCheckboxInfo checkbox_info(NULL, checkbox_name, false);
58   handler.DescribeAccessibilityEvent(
59       NotificationType::ACCESSIBILITY_CONTROL_FOCUSED,
60       &checkbox_info,
61       &description,
62       &earcon);
63   EXPECT_EQ(chromeos::EARCON_CHECK_OFF, earcon);
64   EXPECT_EQ("Accessibility Unchecked check box", description);
65   checkbox_info.SetChecked(true);
66   handler.DescribeAccessibilityEvent(
67       NotificationType::ACCESSIBILITY_CONTROL_FOCUSED,
68       &checkbox_info,
69       &description,
70       &earcon);
71   EXPECT_EQ(chromeos::EARCON_CHECK_ON, earcon);
72   EXPECT_EQ("Accessibility Checked check box", description);
73 
74   // Test a control with a value and index.
75   std::string combobox_name = "Language";
76   std::string combobox_value = "English";
77   AccessibilityComboBoxInfo combobox_info(
78       NULL, combobox_name, combobox_value, 12, 35);
79   handler.DescribeAccessibilityEvent(
80       NotificationType::ACCESSIBILITY_CONTROL_FOCUSED,
81       &combobox_info,
82       &description,
83       &earcon);
84   EXPECT_EQ(chromeos::EARCON_LISTBOX, earcon);
85   EXPECT_EQ("English Language Combo box 13 of 35", description);
86 }
87 
TEST_F(WizardAccessibilityHandlerTest,TestTextEvents)88 TEST_F(WizardAccessibilityHandlerTest, TestTextEvents) {
89   WizardAccessibilityHandler handler;
90 
91   std::string description;
92   EarconType earcon;
93 
94   AccessibilityTextBoxInfo textbox_info(NULL, "", false);
95   handler.DescribeAccessibilityEvent(
96       NotificationType::ACCESSIBILITY_CONTROL_FOCUSED,
97       &textbox_info,
98       &description,
99       &earcon);
100   EXPECT_EQ("Text box", description);
101   EXPECT_EQ(chromeos::EARCON_TEXTBOX, earcon);
102 
103   // Type "hello world.", one character at a time.
104   ChangeText(&handler, &textbox_info, "h", 1, 1, &description);
105   EXPECT_EQ("h", description);
106   ChangeText(&handler, &textbox_info, "he", 2, 2, &description);
107   EXPECT_EQ("e", description);
108   ChangeText(&handler, &textbox_info, "hel", 3, 3, &description);
109   EXPECT_EQ("l", description);
110   ChangeText(&handler, &textbox_info, "hell", 4, 4, &description);
111   EXPECT_EQ("l", description);
112   ChangeText(&handler, &textbox_info, "hello", 5, 5, &description);
113   EXPECT_EQ("o", description);
114   ChangeText(&handler, &textbox_info, "hello ", 6, 6, &description);
115   EXPECT_EQ("Space", description);
116   ChangeText(&handler, &textbox_info, "hello w", 7, 7, &description);
117   EXPECT_EQ("w", description);
118   ChangeText(&handler, &textbox_info, "hello wo", 8, 8, &description);
119   EXPECT_EQ("o", description);
120   ChangeText(&handler, &textbox_info, "hello wor", 9, 9, &description);
121   EXPECT_EQ("r", description);
122   ChangeText(&handler, &textbox_info, "hello worl", 10, 10, &description);
123   EXPECT_EQ("l", description);
124   ChangeText(&handler, &textbox_info, "hello world", 11, 11, &description);
125   EXPECT_EQ("d", description);
126   ChangeText(&handler, &textbox_info, "hello world.", 12, 12, &description);
127   EXPECT_EQ("Period", description);
128 
129   // Move by characters and by words.
130   ChangeText(&handler, &textbox_info, "hello world.", 11, 11, &description);
131   EXPECT_EQ("Period", description);
132   ChangeText(&handler, &textbox_info, "hello world.", 6, 6, &description);
133   EXPECT_EQ("world", description);
134   ChangeText(&handler, &textbox_info, "hello world.", 0, 0, &description);
135   EXPECT_EQ("hello ", description);
136   ChangeText(&handler, &textbox_info, "hello world.", 1, 1, &description);
137   EXPECT_EQ("h", description);
138   ChangeText(&handler, &textbox_info, "hello world.", 5, 5, &description);
139   EXPECT_EQ("ello", description);
140 
141   // Delete characters and words.
142   ChangeText(&handler, &textbox_info, "hell world.", 4, 4, &description);
143   EXPECT_EQ("o", description);
144   ChangeText(&handler, &textbox_info, "hel world.", 3, 3, &description);
145   EXPECT_EQ("l", description);
146   ChangeText(&handler, &textbox_info, " world.", 0, 0, &description);
147   EXPECT_EQ("hel", description);
148 
149   // Select characters and words.
150   ChangeText(&handler, &textbox_info, " world.", 0, 1, &description);
151   EXPECT_EQ("Space", description);
152   ChangeText(&handler, &textbox_info, " world.", 0, 4, &description);
153   EXPECT_EQ("wor", description);
154   ChangeText(&handler, &textbox_info, " world.", 1, 4, &description);
155   EXPECT_EQ("Space", description);
156   ChangeText(&handler, &textbox_info, " world.", 4, 4, &description);
157   EXPECT_EQ("Unselected", description);
158 
159   // If the string suddenly changes, it should just speak the new value.
160   ChangeText(&handler, &textbox_info, "Potato", 0, 0, &description);
161   EXPECT_EQ("Potato", description);
162 }
163 
164 }
165