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

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

Issue 439703002: Allow app list tiles to show search results in the experimental app list. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix athena Created 6 years, 4 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/app_list_view_unittest.cc
diff --git a/ui/app_list/views/app_list_view_unittest.cc b/ui/app_list/views/app_list_view_unittest.cc
index 880269afd800d454cdfcc0c00affe6782503f379..4711d28893331fa4768121694b69e6f5de4fc23a 100644
--- a/ui/app_list/views/app_list_view_unittest.cc
+++ b/ui/app_list/views/app_list_view_unittest.cc
@@ -33,8 +33,6 @@
namespace app_list {
namespace test {
-namespace {
-
enum TestType {
TEST_TYPE_START = 0,
NORMAL = TEST_TYPE_START,
@@ -43,24 +41,6 @@ enum TestType {
TEST_TYPE_END,
};
-bool IsViewAtOrigin(views::View* view) {
- return view->bounds().origin().IsOrigin();
-}
-
-size_t GetVisibleTileItemViews(const std::vector<TileItemView*>& tiles) {
- size_t count = 0;
- for (std::vector<TileItemView*>::const_iterator it = tiles.begin();
- it != tiles.end();
- ++it) {
- if ((*it)->visible())
- count++;
- }
- return count;
-}
-
-// Choose a set that is 3 regular app list pages and 2 landscape app list pages.
-const int kInitialItems = 34;
-
// Allows the same tests to run with different contexts: either an Ash-style
// root window or a desktop window tree host.
class AppListViewTestContext {
@@ -126,6 +106,35 @@ class AppListViewTestContext {
DISALLOW_COPY_AND_ASSIGN(AppListViewTestContext);
};
+namespace {
+
+bool IsViewAtOrigin(views::View* view) {
+ return view->bounds().origin().IsOrigin();
+}
+
+size_t GetVisibleTileItemViews(const std::vector<TileItemView*>& tiles) {
+ size_t count = 0;
+ for (std::vector<TileItemView*>::const_iterator it = tiles.begin();
+ it != tiles.end();
+ ++it) {
+ if ((*it)->visible())
+ count++;
+ }
+ return count;
+}
+
+// Choose a set that is 3 regular app list pages and 2 landscape app list pages.
+const int kInitialItems = 34;
+
+class TestTileSearchResult : public SearchResult {
+ public:
+ TestTileSearchResult() { set_display_type(DISPLAY_TILE); }
+ virtual ~TestTileSearchResult() {}
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(TestTileSearchResult);
+};
+
// Extend the regular AppListTestViewDelegate to communicate back to the test
// context. Note the test context doesn't simply inherit this, because the
// delegate is owned by the view.
@@ -147,6 +156,99 @@ class UnitTestViewDelegate : public app_list::test::AppListTestViewDelegate {
DISALLOW_COPY_AND_ASSIGN(UnitTestViewDelegate);
};
+class AppListViewTestAura : public views::ViewsTestBase,
+ public ::testing::WithParamInterface<int> {
+ public:
+ AppListViewTestAura() {}
+ virtual ~AppListViewTestAura() {}
+
+ // testing::Test overrides:
+ virtual void SetUp() OVERRIDE {
+ views::ViewsTestBase::SetUp();
+
+ // On Ash (only) the app list is placed into an aura::Window "container",
+ // which is also used to determine the context. In tests, use the ash root
+ // window as the parent. This only works on aura where the root window is a
+ // NativeView as well as a NativeWindow.
+ gfx::NativeView container = NULL;
+#if defined(USE_AURA)
+ container = GetContext();
+#endif
+
+ test_context_.reset(new AppListViewTestContext(GetParam(), container));
+ }
+
+ virtual void TearDown() OVERRIDE {
+ test_context_.reset();
+ views::ViewsTestBase::TearDown();
+ }
+
+ protected:
+ scoped_ptr<AppListViewTestContext> test_context_;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(AppListViewTestAura);
+};
+
+class AppListViewTestDesktop : public views::ViewsTestBase,
+ public ::testing::WithParamInterface<int> {
+ public:
+ AppListViewTestDesktop() {}
+ virtual ~AppListViewTestDesktop() {}
+
+ // testing::Test overrides:
+ virtual void SetUp() OVERRIDE {
+ set_views_delegate(new AppListViewTestViewsDelegate(this));
+ views::ViewsTestBase::SetUp();
+ test_context_.reset(new AppListViewTestContext(GetParam(), NULL));
+ }
+
+ virtual void TearDown() OVERRIDE {
+ test_context_.reset();
+ views::ViewsTestBase::TearDown();
+ }
+
+ protected:
+ scoped_ptr<AppListViewTestContext> test_context_;
+
+ private:
+ class AppListViewTestViewsDelegate : public views::TestViewsDelegate {
+ public:
+ AppListViewTestViewsDelegate(AppListViewTestDesktop* parent)
+ : parent_(parent) {}
+
+ // Overridden from views::ViewsDelegate:
+ virtual void OnBeforeWidgetInit(
+ views::Widget::InitParams* params,
+ views::internal::NativeWidgetDelegate* delegate) OVERRIDE;
+
+ private:
+ AppListViewTestDesktop* parent_;
+
+ DISALLOW_COPY_AND_ASSIGN(AppListViewTestViewsDelegate);
+ };
+
+ DISALLOW_COPY_AND_ASSIGN(AppListViewTestDesktop);
+};
+
+void AppListViewTestDesktop::AppListViewTestViewsDelegate::OnBeforeWidgetInit(
+ views::Widget::InitParams* params,
+ views::internal::NativeWidgetDelegate* delegate) {
+// Mimic the logic in ChromeViewsDelegate::OnBeforeWidgetInit(). Except, for
+// ChromeOS, use the root window from the AuraTestHelper rather than depending
+// on ash::Shell:GetPrimaryRootWindow(). Also assume non-ChromeOS is never the
+// Ash desktop, as that is covered by AppListViewTestAura.
+#if defined(OS_CHROMEOS)
+ if (!params->parent && !params->context)
+ params->context = parent_->GetContext();
+#elif defined(USE_AURA)
+ if (params->parent == NULL && params->context == NULL && !params->child)
+ params->native_widget = new views::DesktopNativeWidgetAura(delegate);
+#endif
+}
+
+} // namespace
+
AppListViewTestContext::AppListViewTestContext(int test_type,
gfx::NativeView parent)
: test_type_(static_cast<TestType>(test_type)) {
@@ -313,7 +415,6 @@ void AppListViewTestContext::RunStartPageTest() {
ShowContentsViewPageAndVerify(contents_view->GetPageIndexForNamedPage(
ContentsView::NAMED_PAGE_START));
EXPECT_FALSE(main_view->search_box_view()->visible());
- EXPECT_EQ(3u, GetVisibleTileItemViews(start_page_view->tile_views()));
gfx::Size view_size(view_->GetPreferredSize());
ShowContentsViewPageAndVerify(
@@ -325,10 +426,12 @@ void AppListViewTestContext::RunStartPageTest() {
EXPECT_EQ(view_size.ToString(), view_->GetPreferredSize().ToString());
// Check tiles hide and show on deletion and addition.
- model->CreateAndAddItem("Test app");
- EXPECT_EQ(4u, GetVisibleTileItemViews(start_page_view->tile_views()));
- model->DeleteItem(model->GetItemName(0));
- EXPECT_EQ(3u, GetVisibleTileItemViews(start_page_view->tile_views()));
+ model->results()->Add(new TestTileSearchResult());
+ start_page_view->Update();
+ EXPECT_EQ(1u, GetVisibleTileItemViews(start_page_view->tile_views()));
+ model->results()->RemoveAll();
+ start_page_view->Update();
+ EXPECT_EQ(0u, GetVisibleTileItemViews(start_page_view->tile_views()));
} else {
EXPECT_EQ(NULL, start_page_view);
}
@@ -410,21 +513,25 @@ void AppListViewTestContext::RunProfileChangeTest() {
EXPECT_EQ(view_->app_list_main_view()->contents_view(),
contents_switcher_view->contents_view());
EXPECT_NO_FATAL_FAILURE(CheckView(start_page_view));
- EXPECT_EQ(1u, GetVisibleTileItemViews(start_page_view->tile_views()));
} else {
EXPECT_EQ(NULL, contents_switcher_view);
EXPECT_EQ(NULL, start_page_view);
}
// New model updates should be processed by the start page view.
- delegate_->GetTestModel()->CreateAndAddItem("Test App");
- if (test_type_ == EXPERIMENTAL)
- EXPECT_EQ(2u, GetVisibleTileItemViews(start_page_view->tile_views()));
+ delegate_->GetTestModel()->results()->Add(new TestTileSearchResult());
+ if (test_type_ == EXPERIMENTAL) {
+ start_page_view->Update();
+ EXPECT_EQ(1u, GetVisibleTileItemViews(start_page_view->tile_views()));
+ }
// Old model updates should be ignored.
- original_test_model->CreateAndAddItem("Test App 2");
- if (test_type_ == EXPERIMENTAL)
- EXPECT_EQ(2u, GetVisibleTileItemViews(start_page_view->tile_views()));
+ original_test_model->results()->Add(new TestTileSearchResult());
+ original_test_model->results()->Add(new TestTileSearchResult());
+ if (test_type_ == EXPERIMENTAL) {
+ start_page_view->Update();
+ EXPECT_EQ(1u, GetVisibleTileItemViews(start_page_view->tile_views()));
+ }
Close();
}
@@ -519,99 +626,6 @@ void AppListViewTestContext::RunSearchResultsTest() {
Close();
}
-class AppListViewTestAura : public views::ViewsTestBase,
- public ::testing::WithParamInterface<int> {
- public:
- AppListViewTestAura() {}
- virtual ~AppListViewTestAura() {}
-
- // testing::Test overrides:
- virtual void SetUp() OVERRIDE {
- views::ViewsTestBase::SetUp();
-
- // On Ash (only) the app list is placed into an aura::Window "container",
- // which is also used to determine the context. In tests, use the ash root
- // window as the parent. This only works on aura where the root window is a
- // NativeView as well as a NativeWindow.
- gfx::NativeView container = NULL;
-#if defined(USE_AURA)
- container = GetContext();
-#endif
-
- test_context_.reset(new AppListViewTestContext(GetParam(), container));
- }
-
- virtual void TearDown() OVERRIDE {
- test_context_.reset();
- views::ViewsTestBase::TearDown();
- }
-
- protected:
- scoped_ptr<AppListViewTestContext> test_context_;
-
- private:
- DISALLOW_COPY_AND_ASSIGN(AppListViewTestAura);
-};
-
-class AppListViewTestDesktop : public views::ViewsTestBase,
- public ::testing::WithParamInterface<int> {
- public:
- AppListViewTestDesktop() {}
- virtual ~AppListViewTestDesktop() {}
-
- // testing::Test overrides:
- virtual void SetUp() OVERRIDE {
- set_views_delegate(new AppListViewTestViewsDelegate(this));
- views::ViewsTestBase::SetUp();
- test_context_.reset(new AppListViewTestContext(GetParam(), NULL));
- }
-
- virtual void TearDown() OVERRIDE {
- test_context_.reset();
- views::ViewsTestBase::TearDown();
- }
-
- protected:
- scoped_ptr<AppListViewTestContext> test_context_;
-
- private:
- class AppListViewTestViewsDelegate : public views::TestViewsDelegate {
- public:
- AppListViewTestViewsDelegate(AppListViewTestDesktop* parent)
- : parent_(parent) {}
-
- // Overridden from views::ViewsDelegate:
- virtual void OnBeforeWidgetInit(
- views::Widget::InitParams* params,
- views::internal::NativeWidgetDelegate* delegate) OVERRIDE;
-
- private:
- AppListViewTestDesktop* parent_;
-
- DISALLOW_COPY_AND_ASSIGN(AppListViewTestViewsDelegate);
- };
-
- DISALLOW_COPY_AND_ASSIGN(AppListViewTestDesktop);
-};
-
-void AppListViewTestDesktop::AppListViewTestViewsDelegate::OnBeforeWidgetInit(
- views::Widget::InitParams* params,
- views::internal::NativeWidgetDelegate* delegate) {
-// Mimic the logic in ChromeViewsDelegate::OnBeforeWidgetInit(). Except, for
-// ChromeOS, use the root window from the AuraTestHelper rather than depending
-// on ash::Shell:GetPrimaryRootWindow(). Also assume non-ChromeOS is never the
-// Ash desktop, as that is covered by AppListViewTestAura.
-#if defined(OS_CHROMEOS)
- if (!params->parent && !params->context)
- params->context = parent_->GetContext();
-#elif defined(USE_AURA)
- if (params->parent == NULL && params->context == NULL && !params->child)
- params->native_widget = new views::DesktopNativeWidgetAura(delegate);
-#endif
-}
-
-} // namespace
-
// Tests showing the app list with basic test model in an ash-style root window.
TEST_P(AppListViewTestAura, Display) {
EXPECT_NO_FATAL_FAILURE(test_context_->RunDisplayTest());

Powered by Google App Engine
This is Rietveld 408576698