| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/pagination_model.h" | 5 #include "ui/app_list/pagination_model.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
| 13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/test/scoped_task_environment.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 15 #include "ui/app_list/pagination_model_observer.h" | 16 #include "ui/app_list/pagination_model_observer.h" |
| 16 | 17 |
| 17 namespace app_list { | 18 namespace app_list { |
| 18 namespace test { | 19 namespace test { |
| 19 | 20 |
| 20 class TestPaginationModelObserver : public PaginationModelObserver { | 21 class TestPaginationModelObserver : public PaginationModelObserver { |
| 21 public: | 22 public: |
| 22 TestPaginationModelObserver() | 23 TestPaginationModelObserver() |
| 23 : model_(NULL), | 24 : model_(NULL), |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 // and |transition_end_count_|. -1 means all the pages should be counted. | 106 // and |transition_end_count_|. -1 means all the pages should be counted. |
| 106 int transition_page_; | 107 int transition_page_; |
| 107 | 108 |
| 108 std::string selected_pages_; | 109 std::string selected_pages_; |
| 109 | 110 |
| 110 DISALLOW_COPY_AND_ASSIGN(TestPaginationModelObserver); | 111 DISALLOW_COPY_AND_ASSIGN(TestPaginationModelObserver); |
| 111 }; | 112 }; |
| 112 | 113 |
| 113 class PaginationModelTest : public testing::Test { | 114 class PaginationModelTest : public testing::Test { |
| 114 public: | 115 public: |
| 115 PaginationModelTest() {} | 116 PaginationModelTest() |
| 117 : scoped_task_environment_( |
| 118 base::test::ScopedTaskEnvironment::MainThreadType::UI) {} |
| 116 ~PaginationModelTest() override {} | 119 ~PaginationModelTest() override {} |
| 117 | 120 |
| 118 // testing::Test overrides: | 121 // testing::Test overrides: |
| 119 void SetUp() override { | 122 void SetUp() override { |
| 120 pagination_.SetTotalPages(5); | 123 pagination_.SetTotalPages(5); |
| 121 pagination_.SetTransitionDurations(1, 1); | 124 pagination_.SetTransitionDurations(1, 1); |
| 122 observer_.set_model(&pagination_); | 125 observer_.set_model(&pagination_); |
| 123 pagination_.AddObserver(&observer_); | 126 pagination_.AddObserver(&observer_); |
| 124 } | 127 } |
| 125 void TearDown() override { | 128 void TearDown() override { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 137 observer_.Reset(); | 140 observer_.Reset(); |
| 138 observer_.set_expected_page_selection(expected_selection); | 141 observer_.set_expected_page_selection(expected_selection); |
| 139 observer_.set_expected_transition_start(expected_transition_start); | 142 observer_.set_expected_transition_start(expected_transition_start); |
| 140 observer_.set_expected_transition_end(expected_transition_end); | 143 observer_.set_expected_transition_end(expected_transition_end); |
| 141 } | 144 } |
| 142 | 145 |
| 143 PaginationModel pagination_; | 146 PaginationModel pagination_; |
| 144 TestPaginationModelObserver observer_; | 147 TestPaginationModelObserver observer_; |
| 145 | 148 |
| 146 private: | 149 private: |
| 147 base::MessageLoopForUI message_loop_; | 150 base::test::ScopedTaskEnvironment scoped_task_environment_; |
| 148 | 151 |
| 149 DISALLOW_COPY_AND_ASSIGN(PaginationModelTest); | 152 DISALLOW_COPY_AND_ASSIGN(PaginationModelTest); |
| 150 }; | 153 }; |
| 151 | 154 |
| 152 TEST_F(PaginationModelTest, SelectPage) { | 155 TEST_F(PaginationModelTest, SelectPage) { |
| 153 pagination_.SelectPage(2, false /* animate */); | 156 pagination_.SelectPage(2, false /* animate */); |
| 154 pagination_.SelectPage(4, false /* animate */); | 157 pagination_.SelectPage(4, false /* animate */); |
| 155 pagination_.SelectPage(3, false /* animate */); | 158 pagination_.SelectPage(3, false /* animate */); |
| 156 pagination_.SelectPage(1, false /* animate */); | 159 pagination_.SelectPage(1, false /* animate */); |
| 157 | 160 |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 EXPECT_EQ(1, pagination_.selected_page()); | 427 EXPECT_EQ(1, pagination_.selected_page()); |
| 425 | 428 |
| 426 // But if the currently selected_page exceeds the total number of pages, | 429 // But if the currently selected_page exceeds the total number of pages, |
| 427 // it automatically switches to the last page. | 430 // it automatically switches to the last page. |
| 428 pagination_.SetTotalPages(1); | 431 pagination_.SetTotalPages(1); |
| 429 EXPECT_EQ(0, pagination_.selected_page()); | 432 EXPECT_EQ(0, pagination_.selected_page()); |
| 430 } | 433 } |
| 431 | 434 |
| 432 } // namespace test | 435 } // namespace test |
| 433 } // namespace app_list | 436 } // namespace app_list |
| OLD | NEW |