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

Unified Diff: ui/app_list/views/search_box_view_unittest.cc

Issue 2952763002: SearchBoxView now enables/disables cursor based on user interaction. (Closed)
Patch Set: SearchBoxView now enables/disables cursor based on user interaction. Created 3 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: 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..f9e007a6e24ace470c24bfeba8d6c548f0f29126 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) {}
@@ -64,6 +76,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,6 +139,7 @@ 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);
@@ -164,5 +182,65 @@ TEST_F(SearchBoxViewTest, CancelAutoLaunch) {
EXPECT_EQ(base::TimeDelta(), GetAutoLaunchTimeout());
}
+// Tests that the placeholder text and cursor are changed properly upon click.
+TEST_F(SearchBoxViewTest, PlaceHolderTextTest) {
+ EnableFullscreenAppList();
+ // 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
+}
+
+// Tests that a keypress enables the cursor and that an empty searchbox disables
+// the cursor.
+TEST_F(SearchBoxViewTest, KeyPressEnablesCursor) {
+ EnableFullscreenAppList();
+ 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_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());
+
+ // Delete the text, the cursor should return to its previous state with the
+ // placeholder text back in place.
+ KeyPress(ui::VKEY_BACK);
+ 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());
+}
+
} // namespace test
} // namespace app_list

Powered by Google App Engine
This is Rietveld 408576698