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

Side by Side Diff: ui/app_list/views/search_box_view_unittest.cc

Issue 185623002: Add Hide and Show to the app list SearchBoxView. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ares_contents_switcher
Patch Set: Created 6 years, 9 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/app_list/views/search_box_view.h" 5 #include "ui/app_list/views/search_box_view.h"
6 6
7 #include <cctype> 7 #include <cctype>
8 #include <map> 8 #include <map>
9 9
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 26 matching lines...) Expand all
37 return false; 37 return false;
38 } 38 }
39 int count_; 39 int count_;
40 40
41 DISALLOW_COPY_AND_ASSIGN(KeyPressCounterView); 41 DISALLOW_COPY_AND_ASSIGN(KeyPressCounterView);
42 }; 42 };
43 43
44 class SearchBoxViewTest : public views::test::WidgetTest, 44 class SearchBoxViewTest : public views::test::WidgetTest,
45 public SearchBoxViewDelegate { 45 public SearchBoxViewDelegate {
46 public: 46 public:
47 SearchBoxViewTest() : query_changed_count_(0) {} 47 SearchBoxViewTest() : query_changed_count_(0), visibility_changed_count_(0) {}
48 virtual ~SearchBoxViewTest() {} 48 virtual ~SearchBoxViewTest() {}
49 49
50 // Overridden from testing::Test: 50 // Overridden from testing::Test:
51 virtual void SetUp() OVERRIDE { 51 virtual void SetUp() OVERRIDE {
52 views::test::WidgetTest::SetUp(); 52 views::test::WidgetTest::SetUp();
53 widget_ = CreateTopLevelPlatformWidget(); 53 widget_ = CreateTopLevelPlatformWidget();
54 view_ = new SearchBoxView(this, &view_delegate_); 54 view_ = new SearchBoxView(this, &view_delegate_);
55 counter_view_ = new KeyPressCounterView(); 55 counter_view_ = new KeyPressCounterView();
56 widget_->GetContentsView()->AddChildView(view_); 56 widget_->GetContentsView()->AddChildView(view_);
57 widget_->GetContentsView()->AddChildView(counter_view_); 57 widget_->GetContentsView()->AddChildView(counter_view_);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 last_query_.clear(); 98 last_query_.clear();
99 return base::UTF16ToUTF8(query); 99 return base::UTF16ToUTF8(query);
100 } 100 }
101 101
102 int GetQueryChangedCountAndReset() { 102 int GetQueryChangedCountAndReset() {
103 int result = query_changed_count_; 103 int result = query_changed_count_;
104 query_changed_count_ = 0; 104 query_changed_count_ = 0;
105 return result; 105 return result;
106 } 106 }
107 107
108 int GetVisibilityChangedCountAndReset() {
109 int result = visibility_changed_count_;
110 visibility_changed_count_ = 0;
111 return result;
112 }
113
108 private: 114 private:
109 // Overridden from SearchBoxViewDelegate: 115 // Overridden from SearchBoxViewDelegate:
110 virtual void QueryChanged(SearchBoxView* sender) OVERRIDE { 116 virtual void QueryChanged(SearchBoxView* sender) OVERRIDE {
111 ++query_changed_count_; 117 ++query_changed_count_;
112 last_query_ = sender->search_box()->text(); 118 last_query_ = sender->search_box()->text();
113 } 119 }
114 120
121 virtual void SearchBoxVisibilityChanged(SearchBoxView* sender) OVERRIDE {
122 ++visibility_changed_count_;
123 }
124
115 AppListTestViewDelegate view_delegate_; 125 AppListTestViewDelegate view_delegate_;
116 views::Widget* widget_; 126 views::Widget* widget_;
117 SearchBoxView* view_; 127 SearchBoxView* view_;
118 KeyPressCounterView* counter_view_; 128 KeyPressCounterView* counter_view_;
119 base::string16 last_query_; 129 base::string16 last_query_;
120 int query_changed_count_; 130 int query_changed_count_;
131 int visibility_changed_count_;
121 132
122 DISALLOW_COPY_AND_ASSIGN(SearchBoxViewTest); 133 DISALLOW_COPY_AND_ASSIGN(SearchBoxViewTest);
123 }; 134 };
124 135
125 TEST_F(SearchBoxViewTest, Basic) { 136 TEST_F(SearchBoxViewTest, Basic) {
126 KeyPress(ui::VKEY_A); 137 KeyPress(ui::VKEY_A);
127 EXPECT_EQ("a", GetLastQueryAndReset()); 138 EXPECT_EQ("a", GetLastQueryAndReset());
128 EXPECT_EQ(1, GetQueryChangedCountAndReset()); 139 EXPECT_EQ(1, GetQueryChangedCountAndReset());
129 EXPECT_EQ(0, GetContentsViewKeyPressCountAndReset()); 140 EXPECT_EQ(0, GetContentsViewKeyPressCountAndReset());
130 141
(...skipping 21 matching lines...) Expand all
152 KeyPress(ui::VKEY_DOWN); 163 KeyPress(ui::VKEY_DOWN);
153 EXPECT_NE(base::TimeDelta(), GetAutoLaunchTimeout()); 164 EXPECT_NE(base::TimeDelta(), GetAutoLaunchTimeout());
154 ResetAutoLaunchTimeout(); 165 ResetAutoLaunchTimeout();
155 166
156 // Clearing search box also cancels. 167 // Clearing search box also cancels.
157 SetLongAutoLaunchTimeout(); 168 SetLongAutoLaunchTimeout();
158 view()->ClearSearch(); 169 view()->ClearSearch();
159 EXPECT_EQ(base::TimeDelta(), GetAutoLaunchTimeout()); 170 EXPECT_EQ(base::TimeDelta(), GetAutoLaunchTimeout());
160 } 171 }
161 172
173 TEST_F(SearchBoxViewTest, VisibilityChange) {
174 view()->Show();
175 EXPECT_EQ(1, GetVisibilityChangedCountAndReset());
176
177 view()->Hide();
178 EXPECT_EQ(1, GetVisibilityChangedCountAndReset());
179 }
180
162 } // namespace test 181 } // namespace test
163 } // namespace app_list 182 } // namespace app_list
OLDNEW
« ui/app_list/views/app_list_view.cc ('K') | « ui/app_list/views/search_box_view_delegate.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698