OLD | NEW |
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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 30 matching lines...) Expand all Loading... |
41 #include "ui/views/test/test_views_delegate.h" | 41 #include "ui/views/test/test_views_delegate.h" |
42 #include "ui/views/test/views_test_base.h" | 42 #include "ui/views/test/views_test_base.h" |
43 #include "ui/views/views_delegate.h" | 43 #include "ui/views/views_delegate.h" |
44 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" | 44 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" |
45 | 45 |
46 namespace app_list { | 46 namespace app_list { |
47 namespace test { | 47 namespace test { |
48 | 48 |
49 namespace { | 49 namespace { |
50 | 50 |
51 enum TestType { | |
52 TEST_TYPE_START = 0, | |
53 NORMAL = TEST_TYPE_START, | |
54 LANDSCAPE, | |
55 EXPERIMENTAL, | |
56 TEST_TYPE_END, | |
57 }; | |
58 | |
59 template <class T> | 51 template <class T> |
60 size_t GetVisibleViews(const std::vector<T*>& tiles) { | 52 size_t GetVisibleViews(const std::vector<T*>& tiles) { |
61 size_t count = 0; | 53 size_t count = 0; |
62 for (const auto& tile : tiles) { | 54 for (const auto& tile : tiles) { |
63 if (tile->visible()) | 55 if (tile->visible()) |
64 count++; | 56 count++; |
65 } | 57 } |
66 return count; | 58 return count; |
67 } | 59 } |
68 | 60 |
(...skipping 16 matching lines...) Expand all Loading... |
85 ~TestStartPageSearchResult() override {} | 77 ~TestStartPageSearchResult() override {} |
86 | 78 |
87 private: | 79 private: |
88 DISALLOW_COPY_AND_ASSIGN(TestStartPageSearchResult); | 80 DISALLOW_COPY_AND_ASSIGN(TestStartPageSearchResult); |
89 }; | 81 }; |
90 | 82 |
91 // Allows the same tests to run with different contexts: either an Ash-style | 83 // Allows the same tests to run with different contexts: either an Ash-style |
92 // root window or a desktop window tree host. | 84 // root window or a desktop window tree host. |
93 class AppListViewTestContext { | 85 class AppListViewTestContext { |
94 public: | 86 public: |
95 AppListViewTestContext(int test_type, gfx::NativeView parent); | 87 explicit AppListViewTestContext(gfx::NativeView parent); |
96 ~AppListViewTestContext(); | 88 ~AppListViewTestContext(); |
97 | 89 |
98 // Test displaying the app list and performs a standard set of checks on its | 90 // Test displaying the app list and performs a standard set of checks on its |
99 // top level views. Then closes the window. | 91 // top level views. Then closes the window. |
100 void RunDisplayTest(); | 92 void RunDisplayTest(); |
101 | 93 |
102 // Hides and reshows the app list with a folder open, expecting the main grid | 94 // Hides and reshows the app list with a folder open, expecting the main grid |
103 // view to be shown. | 95 // view to be shown. |
104 void RunReshowWithOpenFolderTest(); | 96 void RunReshowWithOpenFolderTest(); |
105 | 97 |
(...skipping 19 matching lines...) Expand all Loading... |
125 static void CheckView(views::View* subview); | 117 static void CheckView(views::View* subview); |
126 | 118 |
127 // Invoked when the Widget is closing, and the view it contains is about to | 119 // Invoked when the Widget is closing, and the view it contains is about to |
128 // be torn down. This only occurs in a run loop and will be used as a signal | 120 // be torn down. This only occurs in a run loop and will be used as a signal |
129 // to quit. | 121 // to quit. |
130 void NativeWidgetClosing() { | 122 void NativeWidgetClosing() { |
131 view_ = NULL; | 123 view_ = NULL; |
132 run_loop_->Quit(); | 124 run_loop_->Quit(); |
133 } | 125 } |
134 | 126 |
135 // Whether the experimental "landscape" app launcher UI is being tested. | |
136 bool is_landscape() const { | |
137 return test_type_ == LANDSCAPE || test_type_ == EXPERIMENTAL; | |
138 } | |
139 | |
140 private: | 127 private: |
141 // Switches the launcher to |state| and lays out to ensure all launcher pages | 128 // Switches the launcher to |state| and lays out to ensure all launcher pages |
142 // are in the correct position. Checks that the state is where it should be | 129 // are in the correct position. Checks that the state is where it should be |
143 // and returns false on failure. | 130 // and returns false on failure. |
144 bool SetAppListState(AppListModel::State state); | 131 bool SetAppListState(AppListModel::State state); |
145 | 132 |
146 // Returns true if all of the pages are in their correct position for |state|. | 133 // Returns true if all of the pages are in their correct position for |state|. |
147 bool IsStateShown(AppListModel::State state); | 134 bool IsStateShown(AppListModel::State state); |
148 | 135 |
149 // Shows the app list and waits until a paint occurs. | 136 // Shows the app list and waits until a paint occurs. |
150 void Show(); | 137 void Show(); |
151 | 138 |
152 // Closes the app list. This sets |view_| to NULL. | 139 // Closes the app list. This sets |view_| to NULL. |
153 void Close(); | 140 void Close(); |
154 | 141 |
155 // Checks the search box widget is at |expected| in the contents view's | 142 // Checks the search box widget is at |expected| in the contents view's |
156 // coordinate space. | 143 // coordinate space. |
157 bool CheckSearchBoxWidget(const gfx::Rect& expected); | 144 bool CheckSearchBoxWidget(const gfx::Rect& expected); |
158 | 145 |
159 // Gets the PaginationModel owned by |view_|. | 146 // Gets the PaginationModel owned by |view_|. |
160 PaginationModel* GetPaginationModel(); | 147 PaginationModel* GetPaginationModel(); |
161 | 148 |
162 const TestType test_type_; | |
163 std::unique_ptr<base::RunLoop> run_loop_; | 149 std::unique_ptr<base::RunLoop> run_loop_; |
164 app_list::AppListView* view_; // Owned by native widget. | 150 app_list::AppListView* view_; // Owned by native widget. |
165 std::unique_ptr<app_list::test::AppListTestViewDelegate> delegate_; | 151 std::unique_ptr<app_list::test::AppListTestViewDelegate> delegate_; |
166 | 152 |
167 DISALLOW_COPY_AND_ASSIGN(AppListViewTestContext); | 153 DISALLOW_COPY_AND_ASSIGN(AppListViewTestContext); |
168 }; | 154 }; |
169 | 155 |
170 // Extend the regular AppListTestViewDelegate to communicate back to the test | 156 // Extend the regular AppListTestViewDelegate to communicate back to the test |
171 // context. Note the test context doesn't simply inherit this, because the | 157 // context. Note the test context doesn't simply inherit this, because the |
172 // delegate is owned by the view. | 158 // delegate is owned by the view. |
173 class UnitTestViewDelegate : public app_list::test::AppListTestViewDelegate { | 159 class UnitTestViewDelegate : public app_list::test::AppListTestViewDelegate { |
174 public: | 160 public: |
175 explicit UnitTestViewDelegate(AppListViewTestContext* parent) | 161 explicit UnitTestViewDelegate(AppListViewTestContext* parent) |
176 : parent_(parent) {} | 162 : parent_(parent) {} |
177 | 163 |
178 // Overridden from app_list::AppListViewDelegate: | 164 // Overridden from app_list::AppListViewDelegate: |
179 bool ShouldCenterWindow() const override { | 165 bool ShouldCenterWindow() const override { |
180 return app_list::switches::IsCenteredAppListEnabled(); | 166 return app_list::switches::IsCenteredAppListEnabled(); |
181 } | 167 } |
182 | 168 |
183 // Overridden from app_list::test::AppListTestViewDelegate: | 169 // Overridden from app_list::test::AppListTestViewDelegate: |
184 void ViewClosing() override { parent_->NativeWidgetClosing(); } | 170 void ViewClosing() override { parent_->NativeWidgetClosing(); } |
185 | 171 |
186 private: | 172 private: |
187 AppListViewTestContext* parent_; | 173 AppListViewTestContext* parent_; |
188 | 174 |
189 DISALLOW_COPY_AND_ASSIGN(UnitTestViewDelegate); | 175 DISALLOW_COPY_AND_ASSIGN(UnitTestViewDelegate); |
190 }; | 176 }; |
191 | 177 |
192 AppListViewTestContext::AppListViewTestContext(int test_type, | 178 AppListViewTestContext::AppListViewTestContext(gfx::NativeView parent) { |
193 gfx::NativeView parent) | |
194 : test_type_(static_cast<TestType>(test_type)) { | |
195 switch (test_type_) { | |
196 case NORMAL: | |
197 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
198 switches::kDisableExperimentalAppList); | |
199 break; | |
200 case LANDSCAPE: | |
201 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
202 switches::kDisableExperimentalAppList); | |
203 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
204 switches::kEnableCenteredAppList); | |
205 break; | |
206 case EXPERIMENTAL: | |
207 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
208 switches::kEnableExperimentalAppList); | |
209 break; | |
210 default: | |
211 NOTREACHED(); | |
212 break; | |
213 } | |
214 | |
215 delegate_.reset(new UnitTestViewDelegate(this)); | 179 delegate_.reset(new UnitTestViewDelegate(this)); |
216 view_ = new app_list::AppListView(delegate_.get()); | 180 view_ = new app_list::AppListView(delegate_.get()); |
217 | 181 |
218 // Initialize centered around a point that ensures the window is wholly shown. | 182 // Initialize centered around a point that ensures the window is wholly shown. |
219 view_->InitAsBubbleAtFixedLocation(parent, | 183 view_->InitAsBubbleAtFixedLocation(parent, |
220 0, | 184 0, |
221 gfx::Point(300, 300), | 185 gfx::Point(300, 300), |
222 views::BubbleBorder::FLOAT, | 186 views::BubbleBorder::FLOAT, |
223 false /* border_accepts_events */); | 187 false /* border_accepts_events */); |
224 } | 188 } |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 void AppListViewTestContext::RunDisplayTest() { | 261 void AppListViewTestContext::RunDisplayTest() { |
298 EXPECT_FALSE(view_->GetWidget()->IsVisible()); | 262 EXPECT_FALSE(view_->GetWidget()->IsVisible()); |
299 EXPECT_EQ(-1, GetPaginationModel()->total_pages()); | 263 EXPECT_EQ(-1, GetPaginationModel()->total_pages()); |
300 delegate_->GetTestModel()->PopulateApps(kInitialItems); | 264 delegate_->GetTestModel()->PopulateApps(kInitialItems); |
301 | 265 |
302 Show(); | 266 Show(); |
303 | 267 |
304 // Explicitly enforce the exact dimensions of the app list. Feel free to | 268 // Explicitly enforce the exact dimensions of the app list. Feel free to |
305 // change these if you need to (they are just here to prevent against | 269 // change these if you need to (they are just here to prevent against |
306 // accidental changes to the window size). | 270 // accidental changes to the window size). |
307 switch (test_type_) { | 271 EXPECT_EQ("768x570", view_->bounds().size().ToString()); |
308 case NORMAL: | |
309 EXPECT_EQ("400x500", view_->bounds().size().ToString()); | |
310 break; | |
311 case LANDSCAPE: | |
312 // NOTE: Height should not exceed 402, because otherwise there might not | |
313 // be enough space to accomodate the virtual keyboard. (LANDSCAPE mode is | |
314 // enabled by default when the virtual keyboard is enabled.) | |
315 EXPECT_EQ("576x402", view_->bounds().size().ToString()); | |
316 break; | |
317 case EXPERIMENTAL: | |
318 EXPECT_EQ("768x570", view_->bounds().size().ToString()); | |
319 break; | |
320 default: | |
321 NOTREACHED(); | |
322 break; | |
323 } | |
324 | 272 |
325 if (is_landscape()) | 273 EXPECT_EQ(2, GetPaginationModel()->total_pages()); |
326 EXPECT_EQ(2, GetPaginationModel()->total_pages()); | |
327 else | |
328 EXPECT_EQ(3, GetPaginationModel()->total_pages()); | |
329 EXPECT_EQ(0, GetPaginationModel()->selected_page()); | 274 EXPECT_EQ(0, GetPaginationModel()->selected_page()); |
330 | 275 |
331 // Checks on the main view. | 276 // Checks on the main view. |
332 AppListMainView* main_view = view_->app_list_main_view(); | 277 AppListMainView* main_view = view_->app_list_main_view(); |
333 EXPECT_NO_FATAL_FAILURE(CheckView(main_view)); | 278 EXPECT_NO_FATAL_FAILURE(CheckView(main_view)); |
334 EXPECT_NO_FATAL_FAILURE(CheckView(main_view->contents_view())); | 279 EXPECT_NO_FATAL_FAILURE(CheckView(main_view->contents_view())); |
335 | 280 |
336 AppListModel::State expected = test_type_ == EXPERIMENTAL | 281 AppListModel::State expected = AppListModel::STATE_START; |
337 ? AppListModel::STATE_START | |
338 : AppListModel::STATE_APPS; | |
339 EXPECT_TRUE(main_view->contents_view()->IsStateActive(expected)); | 282 EXPECT_TRUE(main_view->contents_view()->IsStateActive(expected)); |
340 EXPECT_EQ(expected, delegate_->GetTestModel()->state()); | 283 EXPECT_EQ(expected, delegate_->GetTestModel()->state()); |
341 | 284 |
342 Close(); | 285 Close(); |
343 } | 286 } |
344 | 287 |
345 void AppListViewTestContext::RunReshowWithOpenFolderTest() { | 288 void AppListViewTestContext::RunReshowWithOpenFolderTest() { |
346 EXPECT_FALSE(view_->GetWidget()->IsVisible()); | 289 EXPECT_FALSE(view_->GetWidget()->IsVisible()); |
347 EXPECT_EQ(-1, GetPaginationModel()->total_pages()); | 290 EXPECT_EQ(-1, GetPaginationModel()->total_pages()); |
348 | 291 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 | 323 |
381 // The main grid view should be showing after a reshow. | 324 // The main grid view should be showing after a reshow. |
382 EXPECT_NO_FATAL_FAILURE(CheckView(main_view)); | 325 EXPECT_NO_FATAL_FAILURE(CheckView(main_view)); |
383 EXPECT_NO_FATAL_FAILURE(CheckView(container_view->apps_grid_view())); | 326 EXPECT_NO_FATAL_FAILURE(CheckView(container_view->apps_grid_view())); |
384 EXPECT_FALSE(container_view->app_list_folder_view()->visible()); | 327 EXPECT_FALSE(container_view->app_list_folder_view()->visible()); |
385 | 328 |
386 Close(); | 329 Close(); |
387 } | 330 } |
388 | 331 |
389 void AppListViewTestContext::RunBackTest() { | 332 void AppListViewTestContext::RunBackTest() { |
390 if (test_type_ != EXPERIMENTAL) { | |
391 Close(); | |
392 return; | |
393 } | |
394 | |
395 EXPECT_FALSE(view_->GetWidget()->IsVisible()); | 333 EXPECT_FALSE(view_->GetWidget()->IsVisible()); |
396 EXPECT_EQ(-1, GetPaginationModel()->total_pages()); | 334 EXPECT_EQ(-1, GetPaginationModel()->total_pages()); |
397 | 335 |
398 Show(); | 336 Show(); |
399 | 337 |
400 AppListMainView* main_view = view_->app_list_main_view(); | 338 AppListMainView* main_view = view_->app_list_main_view(); |
401 ContentsView* contents_view = main_view->contents_view(); | 339 ContentsView* contents_view = main_view->contents_view(); |
402 SearchBoxView* search_box_view = main_view->search_box_view(); | 340 SearchBoxView* search_box_view = main_view->search_box_view(); |
403 | 341 |
404 // Show the apps grid. | 342 // Show the apps grid. |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
450 model->PopulateApps(3); | 388 model->PopulateApps(3); |
451 | 389 |
452 Show(); | 390 Show(); |
453 | 391 |
454 AppListMainView* main_view = view_->app_list_main_view(); | 392 AppListMainView* main_view = view_->app_list_main_view(); |
455 StartPageView* start_page_view = | 393 StartPageView* start_page_view = |
456 main_view->contents_view()->start_page_view(); | 394 main_view->contents_view()->start_page_view(); |
457 // Checks on the main view. | 395 // Checks on the main view. |
458 EXPECT_NO_FATAL_FAILURE(CheckView(main_view)); | 396 EXPECT_NO_FATAL_FAILURE(CheckView(main_view)); |
459 EXPECT_NO_FATAL_FAILURE(CheckView(main_view->contents_view())); | 397 EXPECT_NO_FATAL_FAILURE(CheckView(main_view->contents_view())); |
460 if (test_type_ == EXPERIMENTAL) { | 398 EXPECT_NO_FATAL_FAILURE(CheckView(start_page_view)); |
461 EXPECT_NO_FATAL_FAILURE(CheckView(start_page_view)); | |
462 | 399 |
463 // Show the start page view. | 400 // Show the start page view. |
464 EXPECT_TRUE(SetAppListState(AppListModel::STATE_START)); | 401 EXPECT_TRUE(SetAppListState(AppListModel::STATE_START)); |
465 gfx::Size view_size(view_->GetPreferredSize()); | 402 gfx::Size view_size(view_->GetPreferredSize()); |
466 | 403 |
467 // The "All apps" button should have its "parent background color" set | 404 // The "All apps" button should have its "parent background color" set |
468 // to the tiles container's background color. | 405 // to the tiles container's background color. |
469 TileItemView* all_apps_button = start_page_view->all_apps_button(); | 406 TileItemView* all_apps_button = start_page_view->all_apps_button(); |
470 EXPECT_TRUE(all_apps_button->visible()); | 407 EXPECT_TRUE(all_apps_button->visible()); |
471 EXPECT_EQ(kLabelBackgroundColor, | 408 EXPECT_EQ(kLabelBackgroundColor, all_apps_button->parent_background_color()); |
472 all_apps_button->parent_background_color()); | |
473 | 409 |
474 // Simulate clicking the "All apps" button. Check that we navigate to the | 410 // Simulate clicking the "All apps" button. Check that we navigate to the |
475 // apps grid view. | 411 // apps grid view. |
476 SimulateClick(all_apps_button); | 412 SimulateClick(all_apps_button); |
477 main_view->contents_view()->Layout(); | 413 main_view->contents_view()->Layout(); |
478 EXPECT_TRUE(IsStateShown(AppListModel::STATE_APPS)); | 414 EXPECT_TRUE(IsStateShown(AppListModel::STATE_APPS)); |
479 | 415 |
480 // Hiding and showing the search box should not affect the app list's | 416 // Hiding and showing the search box should not affect the app list's |
481 // preferred size. This is a regression test for http://crbug.com/386912. | 417 // preferred size. This is a regression test for http://crbug.com/386912. |
482 EXPECT_EQ(view_size.ToString(), view_->GetPreferredSize().ToString()); | 418 EXPECT_EQ(view_size.ToString(), view_->GetPreferredSize().ToString()); |
483 | 419 |
484 // Check tiles hide and show on deletion and addition. | 420 // Check tiles hide and show on deletion and addition. |
485 EXPECT_TRUE(SetAppListState(AppListModel::STATE_START)); | 421 EXPECT_TRUE(SetAppListState(AppListModel::STATE_START)); |
486 model->results()->Add(new TestStartPageSearchResult()); | 422 model->results()->Add(new TestStartPageSearchResult()); |
487 start_page_view->UpdateForTesting(); | 423 start_page_view->UpdateForTesting(); |
488 EXPECT_EQ(1u, GetVisibleViews(start_page_view->tile_views())); | 424 EXPECT_EQ(1u, GetVisibleViews(start_page_view->tile_views())); |
489 model->results()->DeleteAll(); | 425 model->results()->DeleteAll(); |
490 start_page_view->UpdateForTesting(); | 426 start_page_view->UpdateForTesting(); |
491 EXPECT_EQ(0u, GetVisibleViews(start_page_view->tile_views())); | 427 EXPECT_EQ(0u, GetVisibleViews(start_page_view->tile_views())); |
492 | 428 |
493 // Tiles should not update when the start page is not active but should be | 429 // Tiles should not update when the start page is not active but should be |
494 // correct once the start page is shown. | 430 // correct once the start page is shown. |
495 EXPECT_TRUE(SetAppListState(AppListModel::STATE_APPS)); | 431 EXPECT_TRUE(SetAppListState(AppListModel::STATE_APPS)); |
496 model->results()->Add(new TestStartPageSearchResult()); | 432 model->results()->Add(new TestStartPageSearchResult()); |
497 start_page_view->UpdateForTesting(); | 433 start_page_view->UpdateForTesting(); |
498 EXPECT_EQ(0u, GetVisibleViews(start_page_view->tile_views())); | 434 EXPECT_EQ(0u, GetVisibleViews(start_page_view->tile_views())); |
499 EXPECT_TRUE(SetAppListState(AppListModel::STATE_START)); | 435 EXPECT_TRUE(SetAppListState(AppListModel::STATE_START)); |
500 EXPECT_EQ(1u, GetVisibleViews(start_page_view->tile_views())); | 436 EXPECT_EQ(1u, GetVisibleViews(start_page_view->tile_views())); |
501 } else { | |
502 EXPECT_EQ(NULL, start_page_view); | |
503 } | |
504 | 437 |
505 Close(); | 438 Close(); |
506 } | 439 } |
507 | 440 |
508 void AppListViewTestContext::RunPageSwitchingAnimationTest() { | 441 void AppListViewTestContext::RunPageSwitchingAnimationTest() { |
509 if (test_type_ == EXPERIMENTAL) { | 442 Show(); |
510 Show(); | |
511 | 443 |
512 AppListMainView* main_view = view_->app_list_main_view(); | 444 AppListMainView* main_view = view_->app_list_main_view(); |
513 // Checks on the main view. | 445 // Checks on the main view. |
514 EXPECT_NO_FATAL_FAILURE(CheckView(main_view)); | 446 EXPECT_NO_FATAL_FAILURE(CheckView(main_view)); |
515 EXPECT_NO_FATAL_FAILURE(CheckView(main_view->contents_view())); | 447 EXPECT_NO_FATAL_FAILURE(CheckView(main_view->contents_view())); |
516 | 448 |
517 ContentsView* contents_view = main_view->contents_view(); | 449 ContentsView* contents_view = main_view->contents_view(); |
518 | 450 |
519 contents_view->SetActiveState(AppListModel::STATE_START); | 451 contents_view->SetActiveState(AppListModel::STATE_START); |
520 contents_view->Layout(); | 452 contents_view->Layout(); |
521 | 453 |
522 IsStateShown(AppListModel::STATE_START); | 454 IsStateShown(AppListModel::STATE_START); |
523 | 455 |
524 // Change pages. View should not have moved without Layout(). | 456 // Change pages. View should not have moved without Layout(). |
525 contents_view->SetActiveState(AppListModel::STATE_SEARCH_RESULTS); | 457 contents_view->SetActiveState(AppListModel::STATE_SEARCH_RESULTS); |
526 IsStateShown(AppListModel::STATE_START); | 458 IsStateShown(AppListModel::STATE_START); |
527 | 459 |
528 // Change to a third page. This queues up the second animation behind the | 460 // Change to a third page. This queues up the second animation behind the |
529 // first. | 461 // first. |
530 contents_view->SetActiveState(AppListModel::STATE_APPS); | 462 contents_view->SetActiveState(AppListModel::STATE_APPS); |
531 IsStateShown(AppListModel::STATE_START); | 463 IsStateShown(AppListModel::STATE_START); |
532 | 464 |
533 // Call Layout(). Should jump to the third page. | 465 // Call Layout(). Should jump to the third page. |
534 contents_view->Layout(); | 466 contents_view->Layout(); |
535 IsStateShown(AppListModel::STATE_APPS); | 467 IsStateShown(AppListModel::STATE_APPS); |
536 } | |
537 | 468 |
538 Close(); | 469 Close(); |
539 } | 470 } |
540 | 471 |
541 void AppListViewTestContext::RunProfileChangeTest() { | 472 void AppListViewTestContext::RunProfileChangeTest() { |
542 EXPECT_FALSE(view_->GetWidget()->IsVisible()); | 473 EXPECT_FALSE(view_->GetWidget()->IsVisible()); |
543 EXPECT_EQ(-1, GetPaginationModel()->total_pages()); | 474 EXPECT_EQ(-1, GetPaginationModel()->total_pages()); |
544 delegate_->GetTestModel()->PopulateApps(kInitialItems); | 475 delegate_->GetTestModel()->PopulateApps(kInitialItems); |
545 | 476 |
546 Show(); | 477 Show(); |
547 | 478 |
548 if (is_landscape()) | 479 EXPECT_EQ(2, GetPaginationModel()->total_pages()); |
549 EXPECT_EQ(2, GetPaginationModel()->total_pages()); | |
550 else | |
551 EXPECT_EQ(3, GetPaginationModel()->total_pages()); | |
552 | 480 |
553 // Change the profile. The original model needs to be kept alive for | 481 // Change the profile. The original model needs to be kept alive for |
554 // observers to unregister themselves. | 482 // observers to unregister themselves. |
555 std::unique_ptr<AppListTestModel> original_test_model( | 483 std::unique_ptr<AppListTestModel> original_test_model( |
556 delegate_->ReleaseTestModel()); | 484 delegate_->ReleaseTestModel()); |
557 delegate_->set_next_profile_app_count(1); | 485 delegate_->set_next_profile_app_count(1); |
558 | 486 |
559 // The original ContentsView is destroyed here. | 487 // The original ContentsView is destroyed here. |
560 view_->SetProfileByPath(base::FilePath()); | 488 view_->SetProfileByPath(base::FilePath()); |
561 EXPECT_EQ(1, GetPaginationModel()->total_pages()); | 489 EXPECT_EQ(1, GetPaginationModel()->total_pages()); |
562 | 490 |
563 StartPageView* start_page_view = | 491 StartPageView* start_page_view = |
564 view_->app_list_main_view()->contents_view()->start_page_view(); | 492 view_->app_list_main_view()->contents_view()->start_page_view(); |
565 if (test_type_ == EXPERIMENTAL) | 493 EXPECT_NO_FATAL_FAILURE(CheckView(start_page_view)); |
566 EXPECT_NO_FATAL_FAILURE(CheckView(start_page_view)); | |
567 else | |
568 EXPECT_EQ(NULL, start_page_view); | |
569 | 494 |
570 // New model updates should be processed by the start page view. | 495 // New model updates should be processed by the start page view. |
571 delegate_->GetTestModel()->results()->Add(new TestStartPageSearchResult()); | 496 delegate_->GetTestModel()->results()->Add(new TestStartPageSearchResult()); |
572 if (test_type_ == EXPERIMENTAL) { | 497 start_page_view->UpdateForTesting(); |
573 start_page_view->UpdateForTesting(); | 498 EXPECT_EQ(1u, GetVisibleViews(start_page_view->tile_views())); |
574 EXPECT_EQ(1u, GetVisibleViews(start_page_view->tile_views())); | |
575 } | |
576 | 499 |
577 // Old model updates should be ignored. | 500 // Old model updates should be ignored. |
578 original_test_model->results()->Add(new TestStartPageSearchResult()); | 501 original_test_model->results()->Add(new TestStartPageSearchResult()); |
579 original_test_model->results()->Add(new TestStartPageSearchResult()); | 502 original_test_model->results()->Add(new TestStartPageSearchResult()); |
580 if (test_type_ == EXPERIMENTAL) { | 503 start_page_view->UpdateForTesting(); |
581 start_page_view->UpdateForTesting(); | 504 EXPECT_EQ(1u, GetVisibleViews(start_page_view->tile_views())); |
582 EXPECT_EQ(1u, GetVisibleViews(start_page_view->tile_views())); | |
583 } | |
584 | 505 |
585 Close(); | 506 Close(); |
586 } | 507 } |
587 | 508 |
588 void AppListViewTestContext::RunSearchResultsTest() { | 509 void AppListViewTestContext::RunSearchResultsTest() { |
589 EXPECT_FALSE(view_->GetWidget()->IsVisible()); | 510 EXPECT_FALSE(view_->GetWidget()->IsVisible()); |
590 EXPECT_EQ(-1, GetPaginationModel()->total_pages()); | 511 EXPECT_EQ(-1, GetPaginationModel()->total_pages()); |
591 AppListTestModel* model = delegate_->GetTestModel(); | 512 AppListTestModel* model = delegate_->GetTestModel(); |
592 model->PopulateApps(3); | 513 model->PopulateApps(3); |
593 | 514 |
(...skipping 10 matching lines...) Expand all Loading... |
604 | 525 |
605 EXPECT_TRUE(IsStateShown(AppListModel::STATE_SEARCH_RESULTS)); | 526 EXPECT_TRUE(IsStateShown(AppListModel::STATE_SEARCH_RESULTS)); |
606 | 527 |
607 // Hide the search results. | 528 // Hide the search results. |
608 contents_view->ShowSearchResults(false); | 529 contents_view->ShowSearchResults(false); |
609 contents_view->Layout(); | 530 contents_view->Layout(); |
610 | 531 |
611 // Check that we return to the page that we were on before the search. | 532 // Check that we return to the page that we were on before the search. |
612 EXPECT_TRUE(IsStateShown(AppListModel::STATE_APPS)); | 533 EXPECT_TRUE(IsStateShown(AppListModel::STATE_APPS)); |
613 | 534 |
614 if (test_type_ == EXPERIMENTAL) { | 535 // Check that typing into the search box triggers the search page. |
615 // Check that typing into the search box triggers the search page. | 536 EXPECT_TRUE(SetAppListState(AppListModel::STATE_START)); |
616 EXPECT_TRUE(SetAppListState(AppListModel::STATE_START)); | 537 view_->Layout(); |
617 view_->Layout(); | 538 EXPECT_TRUE(IsStateShown(AppListModel::STATE_START)); |
618 EXPECT_TRUE(IsStateShown(AppListModel::STATE_START)); | |
619 | 539 |
620 base::string16 search_text = base::UTF8ToUTF16("test"); | 540 base::string16 search_text = base::UTF8ToUTF16("test"); |
621 main_view->search_box_view()->search_box()->SetText(base::string16()); | 541 main_view->search_box_view()->search_box()->SetText(base::string16()); |
622 main_view->search_box_view()->search_box()->InsertText(search_text); | 542 main_view->search_box_view()->search_box()->InsertText(search_text); |
623 // Check that the current search is using |search_text|. | 543 // Check that the current search is using |search_text|. |
624 EXPECT_EQ(search_text, delegate_->GetTestModel()->search_box()->text()); | 544 EXPECT_EQ(search_text, delegate_->GetTestModel()->search_box()->text()); |
625 EXPECT_EQ(search_text, main_view->search_box_view()->search_box()->text()); | 545 EXPECT_EQ(search_text, main_view->search_box_view()->search_box()->text()); |
626 contents_view->Layout(); | 546 contents_view->Layout(); |
627 EXPECT_TRUE( | 547 EXPECT_TRUE(contents_view->IsStateActive(AppListModel::STATE_SEARCH_RESULTS)); |
628 contents_view->IsStateActive(AppListModel::STATE_SEARCH_RESULTS)); | 548 EXPECT_TRUE(CheckSearchBoxWidget(contents_view->GetDefaultSearchBoxBounds())); |
629 EXPECT_TRUE( | |
630 CheckSearchBoxWidget(contents_view->GetDefaultSearchBoxBounds())); | |
631 | 549 |
632 // Check that typing into the search box triggers the search page. | 550 // Check that typing into the search box triggers the search page. |
633 EXPECT_TRUE(SetAppListState(AppListModel::STATE_APPS)); | 551 EXPECT_TRUE(SetAppListState(AppListModel::STATE_APPS)); |
634 contents_view->Layout(); | 552 contents_view->Layout(); |
635 EXPECT_TRUE(IsStateShown(AppListModel::STATE_APPS)); | 553 EXPECT_TRUE(IsStateShown(AppListModel::STATE_APPS)); |
636 EXPECT_TRUE( | 554 EXPECT_TRUE(CheckSearchBoxWidget(contents_view->GetDefaultSearchBoxBounds())); |
637 CheckSearchBoxWidget(contents_view->GetDefaultSearchBoxBounds())); | |
638 | 555 |
639 base::string16 new_search_text = base::UTF8ToUTF16("apple"); | 556 base::string16 new_search_text = base::UTF8ToUTF16("apple"); |
640 main_view->search_box_view()->search_box()->SetText(base::string16()); | 557 main_view->search_box_view()->search_box()->SetText(base::string16()); |
641 main_view->search_box_view()->search_box()->InsertText(new_search_text); | 558 main_view->search_box_view()->search_box()->InsertText(new_search_text); |
642 // Check that the current search is using |new_search_text|. | 559 // Check that the current search is using |new_search_text|. |
643 EXPECT_EQ(new_search_text, delegate_->GetTestModel()->search_box()->text()); | 560 EXPECT_EQ(new_search_text, delegate_->GetTestModel()->search_box()->text()); |
644 EXPECT_EQ(new_search_text, | 561 EXPECT_EQ(new_search_text, |
645 main_view->search_box_view()->search_box()->text()); | 562 main_view->search_box_view()->search_box()->text()); |
646 contents_view->Layout(); | 563 contents_view->Layout(); |
647 EXPECT_TRUE(IsStateShown(AppListModel::STATE_SEARCH_RESULTS)); | 564 EXPECT_TRUE(IsStateShown(AppListModel::STATE_SEARCH_RESULTS)); |
648 EXPECT_TRUE( | 565 EXPECT_TRUE(CheckSearchBoxWidget(contents_view->GetDefaultSearchBoxBounds())); |
649 CheckSearchBoxWidget(contents_view->GetDefaultSearchBoxBounds())); | |
650 } | |
651 | 566 |
652 Close(); | 567 Close(); |
653 } | 568 } |
654 | 569 |
655 void AppListViewTestContext::RunAppListOverlayTest() { | 570 void AppListViewTestContext::RunAppListOverlayTest() { |
656 Show(); | 571 Show(); |
657 | 572 |
658 AppListMainView* main_view = view_->app_list_main_view(); | 573 AppListMainView* main_view = view_->app_list_main_view(); |
659 SearchBoxView* search_box_view = main_view->search_box_view(); | 574 SearchBoxView* search_box_view = main_view->search_box_view(); |
660 | 575 |
661 // The search box should not be enabled when the app list overlay is shown. | 576 // The search box should not be enabled when the app list overlay is shown. |
662 view_->SetAppListOverlayVisible(true); | 577 view_->SetAppListOverlayVisible(true); |
663 EXPECT_FALSE(search_box_view->enabled()); | 578 EXPECT_FALSE(search_box_view->enabled()); |
664 | 579 |
665 // The search box should be refocused when the app list overlay is hidden. | 580 // The search box should be refocused when the app list overlay is hidden. |
666 view_->SetAppListOverlayVisible(false); | 581 view_->SetAppListOverlayVisible(false); |
667 EXPECT_TRUE(search_box_view->enabled()); | 582 EXPECT_TRUE(search_box_view->enabled()); |
668 EXPECT_EQ(search_box_view->search_box(), | 583 EXPECT_EQ(search_box_view->search_box(), |
669 view_->GetWidget()->GetFocusManager()->GetFocusedView()); | 584 view_->GetWidget()->GetFocusManager()->GetFocusedView()); |
670 | 585 |
671 Close(); | 586 Close(); |
672 } | 587 } |
673 | 588 |
674 class AppListViewTestAura : public views::ViewsTestBase, | 589 class AppListViewTestAura : public views::ViewsTestBase { |
675 public ::testing::WithParamInterface<int> { | |
676 public: | 590 public: |
677 AppListViewTestAura() {} | 591 AppListViewTestAura() {} |
678 virtual ~AppListViewTestAura() {} | 592 ~AppListViewTestAura() override {} |
679 | 593 |
680 // testing::Test overrides: | 594 // testing::Test overrides: |
681 void SetUp() override { | 595 void SetUp() override { |
682 views::ViewsTestBase::SetUp(); | 596 views::ViewsTestBase::SetUp(); |
683 | 597 |
684 // On Ash (only) the app list is placed into an aura::Window "container", | 598 // On Ash (only) the app list is placed into an aura::Window "container", |
685 // which is also used to determine the context. In tests, use the ash root | 599 // which is also used to determine the context. In tests, use the ash root |
686 // window as the parent. This only works on aura where the root window is a | 600 // window as the parent. This only works on aura where the root window is a |
687 // NativeView as well as a NativeWindow. | 601 // NativeView as well as a NativeWindow. |
688 gfx::NativeView container = NULL; | 602 gfx::NativeView container = NULL; |
689 #if defined(USE_AURA) | 603 #if defined(USE_AURA) |
690 container = GetContext(); | 604 container = GetContext(); |
691 #endif | 605 #endif |
692 | 606 |
693 test_context_.reset(new AppListViewTestContext(GetParam(), container)); | 607 test_context_.reset(new AppListViewTestContext(container)); |
694 } | 608 } |
695 | 609 |
696 void TearDown() override { | 610 void TearDown() override { |
697 test_context_.reset(); | 611 test_context_.reset(); |
698 views::ViewsTestBase::TearDown(); | 612 views::ViewsTestBase::TearDown(); |
699 } | 613 } |
700 | 614 |
701 protected: | 615 protected: |
702 std::unique_ptr<AppListViewTestContext> test_context_; | 616 std::unique_ptr<AppListViewTestContext> test_context_; |
703 | 617 |
704 private: | 618 private: |
705 DISALLOW_COPY_AND_ASSIGN(AppListViewTestAura); | 619 DISALLOW_COPY_AND_ASSIGN(AppListViewTestAura); |
706 }; | 620 }; |
707 | 621 |
708 class AppListViewTestDesktop : public views::ViewsTestBase, | 622 class AppListViewTestDesktop : public views::ViewsTestBase { |
709 public ::testing::WithParamInterface<int> { | |
710 public: | 623 public: |
711 AppListViewTestDesktop() {} | 624 AppListViewTestDesktop() {} |
712 virtual ~AppListViewTestDesktop() {} | 625 ~AppListViewTestDesktop() override {} |
713 | 626 |
714 // testing::Test overrides: | 627 // testing::Test overrides: |
715 void SetUp() override { | 628 void SetUp() override { |
716 set_views_delegate(base::MakeUnique<AppListViewTestViewsDelegate>(this)); | 629 set_views_delegate(base::MakeUnique<AppListViewTestViewsDelegate>(this)); |
717 views::ViewsTestBase::SetUp(); | 630 views::ViewsTestBase::SetUp(); |
718 test_context_.reset(new AppListViewTestContext(GetParam(), NULL)); | 631 test_context_.reset(new AppListViewTestContext(NULL)); |
719 } | 632 } |
720 | 633 |
721 void TearDown() override { | 634 void TearDown() override { |
722 test_context_.reset(); | 635 test_context_.reset(); |
723 views::ViewsTestBase::TearDown(); | 636 views::ViewsTestBase::TearDown(); |
724 } | 637 } |
725 | 638 |
726 protected: | 639 protected: |
727 std::unique_ptr<AppListViewTestContext> test_context_; | 640 std::unique_ptr<AppListViewTestContext> test_context_; |
728 | 641 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
764 params->context = parent_->GetContext(); | 677 params->context = parent_->GetContext(); |
765 #elif defined(USE_AURA) | 678 #elif defined(USE_AURA) |
766 if (params->parent == NULL && params->context == NULL && !params->child) | 679 if (params->parent == NULL && params->context == NULL && !params->child) |
767 params->native_widget = new views::DesktopNativeWidgetAura(delegate); | 680 params->native_widget = new views::DesktopNativeWidgetAura(delegate); |
768 #endif | 681 #endif |
769 } | 682 } |
770 | 683 |
771 } // namespace | 684 } // namespace |
772 | 685 |
773 // Tests showing the app list with basic test model in an ash-style root window. | 686 // Tests showing the app list with basic test model in an ash-style root window. |
774 TEST_P(AppListViewTestAura, Display) { | 687 TEST_F(AppListViewTestAura, Display) { |
775 EXPECT_NO_FATAL_FAILURE(test_context_->RunDisplayTest()); | 688 EXPECT_NO_FATAL_FAILURE(test_context_->RunDisplayTest()); |
776 } | 689 } |
777 | 690 |
778 // Tests showing the app list on the desktop. Note on ChromeOS, this will still | 691 // Tests showing the app list on the desktop. Note on ChromeOS, this will still |
779 // use the regular root window. | 692 // use the regular root window. |
780 TEST_P(AppListViewTestDesktop, Display) { | 693 TEST_F(AppListViewTestDesktop, Display) { |
781 EXPECT_NO_FATAL_FAILURE(test_context_->RunDisplayTest()); | 694 EXPECT_NO_FATAL_FAILURE(test_context_->RunDisplayTest()); |
782 } | 695 } |
783 | 696 |
784 // Tests that the main grid view is shown after hiding and reshowing the app | 697 // Tests that the main grid view is shown after hiding and reshowing the app |
785 // list with a folder view open. This is a regression test for crbug.com/357058. | 698 // list with a folder view open. This is a regression test for crbug.com/357058. |
786 TEST_P(AppListViewTestAura, ReshowWithOpenFolder) { | 699 TEST_F(AppListViewTestAura, ReshowWithOpenFolder) { |
787 EXPECT_NO_FATAL_FAILURE(test_context_->RunReshowWithOpenFolderTest()); | 700 EXPECT_NO_FATAL_FAILURE(test_context_->RunReshowWithOpenFolderTest()); |
788 } | 701 } |
789 | 702 |
790 TEST_P(AppListViewTestDesktop, ReshowWithOpenFolder) { | 703 TEST_F(AppListViewTestDesktop, ReshowWithOpenFolder) { |
791 EXPECT_NO_FATAL_FAILURE(test_context_->RunReshowWithOpenFolderTest()); | 704 EXPECT_NO_FATAL_FAILURE(test_context_->RunReshowWithOpenFolderTest()); |
792 } | 705 } |
793 | 706 |
794 // Tests that the start page view operates correctly. | 707 // Tests that the start page view operates correctly. |
795 TEST_P(AppListViewTestAura, StartPageTest) { | 708 TEST_F(AppListViewTestAura, StartPageTest) { |
796 EXPECT_NO_FATAL_FAILURE(test_context_->RunStartPageTest()); | 709 EXPECT_NO_FATAL_FAILURE(test_context_->RunStartPageTest()); |
797 } | 710 } |
798 | 711 |
799 TEST_P(AppListViewTestDesktop, StartPageTest) { | 712 TEST_F(AppListViewTestDesktop, StartPageTest) { |
800 EXPECT_NO_FATAL_FAILURE(test_context_->RunStartPageTest()); | 713 EXPECT_NO_FATAL_FAILURE(test_context_->RunStartPageTest()); |
801 } | 714 } |
802 | 715 |
803 // Tests that the start page view operates correctly. | 716 // Tests that the start page view operates correctly. |
804 TEST_P(AppListViewTestAura, PageSwitchingAnimationTest) { | 717 TEST_F(AppListViewTestAura, PageSwitchingAnimationTest) { |
805 EXPECT_NO_FATAL_FAILURE(test_context_->RunPageSwitchingAnimationTest()); | 718 EXPECT_NO_FATAL_FAILURE(test_context_->RunPageSwitchingAnimationTest()); |
806 } | 719 } |
807 | 720 |
808 TEST_P(AppListViewTestDesktop, PageSwitchingAnimationTest) { | 721 TEST_F(AppListViewTestDesktop, PageSwitchingAnimationTest) { |
809 EXPECT_NO_FATAL_FAILURE(test_context_->RunPageSwitchingAnimationTest()); | 722 EXPECT_NO_FATAL_FAILURE(test_context_->RunPageSwitchingAnimationTest()); |
810 } | 723 } |
811 | 724 |
812 // Tests that the profile changes operate correctly. | 725 // Tests that the profile changes operate correctly. |
813 TEST_P(AppListViewTestAura, ProfileChangeTest) { | 726 TEST_F(AppListViewTestAura, ProfileChangeTest) { |
814 EXPECT_NO_FATAL_FAILURE(test_context_->RunProfileChangeTest()); | 727 EXPECT_NO_FATAL_FAILURE(test_context_->RunProfileChangeTest()); |
815 } | 728 } |
816 | 729 |
817 TEST_P(AppListViewTestDesktop, ProfileChangeTest) { | 730 TEST_F(AppListViewTestDesktop, ProfileChangeTest) { |
818 EXPECT_NO_FATAL_FAILURE(test_context_->RunProfileChangeTest()); | 731 EXPECT_NO_FATAL_FAILURE(test_context_->RunProfileChangeTest()); |
819 } | 732 } |
820 | 733 |
821 // Tests that the correct views are displayed for showing search results. | 734 // Tests that the correct views are displayed for showing search results. |
822 TEST_P(AppListViewTestAura, SearchResultsTest) { | 735 TEST_F(AppListViewTestAura, SearchResultsTest) { |
823 EXPECT_NO_FATAL_FAILURE(test_context_->RunSearchResultsTest()); | 736 EXPECT_NO_FATAL_FAILURE(test_context_->RunSearchResultsTest()); |
824 } | 737 } |
825 | 738 |
826 TEST_P(AppListViewTestDesktop, SearchResultsTest) { | 739 TEST_F(AppListViewTestDesktop, SearchResultsTest) { |
827 EXPECT_NO_FATAL_FAILURE(test_context_->RunSearchResultsTest()); | 740 EXPECT_NO_FATAL_FAILURE(test_context_->RunSearchResultsTest()); |
828 } | 741 } |
829 | 742 |
830 // Tests that the back button navigates through the app list correctly. | 743 // Tests that the back button navigates through the app list correctly. |
831 TEST_P(AppListViewTestAura, BackTest) { | 744 TEST_F(AppListViewTestAura, BackTest) { |
832 EXPECT_NO_FATAL_FAILURE(test_context_->RunBackTest()); | 745 EXPECT_NO_FATAL_FAILURE(test_context_->RunBackTest()); |
833 } | 746 } |
834 | 747 |
835 TEST_P(AppListViewTestDesktop, BackTest) { | 748 TEST_F(AppListViewTestDesktop, BackTest) { |
836 EXPECT_NO_FATAL_FAILURE(test_context_->RunBackTest()); | 749 EXPECT_NO_FATAL_FAILURE(test_context_->RunBackTest()); |
837 } | 750 } |
838 | 751 |
839 // Tests that the correct views are displayed for showing search results. | 752 // Tests that the correct views are displayed for showing search results. |
840 TEST_P(AppListViewTestAura, AppListOverlayTest) { | 753 TEST_F(AppListViewTestAura, AppListOverlayTest) { |
841 EXPECT_NO_FATAL_FAILURE(test_context_->RunAppListOverlayTest()); | 754 EXPECT_NO_FATAL_FAILURE(test_context_->RunAppListOverlayTest()); |
842 } | 755 } |
843 | 756 |
844 TEST_P(AppListViewTestDesktop, AppListOverlayTest) { | 757 TEST_F(AppListViewTestDesktop, AppListOverlayTest) { |
845 EXPECT_NO_FATAL_FAILURE(test_context_->RunAppListOverlayTest()); | 758 EXPECT_NO_FATAL_FAILURE(test_context_->RunAppListOverlayTest()); |
846 } | 759 } |
847 | 760 |
848 #if defined(USE_AURA) | |
849 INSTANTIATE_TEST_CASE_P(AppListViewTestAuraInstance, | |
850 AppListViewTestAura, | |
851 ::testing::Range<int>(TEST_TYPE_START, TEST_TYPE_END)); | |
852 #endif | |
853 | |
854 INSTANTIATE_TEST_CASE_P(AppListViewTestDesktopInstance, | |
855 AppListViewTestDesktop, | |
856 ::testing::Range<int>(TEST_TYPE_START, TEST_TYPE_END)); | |
857 | |
858 } // namespace test | 761 } // namespace test |
859 } // namespace app_list | 762 } // namespace app_list |
OLD | NEW |