Index: athena/home/athena_start_page_view_unittest.cc |
diff --git a/athena/home/athena_start_page_view_unittest.cc b/athena/home/athena_start_page_view_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..10c532c7bffa8fb121dd40ce37285f4360285a1f |
--- /dev/null |
+++ b/athena/home/athena_start_page_view_unittest.cc |
@@ -0,0 +1,188 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "athena/home/athena_start_page_view.h" |
+ |
+#include "athena/home/home_card_constants.h" |
+#include "base/command_line.h" |
+#include "base/format_macros.h" |
+#include "base/strings/stringprintf.h" |
+#include "base/strings/utf_string_conversions.h" |
+#include "ui/app_list/app_list_switches.h" |
+#include "ui/app_list/search_box_model.h" |
+#include "ui/app_list/test/app_list_test_model.h" |
+#include "ui/app_list/test/app_list_test_view_delegate.h" |
+#include "ui/app_list/views/search_box_view.h" |
+#include "ui/gfx/geometry/rect.h" |
+#include "ui/views/controls/textfield/textfield.h" |
+#include "ui/views/test/views_test_base.h" |
+ |
+namespace athena { |
+ |
+class AthenaTestViewDelegate : public app_list::test::AppListTestViewDelegate { |
+ public: |
+ AthenaTestViewDelegate() {} |
+ virtual ~AthenaTestViewDelegate() {} |
+ |
+ private: |
+ // app_list::AppListViewDelegate: |
+ virtual views::View* CreateStartPageWebView(const gfx::Size& size) OVERRIDE { |
+ return new views::View(); |
+ } |
+ |
+ DISALLOW_COPY_AND_ASSIGN(AthenaTestViewDelegate); |
+}; |
+ |
+class AthenaStartPageViewTest : public views::ViewsTestBase { |
+ public: |
+ AthenaStartPageViewTest() {} |
+ virtual ~AthenaStartPageViewTest() {} |
+ |
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
|
+ virtual void SetUp() OVERRIDE { |
+ views::ViewsTestBase::SetUp(); |
+ base::CommandLine::ForCurrentProcess()->AppendSwitch( |
+ app_list::switches::kEnableExperimentalAppList); |
+ app_list::test::AppListTestModel* model = view_delegate_.GetTestModel(); |
+ for (size_t i = 0; i < kNumApps; ++i) { |
+ model->AddItem(new app_list::test::AppListTestModel::AppListTestItem( |
+ base::StringPrintf("id-%" PRIuS, i), model)); |
+ } |
+ |
+ view_.reset(new AthenaStartPageView(&view_delegate_)); |
+ view_->SetSize(gfx::Size(1280, 800)); |
+ view_->Layout(); |
+ } |
+ virtual void TearDown() OVERRIDE { |
+ view_.reset(); |
+ views::ViewsTestBase::TearDown(); |
+ } |
+ |
+ void Rotate() { |
+ view_->SetSize(gfx::Size(800, 1280)); |
+ view_->Layout(); |
+ } |
+ |
+ protected: |
+ 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.
|
+ return view_->app_icon_container_->layer()->GetTargetBounds(); |
+ } |
+ gfx::Rect control_bounds() { |
+ return view_->control_icon_container_->layer()->GetTargetBounds(); |
+ } |
+ gfx::Rect search_box_bounds() { |
+ return view_->search_box_container_->layer()->GetTargetBounds(); |
+ } |
+ gfx::Rect logo_bounds() { |
+ return view_->logo_->layer()->GetTargetBounds(); |
+ } |
+ bool logo_visible() { |
+ return view_->logo_->layer()->GetTargetOpacity() > 0 && |
+ view_->logo_->layer()->GetTargetVisibility(); |
+ } |
+ gfx::Size search_box_preferred_size() { |
+ return view_->search_box_container_->GetPreferredSize(); |
+ } |
+ |
+ void SetSearchQuery(const base::string16& query) { |
+ view_delegate_.GetModel()->search_box()->SetText(query); |
+ } |
+ |
+ base::string16 GetVisibleQuery() { |
+ return view_->search_box_view_->search_box()->text(); |
+ } |
+ |
+ scoped_ptr<AthenaStartPageView> view_; |
+ |
+ private: |
+ 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.
|
+ |
+ AthenaTestViewDelegate view_delegate_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(AthenaStartPageViewTest); |
+}; |
+ |
+const size_t AthenaStartPageViewTest::kNumApps = 10; |
+ |
+TEST_F(AthenaStartPageViewTest, BasicLayout) { |
+ // BOTTOM state. logo is invisible. icons, search box, and controls are |
+ // arranged horizontally. |
+ EXPECT_FALSE(logo_visible()); |
+ EXPECT_EQ(icons_bounds().y(), control_bounds().y()); |
+ EXPECT_LE(control_bounds().y(), search_box_bounds().y()); |
+ EXPECT_LE(icons_bounds().right(), search_box_bounds().x()); |
+ EXPECT_LE(search_box_bounds().right(), control_bounds().x()); |
+ EXPECT_LE(0, icons_bounds().y()); |
+ EXPECT_GE(kHomeCardHeight, icons_bounds().bottom()); |
+ EXPECT_GE(kHomeCardHeight, search_box_bounds().bottom()); |
+ EXPECT_GE(kHomeCardHeight, control_bounds().bottom()); |
+ EXPECT_EQ(search_box_preferred_size().ToString(), |
+ search_box_bounds().size().ToString()); |
+ |
+ // CENTERED state. logo is visible. search box appears below the logo, |
+ // icons and controls are arranged horizontally and below the search box. |
+ view_->SetLayoutState(1.0f); |
+ EXPECT_TRUE(logo_visible()); |
+ EXPECT_NEAR(logo_bounds().x() + logo_bounds().width() / 2, |
+ search_box_bounds().x() + search_box_bounds().width() / 2, |
+ 1); |
+ EXPECT_LE(logo_bounds().bottom(), search_box_bounds().y()); |
+ EXPECT_EQ(icons_bounds().y(), control_bounds().y()); |
+ EXPECT_LE(icons_bounds().right(), control_bounds().x()); |
+ EXPECT_LE(search_box_bounds().bottom(), icons_bounds().y()); |
+} |
+ |
+TEST_F(AthenaStartPageViewTest, NarrowLayout) { |
+ 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.
|
+ |
+ // BOTTOM state. logo is invisible. icons, search box, and controls are |
+ // arranged horizontally. |
+ EXPECT_FALSE(logo_visible()); |
+ EXPECT_EQ(icons_bounds().y(), control_bounds().y()); |
+ EXPECT_LE(control_bounds().y(), search_box_bounds().y()); |
+ EXPECT_LE(icons_bounds().right(), search_box_bounds().x()); |
+ EXPECT_LE(search_box_bounds().right(), control_bounds().x()); |
+ EXPECT_LE(0, icons_bounds().y()); |
+ EXPECT_GE(kHomeCardHeight, icons_bounds().bottom()); |
+ EXPECT_GE(kHomeCardHeight, search_box_bounds().bottom()); |
+ EXPECT_GE(kHomeCardHeight, control_bounds().bottom()); |
+ EXPECT_GT(search_box_preferred_size().width(), search_box_bounds().width()); |
+ EXPECT_EQ(search_box_preferred_size().height(), search_box_bounds().height()); |
+ |
+ // CENTERED state. logo is visible. search box appears below the logo, |
+ // icons and controls are arranged horizontally and below the search box. |
+ view_->SetLayoutState(1.0f); |
+ EXPECT_TRUE(logo_visible()); |
+ EXPECT_NEAR(logo_bounds().x() + logo_bounds().width() / 2, |
+ search_box_bounds().x() + search_box_bounds().width() / 2, |
+ 1); |
+ EXPECT_LE(logo_bounds().bottom(), search_box_bounds().y()); |
+ EXPECT_EQ(icons_bounds().y(), control_bounds().y()); |
+ EXPECT_LE(icons_bounds().right(), control_bounds().x()); |
+ EXPECT_LE(search_box_bounds().bottom(), icons_bounds().y()); |
+ |
+ // Search box size should be expanded to the preferred size. |
+ EXPECT_EQ(search_box_preferred_size().ToString(), |
+ search_box_bounds().size().ToString()); |
+} |
+ |
+TEST_F(AthenaStartPageViewTest, SearchBox) { |
+ view_->SetLayoutState(1.0f); |
+ EXPECT_TRUE(logo_visible()); |
+ |
+ const gfx::Rect base_search_box_bounds = search_box_bounds(); |
+ |
+ const base::string16 query = base::UTF8ToUTF16("test"); |
+ SetSearchQuery(query); |
+ |
+ EXPECT_FALSE(logo_visible()); |
+ EXPECT_GT(base_search_box_bounds.y(), search_box_bounds().y()); |
+ EXPECT_EQ(query, GetVisibleQuery()); |
+ |
+ SetSearchQuery(base::string16()); |
+ EXPECT_TRUE(logo_visible()); |
+ EXPECT_EQ(base_search_box_bounds.ToString(), search_box_bounds().ToString()); |
+ EXPECT_TRUE(GetVisibleQuery().empty()); |
+} |
+ |
+} // namespace athena |