summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorxiyuan@chromium.org <xiyuan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-29 06:20:04 +0000
committerxiyuan@chromium.org <xiyuan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-29 06:20:04 +0000
commite9780eaf04303fdd1233ee9dedddf5f8b0a008e0 (patch)
tree83aa86c0426b7f04a7ecaef5754a0b43416d0d56 /ui
parent4307501da6002d24795202fcb34d630ed3ff07ba (diff)
downloadchromium_src-e9780eaf04303fdd1233ee9dedddf5f8b0a008e0.zip
chromium_src-e9780eaf04303fdd1233ee9dedddf5f8b0a008e0.tar.gz
chromium_src-e9780eaf04303fdd1233ee9dedddf5f8b0a008e0.tar.bz2
app_list: Fix crash after uninstalling last app.
BUG=145274 TEST=There should be no crash after uninstalling the last app and then selecting an app. R=sky@chromium.org Review URL: https://chromiumcodereview.appspot.com/10892017 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@153863 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r--ui/app_list/app_list.gyp1
-rw-r--r--ui/app_list/apps_grid_view.cc12
-rw-r--r--ui/app_list/apps_grid_view.h3
-rw-r--r--ui/app_list/apps_grid_view_unittest.cc23
4 files changed, 39 insertions, 0 deletions
diff --git a/ui/app_list/app_list.gyp b/ui/app_list/app_list.gyp
index 6214b4e..2210ded 100644
--- a/ui/app_list/app_list.gyp
+++ b/ui/app_list/app_list.gyp
@@ -76,6 +76,7 @@
'../compositor/compositor.gyp:compositor',
'../compositor/compositor.gyp:compositor_test_support',
'../views/views.gyp:views',
+ '../views/views.gyp:test_support_views',
'app_list',
],
'sources': [
diff --git a/ui/app_list/apps_grid_view.cc b/ui/app_list/apps_grid_view.cc
index 33b5ac0..3895bf6 100644
--- a/ui/app_list/apps_grid_view.cc
+++ b/ui/app_list/apps_grid_view.cc
@@ -237,6 +237,18 @@ void AppsGridView::OnPaintFocusBorder(gfx::Canvas* canvas) {
// Override to not paint focus frame.
}
+void AppsGridView::ViewHierarchyChanged(bool is_add,
+ views::View* parent,
+ views::View* child) {
+ if (!is_add) {
+ if (parent == this &&
+ selected_item_index_ >= 0 &&
+ GetItemViewAtIndex(selected_item_index_) == child) {
+ selected_item_index_ = -1;
+ }
+ }
+}
+
void AppsGridView::Update() {
selected_item_index_ = -1;
RemoveAllChildViews(true);
diff --git a/ui/app_list/apps_grid_view.h b/ui/app_list/apps_grid_view.h
index c611d2f..d00f8a4 100644
--- a/ui/app_list/apps_grid_view.h
+++ b/ui/app_list/apps_grid_view.h
@@ -52,6 +52,9 @@ class APP_LIST_EXPORT AppsGridView : public views::View,
virtual bool OnKeyPressed(const ui::KeyEvent& event) OVERRIDE;
virtual bool OnKeyReleased(const ui::KeyEvent& event) OVERRIDE;
virtual void OnPaintFocusBorder(gfx::Canvas* canvas) OVERRIDE;
+ virtual void ViewHierarchyChanged(bool is_add,
+ views::View* parent,
+ views::View* child) OVERRIDE;
private:
// Updates from model.
diff --git a/ui/app_list/apps_grid_view_unittest.cc b/ui/app_list/apps_grid_view_unittest.cc
index 763ea14..7b34584 100644
--- a/ui/app_list/apps_grid_view_unittest.cc
+++ b/ui/app_list/apps_grid_view_unittest.cc
@@ -68,6 +68,11 @@ class AppsGridViewTest : public testing::Test {
item->SetHighlighted(true);
}
+ AppListItemView* GetItemViewAt(int index) {
+ DCHECK(index >= 0 && index < apps_grid_view_->child_count());
+ return static_cast<AppListItemView*>(apps_grid_view_->child_at(index));
+ }
+
scoped_ptr<AppListModel::Apps> apps_model_;
scoped_ptr<PaginationModel> pagination_model_;
scoped_ptr<AppsGridView> apps_grid_view_;
@@ -109,5 +114,23 @@ TEST_F(AppsGridViewTest, EnsureHighlightedVisible) {
EXPECT_EQ(kPages - 1, pagination_model_->selected_page());
}
+TEST_F(AppsGridViewTest, RemoveSelectedLastApp) {
+ const int kTotalItems = 2;
+ const int kLastItemIndex = kTotalItems - 1;
+
+ PopulateApps(kTotalItems);
+
+ AppListItemView* last_item = GetItemViewAt(kLastItemIndex);
+ apps_grid_view_->SetSelectedItem(last_item);
+ apps_model_->DeleteAt(kLastItemIndex);
+
+ EXPECT_FALSE(apps_grid_view_->IsSelectedItem(last_item));
+
+ // No crash happens.
+ AppListItemView* item = GetItemViewAt(0);
+ apps_grid_view_->SetSelectedItem(item);
+ EXPECT_TRUE(apps_grid_view_->IsSelectedItem(item));
+}
+
} // namespace test
} // namespace app_list