Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 class AthenaTestViewDelegate : public app_list::test::AppListTestViewDelegate { | |
| 24 public: | |
| 25 AthenaTestViewDelegate() {} | |
| 26 virtual ~AthenaTestViewDelegate() {} | |
| 27 | |
| 28 private: | |
| 29 // app_list::AppListViewDelegate: | |
| 30 virtual views::View* CreateStartPageWebView(const gfx::Size& size) OVERRIDE { | |
| 31 return new views::View(); | |
| 32 } | |
| 33 | |
| 34 DISALLOW_COPY_AND_ASSIGN(AthenaTestViewDelegate); | |
| 35 }; | |
| 36 | |
| 37 class AthenaStartPageViewTest : public views::ViewsTestBase { | |
| 38 public: | |
| 39 AthenaStartPageViewTest() {} | |
| 40 virtual ~AthenaStartPageViewTest() {} | |
| 41 | |
|
oshima
2014/08/28 20:44:52
// views::ViewsTestBase:
Jun Mukai
2014/08/28 21:55:36
Done but I personally prefers to have the original
| |
| 42 virtual void SetUp() OVERRIDE { | |
| 43 views::ViewsTestBase::SetUp(); | |
| 44 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 45 app_list::switches::kEnableExperimentalAppList); | |
| 46 app_list::test::AppListTestModel* model = view_delegate_.GetTestModel(); | |
| 47 for (size_t i = 0; i < kNumApps; ++i) { | |
| 48 model->AddItem(new app_list::test::AppListTestModel::AppListTestItem( | |
| 49 base::StringPrintf("id-%" PRIuS, i), model)); | |
| 50 } | |
| 51 | |
| 52 view_.reset(new AthenaStartPageView(&view_delegate_)); | |
| 53 view_->SetSize(gfx::Size(1280, 800)); | |
| 54 view_->Layout(); | |
| 55 } | |
| 56 virtual void TearDown() OVERRIDE { | |
| 57 view_.reset(); | |
| 58 views::ViewsTestBase::TearDown(); | |
| 59 } | |
| 60 | |
| 61 void Rotate() { | |
| 62 view_->SetSize(gfx::Size(800, 1280)); | |
| 63 view_->Layout(); | |
| 64 } | |
| 65 | |
| 66 protected: | |
| 67 gfx::Rect icons_bounds() { | |
|
oshima
2014/08/28 20:44:52
The actual code is complicated enough that this sh
Jun Mukai
2014/08/28 21:55:36
Done.
| |
| 68 return view_->app_icon_container_->layer()->GetTargetBounds(); | |
| 69 } | |
| 70 gfx::Rect control_bounds() { | |
| 71 return view_->control_icon_container_->layer()->GetTargetBounds(); | |
| 72 } | |
| 73 gfx::Rect search_box_bounds() { | |
| 74 return view_->search_box_container_->layer()->GetTargetBounds(); | |
| 75 } | |
| 76 gfx::Rect logo_bounds() { | |
| 77 return view_->logo_->layer()->GetTargetBounds(); | |
| 78 } | |
| 79 bool logo_visible() { | |
| 80 return view_->logo_->layer()->GetTargetOpacity() > 0 && | |
| 81 view_->logo_->layer()->GetTargetVisibility(); | |
| 82 } | |
| 83 gfx::Size search_box_preferred_size() { | |
| 84 return view_->search_box_container_->GetPreferredSize(); | |
| 85 } | |
| 86 | |
| 87 void SetSearchQuery(const base::string16& query) { | |
| 88 view_delegate_.GetModel()->search_box()->SetText(query); | |
| 89 } | |
| 90 | |
| 91 base::string16 GetVisibleQuery() { | |
| 92 return view_->search_box_view_->search_box()->text(); | |
| 93 } | |
| 94 | |
| 95 scoped_ptr<AthenaStartPageView> view_; | |
| 96 | |
| 97 private: | |
| 98 static const size_t kNumApps; | |
|
oshima
2014/08/28 20:44:52
optional: you can just put it in anonymous namespa
Jun Mukai
2014/08/28 21:55:36
Done.
| |
| 99 | |
| 100 AthenaTestViewDelegate view_delegate_; | |
| 101 | |
| 102 DISALLOW_COPY_AND_ASSIGN(AthenaStartPageViewTest); | |
| 103 }; | |
| 104 | |
| 105 const size_t AthenaStartPageViewTest::kNumApps = 10; | |
| 106 | |
| 107 TEST_F(AthenaStartPageViewTest, BasicLayout) { | |
| 108 // BOTTOM state. logo is invisible. icons, search box, and controls are | |
| 109 // arranged horizontally. | |
| 110 EXPECT_FALSE(logo_visible()); | |
| 111 EXPECT_EQ(icons_bounds().y(), control_bounds().y()); | |
| 112 EXPECT_LE(control_bounds().y(), search_box_bounds().y()); | |
| 113 EXPECT_LE(icons_bounds().right(), search_box_bounds().x()); | |
| 114 EXPECT_LE(search_box_bounds().right(), control_bounds().x()); | |
| 115 EXPECT_LE(0, icons_bounds().y()); | |
| 116 EXPECT_GE(kHomeCardHeight, icons_bounds().bottom()); | |
| 117 EXPECT_GE(kHomeCardHeight, search_box_bounds().bottom()); | |
| 118 EXPECT_GE(kHomeCardHeight, control_bounds().bottom()); | |
| 119 EXPECT_EQ(search_box_preferred_size().ToString(), | |
| 120 search_box_bounds().size().ToString()); | |
| 121 | |
| 122 // CENTERED state. logo is visible. search box appears below the logo, | |
| 123 // icons and controls are arranged horizontally and below the search box. | |
| 124 view_->SetLayoutState(1.0f); | |
| 125 EXPECT_TRUE(logo_visible()); | |
| 126 EXPECT_NEAR(logo_bounds().x() + logo_bounds().width() / 2, | |
| 127 search_box_bounds().x() + search_box_bounds().width() / 2, | |
| 128 1); | |
| 129 EXPECT_LE(logo_bounds().bottom(), search_box_bounds().y()); | |
| 130 EXPECT_EQ(icons_bounds().y(), control_bounds().y()); | |
| 131 EXPECT_LE(icons_bounds().right(), control_bounds().x()); | |
| 132 EXPECT_LE(search_box_bounds().bottom(), icons_bounds().y()); | |
| 133 } | |
| 134 | |
| 135 TEST_F(AthenaStartPageViewTest, NarrowLayout) { | |
| 136 Rotate(); | |
|
oshima
2014/08/28 20:44:52
Can you test the re-layout scenario (Wide->narrow-
Jun Mukai
2014/08/28 21:55:36
Done.
| |
| 137 | |
| 138 // BOTTOM state. logo is invisible. icons, search box, and controls are | |
| 139 // arranged horizontally. | |
| 140 EXPECT_FALSE(logo_visible()); | |
| 141 EXPECT_EQ(icons_bounds().y(), control_bounds().y()); | |
| 142 EXPECT_LE(control_bounds().y(), search_box_bounds().y()); | |
| 143 EXPECT_LE(icons_bounds().right(), search_box_bounds().x()); | |
| 144 EXPECT_LE(search_box_bounds().right(), control_bounds().x()); | |
| 145 EXPECT_LE(0, icons_bounds().y()); | |
| 146 EXPECT_GE(kHomeCardHeight, icons_bounds().bottom()); | |
| 147 EXPECT_GE(kHomeCardHeight, search_box_bounds().bottom()); | |
| 148 EXPECT_GE(kHomeCardHeight, control_bounds().bottom()); | |
| 149 EXPECT_GT(search_box_preferred_size().width(), search_box_bounds().width()); | |
| 150 EXPECT_EQ(search_box_preferred_size().height(), search_box_bounds().height()); | |
| 151 | |
| 152 // CENTERED state. logo is visible. search box appears below the logo, | |
| 153 // icons and controls are arranged horizontally and below the search box. | |
| 154 view_->SetLayoutState(1.0f); | |
| 155 EXPECT_TRUE(logo_visible()); | |
| 156 EXPECT_NEAR(logo_bounds().x() + logo_bounds().width() / 2, | |
| 157 search_box_bounds().x() + search_box_bounds().width() / 2, | |
| 158 1); | |
| 159 EXPECT_LE(logo_bounds().bottom(), search_box_bounds().y()); | |
| 160 EXPECT_EQ(icons_bounds().y(), control_bounds().y()); | |
| 161 EXPECT_LE(icons_bounds().right(), control_bounds().x()); | |
| 162 EXPECT_LE(search_box_bounds().bottom(), icons_bounds().y()); | |
| 163 | |
| 164 // Search box size should be expanded to the preferred size. | |
| 165 EXPECT_EQ(search_box_preferred_size().ToString(), | |
| 166 search_box_bounds().size().ToString()); | |
| 167 } | |
| 168 | |
| 169 TEST_F(AthenaStartPageViewTest, SearchBox) { | |
| 170 view_->SetLayoutState(1.0f); | |
| 171 EXPECT_TRUE(logo_visible()); | |
| 172 | |
| 173 const gfx::Rect base_search_box_bounds = search_box_bounds(); | |
| 174 | |
| 175 const base::string16 query = base::UTF8ToUTF16("test"); | |
| 176 SetSearchQuery(query); | |
| 177 | |
| 178 EXPECT_FALSE(logo_visible()); | |
| 179 EXPECT_GT(base_search_box_bounds.y(), search_box_bounds().y()); | |
| 180 EXPECT_EQ(query, GetVisibleQuery()); | |
| 181 | |
| 182 SetSearchQuery(base::string16()); | |
| 183 EXPECT_TRUE(logo_visible()); | |
| 184 EXPECT_EQ(base_search_box_bounds.ToString(), search_box_bounds().ToString()); | |
| 185 EXPECT_TRUE(GetVisibleQuery().empty()); | |
| 186 } | |
| 187 | |
| 188 } // namespace athena | |
| OLD | NEW |