Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(195)

Unified Diff: ash/system/ime/tray_ime_chromeos_unittest.cc

Issue 843603004: Moves smart deploy UI into the IME tray. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Unsplit. Remove IME tray in Linux. Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ash/system/ime/tray_ime_chromeos.cc ('k') | ash/system/tray/system_tray.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ash/system/ime/tray_ime_chromeos_unittest.cc
diff --git a/ash/system/ime/tray_ime_chromeos_unittest.cc b/ash/system/ime/tray_ime_chromeos_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..f891f5a133579e62f4daf2cb9c7aa933d403dca4
--- /dev/null
+++ b/ash/system/ime/tray_ime_chromeos_unittest.cc
@@ -0,0 +1,164 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#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"
+#include "base/command_line.h"
+#include "ui/keyboard/keyboard_switches.h"
+#include "ui/keyboard/keyboard_util.h"
+
+namespace ash {
+
+class TrayIMETest : public test::AshTestBase {
+ public:
+ TrayIMETest() {}
+ virtual ~TrayIMETest() {}
+
+ TrayIME* tray() { return tray_.get(); }
+
+ views::View* default_view() { return default_view_.get(); }
+
+ 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
+ // is not created in ash tests.
+ void SetAccessibilityKeyboardEnabled(bool enabled);
+
+ // Resets |tray_| and |default_view_| so that all components of
+ // 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<TrayIME> tray_;
+ scoped_ptr<views::View> default_view_;
+ scoped_ptr<views::View> detailed_view_;
+};
+
+void TrayIMETest::SetUpForStatusAreaWidget(
+ StatusAreaWidget* status_area_widget) {
+ tray_.reset(new TrayIME(status_area_widget->system_tray()));
+ default_view_.reset(tray_->CreateDefaultView(
+ StatusAreaWidgetTestHelper::GetUserLoginStatus()));
+ detailed_view_.reset(tray_->CreateDetailedView(
+ StatusAreaWidgetTestHelper::GetUserLoginStatus()));
+}
+
+void TrayIMETest::SetAccessibilityKeyboardEnabled(bool enabled) {
+ Shell::GetInstance()->accessibility_delegate()->SetVirtualKeyboardEnabled(
+ enabled);
+ keyboard::SetAccessibilityKeyboardEnabled(enabled);
+ ui::AccessibilityNotificationVisibility notification =
+ enabled ? ui::AccessibilityNotificationVisibility::A11Y_NOTIFICATION_SHOW
+ : ui::AccessibilityNotificationVisibility::A11Y_NOTIFICATION_NONE;
+ Shell::GetInstance()->system_tray_notifier()->NotifyAccessibilityModeChanged(
+ notification);
+}
+
+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();
+}
+
+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 TrayIMETest::TearDown() {
+ SetAccessibilityKeyboardEnabled(false);
+ TearDownViews();
+ test::AshTestBase::TearDown();
+}
+
+// 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 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.
+ SetAccessibilityKeyboardEnabled(true);
+ EXPECT_FALSE(default_view()->visible());
+ // Disable the a11y keyboard.
+ SetAccessibilityKeyboardEnabled(false);
+ EXPECT_TRUE(default_view()->visible());
+}
+
+// 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());
+ 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());
+ // 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());
+ EXPECT_TRUE(default_view()->visible());
+}
+
+} // namespace ash
« no previous file with comments | « ash/system/ime/tray_ime_chromeos.cc ('k') | ash/system/tray/system_tray.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698