OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <algorithm> | 5 #include <algorithm> |
6 | 6 |
7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
8 #include "chrome/browser/chromeos/input_method/input_method_util.h" | 8 #include "chrome/browser/chromeos/input_method/input_method_util.h" |
9 #include "chrome/browser/chromeos/input_method/mode_indicator_controller.h" | 9 #include "chrome/browser/chromeos/input_method/mode_indicator_controller.h" |
10 #include "chrome/test/base/in_process_browser_test.h" | 10 #include "chrome/test/base/in_process_browser_test.h" |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 InitializeIMF(); | 119 InitializeIMF(); |
120 | 120 |
121 InputMethodManager* imm = InputMethodManager::Get(); | 121 InputMethodManager* imm = InputMethodManager::Get(); |
122 ASSERT_TRUE(imm); | 122 ASSERT_TRUE(imm); |
123 | 123 |
124 std::vector<std::string> keyboard_layouts; | 124 std::vector<std::string> keyboard_layouts; |
125 keyboard_layouts.push_back( | 125 keyboard_layouts.push_back( |
126 extension_ime_util::GetInputMethodIDByEngineID("xkb:fr::fra")); | 126 extension_ime_util::GetInputMethodIDByEngineID("xkb:fr::fra")); |
127 | 127 |
128 // Add keyboard layouts to enable the mode indicator. | 128 // Add keyboard layouts to enable the mode indicator. |
129 imm->EnableLoginLayouts("fr", keyboard_layouts); | 129 imm->GetActiveIMEState()->EnableLoginLayouts("fr", keyboard_layouts); |
130 ASSERT_LT(1UL, imm->GetNumActiveInputMethods()); | 130 ASSERT_LT(1UL, imm->GetActiveIMEState()->GetNumActiveInputMethods()); |
131 | 131 |
132 chromeos::IMECandidateWindowHandlerInterface* candidate_window = | 132 chromeos::IMECandidateWindowHandlerInterface* candidate_window = |
133 chromeos::IMEBridge::Get()->GetCandidateWindowHandler(); | 133 chromeos::IMEBridge::Get()->GetCandidateWindowHandler(); |
134 candidate_window->FocusStateChanged(true); | 134 candidate_window->FocusStateChanged(true); |
135 | 135 |
136 // Check if the size of the mode indicator is expected. | 136 // Check if the size of the mode indicator is expected. |
137 gfx::Rect cursor1_bounds(100, 100, 1, 20); | 137 gfx::Rect cursor1_bounds(100, 100, 1, 20); |
138 gfx::Rect mi1_bounds; | 138 gfx::Rect mi1_bounds; |
139 { | 139 { |
140 ScopedModeIndicatorObserverForTesting observer; | 140 ScopedModeIndicatorObserverForTesting observer; |
141 candidate_window->SetCursorBounds(cursor1_bounds, cursor1_bounds); | 141 candidate_window->SetCursorBounds(cursor1_bounds, cursor1_bounds); |
142 EXPECT_TRUE(imm->SwitchToNextInputMethod()); | 142 EXPECT_TRUE(imm->GetActiveIMEState()->SwitchToNextInputMethod()); |
143 mi1_bounds = observer.last_bounds(); | 143 mi1_bounds = observer.last_bounds(); |
144 // The bounds should be bigger than the inner size. | 144 // The bounds should be bigger than the inner size. |
145 EXPECT_LE(kInnerSize, mi1_bounds.width()); | 145 EXPECT_LE(kInnerSize, mi1_bounds.width()); |
146 EXPECT_LE(kInnerSize, mi1_bounds.height()); | 146 EXPECT_LE(kInnerSize, mi1_bounds.height()); |
147 EXPECT_TRUE(observer.is_displayed()); | 147 EXPECT_TRUE(observer.is_displayed()); |
148 } | 148 } |
149 | 149 |
150 // Check if the location of the mode indicator is coresponded to | 150 // Check if the location of the mode indicator is coresponded to |
151 // the cursor bounds. | 151 // the cursor bounds. |
152 gfx::Rect cursor2_bounds(50, 200, 1, 20); | 152 gfx::Rect cursor2_bounds(50, 200, 1, 20); |
153 gfx::Rect mi2_bounds; | 153 gfx::Rect mi2_bounds; |
154 { | 154 { |
155 ScopedModeIndicatorObserverForTesting observer; | 155 ScopedModeIndicatorObserverForTesting observer; |
156 candidate_window->SetCursorBounds(cursor2_bounds, cursor2_bounds); | 156 candidate_window->SetCursorBounds(cursor2_bounds, cursor2_bounds); |
157 EXPECT_TRUE(imm->SwitchToNextInputMethod()); | 157 EXPECT_TRUE(imm->GetActiveIMEState()->SwitchToNextInputMethod()); |
158 mi2_bounds = observer.last_bounds(); | 158 mi2_bounds = observer.last_bounds(); |
159 EXPECT_TRUE(observer.is_displayed()); | 159 EXPECT_TRUE(observer.is_displayed()); |
160 } | 160 } |
161 | 161 |
162 EXPECT_EQ(cursor1_bounds.x() - cursor2_bounds.x(), | 162 EXPECT_EQ(cursor1_bounds.x() - cursor2_bounds.x(), |
163 mi1_bounds.x() - mi2_bounds.x()); | 163 mi1_bounds.x() - mi2_bounds.x()); |
164 EXPECT_EQ(cursor1_bounds.y() - cursor2_bounds.y(), | 164 EXPECT_EQ(cursor1_bounds.y() - cursor2_bounds.y(), |
165 mi1_bounds.y() - mi2_bounds.y()); | 165 mi1_bounds.y() - mi2_bounds.y()); |
166 EXPECT_EQ(mi1_bounds.width(), mi2_bounds.width()); | 166 EXPECT_EQ(mi1_bounds.width(), mi2_bounds.width()); |
167 EXPECT_EQ(mi1_bounds.height(), mi2_bounds.height()); | 167 EXPECT_EQ(mi1_bounds.height(), mi2_bounds.height()); |
168 | 168 |
169 const gfx::Rect screen_bounds = | 169 const gfx::Rect screen_bounds = |
170 ash::Shell::GetScreen()->GetDisplayMatching(cursor1_bounds).work_area(); | 170 ash::Shell::GetScreen()->GetDisplayMatching(cursor1_bounds).work_area(); |
171 | 171 |
172 // Check if the location of the mode indicator is concidered with | 172 // Check if the location of the mode indicator is concidered with |
173 // the screen size. | 173 // the screen size. |
174 const gfx::Rect cursor3_bounds(100, screen_bounds.bottom() - 25, 1, 20); | 174 const gfx::Rect cursor3_bounds(100, screen_bounds.bottom() - 25, 1, 20); |
175 gfx::Rect mi3_bounds; | 175 gfx::Rect mi3_bounds; |
176 { | 176 { |
177 ScopedModeIndicatorObserverForTesting observer; | 177 ScopedModeIndicatorObserverForTesting observer; |
178 candidate_window->SetCursorBounds(cursor3_bounds, cursor3_bounds); | 178 candidate_window->SetCursorBounds(cursor3_bounds, cursor3_bounds); |
179 EXPECT_TRUE(imm->SwitchToNextInputMethod()); | 179 EXPECT_TRUE(imm->GetActiveIMEState()->SwitchToNextInputMethod()); |
180 mi3_bounds = observer.last_bounds(); | 180 mi3_bounds = observer.last_bounds(); |
181 EXPECT_TRUE(observer.is_displayed()); | 181 EXPECT_TRUE(observer.is_displayed()); |
182 EXPECT_LT(mi3_bounds.bottom(), screen_bounds.bottom()); | 182 EXPECT_LT(mi3_bounds.bottom(), screen_bounds.bottom()); |
183 } | 183 } |
184 } | 184 } |
185 | 185 |
186 IN_PROC_BROWSER_TEST_F(ModeIndicatorBrowserTest, NumOfWidgets) { | 186 IN_PROC_BROWSER_TEST_F(ModeIndicatorBrowserTest, NumOfWidgets) { |
187 InitializeIMF(); | 187 InitializeIMF(); |
188 | 188 |
189 InputMethodManager* imm = InputMethodManager::Get(); | 189 InputMethodManager* imm = InputMethodManager::Get(); |
190 ASSERT_TRUE(imm); | 190 ASSERT_TRUE(imm); |
191 | 191 |
192 std::vector<std::string> keyboard_layouts; | 192 std::vector<std::string> keyboard_layouts; |
193 keyboard_layouts.push_back( | 193 keyboard_layouts.push_back( |
194 extension_ime_util::GetInputMethodIDByEngineID("xkb:fr::fra")); | 194 extension_ime_util::GetInputMethodIDByEngineID("xkb:fr::fra")); |
195 | 195 |
196 // Add keyboard layouts to enable the mode indicator. | 196 // Add keyboard layouts to enable the mode indicator. |
197 imm->EnableLoginLayouts("fr", keyboard_layouts); | 197 imm->GetActiveIMEState()->EnableLoginLayouts("fr", keyboard_layouts); |
198 ASSERT_LT(1UL, imm->GetNumActiveInputMethods()); | 198 ASSERT_LT(1UL, imm->GetActiveIMEState()->GetNumActiveInputMethods()); |
199 | 199 |
200 chromeos::IMECandidateWindowHandlerInterface* candidate_window = | 200 chromeos::IMECandidateWindowHandlerInterface* candidate_window = |
201 chromeos::IMEBridge::Get()->GetCandidateWindowHandler(); | 201 chromeos::IMEBridge::Get()->GetCandidateWindowHandler(); |
202 candidate_window->FocusStateChanged(true); | 202 candidate_window->FocusStateChanged(true); |
203 | 203 |
204 { | 204 { |
205 ScopedModeIndicatorObserverForTesting observer; | 205 ScopedModeIndicatorObserverForTesting observer; |
206 | 206 |
207 EXPECT_TRUE(imm->SwitchToNextInputMethod()); | 207 EXPECT_TRUE(imm->GetActiveIMEState()->SwitchToNextInputMethod()); |
208 EXPECT_EQ(1UL, observer.max_widget_list_size()); | 208 EXPECT_EQ(1UL, observer.max_widget_list_size()); |
209 const views::Widget* widget1 = observer.widget_list()[0]; | 209 const views::Widget* widget1 = observer.widget_list()[0]; |
210 | 210 |
211 EXPECT_TRUE(imm->SwitchToNextInputMethod()); | 211 EXPECT_TRUE(imm->GetActiveIMEState()->SwitchToNextInputMethod()); |
212 EXPECT_EQ(2UL, observer.max_widget_list_size()); | 212 EXPECT_EQ(2UL, observer.max_widget_list_size()); |
213 | 213 |
214 // When a new mode indicator is displayed, the previous one should be | 214 // When a new mode indicator is displayed, the previous one should be |
215 // closed. | 215 // closed. |
216 content::RunAllPendingInMessageLoop(); | 216 content::RunAllPendingInMessageLoop(); |
217 EXPECT_EQ(1UL, observer.widget_list_size()); | 217 EXPECT_EQ(1UL, observer.widget_list_size()); |
218 const views::Widget* widget2 = observer.widget_list()[0]; | 218 const views::Widget* widget2 = observer.widget_list()[0]; |
219 EXPECT_NE(widget1, widget2); | 219 EXPECT_NE(widget1, widget2); |
220 } | 220 } |
221 } | 221 } |
222 } // namespace input_method | 222 } // namespace input_method |
223 } // namespace chromeos | 223 } // namespace chromeos |
OLD | NEW |