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

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: Activates window when clicked. 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..6faf7d0295c02c84191110911e619ceab48afc09
--- /dev/null
+++ b/ash/system/chromeos/ime_menu/ime_menu_tray_unittest.cc
@@ -0,0 +1,124 @@
+// 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/window_state.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 "ash/wm/window_state_aura.h"
+#include "base/strings/utf_string_conversions.h"
+#include "base/time/time.h"
+#include "ui/aura/window.h"
+#include "ui/events/event.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.
+ base::string16 GetTrayText() { return GetTray()->GetLabelTextForTesting(); }
+
+ // 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));
+ wm::WindowState* window_state = wm::GetWindowState(window.get());
+ GetTray()->SetWindowState(window_state);
+
+ // 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());
+
+ GetTray()->SetWindowState(nullptr);
+}
+
+TEST_F(ImeMenuTrayTest, PerformAction) {
+ ASSERT_TRUE(GetTray());
+ ASSERT_TRUE(GetSystemTrayDelegate());
+
+ std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0));
+ wm::WindowState* window_state = wm::GetWindowState(window.get());
+ window_state->Minimize();
+ ASSERT_TRUE(window_state->IsMinimized());
+ ASSERT_FALSE(window_state->IsActive());
+
+ GetTray()->SetWindowState(window_state);
+ WmShell::Get()->system_tray_notifier()->NotifyRefreshIMEMenu(true);
+ ASSERT_TRUE(GetTray()->visible());
+
+ // 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_TRUE(window_state->IsActive());
+ ASSERT_TRUE(IsTrayBackgroundActive());
+
+ // Tabs on the tray when the window is unminimized.
+ GetTray()->PerformAction(tap);
+ ASSERT_FALSE(window_state->IsActive());
+ ASSERT_FALSE(IsTrayBackgroundActive());
+
+ GetTray()->SetWindowState(nullptr);
+}
+
+} // namespace ash

Powered by Google App Engine
This is Rietveld 408576698