| 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 "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 |
| 42 bool IsViewAtOrigin(views::View* view) { |
| 43 return view->bounds().origin().IsOrigin(); |
| 44 } |
| 45 |
| 33 // Choose a set that is 3 regular app list pages and 2 landscape app list pages. | 46 // Choose a set that is 3 regular app list pages and 2 landscape app list pages. |
| 34 const int kInitialItems = 34; | 47 const int kInitialItems = 34; |
| 35 | 48 |
| 36 // Allows the same tests to run with different contexts: either an Ash-style | 49 // Allows the same tests to run with different contexts: either an Ash-style |
| 37 // root window or a desktop window tree host. | 50 // root window or a desktop window tree host. |
| 38 class AppListViewTestContext { | 51 class AppListViewTestContext { |
| 39 public: | 52 public: |
| 40 AppListViewTestContext(bool is_landscape, aura::Window* parent); | 53 AppListViewTestContext(int test_type, aura::Window* parent); |
| 41 ~AppListViewTestContext(); | 54 ~AppListViewTestContext(); |
| 42 | 55 |
| 43 // Test displaying the app list and performs a standard set of checks on its | 56 // Test displaying the app list and performs a standard set of checks on its |
| 44 // top level views. Then closes the window. | 57 // top level views. Then closes the window. |
| 45 void RunDisplayTest(); | 58 void RunDisplayTest(); |
| 46 | 59 |
| 47 // Hides and reshows the app list with a folder open, expecting the main grid | 60 // Hides and reshows the app list with a folder open, expecting the main grid |
| 48 // view to be shown. | 61 // view to be shown. |
| 49 void RunReshowWithOpenFolderTest(); | 62 void RunReshowWithOpenFolderTest(); |
| 50 | 63 |
| 64 // Tests displaying of the experimental app list and shows the start page. |
| 65 void RunStartPageTest(); |
| 66 |
| 51 // A standard set of checks on a view, e.g., ensuring it is drawn and visible. | 67 // A standard set of checks on a view, e.g., ensuring it is drawn and visible. |
| 52 static void CheckView(views::View* subview); | 68 static void CheckView(views::View* subview); |
| 53 | 69 |
| 54 // Invoked when the Widget is closing, and the view it contains is about to | 70 // 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 | 71 // be torn down. This only occurs in a run loop and will be used as a signal |
| 56 // to quit. | 72 // to quit. |
| 57 void NativeWidgetClosing() { | 73 void NativeWidgetClosing() { |
| 58 view_ = NULL; | 74 view_ = NULL; |
| 59 run_loop_->Quit(); | 75 run_loop_->Quit(); |
| 60 } | 76 } |
| 61 | 77 |
| 62 // Whether the experimental "landscape" app launcher UI is being tested. | 78 // Whether the experimental "landscape" app launcher UI is being tested. |
| 63 bool is_landscape() const { return is_landscape_; } | 79 bool is_landscape() const { |
| 80 return test_type_ == LANDSCAPE || test_type_ == EXPERIMENTAL; |
| 81 } |
| 64 | 82 |
| 65 private: | 83 private: |
| 66 // Shows the app list and waits until a paint occurs. | 84 // Shows the app list and waits until a paint occurs. |
| 67 void Show(); | 85 void Show(); |
| 68 | 86 |
| 69 // Closes the app list. This sets |view_| to NULL. | 87 // Closes the app list. This sets |view_| to NULL. |
| 70 void Close(); | 88 void Close(); |
| 71 | 89 |
| 72 const bool is_landscape_; | 90 const TestType test_type_; |
| 73 scoped_ptr<base::RunLoop> run_loop_; | 91 scoped_ptr<base::RunLoop> run_loop_; |
| 74 PaginationModel pagination_model_; | 92 PaginationModel pagination_model_; |
| 75 app_list::AppListView* view_; // Owned by native widget. | 93 app_list::AppListView* view_; // Owned by native widget. |
| 76 app_list::test::AppListTestViewDelegate* delegate_; // Owned by |view_|; | 94 app_list::test::AppListTestViewDelegate* delegate_; // Owned by |view_|; |
| 77 | 95 |
| 78 DISALLOW_COPY_AND_ASSIGN(AppListViewTestContext); | 96 DISALLOW_COPY_AND_ASSIGN(AppListViewTestContext); |
| 79 }; | 97 }; |
| 80 | 98 |
| 81 // Extend the regular AppListTestViewDelegate to communicate back to the test | 99 // Extend the regular AppListTestViewDelegate to communicate back to the test |
| 82 // context. Note the test context doesn't simply inherit this, because the | 100 // context. Note the test context doesn't simply inherit this, because the |
| 83 // delegate is owned by the view. | 101 // delegate is owned by the view. |
| 84 class UnitTestViewDelegate : public app_list::test::AppListTestViewDelegate { | 102 class UnitTestViewDelegate : public app_list::test::AppListTestViewDelegate { |
| 85 public: | 103 public: |
| 86 UnitTestViewDelegate(AppListViewTestContext* parent) : parent_(parent) {} | 104 UnitTestViewDelegate(AppListViewTestContext* parent) : parent_(parent) {} |
| 87 | 105 |
| 88 // Overridden from app_list::AppListViewDelegate: | 106 // Overridden from app_list::AppListViewDelegate: |
| 89 virtual bool ShouldCenterWindow() const OVERRIDE { | 107 virtual bool ShouldCenterWindow() const OVERRIDE { |
| 90 return app_list::switches::IsCenteredAppListEnabled(); | 108 return app_list::switches::IsCenteredAppListEnabled(); |
| 91 } | 109 } |
| 92 | 110 |
| 93 // Overridden from app_list::test::AppListTestViewDelegate: | 111 // Overridden from app_list::test::AppListTestViewDelegate: |
| 94 virtual void ViewClosing() OVERRIDE { parent_->NativeWidgetClosing(); } | 112 virtual void ViewClosing() OVERRIDE { parent_->NativeWidgetClosing(); } |
| 95 | 113 |
| 96 private: | 114 private: |
| 97 AppListViewTestContext* parent_; | 115 AppListViewTestContext* parent_; |
| 98 | 116 |
| 99 DISALLOW_COPY_AND_ASSIGN(UnitTestViewDelegate); | 117 DISALLOW_COPY_AND_ASSIGN(UnitTestViewDelegate); |
| 100 }; | 118 }; |
| 101 | 119 |
| 102 AppListViewTestContext::AppListViewTestContext(bool is_landscape, | 120 AppListViewTestContext::AppListViewTestContext(int test_type, |
| 103 aura::Window* parent) | 121 aura::Window* parent) |
| 104 : is_landscape_(is_landscape) { | 122 : test_type_(static_cast<TestType>(test_type)) { |
| 105 if (is_landscape_) { | 123 switch (test_type_) { |
| 106 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 124 case NORMAL: |
| 107 switches::kEnableCenteredAppList); | 125 break; |
| 126 case LANDSCAPE: |
| 127 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 128 switches::kEnableCenteredAppList); |
| 129 break; |
| 130 case EXPERIMENTAL: |
| 131 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 132 switches::kEnableExperimentalAppList); |
| 133 break; |
| 134 default: |
| 135 NOTREACHED(); |
| 136 break; |
| 108 } | 137 } |
| 109 | 138 |
| 110 delegate_ = new UnitTestViewDelegate(this); | 139 delegate_ = new UnitTestViewDelegate(this); |
| 111 view_ = new app_list::AppListView(delegate_); | 140 view_ = new app_list::AppListView(delegate_); |
| 112 | 141 |
| 113 // Initialize centered around a point that ensures the window is wholly shown. | 142 // Initialize centered around a point that ensures the window is wholly shown. |
| 114 view_->InitAsBubbleAtFixedLocation(parent, | 143 view_->InitAsBubbleAtFixedLocation(parent, |
| 115 &pagination_model_, | 144 &pagination_model_, |
| 116 gfx::Point(300, 300), | 145 gfx::Point(300, 300), |
| 117 views::BubbleBorder::FLOAT, | 146 views::BubbleBorder::FLOAT, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 // |view_| should have been deleted and set to NULL via ViewClosing(). | 179 // |view_| should have been deleted and set to NULL via ViewClosing(). |
| 151 EXPECT_FALSE(view_); | 180 EXPECT_FALSE(view_); |
| 152 } | 181 } |
| 153 | 182 |
| 154 void AppListViewTestContext::RunDisplayTest() { | 183 void AppListViewTestContext::RunDisplayTest() { |
| 155 EXPECT_FALSE(view_->GetWidget()->IsVisible()); | 184 EXPECT_FALSE(view_->GetWidget()->IsVisible()); |
| 156 EXPECT_EQ(-1, pagination_model_.total_pages()); | 185 EXPECT_EQ(-1, pagination_model_.total_pages()); |
| 157 delegate_->GetTestModel()->PopulateApps(kInitialItems); | 186 delegate_->GetTestModel()->PopulateApps(kInitialItems); |
| 158 | 187 |
| 159 Show(); | 188 Show(); |
| 160 if (is_landscape_) | 189 if (is_landscape()) |
| 161 EXPECT_EQ(2, pagination_model_.total_pages()); | 190 EXPECT_EQ(2, pagination_model_.total_pages()); |
| 162 else | 191 else |
| 163 EXPECT_EQ(3, pagination_model_.total_pages()); | 192 EXPECT_EQ(3, pagination_model_.total_pages()); |
| 164 EXPECT_EQ(0, pagination_model_.selected_page()); | 193 EXPECT_EQ(0, pagination_model_.selected_page()); |
| 165 | 194 |
| 166 // Checks on the main view. | 195 // Checks on the main view. |
| 167 AppListMainView* main_view = view_->app_list_main_view(); | 196 AppListMainView* main_view = view_->app_list_main_view(); |
| 168 EXPECT_NO_FATAL_FAILURE(CheckView(main_view)); | 197 EXPECT_NO_FATAL_FAILURE(CheckView(main_view)); |
| 169 EXPECT_NO_FATAL_FAILURE(CheckView(main_view->search_box_view())); | 198 EXPECT_NO_FATAL_FAILURE(CheckView(main_view->search_box_view())); |
| 170 EXPECT_NO_FATAL_FAILURE(CheckView(main_view->contents_view())); | 199 EXPECT_NO_FATAL_FAILURE(CheckView(main_view->contents_view())); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 Show(); | 238 Show(); |
| 210 | 239 |
| 211 // The main grid view should be showing after a reshow. | 240 // The main grid view should be showing after a reshow. |
| 212 EXPECT_NO_FATAL_FAILURE(CheckView(main_view)); | 241 EXPECT_NO_FATAL_FAILURE(CheckView(main_view)); |
| 213 EXPECT_NO_FATAL_FAILURE(CheckView(container_view->apps_grid_view())); | 242 EXPECT_NO_FATAL_FAILURE(CheckView(container_view->apps_grid_view())); |
| 214 EXPECT_FALSE(container_view->app_list_folder_view()->visible()); | 243 EXPECT_FALSE(container_view->app_list_folder_view()->visible()); |
| 215 | 244 |
| 216 Close(); | 245 Close(); |
| 217 } | 246 } |
| 218 | 247 |
| 248 void AppListViewTestContext::RunStartPageTest() { |
| 249 EXPECT_FALSE(view_->GetWidget()->IsVisible()); |
| 250 EXPECT_EQ(-1, pagination_model_.total_pages()); |
| 251 delegate_->GetTestModel()->PopulateApps(kInitialItems); |
| 252 |
| 253 Show(); |
| 254 |
| 255 AppListMainView* main_view = view_->app_list_main_view(); |
| 256 StartPageView* start_page_view = |
| 257 main_view->contents_view()->start_page_view(); |
| 258 // Checks on the main view. |
| 259 EXPECT_NO_FATAL_FAILURE(CheckView(main_view)); |
| 260 EXPECT_NO_FATAL_FAILURE(CheckView(main_view->contents_view())); |
| 261 if (test_type_ == EXPERIMENTAL) { |
| 262 EXPECT_NO_FATAL_FAILURE(CheckView(start_page_view)); |
| 263 |
| 264 main_view->contents_view()->SetShowState(ContentsView::SHOW_START_PAGE); |
| 265 main_view->contents_view()->Layout(); |
| 266 EXPECT_FALSE(main_view->search_box_view()->visible()); |
| 267 EXPECT_TRUE(IsViewAtOrigin(start_page_view)); |
| 268 EXPECT_FALSE( |
| 269 IsViewAtOrigin(main_view->contents_view()->apps_container_view())); |
| 270 |
| 271 main_view->contents_view()->SetShowState(ContentsView::SHOW_APPS); |
| 272 main_view->contents_view()->Layout(); |
| 273 EXPECT_TRUE(main_view->search_box_view()->visible()); |
| 274 EXPECT_FALSE(IsViewAtOrigin(start_page_view)); |
| 275 EXPECT_TRUE( |
| 276 IsViewAtOrigin(main_view->contents_view()->apps_container_view())); |
| 277 } else { |
| 278 EXPECT_EQ(NULL, start_page_view); |
| 279 } |
| 280 |
| 281 Close(); |
| 282 } |
| 283 |
| 219 class AppListViewTestAura : public views::ViewsTestBase, | 284 class AppListViewTestAura : public views::ViewsTestBase, |
| 220 public ::testing::WithParamInterface<bool> { | 285 public ::testing::WithParamInterface<int> { |
| 221 public: | 286 public: |
| 222 AppListViewTestAura() {} | 287 AppListViewTestAura() {} |
| 223 virtual ~AppListViewTestAura() {} | 288 virtual ~AppListViewTestAura() {} |
| 224 | 289 |
| 225 // testing::Test overrides: | 290 // testing::Test overrides: |
| 226 virtual void SetUp() OVERRIDE { | 291 virtual void SetUp() OVERRIDE { |
| 227 views::ViewsTestBase::SetUp(); | 292 views::ViewsTestBase::SetUp(); |
| 228 test_context_.reset(new AppListViewTestContext(GetParam(), GetContext())); | 293 test_context_.reset(new AppListViewTestContext(GetParam(), GetContext())); |
| 229 } | 294 } |
| 230 | 295 |
| 231 virtual void TearDown() OVERRIDE { | 296 virtual void TearDown() OVERRIDE { |
| 232 test_context_.reset(); | 297 test_context_.reset(); |
| 233 views::ViewsTestBase::TearDown(); | 298 views::ViewsTestBase::TearDown(); |
| 234 } | 299 } |
| 235 | 300 |
| 236 protected: | 301 protected: |
| 237 scoped_ptr<AppListViewTestContext> test_context_; | 302 scoped_ptr<AppListViewTestContext> test_context_; |
| 238 | 303 |
| 239 private: | 304 private: |
| 240 DISALLOW_COPY_AND_ASSIGN(AppListViewTestAura); | 305 DISALLOW_COPY_AND_ASSIGN(AppListViewTestAura); |
| 241 }; | 306 }; |
| 242 | 307 |
| 243 class AppListViewTestDesktop : public views::ViewsTestBase, | 308 class AppListViewTestDesktop : public views::ViewsTestBase, |
| 244 public ::testing::WithParamInterface<bool> { | 309 public ::testing::WithParamInterface<int> { |
| 245 public: | 310 public: |
| 246 AppListViewTestDesktop() {} | 311 AppListViewTestDesktop() {} |
| 247 virtual ~AppListViewTestDesktop() {} | 312 virtual ~AppListViewTestDesktop() {} |
| 248 | 313 |
| 249 // testing::Test overrides: | 314 // testing::Test overrides: |
| 250 virtual void SetUp() OVERRIDE { | 315 virtual void SetUp() OVERRIDE { |
| 251 set_views_delegate(new AppListViewTestViewsDelegate(this)); | 316 set_views_delegate(new AppListViewTestViewsDelegate(this)); |
| 252 views::ViewsTestBase::SetUp(); | 317 views::ViewsTestBase::SetUp(); |
| 253 test_context_.reset(new AppListViewTestContext(GetParam(), NULL)); | 318 test_context_.reset(new AppListViewTestContext(GetParam(), NULL)); |
| 254 } | 319 } |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 // Tests that the main grid view is shown after hiding and reshowing the app | 378 // Tests that the main grid view is shown after hiding and reshowing the app |
| 314 // list with a folder view open. This is a regression test for crbug.com/357058. | 379 // list with a folder view open. This is a regression test for crbug.com/357058. |
| 315 TEST_P(AppListViewTestAura, ReshowWithOpenFolder) { | 380 TEST_P(AppListViewTestAura, ReshowWithOpenFolder) { |
| 316 EXPECT_NO_FATAL_FAILURE(test_context_->RunReshowWithOpenFolderTest()); | 381 EXPECT_NO_FATAL_FAILURE(test_context_->RunReshowWithOpenFolderTest()); |
| 317 } | 382 } |
| 318 | 383 |
| 319 TEST_P(AppListViewTestDesktop, ReshowWithOpenFolder) { | 384 TEST_P(AppListViewTestDesktop, ReshowWithOpenFolder) { |
| 320 EXPECT_NO_FATAL_FAILURE(test_context_->RunReshowWithOpenFolderTest()); | 385 EXPECT_NO_FATAL_FAILURE(test_context_->RunReshowWithOpenFolderTest()); |
| 321 } | 386 } |
| 322 | 387 |
| 388 // Tests that the start page view operates correctly. |
| 389 TEST_P(AppListViewTestAura, StartPageTest) { |
| 390 EXPECT_NO_FATAL_FAILURE(test_context_->RunStartPageTest()); |
| 391 } |
| 392 |
| 393 TEST_P(AppListViewTestDesktop, StartPageTest) { |
| 394 EXPECT_NO_FATAL_FAILURE(test_context_->RunStartPageTest()); |
| 395 } |
| 396 |
| 323 INSTANTIATE_TEST_CASE_P(AppListViewTestAuraInstance, | 397 INSTANTIATE_TEST_CASE_P(AppListViewTestAuraInstance, |
| 324 AppListViewTestAura, | 398 AppListViewTestAura, |
| 325 ::testing::Bool()); | 399 ::testing::Range<int>(TEST_TYPE_START, TEST_TYPE_END)); |
| 326 | 400 |
| 327 INSTANTIATE_TEST_CASE_P(AppListViewTestDesktopInstance, | 401 INSTANTIATE_TEST_CASE_P(AppListViewTestDesktopInstance, |
| 328 AppListViewTestDesktop, | 402 AppListViewTestDesktop, |
| 329 ::testing::Bool()); | 403 ::testing::Range<int>(TEST_TYPE_START, TEST_TYPE_END)); |
| 330 | 404 |
| 331 } // namespace test | 405 } // namespace test |
| 332 } // namespace app_list | 406 } // namespace app_list |
| OLD | NEW |