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

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

Issue 2271483003: Updates the IME list when the IME has refreshed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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/common/system/chromeos/ime_menu/ime_menu_tray_unittest.cc
diff --git a/ash/common/system/chromeos/ime_menu/ime_menu_tray_unittest.cc b/ash/common/system/chromeos/ime_menu/ime_menu_tray_unittest.cc
index 843d3a2111365850daab64b492d37f55588bbbf9..0dbcb831f40b47937f132010a3148d04c0cb496f 100644
--- a/ash/common/system/chromeos/ime_menu/ime_menu_tray_unittest.cc
+++ b/ash/common/system/chromeos/ime_menu/ime_menu_tray_unittest.cc
@@ -4,6 +4,7 @@
#include "ash/common/system/chromeos/ime_menu/ime_menu_tray.h"
+#include "ash/common/system/chromeos/ime_menu/ime_list_view.h"
#include "ash/common/system/status_area_widget.h"
#include "ash/common/system/tray/ime_info.h"
#include "ash/common/system/tray/system_tray_notifier.h"
@@ -12,6 +13,7 @@
#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 "ui/accessibility/ax_view_state.h"
#include "ui/events/event.h"
#include "ui/views/controls/label.h"
@@ -43,7 +45,37 @@ class ImeMenuTrayTest : public test::AshTestBase {
// Returns true if the IME menu bubble has been shown.
bool IsBubbleShown() {
- return (GetTray()->bubble_ && GetTray()->bubble_->bubble_view());
+ return GetTray()->bubble_ && GetTray()->bubble_->bubble_view();
+ }
+
+ // Returns true if the IME menu list has been updated with the right IME list.
+ bool IsTrayImeListValid(const std::vector<IMEInfo>& list,
James Cook 2016/08/24 16:03:53 nit: How about |expected_list| or |expected_imes|
Azure Wei 2016/08/25 02:10:43 Done.
+ const IMEInfo& info) {
+ std::map<views::View*, std::string> ime_map =
+ GetTray()->ime_list_view_->ime_map_;
+ if (ime_map.size() != list.size())
+ return false;
+
+ std::vector<std::string> ime_ids;
James Cook 2016/08/24 16:03:52 nit: |expected_ime_ids| or similar
Azure Wei 2016/08/25 02:10:43 Done.
+ for (auto ime : list) {
James Cook 2016/08/24 16:03:53 nit: Always use const auto& or auto& or const IMEI
Azure Wei 2016/08/25 02:10:43 Done.
+ ime_ids.push_back(ime.id);
+ }
+ for (auto ime : ime_map) {
James Cook 2016/08/24 16:03:52 ditto
Azure Wei 2016/08/25 02:10:43 Done.
+ // Tests that all the IMEs on the view is in the list of selected IMEs.
+ if (std::find(ime_ids.begin(), ime_ids.end(), ime.second) ==
+ ime_ids.end()) {
+ return false;
+ }
+
+ // Tests that the checked IME is the current IME.
+ ui::AXViewState state;
+ ime.first->GetAccessibleState(&state);
+ if (state.HasStateFlag(ui::AX_STATE_CHECKED)) {
+ if (ime.second != info.id)
+ return false;
+ }
+ }
+ return true;
}
private:
@@ -68,25 +100,13 @@ TEST_F(ImeMenuTrayTest, TrayLabelTest) {
ASSERT_TRUE(IsVisible());
// Changes the input method to "ime1".
- IMEInfo info1;
- info1.id = "ime1";
- info1.name = UTF8ToUTF16("English");
- info1.medium_name = UTF8ToUTF16("English");
- info1.short_name = UTF8ToUTF16("US");
- info1.third_party = false;
- info1.selected = true;
+ IMEInfo info1(true, false, "ime1", "English", "English", "US");
GetSystemTrayDelegate()->SetCurrentIME(info1);
WmShell::Get()->system_tray_notifier()->NotifyRefreshIME();
EXPECT_EQ(UTF8ToUTF16("US"), GetTrayText());
// Changes the input method to a third-party IME extension.
- IMEInfo info2;
- info2.id = "ime2";
- info2.name = UTF8ToUTF16("English UK");
- info2.medium_name = UTF8ToUTF16("English UK");
- info2.short_name = UTF8ToUTF16("UK");
- info2.third_party = true;
- info2.selected = true;
+ IMEInfo info2(true, true, "ime2", "English UK", "English UK", "UK");
GetSystemTrayDelegate()->SetCurrentIME(info2);
WmShell::Get()->system_tray_notifier()->NotifyRefreshIME();
EXPECT_EQ(UTF8ToUTF16("UK*"), GetTrayText());
@@ -120,4 +140,39 @@ TEST_F(ImeMenuTrayTest, PerformAction) {
EXPECT_FALSE(IsTrayBackgroundActive());
}
+// Tests that IME menu list updates when changing the current IME. This should
+// only happen by using shortcuts (Ctrl + Space / Ctrl + Shift + Space) to
+// switch IMEs.
+TEST_F(ImeMenuTrayTest, RefreshImeWithListViewCreated) {
+ WmShell::Get()->system_tray_notifier()->NotifyRefreshIMEMenu(true);
+ ASSERT_TRUE(IsVisible());
+ ASSERT_FALSE(IsTrayBackgroundActive());
+
+ ui::GestureEvent tap(0, 0, 0, base::TimeTicks(),
+ ui::GestureEventDetails(ui::ET_GESTURE_TAP));
+ GetTray()->PerformAction(tap);
+
+ EXPECT_TRUE(IsTrayBackgroundActive());
+ EXPECT_TRUE(IsBubbleShown());
+
+ IMEInfo info1(true, false, "ime", "English", "English", "US");
+ IMEInfo info2(false, true, "ime2", "English UK", "English UK", "UK");
+ IMEInfo info3(false, false, "ime3", "Pinyin", "Chinese Pinyin", "拼");
+ std::vector<IMEInfo> ime_info_list{info1, info2, info3};
+
+ GetSystemTrayDelegate()->SetAvailableIMEList(ime_info_list);
+ GetSystemTrayDelegate()->SetCurrentIME(info1);
+ WmShell::Get()->system_tray_notifier()->NotifyRefreshIME();
+ EXPECT_EQ(UTF8ToUTF16("US"), GetTrayText());
+ EXPECT_TRUE(IsTrayImeListValid(ime_info_list, info1));
+
+ ime_info_list[0].selected = false;
+ ime_info_list[2].selected = true;
+ GetSystemTrayDelegate()->SetAvailableIMEList(ime_info_list);
+ GetSystemTrayDelegate()->SetCurrentIME(info3);
+ WmShell::Get()->system_tray_notifier()->NotifyRefreshIME();
+ EXPECT_EQ(UTF8ToUTF16("拼"), GetTrayText());
+ EXPECT_TRUE(IsTrayImeListValid(ime_info_list, info3));
+}
James Cook 2016/08/24 16:03:52 Nice test. Easy to read.
+
} // namespace ash

Powered by Google App Engine
This is Rietveld 408576698