summaryrefslogtreecommitdiffstats
path: root/ui/app_list
diff options
context:
space:
mode:
authormukai@chromium.org <mukai@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-20 10:20:38 +0000
committermukai@chromium.org <mukai@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-20 10:20:38 +0000
commit5d80cd28f272a3b6a7730344f46c723b9940a102 (patch)
tree925845d9fb7242446551e9c5b88c8f1303e79011 /ui/app_list
parentd10623f4019113ae5301f3aa09631b9472f04a27 (diff)
downloadchromium_src-5d80cd28f272a3b6a7730344f46c723b9940a102.zip
chromium_src-5d80cd28f272a3b6a7730344f46c723b9940a102.tar.gz
chromium_src-5d80cd28f272a3b6a7730344f46c723b9940a102.tar.bz2
Moves to the last page again in case that the selected page is lost.
BUG=133260 TEST=app_list_unittest passed Review URL: https://chromiumcodereview.appspot.com/10571002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@143161 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/app_list')
-rw-r--r--ui/app_list/apps_grid_view.cc2
-rw-r--r--ui/app_list/pagination_model.cc4
-rw-r--r--ui/app_list/pagination_model_unittest.cc29
3 files changed, 28 insertions, 7 deletions
diff --git a/ui/app_list/apps_grid_view.cc b/ui/app_list/apps_grid_view.cc
index e57389a..38bbda4 100644
--- a/ui/app_list/apps_grid_view.cc
+++ b/ui/app_list/apps_grid_view.cc
@@ -290,8 +290,6 @@ void AppsGridView::Update() {
void AppsGridView::UpdatePaginationModel() {
pagination_model_->SetTotalPages(
(child_count() - 1) / tiles_per_page() + 1);
- if (pagination_model_->selected_page() < 0)
- pagination_model_->SelectPage(0, false /* animate */);
}
AppListItemView* AppsGridView::CreateViewForItemAtIndex(size_t index) {
diff --git a/ui/app_list/pagination_model.cc b/ui/app_list/pagination_model.cc
index 6fa19b6..d58a5fc 100644
--- a/ui/app_list/pagination_model.cc
+++ b/ui/app_list/pagination_model.cc
@@ -27,6 +27,10 @@ void PaginationModel::SetTotalPages(int total_pages) {
return;
total_pages_ = total_pages;
+ if (selected_page_ < 0)
+ SelectPage(0, false /* animate */);
+ if (selected_page_ >= total_pages_)
+ SelectPage(total_pages_ - 1, false /* animate */);
FOR_EACH_OBSERVER(PaginationModelObserver,
observers_,
TotalPagesChanged());
diff --git a/ui/app_list/pagination_model_unittest.cc b/ui/app_list/pagination_model_unittest.cc
index ed6a480..2a6624d 100644
--- a/ui/app_list/pagination_model_unittest.cc
+++ b/ui/app_list/pagination_model_unittest.cc
@@ -138,7 +138,6 @@ class PaginationModelTest : public testing::Test {
};
TEST_F(PaginationModelTest, SelectPage) {
- pagination_.SelectPage(0, false /* animate */);
pagination_.SelectPage(2, false /* animate */);
pagination_.SelectPage(4, false /* animate */);
pagination_.SelectPage(3, false /* animate */);
@@ -146,13 +145,13 @@ TEST_F(PaginationModelTest, SelectPage) {
EXPECT_EQ(0, observer_.transition_start_count());
EXPECT_EQ(0, observer_.transition_end_count());
- EXPECT_EQ(5, observer_.selection_count());
- EXPECT_EQ(std::string("0 2 4 3 1"), observer_.selected_pages());
+ EXPECT_EQ(4, observer_.selection_count());
+ EXPECT_EQ(std::string("2 4 3 1"), observer_.selected_pages());
// Nothing happens if select the same page.
pagination_.SelectPage(1, false /* animate */);
- EXPECT_EQ(5, observer_.selection_count());
- EXPECT_EQ(std::string("0 2 4 3 1"), observer_.selected_pages());
+ EXPECT_EQ(4, observer_.selection_count());
+ EXPECT_EQ(std::string("2 4 3 1"), observer_.selected_pages());
}
TEST_F(PaginationModelTest, SelectPageAnimated) {
@@ -369,5 +368,25 @@ TEST_F(PaginationModelTest, LongScroll) {
EXPECT_EQ(1, observer_.selection_count());
}
+TEST_F(PaginationModelTest, SelectedPageIsLost) {
+ pagination_.SetTotalPages(2);
+ // The selected page is set to 0 once the total number of pages are set.
+ EXPECT_EQ(0, pagination_.selected_page());
+
+ pagination_.SelectPage(1, false /* animate */);
+ EXPECT_EQ(1, pagination_.selected_page());
+
+ // The selected page is unchanged if it's still valid.
+ pagination_.SetTotalPages(3);
+ EXPECT_EQ(1, pagination_.selected_page());
+ pagination_.SetTotalPages(2);
+ EXPECT_EQ(1, pagination_.selected_page());
+
+ // But if the currently selected_page exceeds the total number of pages,
+ // it automatically switches to the last page.
+ pagination_.SetTotalPages(1);
+ EXPECT_EQ(0, pagination_.selected_page());
+}
+
} // namespace test
} // namespace app_list