Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(475)

Side by Side Diff: ui/app_list/apps_grid_view_unittest.cc

Issue 10892017: app_list: Fix crash after uninstalling last app. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add test Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/app_list/apps_grid_view.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/apps_grid_view.h" 5 #include "ui/app_list/apps_grid_view.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 AppListItemModel* item = new AppListItemModel; 61 AppListItemModel* item = new AppListItemModel;
62 item->SetTitle(title); 62 item->SetTitle(title);
63 return item; 63 return item;
64 } 64 }
65 65
66 void HighlightItemAt(int index) { 66 void HighlightItemAt(int index) {
67 AppListItemModel* item = apps_model_->GetItemAt(index); 67 AppListItemModel* item = apps_model_->GetItemAt(index);
68 item->SetHighlighted(true); 68 item->SetHighlighted(true);
69 } 69 }
70 70
71 AppListItemView* GetItemViewAt(int index) {
72 DCHECK(index >= 0 && index < apps_grid_view_->child_count());
73 return static_cast<AppListItemView*>(apps_grid_view_->child_at(index));
74 }
75
71 scoped_ptr<AppListModel::Apps> apps_model_; 76 scoped_ptr<AppListModel::Apps> apps_model_;
72 scoped_ptr<PaginationModel> pagination_model_; 77 scoped_ptr<PaginationModel> pagination_model_;
73 scoped_ptr<AppsGridView> apps_grid_view_; 78 scoped_ptr<AppsGridView> apps_grid_view_;
74 79
75 private: 80 private:
76 DISALLOW_COPY_AND_ASSIGN(AppsGridViewTest); 81 DISALLOW_COPY_AND_ASSIGN(AppsGridViewTest);
77 }; 82 };
78 83
79 TEST_F(AppsGridViewTest, CreatePage) { 84 TEST_F(AppsGridViewTest, CreatePage) {
80 // Fully populates a page. 85 // Fully populates a page.
(...skipping 21 matching lines...) Expand all
102 107
103 // Highlight first one on 2nd page and 2nd page should be selected. 108 // Highlight first one on 2nd page and 2nd page should be selected.
104 HighlightItemAt(apps_grid_view_->tiles_per_page() + 1); 109 HighlightItemAt(apps_grid_view_->tiles_per_page() + 1);
105 EXPECT_EQ(1, pagination_model_->selected_page()); 110 EXPECT_EQ(1, pagination_model_->selected_page());
106 111
107 // Highlight last one in the model and last page should be selected. 112 // Highlight last one in the model and last page should be selected.
108 HighlightItemAt(apps_model_->item_count() - 1); 113 HighlightItemAt(apps_model_->item_count() - 1);
109 EXPECT_EQ(kPages - 1, pagination_model_->selected_page()); 114 EXPECT_EQ(kPages - 1, pagination_model_->selected_page());
110 } 115 }
111 116
117 TEST_F(AppsGridViewTest, RemoveSelectedLastApp) {
118 const int kTotalItems = 2;
119 const int kLastItemIndex = kTotalItems - 1;
120
121 PopulateApps(kTotalItems);
122
123 AppListItemView* last_item = GetItemViewAt(kLastItemIndex);
124 apps_grid_view_->SetSelectedItem(last_item);
125 apps_model_->DeleteAt(kLastItemIndex);
126
127 EXPECT_FALSE(apps_grid_view_->IsSelectedItem(last_item));
128
129 // No crash happens.
130 AppListItemView* item = GetItemViewAt(0);
131 apps_grid_view_->SetSelectedItem(item);
132 EXPECT_TRUE(apps_grid_view_->IsSelectedItem(item));
133 }
134
112 } // namespace test 135 } // namespace test
113 } // namespace app_list 136 } // namespace app_list
OLDNEW
« no previous file with comments | « ui/app_list/apps_grid_view.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698