Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / ui / app_list / views / app_list_view_unittest.cc
blobd1c4fc731afb9d0575aefbcd2759912d9e460113
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/app_list_view.h"
7 #include "base/command_line.h"
8 #include "base/run_loop.h"
9 #include "base/strings/string_util.h"
10 #include "base/strings/utf_string_conversions.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "ui/app_list/app_list_switches.h"
13 #include "ui/app_list/pagination_model.h"
14 #include "ui/app_list/search_box_model.h"
15 #include "ui/app_list/test/app_list_test_model.h"
16 #include "ui/app_list/test/app_list_test_view_delegate.h"
17 #include "ui/app_list/views/app_list_folder_view.h"
18 #include "ui/app_list/views/app_list_main_view.h"
19 #include "ui/app_list/views/apps_container_view.h"
20 #include "ui/app_list/views/apps_grid_view.h"
21 #include "ui/app_list/views/contents_switcher_view.h"
22 #include "ui/app_list/views/contents_view.h"
23 #include "ui/app_list/views/search_box_view.h"
24 #include "ui/app_list/views/search_result_list_view.h"
25 #include "ui/app_list/views/start_page_view.h"
26 #include "ui/app_list/views/test/apps_grid_view_test_api.h"
27 #include "ui/app_list/views/tile_item_view.h"
28 #include "ui/views/controls/textfield/textfield.h"
29 #include "ui/views/test/views_test_base.h"
30 #include "ui/views/views_delegate.h"
31 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
33 namespace app_list {
34 namespace test {
36 namespace {
38 enum TestType {
39 TEST_TYPE_START = 0,
40 NORMAL = TEST_TYPE_START,
41 LANDSCAPE,
42 EXPERIMENTAL,
43 TEST_TYPE_END,
46 bool IsViewAtOrigin(views::View* view) {
47 return view->bounds().origin().IsOrigin();
50 size_t GetVisibleTileItemViews(const std::vector<TileItemView*>& tiles) {
51 size_t count = 0;
52 for (std::vector<TileItemView*>::const_iterator it = tiles.begin();
53 it != tiles.end();
54 ++it) {
55 if ((*it)->visible())
56 count++;
58 return count;
61 // Choose a set that is 3 regular app list pages and 2 landscape app list pages.
62 const int kInitialItems = 34;
64 class TestTileSearchResult : public SearchResult {
65 public:
66 TestTileSearchResult() { set_display_type(DISPLAY_TILE); }
67 virtual ~TestTileSearchResult() {}
69 private:
70 DISALLOW_COPY_AND_ASSIGN(TestTileSearchResult);
73 // Allows the same tests to run with different contexts: either an Ash-style
74 // root window or a desktop window tree host.
75 class AppListViewTestContext {
76 public:
77 AppListViewTestContext(int test_type, gfx::NativeView parent);
78 ~AppListViewTestContext();
80 // Test displaying the app list and performs a standard set of checks on its
81 // top level views. Then closes the window.
82 void RunDisplayTest();
84 // Hides and reshows the app list with a folder open, expecting the main grid
85 // view to be shown.
86 void RunReshowWithOpenFolderTest();
88 // Tests displaying of the experimental app list and shows the start page.
89 void RunStartPageTest();
91 // Tests switching rapidly between multiple pages of the launcher.
92 void RunPageSwitchingAnimationTest();
94 // Tests changing the App List profile.
95 void RunProfileChangeTest();
97 // Tests displaying of the search results.
98 void RunSearchResultsTest();
100 // A standard set of checks on a view, e.g., ensuring it is drawn and visible.
101 static void CheckView(views::View* subview);
103 // Invoked when the Widget is closing, and the view it contains is about to
104 // be torn down. This only occurs in a run loop and will be used as a signal
105 // to quit.
106 void NativeWidgetClosing() {
107 view_ = NULL;
108 run_loop_->Quit();
111 // Whether the experimental "landscape" app launcher UI is being tested.
112 bool is_landscape() const {
113 return test_type_ == LANDSCAPE || test_type_ == EXPERIMENTAL;
116 private:
117 // Switches the active launcher page in the contents view and lays out to
118 // ensure all launcher pages are in the correct position.
119 void ShowContentsViewPageAndVerify(int index);
121 // Shows the app list and waits until a paint occurs.
122 void Show();
124 // Closes the app list. This sets |view_| to NULL.
125 void Close();
127 // Gets the PaginationModel owned by |view_|.
128 PaginationModel* GetPaginationModel();
130 const TestType test_type_;
131 scoped_ptr<base::RunLoop> run_loop_;
132 app_list::AppListView* view_; // Owned by native widget.
133 app_list::test::AppListTestViewDelegate* delegate_; // Owned by |view_|;
135 DISALLOW_COPY_AND_ASSIGN(AppListViewTestContext);
138 // Extend the regular AppListTestViewDelegate to communicate back to the test
139 // context. Note the test context doesn't simply inherit this, because the
140 // delegate is owned by the view.
141 class UnitTestViewDelegate : public app_list::test::AppListTestViewDelegate {
142 public:
143 UnitTestViewDelegate(AppListViewTestContext* parent) : parent_(parent) {}
145 // Overridden from app_list::AppListViewDelegate:
146 virtual bool ShouldCenterWindow() const OVERRIDE {
147 return app_list::switches::IsCenteredAppListEnabled();
150 // Overridden from app_list::test::AppListTestViewDelegate:
151 virtual void ViewClosing() OVERRIDE { parent_->NativeWidgetClosing(); }
153 private:
154 AppListViewTestContext* parent_;
156 DISALLOW_COPY_AND_ASSIGN(UnitTestViewDelegate);
159 AppListViewTestContext::AppListViewTestContext(int test_type,
160 gfx::NativeView parent)
161 : test_type_(static_cast<TestType>(test_type)) {
162 switch (test_type_) {
163 case NORMAL:
164 break;
165 case LANDSCAPE:
166 base::CommandLine::ForCurrentProcess()->AppendSwitch(
167 switches::kEnableCenteredAppList);
168 break;
169 case EXPERIMENTAL:
170 base::CommandLine::ForCurrentProcess()->AppendSwitch(
171 switches::kEnableExperimentalAppList);
172 break;
173 default:
174 NOTREACHED();
175 break;
178 delegate_ = new UnitTestViewDelegate(this);
179 view_ = new app_list::AppListView(delegate_);
181 // Initialize centered around a point that ensures the window is wholly shown.
182 view_->InitAsBubbleAtFixedLocation(parent,
184 gfx::Point(300, 300),
185 views::BubbleBorder::FLOAT,
186 false /* border_accepts_events */);
189 AppListViewTestContext::~AppListViewTestContext() {
190 // The view observes the PaginationModel which is about to get destroyed, so
191 // if the view is not already deleted by the time this destructor is called,
192 // there will be problems.
193 EXPECT_FALSE(view_);
196 // static
197 void AppListViewTestContext::CheckView(views::View* subview) {
198 ASSERT_TRUE(subview);
199 EXPECT_TRUE(subview->parent());
200 EXPECT_TRUE(subview->visible());
201 EXPECT_TRUE(subview->IsDrawn());
204 void AppListViewTestContext::ShowContentsViewPageAndVerify(int index) {
205 ContentsView* contents_view = view_->app_list_main_view()->contents_view();
206 contents_view->SetActivePage(index);
207 contents_view->Layout();
208 for (int i = 0; i < contents_view->NumLauncherPages(); ++i) {
209 EXPECT_EQ(i == index, IsViewAtOrigin(contents_view->GetPageView(i)));
213 void AppListViewTestContext::Show() {
214 view_->GetWidget()->Show();
215 run_loop_.reset(new base::RunLoop);
216 view_->SetNextPaintCallback(run_loop_->QuitClosure());
217 run_loop_->Run();
219 EXPECT_TRUE(view_->GetWidget()->IsVisible());
222 void AppListViewTestContext::Close() {
223 view_->GetWidget()->Close();
224 run_loop_.reset(new base::RunLoop);
225 run_loop_->Run();
227 // |view_| should have been deleted and set to NULL via ViewClosing().
228 EXPECT_FALSE(view_);
231 PaginationModel* AppListViewTestContext::GetPaginationModel() {
232 return view_->GetAppsPaginationModel();
235 void AppListViewTestContext::RunDisplayTest() {
236 EXPECT_FALSE(view_->GetWidget()->IsVisible());
237 EXPECT_EQ(-1, GetPaginationModel()->total_pages());
238 delegate_->GetTestModel()->PopulateApps(kInitialItems);
240 Show();
241 if (is_landscape())
242 EXPECT_EQ(2, GetPaginationModel()->total_pages());
243 else
244 EXPECT_EQ(3, GetPaginationModel()->total_pages());
245 EXPECT_EQ(0, GetPaginationModel()->selected_page());
247 // Checks on the main view.
248 AppListMainView* main_view = view_->app_list_main_view();
249 EXPECT_NO_FATAL_FAILURE(CheckView(main_view));
250 EXPECT_NO_FATAL_FAILURE(CheckView(main_view->contents_view()));
252 EXPECT_TRUE(main_view->contents_view()->IsNamedPageActive(
253 test_type_ == EXPERIMENTAL ? ContentsView::NAMED_PAGE_START
254 : ContentsView::NAMED_PAGE_APPS));
256 Close();
259 void AppListViewTestContext::RunReshowWithOpenFolderTest() {
260 EXPECT_FALSE(view_->GetWidget()->IsVisible());
261 EXPECT_EQ(-1, GetPaginationModel()->total_pages());
263 AppListTestModel* model = delegate_->GetTestModel();
264 model->PopulateApps(kInitialItems);
265 const std::string folder_id =
266 model->MergeItems(model->top_level_item_list()->item_at(0)->id(),
267 model->top_level_item_list()->item_at(1)->id());
269 AppListFolderItem* folder_item = model->FindFolderItem(folder_id);
270 EXPECT_TRUE(folder_item);
272 Show();
274 // The main grid view should be showing initially.
275 AppListMainView* main_view = view_->app_list_main_view();
276 AppsContainerView* container_view =
277 main_view->contents_view()->apps_container_view();
278 EXPECT_NO_FATAL_FAILURE(CheckView(main_view));
279 EXPECT_NO_FATAL_FAILURE(CheckView(container_view->apps_grid_view()));
280 EXPECT_FALSE(container_view->app_list_folder_view()->visible());
282 AppsGridViewTestApi test_api(container_view->apps_grid_view());
283 test_api.PressItemAt(0);
285 // After pressing the folder item, the folder view should be showing.
286 EXPECT_NO_FATAL_FAILURE(CheckView(main_view));
287 EXPECT_NO_FATAL_FAILURE(CheckView(container_view->app_list_folder_view()));
288 EXPECT_FALSE(container_view->apps_grid_view()->visible());
290 view_->GetWidget()->Hide();
291 EXPECT_FALSE(view_->GetWidget()->IsVisible());
293 Show();
295 // The main grid view should be showing after a reshow.
296 EXPECT_NO_FATAL_FAILURE(CheckView(main_view));
297 EXPECT_NO_FATAL_FAILURE(CheckView(container_view->apps_grid_view()));
298 EXPECT_FALSE(container_view->app_list_folder_view()->visible());
300 Close();
303 void AppListViewTestContext::RunStartPageTest() {
304 EXPECT_FALSE(view_->GetWidget()->IsVisible());
305 EXPECT_EQ(-1, GetPaginationModel()->total_pages());
306 AppListTestModel* model = delegate_->GetTestModel();
307 model->PopulateApps(3);
309 Show();
311 AppListMainView* main_view = view_->app_list_main_view();
312 StartPageView* start_page_view =
313 main_view->contents_view()->start_page_view();
314 // Checks on the main view.
315 EXPECT_NO_FATAL_FAILURE(CheckView(main_view));
316 EXPECT_NO_FATAL_FAILURE(CheckView(main_view->contents_view()));
317 if (test_type_ == EXPERIMENTAL) {
318 EXPECT_NO_FATAL_FAILURE(CheckView(start_page_view));
320 // Show the start page view.
321 ContentsView* contents_view = main_view->contents_view();
322 ShowContentsViewPageAndVerify(contents_view->GetPageIndexForNamedPage(
323 ContentsView::NAMED_PAGE_START));
324 EXPECT_FALSE(main_view->search_box_view()->visible());
326 gfx::Size view_size(view_->GetPreferredSize());
327 ShowContentsViewPageAndVerify(
328 contents_view->GetPageIndexForNamedPage(ContentsView::NAMED_PAGE_APPS));
329 EXPECT_TRUE(main_view->search_box_view()->visible());
331 // Hiding and showing the search box should not affect the app list's
332 // preferred size. This is a regression test for http://crbug.com/386912.
333 EXPECT_EQ(view_size.ToString(), view_->GetPreferredSize().ToString());
335 // Check tiles hide and show on deletion and addition.
336 model->results()->Add(new TestTileSearchResult());
337 start_page_view->UpdateForTesting();
338 EXPECT_EQ(1u, GetVisibleTileItemViews(start_page_view->tile_views()));
339 model->results()->DeleteAll();
340 start_page_view->UpdateForTesting();
341 EXPECT_EQ(0u, GetVisibleTileItemViews(start_page_view->tile_views()));
342 } else {
343 EXPECT_EQ(NULL, start_page_view);
346 Close();
349 void AppListViewTestContext::RunPageSwitchingAnimationTest() {
350 if (test_type_ == EXPERIMENTAL) {
351 Show();
353 AppListMainView* main_view = view_->app_list_main_view();
354 // Checks on the main view.
355 EXPECT_NO_FATAL_FAILURE(CheckView(main_view));
356 EXPECT_NO_FATAL_FAILURE(CheckView(main_view->contents_view()));
358 ContentsView* contents_view = main_view->contents_view();
359 // Pad the ContentsView with blank pages so we have at least 3 views.
360 while (contents_view->NumLauncherPages() < 3)
361 contents_view->AddBlankPageForTesting();
363 contents_view->SetActivePage(0);
364 contents_view->Layout();
365 EXPECT_TRUE(IsViewAtOrigin(contents_view->GetPageView(0)));
366 EXPECT_FALSE(IsViewAtOrigin(contents_view->GetPageView(1)));
367 EXPECT_FALSE(IsViewAtOrigin(contents_view->GetPageView(2)));
369 // Change pages. View should not have moved without Layout().
370 contents_view->SetActivePage(1);
371 EXPECT_TRUE(IsViewAtOrigin(contents_view->GetPageView(0)));
372 EXPECT_FALSE(IsViewAtOrigin(contents_view->GetPageView(1)));
373 EXPECT_FALSE(IsViewAtOrigin(contents_view->GetPageView(2)));
375 // Change to a third page. This queues up the second animation behind the
376 // first.
377 contents_view->SetActivePage(2);
378 EXPECT_TRUE(IsViewAtOrigin(contents_view->GetPageView(0)));
379 EXPECT_FALSE(IsViewAtOrigin(contents_view->GetPageView(1)));
380 EXPECT_FALSE(IsViewAtOrigin(contents_view->GetPageView(2)));
382 // Call Layout(). Should jump to the third page.
383 contents_view->Layout();
384 EXPECT_FALSE(IsViewAtOrigin(contents_view->GetPageView(0)));
385 EXPECT_FALSE(IsViewAtOrigin(contents_view->GetPageView(1)));
386 EXPECT_TRUE(IsViewAtOrigin(contents_view->GetPageView(2)));
389 Close();
392 void AppListViewTestContext::RunProfileChangeTest() {
393 EXPECT_FALSE(view_->GetWidget()->IsVisible());
394 EXPECT_EQ(-1, GetPaginationModel()->total_pages());
395 delegate_->GetTestModel()->PopulateApps(kInitialItems);
397 Show();
399 if (is_landscape())
400 EXPECT_EQ(2, GetPaginationModel()->total_pages());
401 else
402 EXPECT_EQ(3, GetPaginationModel()->total_pages());
404 // Change the profile. The original model needs to be kept alive for
405 // observers to unregister themselves.
406 scoped_ptr<AppListTestModel> original_test_model(
407 delegate_->ReleaseTestModel());
408 delegate_->set_next_profile_app_count(1);
410 // The original ContentsView is destroyed here.
411 view_->SetProfileByPath(base::FilePath());
412 EXPECT_EQ(1, GetPaginationModel()->total_pages());
414 StartPageView* start_page_view =
415 view_->app_list_main_view()->contents_view()->start_page_view();
416 ContentsSwitcherView* contents_switcher_view =
417 view_->app_list_main_view()->contents_switcher_view();
418 if (test_type_ == EXPERIMENTAL) {
419 EXPECT_NO_FATAL_FAILURE(CheckView(contents_switcher_view));
420 EXPECT_EQ(view_->app_list_main_view()->contents_view(),
421 contents_switcher_view->contents_view());
422 EXPECT_NO_FATAL_FAILURE(CheckView(start_page_view));
423 } else {
424 EXPECT_EQ(NULL, contents_switcher_view);
425 EXPECT_EQ(NULL, start_page_view);
428 // New model updates should be processed by the start page view.
429 delegate_->GetTestModel()->results()->Add(new TestTileSearchResult());
430 if (test_type_ == EXPERIMENTAL) {
431 start_page_view->UpdateForTesting();
432 EXPECT_EQ(1u, GetVisibleTileItemViews(start_page_view->tile_views()));
435 // Old model updates should be ignored.
436 original_test_model->results()->Add(new TestTileSearchResult());
437 original_test_model->results()->Add(new TestTileSearchResult());
438 if (test_type_ == EXPERIMENTAL) {
439 start_page_view->UpdateForTesting();
440 EXPECT_EQ(1u, GetVisibleTileItemViews(start_page_view->tile_views()));
443 Close();
446 void AppListViewTestContext::RunSearchResultsTest() {
447 EXPECT_FALSE(view_->GetWidget()->IsVisible());
448 EXPECT_EQ(-1, GetPaginationModel()->total_pages());
449 AppListTestModel* model = delegate_->GetTestModel();
450 model->PopulateApps(3);
452 Show();
454 AppListMainView* main_view = view_->app_list_main_view();
455 ContentsView* contents_view = main_view->contents_view();
456 ShowContentsViewPageAndVerify(
457 contents_view->GetPageIndexForNamedPage(ContentsView::NAMED_PAGE_APPS));
458 EXPECT_TRUE(main_view->search_box_view()->visible());
460 // Show the search results.
461 contents_view->ShowSearchResults(true);
462 contents_view->Layout();
463 EXPECT_TRUE(contents_view->IsShowingSearchResults());
464 EXPECT_TRUE(main_view->search_box_view()->visible());
466 if (test_type_ == EXPERIMENTAL) {
467 EXPECT_TRUE(
468 contents_view->IsNamedPageActive(ContentsView::NAMED_PAGE_START));
469 EXPECT_TRUE(IsViewAtOrigin(contents_view->start_page_view()));
470 } else {
471 EXPECT_TRUE(contents_view->IsNamedPageActive(
472 ContentsView::NAMED_PAGE_SEARCH_RESULTS));
473 EXPECT_TRUE(IsViewAtOrigin(contents_view->search_results_view()));
476 // Hide the search results.
477 contents_view->ShowSearchResults(false);
478 contents_view->Layout();
479 EXPECT_FALSE(contents_view->IsShowingSearchResults());
481 // Check that we return to the page that we were on before the search.
482 EXPECT_TRUE(contents_view->IsNamedPageActive(ContentsView::NAMED_PAGE_APPS));
483 EXPECT_TRUE(IsViewAtOrigin(contents_view->apps_container_view()));
484 EXPECT_TRUE(main_view->search_box_view()->visible());
486 if (test_type_ == EXPERIMENTAL) {
487 ShowContentsViewPageAndVerify(contents_view->GetPageIndexForNamedPage(
488 ContentsView::NAMED_PAGE_START));
490 // Check that typing into the dummy search box triggers the search page.
491 base::string16 search_text = base::UTF8ToUTF16("test");
492 SearchBoxView* dummy_search_box =
493 contents_view->start_page_view()->dummy_search_box_view();
494 EXPECT_TRUE(dummy_search_box->IsDrawn());
495 dummy_search_box->search_box()->InsertText(search_text);
496 contents_view->Layout();
497 // Check that the current search is using |search_text|.
498 EXPECT_EQ(search_text, delegate_->GetTestModel()->search_box()->text());
499 EXPECT_TRUE(contents_view->IsShowingSearchResults());
500 EXPECT_FALSE(dummy_search_box->IsDrawn());
501 EXPECT_TRUE(main_view->search_box_view()->visible());
502 EXPECT_EQ(search_text, main_view->search_box_view()->search_box()->text());
503 EXPECT_TRUE(
504 contents_view->IsNamedPageActive(ContentsView::NAMED_PAGE_START));
505 EXPECT_TRUE(IsViewAtOrigin(contents_view->start_page_view()));
507 // Check that typing into the real search box triggers the search page.
508 ShowContentsViewPageAndVerify(
509 contents_view->GetPageIndexForNamedPage(ContentsView::NAMED_PAGE_APPS));
510 EXPECT_TRUE(IsViewAtOrigin(contents_view->apps_container_view()));
512 base::string16 new_search_text = base::UTF8ToUTF16("apple");
513 main_view->search_box_view()->search_box()->SetText(base::string16());
514 main_view->search_box_view()->search_box()->InsertText(new_search_text);
515 // Check that the current search is using |search_text|.
516 EXPECT_EQ(new_search_text, delegate_->GetTestModel()->search_box()->text());
517 EXPECT_EQ(new_search_text,
518 main_view->search_box_view()->search_box()->text());
519 EXPECT_TRUE(contents_view->IsShowingSearchResults());
520 EXPECT_FALSE(dummy_search_box->IsDrawn());
521 EXPECT_TRUE(main_view->search_box_view()->visible());
522 EXPECT_TRUE(dummy_search_box->search_box()->text().empty());
524 // Check that the dummy search box is clear when reshowing the start page.
525 ShowContentsViewPageAndVerify(
526 contents_view->GetPageIndexForNamedPage(ContentsView::NAMED_PAGE_APPS));
527 ShowContentsViewPageAndVerify(contents_view->GetPageIndexForNamedPage(
528 ContentsView::NAMED_PAGE_START));
529 EXPECT_TRUE(dummy_search_box->IsDrawn());
530 EXPECT_TRUE(dummy_search_box->search_box()->text().empty());
533 Close();
536 class AppListViewTestAura : public views::ViewsTestBase,
537 public ::testing::WithParamInterface<int> {
538 public:
539 AppListViewTestAura() {}
540 virtual ~AppListViewTestAura() {}
542 // testing::Test overrides:
543 virtual void SetUp() OVERRIDE {
544 views::ViewsTestBase::SetUp();
546 // On Ash (only) the app list is placed into an aura::Window "container",
547 // which is also used to determine the context. In tests, use the ash root
548 // window as the parent. This only works on aura where the root window is a
549 // NativeView as well as a NativeWindow.
550 gfx::NativeView container = NULL;
551 #if defined(USE_AURA)
552 container = GetContext();
553 #endif
555 test_context_.reset(new AppListViewTestContext(GetParam(), container));
558 virtual void TearDown() OVERRIDE {
559 test_context_.reset();
560 views::ViewsTestBase::TearDown();
563 protected:
564 scoped_ptr<AppListViewTestContext> test_context_;
566 private:
567 DISALLOW_COPY_AND_ASSIGN(AppListViewTestAura);
570 class AppListViewTestDesktop : public views::ViewsTestBase,
571 public ::testing::WithParamInterface<int> {
572 public:
573 AppListViewTestDesktop() {}
574 virtual ~AppListViewTestDesktop() {}
576 // testing::Test overrides:
577 virtual void SetUp() OVERRIDE {
578 set_views_delegate(new AppListViewTestViewsDelegate(this));
579 views::ViewsTestBase::SetUp();
580 test_context_.reset(new AppListViewTestContext(GetParam(), NULL));
583 virtual void TearDown() OVERRIDE {
584 test_context_.reset();
585 views::ViewsTestBase::TearDown();
588 protected:
589 scoped_ptr<AppListViewTestContext> test_context_;
591 private:
592 class AppListViewTestViewsDelegate : public views::TestViewsDelegate {
593 public:
594 AppListViewTestViewsDelegate(AppListViewTestDesktop* parent)
595 : parent_(parent) {}
597 // Overridden from views::ViewsDelegate:
598 virtual void OnBeforeWidgetInit(
599 views::Widget::InitParams* params,
600 views::internal::NativeWidgetDelegate* delegate) OVERRIDE;
602 private:
603 AppListViewTestDesktop* parent_;
605 DISALLOW_COPY_AND_ASSIGN(AppListViewTestViewsDelegate);
608 DISALLOW_COPY_AND_ASSIGN(AppListViewTestDesktop);
611 void AppListViewTestDesktop::AppListViewTestViewsDelegate::OnBeforeWidgetInit(
612 views::Widget::InitParams* params,
613 views::internal::NativeWidgetDelegate* delegate) {
614 // Mimic the logic in ChromeViewsDelegate::OnBeforeWidgetInit(). Except, for
615 // ChromeOS, use the root window from the AuraTestHelper rather than depending
616 // on ash::Shell:GetPrimaryRootWindow(). Also assume non-ChromeOS is never the
617 // Ash desktop, as that is covered by AppListViewTestAura.
618 #if defined(OS_CHROMEOS)
619 if (!params->parent && !params->context)
620 params->context = parent_->GetContext();
621 #elif defined(USE_AURA)
622 if (params->parent == NULL && params->context == NULL && !params->child)
623 params->native_widget = new views::DesktopNativeWidgetAura(delegate);
624 #endif
627 } // namespace
629 // Tests showing the app list with basic test model in an ash-style root window.
630 TEST_P(AppListViewTestAura, Display) {
631 EXPECT_NO_FATAL_FAILURE(test_context_->RunDisplayTest());
634 // Tests showing the app list on the desktop. Note on ChromeOS, this will still
635 // use the regular root window.
636 TEST_P(AppListViewTestDesktop, Display) {
637 EXPECT_NO_FATAL_FAILURE(test_context_->RunDisplayTest());
640 // Tests that the main grid view is shown after hiding and reshowing the app
641 // list with a folder view open. This is a regression test for crbug.com/357058.
642 TEST_P(AppListViewTestAura, ReshowWithOpenFolder) {
643 EXPECT_NO_FATAL_FAILURE(test_context_->RunReshowWithOpenFolderTest());
646 TEST_P(AppListViewTestDesktop, ReshowWithOpenFolder) {
647 EXPECT_NO_FATAL_FAILURE(test_context_->RunReshowWithOpenFolderTest());
650 // Tests that the start page view operates correctly.
651 TEST_P(AppListViewTestAura, StartPageTest) {
652 EXPECT_NO_FATAL_FAILURE(test_context_->RunStartPageTest());
655 TEST_P(AppListViewTestDesktop, StartPageTest) {
656 EXPECT_NO_FATAL_FAILURE(test_context_->RunStartPageTest());
659 // Tests that the start page view operates correctly.
660 TEST_P(AppListViewTestAura, PageSwitchingAnimationTest) {
661 EXPECT_NO_FATAL_FAILURE(test_context_->RunPageSwitchingAnimationTest());
664 TEST_P(AppListViewTestDesktop, PageSwitchingAnimationTest) {
665 EXPECT_NO_FATAL_FAILURE(test_context_->RunPageSwitchingAnimationTest());
668 // Tests that the profile changes operate correctly.
669 TEST_P(AppListViewTestAura, ProfileChangeTest) {
670 EXPECT_NO_FATAL_FAILURE(test_context_->RunProfileChangeTest());
673 TEST_P(AppListViewTestDesktop, ProfileChangeTest) {
674 EXPECT_NO_FATAL_FAILURE(test_context_->RunProfileChangeTest());
677 // Tests that the correct views are displayed for showing search results.
678 TEST_P(AppListViewTestAura, SearchResultsTest) {
679 EXPECT_NO_FATAL_FAILURE(test_context_->RunSearchResultsTest());
682 TEST_P(AppListViewTestDesktop, SearchResultsTest) {
683 EXPECT_NO_FATAL_FAILURE(test_context_->RunSearchResultsTest());
686 INSTANTIATE_TEST_CASE_P(AppListViewTestAuraInstance,
687 AppListViewTestAura,
688 ::testing::Range<int>(TEST_TYPE_START, TEST_TYPE_END));
690 INSTANTIATE_TEST_CASE_P(AppListViewTestDesktopInstance,
691 AppListViewTestDesktop,
692 ::testing::Range<int>(TEST_TYPE_START, TEST_TYPE_END));
694 } // namespace test
695 } // namespace app_list