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

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

Issue 291653003: Add a unit test for the experimental app list. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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 | « no previous file | ui/app_list/views/contents_view.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/app_list/views/app_list_view.h" 5 #include "ui/app_list/views/app_list_view.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "ui/app_list/app_list_switches.h" 11 #include "ui/app_list/app_list_switches.h"
12 #include "ui/app_list/pagination_model.h" 12 #include "ui/app_list/pagination_model.h"
13 #include "ui/app_list/test/app_list_test_model.h" 13 #include "ui/app_list/test/app_list_test_model.h"
14 #include "ui/app_list/test/app_list_test_view_delegate.h" 14 #include "ui/app_list/test/app_list_test_view_delegate.h"
15 #include "ui/app_list/views/app_list_folder_view.h" 15 #include "ui/app_list/views/app_list_folder_view.h"
16 #include "ui/app_list/views/app_list_main_view.h" 16 #include "ui/app_list/views/app_list_main_view.h"
17 #include "ui/app_list/views/apps_container_view.h" 17 #include "ui/app_list/views/apps_container_view.h"
18 #include "ui/app_list/views/apps_grid_view.h" 18 #include "ui/app_list/views/apps_grid_view.h"
19 #include "ui/app_list/views/contents_view.h" 19 #include "ui/app_list/views/contents_view.h"
20 #include "ui/app_list/views/search_box_view.h" 20 #include "ui/app_list/views/search_box_view.h"
21 #include "ui/app_list/views/start_page_view.h"
21 #include "ui/app_list/views/test/apps_grid_view_test_api.h" 22 #include "ui/app_list/views/test/apps_grid_view_test_api.h"
22 #include "ui/aura/test/aura_test_base.h" 23 #include "ui/aura/test/aura_test_base.h"
23 #include "ui/aura/window.h" 24 #include "ui/aura/window.h"
24 #include "ui/views/test/views_test_base.h" 25 #include "ui/views/test/views_test_base.h"
25 #include "ui/views/views_delegate.h" 26 #include "ui/views/views_delegate.h"
26 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" 27 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
27 28
28 namespace app_list { 29 namespace app_list {
29 namespace test { 30 namespace test {
30 31
31 namespace { 32 namespace {
32 33
34 enum TestType {
35 TEST_TYPE_START = 0,
36 NORMAL = TEST_TYPE_START,
37 LANDSCAPE,
38 EXPERIMENTAL,
39 TEST_TYPE_END,
40 };
41
33 // Choose a set that is 3 regular app list pages and 2 landscape app list pages. 42 // Choose a set that is 3 regular app list pages and 2 landscape app list pages.
34 const int kInitialItems = 34; 43 const int kInitialItems = 34;
35 44
36 // Allows the same tests to run with different contexts: either an Ash-style 45 // Allows the same tests to run with different contexts: either an Ash-style
37 // root window or a desktop window tree host. 46 // root window or a desktop window tree host.
38 class AppListViewTestContext { 47 class AppListViewTestContext {
39 public: 48 public:
40 AppListViewTestContext(bool is_landscape, aura::Window* parent); 49 AppListViewTestContext(int test_type, aura::Window* parent);
41 ~AppListViewTestContext(); 50 ~AppListViewTestContext();
42 51
43 // Test displaying the app list and performs a standard set of checks on its 52 // Test displaying the app list and performs a standard set of checks on its
44 // top level views. Then closes the window. 53 // top level views. Then closes the window.
45 void RunDisplayTest(); 54 void RunDisplayTest();
46 55
47 // Hides and reshows the app list with a folder open, expecting the main grid 56 // Hides and reshows the app list with a folder open, expecting the main grid
48 // view to be shown. 57 // view to be shown.
49 void RunReshowWithOpenFolderTest(); 58 void RunReshowWithOpenFolderTest();
50 59
60 // Tests displaying of the experimental app list and shows the start page.
61 void RunStartPageTest();
62
51 // A standard set of checks on a view, e.g., ensuring it is drawn and visible. 63 // A standard set of checks on a view, e.g., ensuring it is drawn and visible.
52 static void CheckView(views::View* subview); 64 static void CheckView(views::View* subview);
53 65
54 // Invoked when the Widget is closing, and the view it contains is about to 66 // Invoked when the Widget is closing, and the view it contains is about to
55 // be torn down. This only occurs in a run loop and will be used as a signal 67 // be torn down. This only occurs in a run loop and will be used as a signal
56 // to quit. 68 // to quit.
57 void NativeWidgetClosing() { 69 void NativeWidgetClosing() {
58 view_ = NULL; 70 view_ = NULL;
59 run_loop_->Quit(); 71 run_loop_->Quit();
60 } 72 }
61 73
62 // Whether the experimental "landscape" app launcher UI is being tested. 74 // Whether the experimental "landscape" app launcher UI is being tested.
63 bool is_landscape() const { return is_landscape_; } 75 bool is_landscape() const {
76 return test_type_ == LANDSCAPE || test_type_ == EXPERIMENTAL;
77 }
64 78
65 private: 79 private:
66 // Shows the app list and waits until a paint occurs. 80 // Shows the app list and waits until a paint occurs.
67 void Show(); 81 void Show();
68 82
69 // Closes the app list. This sets |view_| to NULL. 83 // Closes the app list. This sets |view_| to NULL.
70 void Close(); 84 void Close();
71 85
72 const bool is_landscape_; 86 const TestType test_type_;
73 scoped_ptr<base::RunLoop> run_loop_; 87 scoped_ptr<base::RunLoop> run_loop_;
74 PaginationModel pagination_model_; 88 PaginationModel pagination_model_;
75 app_list::AppListView* view_; // Owned by native widget. 89 app_list::AppListView* view_; // Owned by native widget.
76 app_list::test::AppListTestViewDelegate* delegate_; // Owned by |view_|; 90 app_list::test::AppListTestViewDelegate* delegate_; // Owned by |view_|;
77 91
78 DISALLOW_COPY_AND_ASSIGN(AppListViewTestContext); 92 DISALLOW_COPY_AND_ASSIGN(AppListViewTestContext);
79 }; 93 };
80 94
81 // Extend the regular AppListTestViewDelegate to communicate back to the test 95 // Extend the regular AppListTestViewDelegate to communicate back to the test
82 // context. Note the test context doesn't simply inherit this, because the 96 // context. Note the test context doesn't simply inherit this, because the
83 // delegate is owned by the view. 97 // delegate is owned by the view.
84 class UnitTestViewDelegate : public app_list::test::AppListTestViewDelegate { 98 class UnitTestViewDelegate : public app_list::test::AppListTestViewDelegate {
85 public: 99 public:
86 UnitTestViewDelegate(AppListViewTestContext* parent) : parent_(parent) {} 100 UnitTestViewDelegate(AppListViewTestContext* parent) : parent_(parent) {}
87 101
88 // Overridden from app_list::AppListViewDelegate: 102 // Overridden from app_list::AppListViewDelegate:
89 virtual bool ShouldCenterWindow() const OVERRIDE { 103 virtual bool ShouldCenterWindow() const OVERRIDE {
90 return app_list::switches::IsCenteredAppListEnabled(); 104 return app_list::switches::IsCenteredAppListEnabled();
91 } 105 }
92 106
93 // Overridden from app_list::test::AppListTestViewDelegate: 107 // Overridden from app_list::test::AppListTestViewDelegate:
94 virtual void ViewClosing() OVERRIDE { parent_->NativeWidgetClosing(); } 108 virtual void ViewClosing() OVERRIDE { parent_->NativeWidgetClosing(); }
95 109
96 private: 110 private:
97 AppListViewTestContext* parent_; 111 AppListViewTestContext* parent_;
98 112
99 DISALLOW_COPY_AND_ASSIGN(UnitTestViewDelegate); 113 DISALLOW_COPY_AND_ASSIGN(UnitTestViewDelegate);
100 }; 114 };
101 115
102 AppListViewTestContext::AppListViewTestContext(bool is_landscape, 116 AppListViewTestContext::AppListViewTestContext(int test_type,
103 aura::Window* parent) 117 aura::Window* parent)
104 : is_landscape_(is_landscape) { 118 : test_type_(static_cast<TestType>(test_type)) {
105 if (is_landscape_) { 119 switch (test_type_) {
106 base::CommandLine::ForCurrentProcess()->AppendSwitch( 120 case NORMAL:
107 switches::kEnableCenteredAppList); 121 break;
122 case LANDSCAPE:
123 base::CommandLine::ForCurrentProcess()->AppendSwitch(
124 switches::kEnableCenteredAppList);
125 break;
126 case EXPERIMENTAL:
127 base::CommandLine::ForCurrentProcess()->AppendSwitch(
128 switches::kEnableExperimentalAppList);
129 break;
130 default:
131 NOTREACHED();
132 break;
108 } 133 }
109 134
110 delegate_ = new UnitTestViewDelegate(this); 135 delegate_ = new UnitTestViewDelegate(this);
111 view_ = new app_list::AppListView(delegate_); 136 view_ = new app_list::AppListView(delegate_);
112 137
113 // Initialize centered around a point that ensures the window is wholly shown. 138 // Initialize centered around a point that ensures the window is wholly shown.
114 view_->InitAsBubbleAtFixedLocation(parent, 139 view_->InitAsBubbleAtFixedLocation(parent,
115 &pagination_model_, 140 &pagination_model_,
116 gfx::Point(300, 300), 141 gfx::Point(300, 300),
117 views::BubbleBorder::FLOAT, 142 views::BubbleBorder::FLOAT,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 // |view_| should have been deleted and set to NULL via ViewClosing(). 175 // |view_| should have been deleted and set to NULL via ViewClosing().
151 EXPECT_FALSE(view_); 176 EXPECT_FALSE(view_);
152 } 177 }
153 178
154 void AppListViewTestContext::RunDisplayTest() { 179 void AppListViewTestContext::RunDisplayTest() {
155 EXPECT_FALSE(view_->GetWidget()->IsVisible()); 180 EXPECT_FALSE(view_->GetWidget()->IsVisible());
156 EXPECT_EQ(-1, pagination_model_.total_pages()); 181 EXPECT_EQ(-1, pagination_model_.total_pages());
157 delegate_->GetTestModel()->PopulateApps(kInitialItems); 182 delegate_->GetTestModel()->PopulateApps(kInitialItems);
158 183
159 Show(); 184 Show();
160 if (is_landscape_) 185 if (is_landscape())
161 EXPECT_EQ(2, pagination_model_.total_pages()); 186 EXPECT_EQ(2, pagination_model_.total_pages());
162 else 187 else
163 EXPECT_EQ(3, pagination_model_.total_pages()); 188 EXPECT_EQ(3, pagination_model_.total_pages());
164 EXPECT_EQ(0, pagination_model_.selected_page()); 189 EXPECT_EQ(0, pagination_model_.selected_page());
165 190
166 // Checks on the main view. 191 // Checks on the main view.
167 AppListMainView* main_view = view_->app_list_main_view(); 192 AppListMainView* main_view = view_->app_list_main_view();
168 EXPECT_NO_FATAL_FAILURE(CheckView(main_view)); 193 EXPECT_NO_FATAL_FAILURE(CheckView(main_view));
169 EXPECT_NO_FATAL_FAILURE(CheckView(main_view->search_box_view())); 194 EXPECT_NO_FATAL_FAILURE(CheckView(main_view->search_box_view()));
170 EXPECT_NO_FATAL_FAILURE(CheckView(main_view->contents_view())); 195 EXPECT_NO_FATAL_FAILURE(CheckView(main_view->contents_view()));
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 Show(); 234 Show();
210 235
211 // The main grid view should be showing after a reshow. 236 // The main grid view should be showing after a reshow.
212 EXPECT_NO_FATAL_FAILURE(CheckView(main_view)); 237 EXPECT_NO_FATAL_FAILURE(CheckView(main_view));
213 EXPECT_NO_FATAL_FAILURE(CheckView(container_view->apps_grid_view())); 238 EXPECT_NO_FATAL_FAILURE(CheckView(container_view->apps_grid_view()));
214 EXPECT_FALSE(container_view->app_list_folder_view()->visible()); 239 EXPECT_FALSE(container_view->app_list_folder_view()->visible());
215 240
216 Close(); 241 Close();
217 } 242 }
218 243
244 void AppListViewTestContext::RunStartPageTest() {
245 if (test_type_ != EXPERIMENTAL)
tapted 2014/05/22 05:01:27 Can it still PopulateApps, and we just check the s
calamity 2014/05/23 04:10:23 Done.
246 return;
247
248 EXPECT_FALSE(view_->GetWidget()->IsVisible());
249 EXPECT_EQ(-1, pagination_model_.total_pages());
250 delegate_->GetTestModel()->PopulateApps(kInitialItems);
251
tapted 2014/05/22 05:01:27 EXPECT_EQ(2, pagination_model_.total_pages()); ?
calamity 2014/05/23 04:10:23 Is this worth rechecking given that it's already c
252 Show();
253
254 // Checks on the main view.
255 AppListMainView* main_view = view_->app_list_main_view();
256 EXPECT_NO_FATAL_FAILURE(CheckView(main_view));
257 EXPECT_NO_FATAL_FAILURE(CheckView(main_view->contents_view()));
258 EXPECT_NO_FATAL_FAILURE(
259 CheckView(main_view->contents_view()->start_page_view()));
260
261 main_view->contents_view()->SetShowState(ContentsView::SHOW_START_PAGE);
262 EXPECT_FALSE(main_view->search_box_view()->visible());
263 main_view->contents_view()->SetShowState(ContentsView::SHOW_APPS);
264 EXPECT_TRUE(main_view->search_box_view()->visible());
265
tapted 2014/05/22 05:01:27 EXPECT_FALSE(main_view->contents_view()->start_pag
calamity 2014/05/23 04:10:23 Yeahhhhhh it's just offscreen. =( Made it check t
266 Close();
267 }
268
219 class AppListViewTestAura : public views::ViewsTestBase, 269 class AppListViewTestAura : public views::ViewsTestBase,
220 public ::testing::WithParamInterface<bool> { 270 public ::testing::WithParamInterface<int> {
221 public: 271 public:
222 AppListViewTestAura() {} 272 AppListViewTestAura() {}
223 virtual ~AppListViewTestAura() {} 273 virtual ~AppListViewTestAura() {}
224 274
225 // testing::Test overrides: 275 // testing::Test overrides:
226 virtual void SetUp() OVERRIDE { 276 virtual void SetUp() OVERRIDE {
227 views::ViewsTestBase::SetUp(); 277 views::ViewsTestBase::SetUp();
228 test_context_.reset(new AppListViewTestContext(GetParam(), GetContext())); 278 test_context_.reset(new AppListViewTestContext(GetParam(), GetContext()));
229 } 279 }
230 280
231 virtual void TearDown() OVERRIDE { 281 virtual void TearDown() OVERRIDE {
232 test_context_.reset(); 282 test_context_.reset();
233 views::ViewsTestBase::TearDown(); 283 views::ViewsTestBase::TearDown();
234 } 284 }
235 285
236 protected: 286 protected:
237 scoped_ptr<AppListViewTestContext> test_context_; 287 scoped_ptr<AppListViewTestContext> test_context_;
238 288
239 private: 289 private:
240 DISALLOW_COPY_AND_ASSIGN(AppListViewTestAura); 290 DISALLOW_COPY_AND_ASSIGN(AppListViewTestAura);
241 }; 291 };
242 292
243 class AppListViewTestDesktop : public views::ViewsTestBase, 293 class AppListViewTestDesktop : public views::ViewsTestBase,
244 public ::testing::WithParamInterface<bool> { 294 public ::testing::WithParamInterface<int> {
245 public: 295 public:
246 AppListViewTestDesktop() {} 296 AppListViewTestDesktop() {}
247 virtual ~AppListViewTestDesktop() {} 297 virtual ~AppListViewTestDesktop() {}
248 298
249 // testing::Test overrides: 299 // testing::Test overrides:
250 virtual void SetUp() OVERRIDE { 300 virtual void SetUp() OVERRIDE {
251 set_views_delegate(new AppListViewTestViewsDelegate(this)); 301 set_views_delegate(new AppListViewTestViewsDelegate(this));
252 views::ViewsTestBase::SetUp(); 302 views::ViewsTestBase::SetUp();
253 test_context_.reset(new AppListViewTestContext(GetParam(), NULL)); 303 test_context_.reset(new AppListViewTestContext(GetParam(), NULL));
254 } 304 }
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 TEST_P(AppListViewTestAura, ReshowWithOpenFolder) { 365 TEST_P(AppListViewTestAura, ReshowWithOpenFolder) {
316 EXPECT_NO_FATAL_FAILURE(test_context_->RunReshowWithOpenFolderTest()); 366 EXPECT_NO_FATAL_FAILURE(test_context_->RunReshowWithOpenFolderTest());
317 } 367 }
318 368
319 TEST_P(AppListViewTestDesktop, ReshowWithOpenFolder) { 369 TEST_P(AppListViewTestDesktop, ReshowWithOpenFolder) {
320 EXPECT_NO_FATAL_FAILURE(test_context_->RunReshowWithOpenFolderTest()); 370 EXPECT_NO_FATAL_FAILURE(test_context_->RunReshowWithOpenFolderTest());
321 } 371 }
322 372
323 INSTANTIATE_TEST_CASE_P(AppListViewTestAuraInstance, 373 INSTANTIATE_TEST_CASE_P(AppListViewTestAuraInstance,
324 AppListViewTestAura, 374 AppListViewTestAura,
325 ::testing::Bool()); 375 ::testing::Range<int>(TEST_TYPE_START, TEST_TYPE_END));
326 376
327 INSTANTIATE_TEST_CASE_P(AppListViewTestDesktopInstance, 377 INSTANTIATE_TEST_CASE_P(AppListViewTestDesktopInstance,
328 AppListViewTestDesktop, 378 AppListViewTestDesktop,
329 ::testing::Bool()); 379 ::testing::Range<int>(TEST_TYPE_START, TEST_TYPE_END));
330 380
331 } // namespace test 381 } // namespace test
332 } // namespace app_list 382 } // namespace app_list
OLDNEW
« no previous file with comments | « no previous file | ui/app_list/views/contents_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698