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

Side by Side Diff: ui/app_list/views/app_list_view_unittest.cc

Issue 210083009: Add a whole-app-list unit test. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nit Created 6 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « ui/app_list/views/app_list_view.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "ui/app_list/views/app_list_view.h"
6
7 #include "base/command_line.h"
8 #include "base/run_loop.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "ui/app_list/app_list_switches.h"
11 #include "ui/app_list/pagination_model.h"
12 #include "ui/app_list/test/app_list_test_model.h"
13 #include "ui/app_list/test/app_list_test_view_delegate.h"
14 #include "ui/app_list/views/app_list_main_view.h"
15 #include "ui/app_list/views/contents_view.h"
16 #include "ui/app_list/views/search_box_view.h"
17 #include "ui/aura/test/aura_test_base.h"
18 #include "ui/aura/window.h"
19 #include "ui/views/test/views_test_base.h"
20 #include "ui/views/views_delegate.h"
21 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
22
23 namespace app_list {
24 namespace test {
25
26 namespace {
27
28 // Choose a set that is 3 regular app list pages and 2 landscape app list pages.
29 const int kInitialItems = 34;
30
31 const char* TestName() {
32 return ::testing::UnitTest::GetInstance()->current_test_info()->name();
33 }
34
35 // Allows the same tests to run with different contexts: either an Ash-style
36 // root window or a desktop window tree host.
37 class AppListViewTestWithContext {
calamity 2014/03/31 05:37:33 AppListViewTestWithContext sounds like this is the
tapted 2014/04/01 00:09:10 Done.
38 public:
39 AppListViewTestWithContext(aura::Window* parent);
40 ~AppListViewTestWithContext();
41
42 // Test displaying the app list and performs a standard set of checks on its
43 // top level views. Then closes the window.
44 void RunDisplayTest();
45
46 // A standard set of checks on a view, e.g., ensuring it is drawn and visible.
47 static void CheckView(views::View* subview);
48
49 // Invoked when the Widget is closing, and the view it contains is about to
50 // be torn down. This only occurs in a run loop and will be used as a signal
51 // to quit.
52 void NativeWidgetClosing() {
53 view_ = NULL;
54 run_loop_->Quit();
55 }
56
57 // Whether the experimental "landscape" app launcher UI is being tested.
58 bool is_landscape() const { return is_landscape_; }
59
60 private:
61 const bool is_landscape_;
62 scoped_ptr<base::RunLoop> run_loop_;
63 PaginationModel pagination_model_;
64 app_list::AppListView* view_; // Owned by native widget.
65 app_list::test::AppListTestViewDelegate* delegate_; // Owned by |view_|;
66
67 DISALLOW_COPY_AND_ASSIGN(AppListViewTestWithContext);
68 };
69
70 // Extend the regular AppListTestViewDelegate to communicate back to the test
71 // context. Note the test context doesn't simply inherit this, because the
72 // delegate is owned by the view.
73 class UnitTestViewDelegate : public app_list::test::AppListTestViewDelegate {
74 public:
75 UnitTestViewDelegate(AppListViewTestWithContext* parent) : parent_(parent) {}
76
77 virtual void ViewClosing() OVERRIDE { parent_->NativeWidgetClosing(); }
calamity 2014/03/31 05:37:33 // Overridden from app_list::test::AppListTestView
tapted 2014/04/01 00:09:10 Done.
78
79 private:
80 AppListViewTestWithContext* parent_;
81
82 DISALLOW_COPY_AND_ASSIGN(UnitTestViewDelegate);
83 };
84
85 AppListViewTestWithContext::AppListViewTestWithContext(aura::Window* parent)
86 : is_landscape_(strstr(TestName(), "Landscape")) {
calamity 2014/03/31 05:37:33 base::EndsWith()?
tapted 2014/04/01 00:09:10 Done.
87 if (is_landscape_) {
88 base::CommandLine::ForCurrentProcess()->AppendSwitch(
89 switches::kEnableExperimentalAppListPosition);
90 }
91
92 delegate_ = new UnitTestViewDelegate(this);
93 view_ = new app_list::AppListView(delegate_);
94
95 // Initialize centered around a point that ensures the window is wholly shown.
96 view_->InitAsBubbleAtFixedLocation(parent,
97 &pagination_model_,
98 gfx::Point(300, 300),
99 views::BubbleBorder::FLOAT,
100 false /* border_accepts_events */);
101 }
102
103 AppListViewTestWithContext::~AppListViewTestWithContext() {
104 // The view observes the PaginationModel which is about to get destroyed, so
105 // if the view is not already deleted by the time this destructor is called,
106 // there will be problems.
107 EXPECT_FALSE(view_);
108 }
109
110 // static
111 void AppListViewTestWithContext::CheckView(views::View* subview) {
112 ASSERT_TRUE(subview);
113 EXPECT_TRUE(subview->parent());
114 EXPECT_TRUE(subview->visible());
115 EXPECT_TRUE(subview->IsDrawn());
116 }
117
118 void AppListViewTestWithContext::RunDisplayTest() {
119 EXPECT_FALSE(view_->GetWidget()->IsVisible());
120 EXPECT_EQ(-1, pagination_model_.total_pages());
121 view_->ShowWhenReady();
calamity 2014/03/31 05:37:33 Hmm. ShowWhenReady() is only used by ChromeOS. Wil
tapted 2014/04/01 00:09:10 Ah, good point. Changed it to GetWidget()->Show()
122 delegate_->GetTestModel()->PopulateApps(kInitialItems);
123
124 run_loop_.reset(new base::RunLoop);
125 AppListView::SetNextPaintCallback(run_loop_->QuitClosure());
126 run_loop_->Run();
127
128 EXPECT_TRUE(view_->GetWidget()->IsVisible());
129
130 if (is_landscape_)
131 EXPECT_EQ(2, pagination_model_.total_pages());
132 else
133 EXPECT_EQ(3, pagination_model_.total_pages());
134 EXPECT_EQ(0, pagination_model_.selected_page());
135
136 // Checks on the main view.
137 AppListMainView* main_view = view_->app_list_main_view();
138 EXPECT_NO_FATAL_FAILURE(CheckView(main_view));
139 EXPECT_NO_FATAL_FAILURE(CheckView(main_view->search_box_view()));
140 EXPECT_NO_FATAL_FAILURE(CheckView(main_view->contents_view()));
141
142 view_->GetWidget()->Close();
143 run_loop_.reset(new base::RunLoop);
144 run_loop_->Run();
145 /* Note: |view_| will be have been deleted here, and set to NULL. */
calamity 2014/03/31 05:37:33 Is this worth EXPECTing then?
tapted 2014/04/01 00:09:10 Done. Also fixed my grammar fail.
146 }
147
148 class AppListViewTestAura : public views::ViewsTestBase {
149 public:
150 AppListViewTestAura() {}
151
152 // testing::Test overrides:
153 virtual void SetUp() OVERRIDE {
154 views::ViewsTestBase::SetUp();
155 test_context_.reset(new AppListViewTestWithContext(GetContext()));
156 }
157
158 virtual void TearDown() OVERRIDE {
159 test_context_.reset();
160 views::ViewsTestBase::TearDown();
161 }
162
163 protected:
164 scoped_ptr<AppListViewTestWithContext> test_context_;
165
166 private:
167 DISALLOW_COPY_AND_ASSIGN(AppListViewTestAura);
168 };
169
170 class AppListViewTestDesktop : public views::ViewsTestBase {
171 public:
172 AppListViewTestDesktop() {}
calamity 2014/03/31 05:37:33 Destructor (and above)?
tapted 2014/04/01 00:09:10 Done.
173
174 // testing::Test overrides:
175 virtual void SetUp() OVERRIDE {
176 set_views_delegate(new AppListViewTestViewsDelegate(this));
177 views::ViewsTestBase::SetUp();
178 test_context_.reset(new AppListViewTestWithContext(NULL));
179 }
180
181 virtual void TearDown() OVERRIDE {
182 test_context_.reset();
183 views::ViewsTestBase::TearDown();
184 }
185
186 protected:
187 scoped_ptr<AppListViewTestWithContext> test_context_;
188
189 private:
190 class AppListViewTestViewsDelegate : public views::TestViewsDelegate {
191 public:
192 AppListViewTestViewsDelegate(AppListViewTestDesktop* parent)
193 : parent_(parent) {}
194
195 // Overridden from views::ViewsDelegate:
196 virtual void OnBeforeWidgetInit(
197 views::Widget::InitParams* params,
198 views::internal::NativeWidgetDelegate* delegate) OVERRIDE;
199
200 private:
201 AppListViewTestDesktop* parent_;
202
203 DISALLOW_COPY_AND_ASSIGN(AppListViewTestViewsDelegate);
204 };
205
206 DISALLOW_COPY_AND_ASSIGN(AppListViewTestDesktop);
207 };
208
209 void AppListViewTestDesktop::AppListViewTestViewsDelegate::OnBeforeWidgetInit(
210 views::Widget::InitParams* params,
211 views::internal::NativeWidgetDelegate* delegate) {
212 // Mimic the logic in ChromeViewsDelegate::OnBeforeWidgetInit(). Except, for
213 // ChromeOS, use the root window from the AuraTestHelper rather than depending
214 // on ash::Shell:GetPrimaryRootWindow(). Also assume non-ChromeOS is never the
215 // Ash desktop, as that is covered by AppListViewTestAura.
216 #if defined(OS_CHROMEOS)
217 if (!params->parent && !params->context)
218 params->context = parent_->GetContext();
219 #elif defined(USE_AURA)
220 if (params->parent == NULL && params->context == NULL && params->top_level)
221 params->native_widget = new views::DesktopNativeWidgetAura(delegate);
222 #endif
223 }
224
225 } // namespace
226
227 // Tests showing the app list with basic test model in an ash-style root window.
228 TEST_F(AppListViewTestAura, Display) {
229 EXPECT_FALSE(test_context_->is_landscape()); // Sanity check.
230 host()->Show();
231 EXPECT_NO_FATAL_FAILURE(test_context_->RunDisplayTest());
232 }
233
234 // Tests showing the app list on the desktop. Note on ChromeOS, this will still
235 // use the regular root window.
236 TEST_F(AppListViewTestDesktop, Display) {
237 EXPECT_FALSE(test_context_->is_landscape());
238 EXPECT_NO_FATAL_FAILURE(test_context_->RunDisplayTest());
239 }
240
241 // Landscape versions of the above.
242
243 TEST_F(AppListViewTestAura, DisplayLandscape) {
244 EXPECT_TRUE(test_context_->is_landscape());
245 host()->Show();
246 EXPECT_NO_FATAL_FAILURE(test_context_->RunDisplayTest());
247 }
248
249 TEST_F(AppListViewTestDesktop, DisplayLandscape) {
250 EXPECT_TRUE(test_context_->is_landscape());
251 EXPECT_NO_FATAL_FAILURE(test_context_->RunDisplayTest());
252 }
253
254 } // namespace test
255 } // namespace app_list
OLDNEW
« no previous file with comments | « ui/app_list/views/app_list_view.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698