Chromium Code Reviews| Index: ui/app_list/views/search_box_view_unittest.cc |
| diff --git a/ui/app_list/views/search_box_view_unittest.cc b/ui/app_list/views/search_box_view_unittest.cc |
| index e24ac55699cb6f7561db6ea1ae36ce4403d4e681..3c6b949e28fcd5d4aab1beba7c2f0a5529ff4f36 100644 |
| --- a/ui/app_list/views/search_box_view_unittest.cc |
| +++ b/ui/app_list/views/search_box_view_unittest.cc |
| @@ -9,14 +9,26 @@ |
| #include "base/macros.h" |
| #include "base/strings/utf_string_conversions.h" |
| +#include "base/test/scoped_feature_list.h" |
| +#include "base/time/time.h" |
| +#include "ui/app_list/app_list_features.h" |
| #include "ui/app_list/test/app_list_test_view_delegate.h" |
| #include "ui/app_list/views/search_box_view_delegate.h" |
| +#include "ui/events/event.h" |
| +#include "ui/gfx/canvas.h" |
| #include "ui/views/controls/textfield/textfield.h" |
| #include "ui/views/test/widget_test.h" |
| namespace app_list { |
| namespace test { |
| +constexpr SkColor kDefaultSearchboxColor = |
| + SkColorSetARGBMacro(0xDE, 0x00, 0x00, 0x00); |
| + |
| +// Color used for placeholder text in zero query state. |
| +constexpr SkColor kZeroQuerySearchboxColor = |
| + SkColorSetARGBMacro(0x8A, 0x00, 0x00, 0x00); |
| + |
| class KeyPressCounterView : public views::View { |
| public: |
| KeyPressCounterView() : count_(0) {} |
| @@ -52,11 +64,18 @@ class SearchBoxViewTest : public views::test::WidgetTest, |
| void SetUp() override { |
| views::test::WidgetTest::SetUp(); |
| widget_ = CreateTopLevelPlatformWidget(); |
| + } |
| + |
| + void ContinueSetUp(bool enable_fullscreen_app_list) { |
|
vadimt
2017/06/22 00:53:05
This reminds me LongMnemonicFunctionName1.
Please
newcomer
2017/06/22 16:17:21
I think the new one is better. LMK.
|
| + if (enable_fullscreen_app_list) |
| + EnableFullscreenAppList(); |
| + |
| view_ = new SearchBoxView(this, &view_delegate_); |
| counter_view_ = new KeyPressCounterView(); |
| widget_->GetContentsView()->AddChildView(view_); |
| widget_->GetContentsView()->AddChildView(counter_view_); |
| view_->set_contents_view(counter_view_); |
| + view_->UnitTestsRunning(); |
| } |
| void TearDown() override { |
| @@ -64,6 +83,11 @@ class SearchBoxViewTest : public views::test::WidgetTest, |
| views::test::WidgetTest::TearDown(); |
| } |
| + void EnableFullscreenAppList() { |
| + scoped_feature_list_.InitAndEnableFeature( |
| + app_list::features::kEnableFullscreenAppList); |
| + } |
| + |
| protected: |
| SearchBoxView* view() { return view_; } |
| @@ -122,12 +146,14 @@ class SearchBoxViewTest : public views::test::WidgetTest, |
| SearchBoxView* view_; |
| KeyPressCounterView* counter_view_; |
| base::string16 last_query_; |
| + base::test::ScopedFeatureList scoped_feature_list_; |
| int query_changed_count_; |
| DISALLOW_COPY_AND_ASSIGN(SearchBoxViewTest); |
| }; |
| TEST_F(SearchBoxViewTest, Basic) { |
| + ContinueSetUp(false); |
| KeyPress(ui::VKEY_A); |
| EXPECT_EQ("a", GetLastQueryAndReset()); |
| EXPECT_EQ(1, GetQueryChangedCountAndReset()); |
| @@ -143,6 +169,7 @@ TEST_F(SearchBoxViewTest, Basic) { |
| } |
| TEST_F(SearchBoxViewTest, CancelAutoLaunch) { |
| + ContinueSetUp(false); |
| SetLongAutoLaunchTimeout(); |
| ASSERT_NE(base::TimeDelta(), GetAutoLaunchTimeout()); |
| @@ -164,5 +191,66 @@ TEST_F(SearchBoxViewTest, CancelAutoLaunch) { |
| EXPECT_EQ(base::TimeDelta(), GetAutoLaunchTimeout()); |
| } |
| +// Tests that a keypress enables the cursor and that an empty searchbox disables |
| +// the cursor. |
| +TEST_F(SearchBoxViewTest, KeyPressEnablesCursor) { |
| + ContinueSetUp(true); |
| + |
| + views::Textfield* search_box_text_field = view()->search_box(); |
| + EXPECT_EQ(search_box_text_field->placeholder_text_draw_flags(), |
| + gfx::Canvas::TEXT_ALIGN_CENTER); |
| + EXPECT_EQ(search_box_text_field->placeholder_text_color(), |
| + kDefaultSearchboxColor); |
| + EXPECT_FALSE(view()->is_cursor_enabled()); |
| + |
| + // Press any key, the search box cursor should enable and the placeholder text |
| + // should be aligned left |
| + KeyPress(ui::VKEY_0); |
| + EXPECT_EQ(search_box_text_field->placeholder_text_draw_flags(), |
| + gfx::Canvas::TEXT_ALIGN_LEFT); |
| + EXPECT_EQ(search_box_text_field->placeholder_text_color(), |
| + kZeroQuerySearchboxColor); |
| + EXPECT_TRUE(view()->is_cursor_enabled()); |
| + |
| + // Delete the text, the cursor should return to its previous state with the |
| + // placeholder text back in place. |
| + view()->ClearSearch(); |
| + EXPECT_EQ(search_box_text_field->placeholder_text_draw_flags(), |
| + gfx::Canvas::TEXT_ALIGN_CENTER); |
| + EXPECT_EQ(search_box_text_field->placeholder_text_color(), |
| + kDefaultSearchboxColor); |
| + EXPECT_FALSE(view()->is_cursor_enabled()); |
| +} |
| + |
| +// Tests that the placeholder text and cursor are changed properly upon click. |
| +TEST_F(SearchBoxViewTest, PlaceHolderTextTest) { |
| + ContinueSetUp(true); |
| + |
| + // Test that with no input the cursor is hidden and the text is center |
| + // aligned. |
| + views::Textfield* search_box_text_field = view()->search_box(); |
| + EXPECT_EQ(search_box_text_field->placeholder_text_draw_flags(), |
| + gfx::Canvas::TEXT_ALIGN_CENTER); |
| + EXPECT_EQ(search_box_text_field->placeholder_text_color(), |
| + kDefaultSearchboxColor); |
| + EXPECT_FALSE(view()->is_cursor_enabled()); |
| + |
| + // click search box, text changes and aligns left but is still there |
| + gfx::Point search_box_point = |
| + search_box_text_field->GetBoundsInScreen().CenterPoint(); |
| + ui::MouseEvent mouse_event = |
| + ui::MouseEvent(ui::ET_MOUSE_PRESSED, search_box_point, search_box_point, |
| + base::TimeTicks::Now(), 0, 0); |
| + EXPECT_TRUE(view()->PassMouseEventForTesting(mouse_event)); |
| + EXPECT_EQ(search_box_text_field->placeholder_text_draw_flags(), |
| + gfx::Canvas::TEXT_ALIGN_LEFT); |
| + EXPECT_EQ(search_box_text_field->placeholder_text_color(), |
| + kZeroQuerySearchboxColor); |
| + EXPECT_TRUE(view()->is_cursor_enabled()); |
| + // Todo(newcomer): Add an EventGenerator for SearchBoxViewTest so we can pass |
| + // gestures through the Textfield to SearchBoxView::HandleGestureEvent() |
| + // crbug.com/735240 |
| +} |
| + |
| } // namespace test |
| } // namespace app_list |