Index: ash/system/ime/tray_ime_chromeos_unittest.cc |
diff --git a/ash/system/chromeos/virtual_keyboard/tray_keyboard_lock_unittest.cc b/ash/system/ime/tray_ime_chromeos_unittest.cc |
similarity index 51% |
copy from ash/system/chromeos/virtual_keyboard/tray_keyboard_lock_unittest.cc |
copy to ash/system/ime/tray_ime_chromeos_unittest.cc |
index c95417712524aef2799f97a75e5f002f3c7a49fb..c73375ce63645f77f3133c65e6e2928603f2fdaa 100644 |
--- a/ash/system/chromeos/virtual_keyboard/tray_keyboard_lock_unittest.cc |
+++ b/ash/system/ime/tray_ime_chromeos_unittest.cc |
@@ -2,11 +2,12 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include "ash/system/chromeos/virtual_keyboard/tray_keyboard_lock.h" |
+#include "ash/system/ime/tray_ime_chromeos.h" |
#include "ash/accessibility_delegate.h" |
#include "ash/shell.h" |
#include "ash/system/status_area_widget.h" |
+#include "ash/system/tray/system_tray_notifier.h" |
#include "ash/test/ash_test_base.h" |
#include "ash/test/status_area_widget_test_helper.h" |
#include "ash/test/virtual_keyboard_test_helper.h" |
@@ -16,16 +17,18 @@ |
namespace ash { |
-class TrayKeyboardLockTest : public test::AshTestBase { |
+class TrayIMETest : public test::AshTestBase { |
public: |
- TrayKeyboardLockTest() {} |
- virtual ~TrayKeyboardLockTest() {} |
+ TrayIMETest() {} |
+ virtual ~TrayIMETest() {} |
- TrayKeyboardLock* tray() { return tray_.get(); } |
+ TrayIME* tray() { return tray_.get(); } |
views::View* default_view() { return default_view_.get(); } |
- // Sets up a TrayKeyboardLock and its default view. |
+ views::View* detailed_view() { return detailed_view_.get(); } |
+ |
+ // Sets up a TrayIME and its default view. |
void SetUpForStatusAreaWidget(StatusAreaWidget* status_area_widget); |
// Mocks enabling the a11y virtual keyboard since the actual a11y manager |
@@ -33,27 +36,37 @@ class TrayKeyboardLockTest : public test::AshTestBase { |
void SetAccessibilityKeyboardEnabled(bool enabled); |
// Resets |tray_| and |default_view_| so that all components of |
- // TrayKeyboardLock have been cleared. Tests may then call |
+ // TrayIME have been cleared. Tests may then call |
// SetUpForStatusAreaWidget in order to initialize the components. |
void TearDownViews(); |
+ // Sets the current number of active IMEs. |
+ void SetIMELength(int length); |
+ |
+ // Returns the view in the detailed views scroll content at the provided |
+ // index. |
+ views::View* GetScrollChildView(int index); |
+ |
// test::AshTestBase: |
virtual void SetUp() override; |
virtual void TearDown() override; |
private: |
- scoped_ptr<TrayKeyboardLock> tray_; |
+ scoped_ptr<TrayIME> tray_; |
scoped_ptr<views::View> default_view_; |
+ scoped_ptr<views::View> detailed_view_; |
}; |
-void TrayKeyboardLockTest::SetUpForStatusAreaWidget( |
+void TrayIMETest::SetUpForStatusAreaWidget( |
StatusAreaWidget* status_area_widget) { |
- tray_.reset(new TrayKeyboardLock(status_area_widget->system_tray())); |
+ tray_.reset(new TrayIME(status_area_widget->system_tray())); |
default_view_.reset(tray_->CreateDefaultView( |
StatusAreaWidgetTestHelper::GetUserLoginStatus())); |
+ detailed_view_.reset(tray_->CreateDetailedView( |
+ StatusAreaWidgetTestHelper::GetUserLoginStatus())); |
} |
-void TrayKeyboardLockTest::SetAccessibilityKeyboardEnabled(bool enabled) { |
+void TrayIMETest::SetAccessibilityKeyboardEnabled(bool enabled) { |
Shell::GetInstance()->accessibility_delegate()->SetVirtualKeyboardEnabled( |
enabled); |
keyboard::SetAccessibilityKeyboardEnabled(enabled); |
@@ -64,32 +77,57 @@ void TrayKeyboardLockTest::SetAccessibilityKeyboardEnabled(bool enabled) { |
notification); |
} |
-void TrayKeyboardLockTest::TearDownViews() { |
- default_view_.reset(); |
+void TrayIMETest::TearDownViews() { |
tray_.reset(); |
+ default_view_.reset(); |
+ detailed_view_.reset(); |
+} |
+ |
+void TrayIMETest::SetIMELength(int length) { |
+ tray_->ime_list_.clear(); |
+ IMEInfo ime; |
+ for (int i = 0; i < length; i++) { |
+ tray_->ime_list_.push_back(ime); |
+ } |
+ tray_->Update(); |
} |
-void TrayKeyboardLockTest::SetUp() { |
+views::View* TrayIMETest::GetScrollChildView(int index) { |
+ TrayDetailsView* details = static_cast<TrayDetailsView*>(detailed_view()); |
+ views::View* content = details->scroll_content(); |
+ EXPECT_TRUE(content); |
+ EXPECT_GT(content->child_count(), index); |
+ return content->child_at(index); |
+} |
+ |
+void TrayIMETest::SetUp() { |
base::CommandLine::ForCurrentProcess()->AppendSwitch( |
keyboard::switches::kEnableAutoVirtualKeyboard); |
test::AshTestBase::SetUp(); |
SetUpForStatusAreaWidget(StatusAreaWidgetTestHelper::GetStatusAreaWidget()); |
} |
-void TrayKeyboardLockTest::TearDown() { |
+void TrayIMETest::TearDown() { |
SetAccessibilityKeyboardEnabled(false); |
TearDownViews(); |
test::AshTestBase::TearDown(); |
} |
-// Tests that when the tray is initially created that the default view is |
-// hidden. |
-TEST_F(TrayKeyboardLockTest, HiddenOnCreation) { |
+// Tests that if the keyboard is not suppressed the default view is hidden |
+// if less than 2 IMEs are present. |
+TEST_F(TrayIMETest, HiddenWithNoIMEs) { |
+ SetIMELength(0); |
+ EXPECT_FALSE(default_view()->visible()); |
+ SetIMELength(1); |
EXPECT_FALSE(default_view()->visible()); |
+ SetIMELength(2); |
+ EXPECT_TRUE(default_view()->visible()); |
} |
-// Tests that the default view and tray are hidden when a11y is enabled. |
-TEST_F(TrayKeyboardLockTest, HidesOnA11yEnabled) { |
+// Tests that if no IMEs are present the default view is hidden when a11y is |
+// enabled. |
+TEST_F(TrayIMETest, HidesOnA11yEnabled) { |
+ SetIMELength(0); |
test::VirtualKeyboardTestHelper::SuppressKeyboard(); |
EXPECT_TRUE(default_view()->visible()); |
// Enable a11y keyboard. |
@@ -100,22 +138,25 @@ TEST_F(TrayKeyboardLockTest, HidesOnA11yEnabled) { |
EXPECT_TRUE(default_view()->visible()); |
} |
-TEST_F(TrayKeyboardLockTest, PerformActionOnDefaultView) { |
+// Tests that clicking on the keyboard toggle causes the virtual keyboard |
+// to toggle between enabled and disabled. |
+TEST_F(TrayIMETest, PerformActionOnDetailedView) { |
+ SetIMELength(0); |
test::VirtualKeyboardTestHelper::SuppressKeyboard(); |
EXPECT_FALSE(keyboard::IsKeyboardEnabled()); |
- EXPECT_TRUE(default_view()->visible()); |
- |
- ui::GestureEvent tap( |
- 0, 0, 0, base::TimeDelta(), ui::GestureEventDetails(ui::ET_GESTURE_TAP)); |
- default_view()->OnGestureEvent(&tap); |
+ views::View* toggle = GetScrollChildView(0); |
+ ui::GestureEvent tap(0, 0, 0, base::TimeDelta(), |
+ ui::GestureEventDetails(ui::ET_GESTURE_TAP)); |
+ // Enable the keyboard. |
+ toggle->OnGestureEvent(&tap); |
EXPECT_TRUE(keyboard::IsKeyboardEnabled()); |
- EXPECT_TRUE(default_view()->visible()); |
- |
- tap = ui::GestureEvent( |
- 0, 0, 0, base::TimeDelta(), ui::GestureEventDetails(ui::ET_GESTURE_TAP)); |
- default_view()->OnGestureEvent(&tap); |
+ // With no IMEs the toggle should be the first child. |
+ toggle = GetScrollChildView(0); |
+ // Clicking again should disable the keyboard. |
+ tap = ui::GestureEvent(0, 0, 0, base::TimeDelta(), |
+ ui::GestureEventDetails(ui::ET_GESTURE_TAP)); |
+ toggle->OnGestureEvent(&tap); |
EXPECT_FALSE(keyboard::IsKeyboardEnabled()); |
Mr4D (OOO till 08-26)
2015/01/12 22:35:37
If the opposite is now true (!visible) - chouldn't
rsadam
2015/01/13 00:05:34
I'm not sure I follow - the keyboard is disabled,
Mr4D (OOO till 08-26)
2015/01/13 15:04:05
Oh - I have meant the test which you have removed
|
- EXPECT_TRUE(default_view()->visible()); |
} |
} // namespace ash |