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.
5 #include "ui/app_list/views/contents_view.h"
7 #include "base/command_line.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "ui/app_list/app_list_switches.h"
11 #include "ui/app_list/test/app_list_test_model.h"
12 #include "ui/app_list/test/app_list_test_view_delegate.h"
13 #include "ui/app_list/views/app_list_main_view.h"
14 #include "ui/app_list/views/contents_animator.h"
15 #include "ui/app_list/views/search_box_view.h"
20 class ContentsViewTest
: public testing::Test
{
23 base::CommandLine::ForCurrentProcess()->AppendSwitch(
24 switches::kEnableExperimentalAppList
);
26 delegate_
.reset(new AppListTestViewDelegate());
27 main_view_
.reset(new app_list::AppListMainView(delegate_
.get()));
28 search_box_view_
.reset(
29 new SearchBoxView(main_view_
.get(), delegate_
.get()));
31 main_view_
->Init(NULL
, 0, search_box_view_
.get());
32 DCHECK(GetContentsView());
35 ~ContentsViewTest() override
{}
38 ContentsView
* GetContentsView() const { return main_view_
->contents_view(); }
41 scoped_ptr
<AppListTestViewDelegate
> delegate_
;
42 scoped_ptr
<AppListMainView
> main_view_
;
43 scoped_ptr
<SearchBoxView
> search_box_view_
;
45 DISALLOW_COPY_AND_ASSIGN(ContentsViewTest
);
48 TEST_F(ContentsViewTest
, CustomAnimationsTest
) {
49 ContentsView
* contents_view
= GetContentsView();
50 ContentsAnimator
* animator
;
51 bool reverse
= true; // Set to true to make sure it is written.
53 // A transition without a custom animation.
54 animator
= contents_view
->GetAnimatorForTransitionForTests(
55 contents_view
->GetPageIndexForState(AppListModel::STATE_START
),
56 contents_view
->GetPageIndexForState(AppListModel::STATE_SEARCH_RESULTS
),
58 EXPECT_EQ("DefaultAnimator", animator
->NameForTests());
59 EXPECT_FALSE(reverse
);
61 // Test some custom animations.
63 animator
= contents_view
->GetAnimatorForTransitionForTests(
64 contents_view
->GetPageIndexForState(AppListModel::STATE_START
),
65 contents_view
->GetPageIndexForState(AppListModel::STATE_APPS
), &reverse
);
66 EXPECT_EQ("StartToAppsAnimator", animator
->NameForTests());
67 EXPECT_FALSE(reverse
);
70 animator
= contents_view
->GetAnimatorForTransitionForTests(
71 contents_view
->GetPageIndexForState(AppListModel::STATE_APPS
),
72 contents_view
->GetPageIndexForState(AppListModel::STATE_START
), &reverse
);
73 EXPECT_EQ("StartToAppsAnimator", animator
->NameForTests());
78 } // namespace app_list