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

Side by Side Diff: athena/home/athena_start_page_view_unittest.cc

Issue 511053003: Shrink the search box if the width is too small. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix Created 6 years, 3 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "athena/home/athena_start_page_view.h"
6
7 #include "athena/home/home_card_constants.h"
8 #include "base/command_line.h"
9 #include "base/format_macros.h"
10 #include "base/strings/stringprintf.h"
11 #include "base/strings/utf_string_conversions.h"
12 #include "ui/app_list/app_list_switches.h"
13 #include "ui/app_list/search_box_model.h"
14 #include "ui/app_list/test/app_list_test_model.h"
15 #include "ui/app_list/test/app_list_test_view_delegate.h"
16 #include "ui/app_list/views/search_box_view.h"
17 #include "ui/gfx/geometry/rect.h"
18 #include "ui/views/controls/textfield/textfield.h"
19 #include "ui/views/test/views_test_base.h"
20
21 namespace athena {
22
23 namespace {
24
25 // The number of dummy applications in this tetst.
26 const size_t kNumApps = 10;
27
28 }
29
30 class AthenaTestViewDelegate : public app_list::test::AppListTestViewDelegate {
31 public:
32 AthenaTestViewDelegate() {}
33 virtual ~AthenaTestViewDelegate() {}
34
35 private:
36 // app_list::AppListViewDelegate:
37 virtual views::View* CreateStartPageWebView(const gfx::Size& size) OVERRIDE {
38 return new views::View();
39 }
40
41 DISALLOW_COPY_AND_ASSIGN(AthenaTestViewDelegate);
42 };
43
44 class AthenaStartPageViewTest : public views::ViewsTestBase {
45 public:
46 AthenaStartPageViewTest() {}
47 virtual ~AthenaStartPageViewTest() {}
48
49 // testing::Test:
50 virtual void SetUp() OVERRIDE {
51 views::ViewsTestBase::SetUp();
52 base::CommandLine::ForCurrentProcess()->AppendSwitch(
53 app_list::switches::kEnableExperimentalAppList);
54 app_list::test::AppListTestModel* model = view_delegate_.GetTestModel();
55 for (size_t i = 0; i < kNumApps; ++i) {
56 model->AddItem(new app_list::test::AppListTestModel::AppListTestItem(
57 base::StringPrintf("id-%" PRIuS, i), model));
58 }
59
60 view_.reset(new AthenaStartPageView(&view_delegate_));
61 SetSize(gfx::Size(1280, 800));
62 }
63 virtual void TearDown() OVERRIDE {
64 view_.reset();
65 views::ViewsTestBase::TearDown();
66 }
67
68 protected:
69 void SetSize(const gfx::Size& new_size) {
70 view_->SetSize(new_size);
71 view_->Layout();
72 }
73
74 gfx::Rect GetIconsBounds() const {
75 return view_->app_icon_container_->layer()->GetTargetBounds();
76 }
77
78 gfx::Rect GetControlBounds() const {
79 return view_->control_icon_container_->layer()->GetTargetBounds();
80 }
81
82 gfx::Rect GetSearchBoxBounds() const {
83 return view_->search_box_container_->layer()->GetTargetBounds();
84 }
85
86 gfx::Rect GetLogoBounds() const {
87 return view_->logo_->layer()->GetTargetBounds();
88 }
89
90 bool IsLogoVisible() const {
91 return view_->logo_->layer()->GetTargetOpacity() > 0 &&
92 view_->logo_->layer()->GetTargetVisibility();
93 }
94
95 gfx::Size GetSearchBoxPreferredSize() {
96 return view_->search_box_container_->GetPreferredSize();
97 }
98
99 void SetSearchQuery(const base::string16& query) {
100 view_delegate_.GetModel()->search_box()->SetText(query);
101 }
102
103 base::string16 GetVisibleQuery() {
104 return view_->search_box_view_->search_box()->text();
105 }
106
107 scoped_ptr<AthenaStartPageView> view_;
108
109 private:
110 AthenaTestViewDelegate view_delegate_;
111
112 DISALLOW_COPY_AND_ASSIGN(AthenaStartPageViewTest);
113 };
114
115 TEST_F(AthenaStartPageViewTest, BasicLayout) {
116 // BOTTOM state. logo is invisible. icons, search box, and controls are
117 // arranged horizontally.
118 EXPECT_FALSE(IsLogoVisible());
119
120 // Three components are aligned at the middle point.
121 EXPECT_NEAR(GetIconsBounds().CenterPoint().y(),
122 GetControlBounds().CenterPoint().y(),
123 1);
124 EXPECT_NEAR(GetIconsBounds().CenterPoint().y(),
125 GetSearchBoxBounds().CenterPoint().y(),
126 1);
127 EXPECT_NEAR(GetControlBounds().CenterPoint().y(),
128 GetSearchBoxBounds().CenterPoint().y(),
129 1);
130
131 // Horizonttaly aligned in the order of icons, search_box, and controls.
132 EXPECT_LE(GetIconsBounds().right(), GetSearchBoxBounds().x());
133 EXPECT_LE(GetSearchBoxBounds().right(), GetControlBounds().x());
134 EXPECT_LE(0, GetIconsBounds().y());
135
136 // Search box should appear in the middle.
137 EXPECT_NEAR(GetSearchBoxBounds().CenterPoint().x(),
138 view_->bounds().CenterPoint().x(),
139 1);
140
141 // Should fit inside of the home card height.
142 EXPECT_GE(kHomeCardHeight, GetIconsBounds().height());
143 EXPECT_GE(kHomeCardHeight, GetSearchBoxBounds().height());
144 EXPECT_GE(kHomeCardHeight, GetControlBounds().height());
145 EXPECT_EQ(GetSearchBoxPreferredSize().ToString(),
146 GetSearchBoxBounds().size().ToString());
147
148 // CENTERED state. logo is visible. search box appears below the logo,
149 // icons and controls are arranged horizontally and below the search box.
150 view_->SetLayoutState(1.0f);
151 EXPECT_TRUE(IsLogoVisible());
152 EXPECT_NEAR(GetLogoBounds().x() + GetLogoBounds().width() / 2,
153 GetSearchBoxBounds().x() + GetSearchBoxBounds().width() / 2,
154 1);
155 EXPECT_LE(GetLogoBounds().bottom(), GetSearchBoxBounds().y());
156 EXPECT_EQ(GetIconsBounds().y(), GetControlBounds().y());
157 EXPECT_LE(GetIconsBounds().right(), GetControlBounds().x());
158 EXPECT_LE(GetSearchBoxBounds().bottom(), GetIconsBounds().y());
159 }
160
161 TEST_F(AthenaStartPageViewTest, NarrowLayout) {
162 SetSize(gfx::Size(800, 1280));
163
164 // BOTTOM state. Similar to BasicLayout.
165 EXPECT_FALSE(IsLogoVisible());
166 // Three components are aligned at the middle point.
167 EXPECT_NEAR(GetIconsBounds().CenterPoint().y(),
168 GetControlBounds().CenterPoint().y(),
169 1);
170 EXPECT_NEAR(GetIconsBounds().CenterPoint().y(),
171 GetSearchBoxBounds().CenterPoint().y(),
172 1);
173 EXPECT_NEAR(GetControlBounds().CenterPoint().y(),
174 GetSearchBoxBounds().CenterPoint().y(),
175 1);
176
177 // Horizonttaly aligned in the order of icons, search_box, and controls.
178 EXPECT_LE(GetIconsBounds().right(), GetSearchBoxBounds().x());
179 EXPECT_LE(GetSearchBoxBounds().right(), GetControlBounds().x());
180 EXPECT_LE(0, GetIconsBounds().y());
181
182 // Search box should appear in the middle.
183 EXPECT_NEAR(GetSearchBoxBounds().CenterPoint().x(),
184 view_->bounds().CenterPoint().x(),
185 1);
186
187 // Should fit inside of the home card height.
188 EXPECT_GE(kHomeCardHeight, GetIconsBounds().height());
189 EXPECT_GE(kHomeCardHeight, GetSearchBoxBounds().height());
190 EXPECT_GE(kHomeCardHeight, GetControlBounds().height());
191
192 // Search box is narrower because of the size is too narrow.
193 EXPECT_GT(GetSearchBoxPreferredSize().width(), GetSearchBoxBounds().width());
194 EXPECT_EQ(GetSearchBoxPreferredSize().height(),
195 GetSearchBoxBounds().height());
196
197 // CENTERED state. Search box should be back to the preferred size.
198 view_->SetLayoutState(1.0f);
199 EXPECT_EQ(GetSearchBoxPreferredSize().ToString(),
200 GetSearchBoxBounds().size().ToString());
201
202 // Back to BOTTOM state, the search box shrinks again.
203 view_->SetLayoutState(0.0f);
204 EXPECT_GT(GetSearchBoxPreferredSize().width(), GetSearchBoxBounds().width());
205
206 // Then set back to the original size, now the size is wide enough so the
207 // search box bounds becomes as preferred.
208 SetSize(gfx::Size(1280, 800));
209 EXPECT_EQ(GetSearchBoxPreferredSize().ToString(),
210 GetSearchBoxBounds().size().ToString());
211 }
212
213 TEST_F(AthenaStartPageViewTest, SearchBox) {
214 view_->SetLayoutState(1.0f);
215 EXPECT_TRUE(IsLogoVisible());
216
217 const gfx::Rect base_search_box_bounds = GetSearchBoxBounds();
218
219 const base::string16 query = base::UTF8ToUTF16("test");
220 SetSearchQuery(query);
221
222 EXPECT_FALSE(IsLogoVisible());
223 EXPECT_GT(base_search_box_bounds.y(), GetSearchBoxBounds().y());
224 EXPECT_EQ(query, GetVisibleQuery());
225
226 SetSearchQuery(base::string16());
227 EXPECT_TRUE(IsLogoVisible());
228 EXPECT_EQ(base_search_box_bounds.ToString(), GetSearchBoxBounds().ToString());
229 EXPECT_TRUE(GetVisibleQuery().empty());
230 }
231
232 } // namespace athena
OLDNEW
« athena/home/athena_start_page_view.cc ('K') | « athena/home/athena_start_page_view.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698