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

Unified Diff: ash/system/chromeos/ime_menu/ime_menu_tray_unittest.cc

Issue 1996563002: Add ImeMenuTray element. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Change SetWindowState() with SetImeWindow(). Created 4 years, 6 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
Index: ash/system/chromeos/ime_menu/ime_menu_tray_unittest.cc
diff --git a/ash/system/chromeos/ime_menu/ime_menu_tray_unittest.cc b/ash/system/chromeos/ime_menu/ime_menu_tray_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..a62c6b0bf38ffca35f599a4508902470c051b037
--- /dev/null
+++ b/ash/system/chromeos/ime_menu/ime_menu_tray_unittest.cc
@@ -0,0 +1,118 @@
+// Copyright 2016 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/chromeos/ime_menu/ime_menu_tray.h"
+
+#include "ash/common/system/tray/system_tray_notifier.h"
+#include "ash/common/wm_shell.h"
+#include "ash/system/status_area_widget.h"
+#include "ash/system/tray/system_tray.h"
+#include "ash/test/ash_test_base.h"
+#include "ash/test/status_area_widget_test_helper.h"
+#include "ash/test/test_system_tray_delegate.h"
+#include "base/strings/utf_string_conversions.h"
+#include "base/time/time.h"
+#include "ui/aura/window.h"
+#include "ui/events/event.h"
+#include "ui/views/controls/label.h"
+#include "ui/wm/core/window_util.h"
+
+namespace ash {
+
+namespace {
+
+ImeMenuTray* GetTray() {
+ return StatusAreaWidgetTestHelper::GetStatusAreaWidget()->ime_menu_tray();
+}
+
+} // namespace
+
+class ImeMenuTrayTest : public test::AshTestBase {
+ public:
+ ImeMenuTrayTest() {}
+ ~ImeMenuTrayTest() override {}
+
+ protected:
+ // Returns the label text of the tray.
+ const base::string16& GetTrayText() { return GetTray()->label_->text(); }
+
+ // Returns true if the background color of the tray is active.
+ bool IsTrayBackgroundActive() {
+ return GetTray()->draw_background_as_active();
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(ImeMenuTrayTest);
+};
+
+TEST_F(ImeMenuTrayTest, ImeMenuTrayVisibility) {
+ ASSERT_TRUE(GetTray());
+ ASSERT_FALSE(GetTray()->visible());
+
+ WmShell::Get()->system_tray_notifier()->NotifyRefreshIMEMenu(true);
+ ASSERT_TRUE(GetTray()->visible());
+
+ WmShell::Get()->system_tray_notifier()->NotifyRefreshIMEMenu(false);
+ ASSERT_FALSE(GetTray()->visible());
+}
+
+TEST_F(ImeMenuTrayTest, TrayLabelTest) {
+ ASSERT_TRUE(GetTray());
+ ASSERT_TRUE(GetSystemTrayDelegate());
+
+ std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0));
+ GetTray()->SetImeWindow(window.get());
+
+ // Changes the input method to "ime1".
+ IMEInfo info1;
+ info1.id = "ime1";
+ info1.name = base::UTF8ToUTF16("English");
+ info1.medium_name = base::UTF8ToUTF16("English");
+ info1.short_name = base::UTF8ToUTF16("US");
+ info1.third_party = false;
+ info1.selected = true;
+ GetSystemTrayDelegate()->SetCurrentIME(info1);
+ WmShell::Get()->system_tray_notifier()->NotifyRefreshIME();
+ ASSERT_EQ(info1.short_name, GetTrayText());
+
+ // Changes the input method to a third-party IME extension.
+ IMEInfo info2;
+ info2.id = "ime2";
+ info2.name = base::UTF8ToUTF16("English UK");
+ info2.medium_name = base::UTF8ToUTF16("English UK");
+ info2.short_name = base::UTF8ToUTF16("UK");
+ info2.third_party = true;
+ info2.selected = true;
+ GetSystemTrayDelegate()->SetCurrentIME(info2);
+ WmShell::Get()->system_tray_notifier()->NotifyRefreshIME();
+ ASSERT_EQ(info2.short_name + base::UTF8ToUTF16("*"), GetTrayText());
+}
+
+TEST_F(ImeMenuTrayTest, PerformAction) {
+ ASSERT_TRUE(GetTray());
+ ASSERT_TRUE(GetSystemTrayDelegate());
+
+ std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0));
+ ::wm::ActivateWindow(window.get());
+ ASSERT_TRUE(::wm::IsActiveWindow(window.get()));
+
+ GetTray()->SetImeWindow(window.get());
+ WmShell::Get()->system_tray_notifier()->NotifyRefreshIMEMenu(true);
+ ASSERT_TRUE(GetTray()->visible());
+ ASSERT_TRUE(IsTrayBackgroundActive());
+
+ // Tabs on the tray when the window is minimized.
+ ui::GestureEvent tap(0, 0, 0, base::TimeTicks(),
+ ui::GestureEventDetails(ui::ET_GESTURE_TAP));
+ GetTray()->PerformAction(tap);
+ ASSERT_FALSE(::wm::IsActiveWindow(window.get()));
+ ASSERT_FALSE(IsTrayBackgroundActive());
+
+ // Tabs on the tray when the window is unminimized.
+ GetTray()->PerformAction(tap);
+ ASSERT_TRUE(::wm::IsActiveWindow(window.get()));
+ ASSERT_TRUE(IsTrayBackgroundActive());
+}
+
+} // namespace ash

Powered by Google App Engine
This is Rietveld 408576698