| 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..4a67a0ffe1f553400e6b2e65c77835ad801617e4
|
| --- /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/wm/window_state.h"
|
| +#include "ash/shell.h"
|
| +#include "ash/system/status_area_widget.h"
|
| +#include "ash/system/tray/system_tray.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/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/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());
|
| +
|
| + Shell::GetInstance()->system_tray_notifier()->NotifyRefreshIMEMenu(true);
|
| + ASSERT_TRUE(GetTray()->visible());
|
| +
|
| + Shell::GetInstance()->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);
|
| + Shell::GetInstance()->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);
|
| + Shell::GetInstance()->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::WindowState* window_state = wm::GetWindowState(window.get());
|
| + window_state->Minimize();
|
| + ASSERT_TRUE(window_state->IsMinimized());
|
| +
|
| + GetTray()->SetWindowState(window_state);
|
| + Shell::GetInstance()->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_FALSE(window_state->IsMinimized());
|
| + ASSERT_TRUE(IsTrayBackgroundActive());
|
| +
|
| + // Tabs on the tray when the window is unminimized.
|
| + GetTray()->PerformAction(tap);
|
| + ASSERT_TRUE(window_state->IsMinimized());
|
| + ASSERT_FALSE(IsTrayBackgroundActive());
|
| +}
|
| +
|
| +} // namespace ash
|
|
|