| 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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 chromeos::IMECandidateWindowHandlerInterface* candidate_window = | 142 chromeos::IMECandidateWindowHandlerInterface* candidate_window = |
| 143 chromeos::IMEBridge::Get()->GetCandidateWindowHandler(); | 143 chromeos::IMEBridge::Get()->GetCandidateWindowHandler(); |
| 144 candidate_window->FocusStateChanged(true); | 144 candidate_window->FocusStateChanged(true); |
| 145 | 145 |
| 146 // Check if the size of the mode indicator is expected. | 146 // Check if the size of the mode indicator is expected. |
| 147 gfx::Rect cursor1_bounds(100, 100, 1, 20); | 147 gfx::Rect cursor1_bounds(100, 100, 1, 20); |
| 148 gfx::Rect mi1_bounds; | 148 gfx::Rect mi1_bounds; |
| 149 { | 149 { |
| 150 ScopedModeIndicatorObserverForTesting observer; | 150 ScopedModeIndicatorObserverForTesting observer; |
| 151 candidate_window->SetCursorBounds(cursor1_bounds, cursor1_bounds); | 151 candidate_window->SetCursorBounds(cursor1_bounds, cursor1_bounds); |
| 152 EXPECT_TRUE(imm->SwitchToNextInputMethod()); | 152 imm->SwitchToNextInputMethod(); |
| 153 mi1_bounds = observer.last_bounds(); | 153 mi1_bounds = observer.last_bounds(); |
| 154 // The bounds should be bigger than the inner size. | 154 // The bounds should be bigger than the inner size. |
| 155 EXPECT_LE(kInnerSize, mi1_bounds.width()); | 155 EXPECT_LE(kInnerSize, mi1_bounds.width()); |
| 156 EXPECT_LE(kInnerSize, mi1_bounds.height()); | 156 EXPECT_LE(kInnerSize, mi1_bounds.height()); |
| 157 EXPECT_TRUE(observer.is_displayed()); | 157 EXPECT_TRUE(observer.is_displayed()); |
| 158 } | 158 } |
| 159 | 159 |
| 160 // Check if the location of the mode indicator is coresponded to | 160 // Check if the location of the mode indicator is coresponded to |
| 161 // the cursor bounds. | 161 // the cursor bounds. |
| 162 gfx::Rect cursor2_bounds(50, 200, 1, 20); | 162 gfx::Rect cursor2_bounds(50, 200, 1, 20); |
| 163 gfx::Rect mi2_bounds; | 163 gfx::Rect mi2_bounds; |
| 164 { | 164 { |
| 165 ScopedModeIndicatorObserverForTesting observer; | 165 ScopedModeIndicatorObserverForTesting observer; |
| 166 candidate_window->SetCursorBounds(cursor2_bounds, cursor2_bounds); | 166 candidate_window->SetCursorBounds(cursor2_bounds, cursor2_bounds); |
| 167 EXPECT_TRUE(imm->SwitchToNextInputMethod()); | 167 imm->SwitchToNextInputMethod(); |
| 168 mi2_bounds = observer.last_bounds(); | 168 mi2_bounds = observer.last_bounds(); |
| 169 EXPECT_TRUE(observer.is_displayed()); | 169 EXPECT_TRUE(observer.is_displayed()); |
| 170 } | 170 } |
| 171 | 171 |
| 172 EXPECT_EQ(cursor1_bounds.x() - cursor2_bounds.x(), | 172 EXPECT_EQ(cursor1_bounds.x() - cursor2_bounds.x(), |
| 173 mi1_bounds.x() - mi2_bounds.x()); | 173 mi1_bounds.x() - mi2_bounds.x()); |
| 174 EXPECT_EQ(cursor1_bounds.y() - cursor2_bounds.y(), | 174 EXPECT_EQ(cursor1_bounds.y() - cursor2_bounds.y(), |
| 175 mi1_bounds.y() - mi2_bounds.y()); | 175 mi1_bounds.y() - mi2_bounds.y()); |
| 176 EXPECT_EQ(mi1_bounds.width(), mi2_bounds.width()); | 176 EXPECT_EQ(mi1_bounds.width(), mi2_bounds.width()); |
| 177 EXPECT_EQ(mi1_bounds.height(), mi2_bounds.height()); | 177 EXPECT_EQ(mi1_bounds.height(), mi2_bounds.height()); |
| 178 | 178 |
| 179 const gfx::Rect screen_bounds = | 179 const gfx::Rect screen_bounds = |
| 180 ash::Shell::GetScreen()->GetDisplayMatching(cursor1_bounds).work_area(); | 180 ash::Shell::GetScreen()->GetDisplayMatching(cursor1_bounds).work_area(); |
| 181 | 181 |
| 182 // Check if the location of the mode indicator is concidered with | 182 // Check if the location of the mode indicator is concidered with |
| 183 // the screen size. | 183 // the screen size. |
| 184 const gfx::Rect cursor3_bounds(100, screen_bounds.bottom() - 25, 1, 20); | 184 const gfx::Rect cursor3_bounds(100, screen_bounds.bottom() - 25, 1, 20); |
| 185 gfx::Rect mi3_bounds; | 185 gfx::Rect mi3_bounds; |
| 186 { | 186 { |
| 187 ScopedModeIndicatorObserverForTesting observer; | 187 ScopedModeIndicatorObserverForTesting observer; |
| 188 candidate_window->SetCursorBounds(cursor3_bounds, cursor3_bounds); | 188 candidate_window->SetCursorBounds(cursor3_bounds, cursor3_bounds); |
| 189 EXPECT_TRUE(imm->SwitchToNextInputMethod()); | 189 imm->SwitchToNextInputMethod(); |
| 190 mi3_bounds = observer.last_bounds(); | 190 mi3_bounds = observer.last_bounds(); |
| 191 EXPECT_TRUE(observer.is_displayed()); | 191 EXPECT_TRUE(observer.is_displayed()); |
| 192 EXPECT_LT(mi3_bounds.bottom(), screen_bounds.bottom()); | 192 EXPECT_LT(mi3_bounds.bottom(), screen_bounds.bottom()); |
| 193 } | 193 } |
| 194 } | 194 } |
| 195 | 195 |
| 196 IN_PROC_BROWSER_TEST_F(ModeIndicatorBrowserTest, NumOfWidgets) { | 196 IN_PROC_BROWSER_TEST_F(ModeIndicatorBrowserTest, NumOfWidgets) { |
| 197 InitializeIMF(); | 197 InitializeIMF(); |
| 198 | 198 |
| 199 InputMethodManager* imm = InputMethodManager::Get(); | 199 InputMethodManager* imm = InputMethodManager::Get(); |
| 200 ASSERT_TRUE(imm); | 200 ASSERT_TRUE(imm); |
| 201 | 201 |
| 202 std::vector<std::string> keyboard_layouts; | 202 std::vector<std::string> keyboard_layouts; |
| 203 keyboard_layouts.push_back( | 203 keyboard_layouts.push_back( |
| 204 extension_ime_util::GetInputMethodIDByEngineID("xkb:fr::fra")); | 204 extension_ime_util::GetInputMethodIDByEngineID("xkb:fr::fra")); |
| 205 | 205 |
| 206 // Add keyboard layouts to enable the mode indicator. | 206 // Add keyboard layouts to enable the mode indicator. |
| 207 imm->EnableLoginLayouts("fr", keyboard_layouts); | 207 imm->EnableLoginLayouts("fr", keyboard_layouts); |
| 208 ASSERT_LT(1UL, imm->GetNumActiveInputMethods()); | 208 ASSERT_LT(1UL, imm->GetNumActiveInputMethods()); |
| 209 | 209 |
| 210 chromeos::IMECandidateWindowHandlerInterface* candidate_window = | 210 chromeos::IMECandidateWindowHandlerInterface* candidate_window = |
| 211 chromeos::IMEBridge::Get()->GetCandidateWindowHandler(); | 211 chromeos::IMEBridge::Get()->GetCandidateWindowHandler(); |
| 212 candidate_window->FocusStateChanged(true); | 212 candidate_window->FocusStateChanged(true); |
| 213 | 213 |
| 214 { | 214 { |
| 215 ScopedModeIndicatorObserverForTesting observer; | 215 ScopedModeIndicatorObserverForTesting observer; |
| 216 | 216 |
| 217 EXPECT_TRUE(imm->SwitchToNextInputMethod()); | 217 imm->SwitchToNextInputMethod(); |
| 218 EXPECT_EQ(1UL, observer.max_widget_list_size()); | 218 EXPECT_EQ(1UL, observer.max_widget_list_size()); |
| 219 const views::Widget* widget1 = observer.widget_list()[0]; | 219 const views::Widget* widget1 = observer.widget_list()[0]; |
| 220 | 220 |
| 221 EXPECT_TRUE(imm->SwitchToNextInputMethod()); | 221 imm->SwitchToNextInputMethod(); |
| 222 EXPECT_EQ(2UL, observer.max_widget_list_size()); | 222 EXPECT_EQ(2UL, observer.max_widget_list_size()); |
| 223 | 223 |
| 224 // When a new mode indicator is displayed, the previous one should be | 224 // When a new mode indicator is displayed, the previous one should be |
| 225 // closed. | 225 // closed. |
| 226 content::RunAllPendingInMessageLoop(); | 226 content::RunAllPendingInMessageLoop(); |
| 227 EXPECT_EQ(1UL, observer.widget_list_size()); | 227 EXPECT_EQ(1UL, observer.widget_list_size()); |
| 228 const views::Widget* widget2 = observer.widget_list()[0]; | 228 const views::Widget* widget2 = observer.widget_list()[0]; |
| 229 EXPECT_NE(widget1, widget2); | 229 EXPECT_NE(widget1, widget2); |
| 230 } | 230 } |
| 231 } | 231 } |
| 232 } // namespace input_method | 232 } // namespace input_method |
| 233 } // namespace chromeos | 233 } // namespace chromeos |
| OLD | NEW |