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

Side by Side Diff: ui/app_list/views/app_list_view_unittest.cc

Issue 302803002: Refactor app list so AppsGridView owns the PaginationModel. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Respond to review comments (tapted and xiyuan). Created 6 years, 6 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
OLDNEW
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"
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 return test_type_ == LANDSCAPE || test_type_ == EXPERIMENTAL; 92 return test_type_ == LANDSCAPE || test_type_ == EXPERIMENTAL;
93 } 93 }
94 94
95 private: 95 private:
96 // Shows the app list and waits until a paint occurs. 96 // Shows the app list and waits until a paint occurs.
97 void Show(); 97 void Show();
98 98
99 // Closes the app list. This sets |view_| to NULL. 99 // Closes the app list. This sets |view_| to NULL.
100 void Close(); 100 void Close();
101 101
102 // Gets the PaginationModel owned by |view_|.
103 PaginationModel* GetPaginationModel();
104
102 const TestType test_type_; 105 const TestType test_type_;
103 scoped_ptr<base::RunLoop> run_loop_; 106 scoped_ptr<base::RunLoop> run_loop_;
104 PaginationModel pagination_model_;
105 app_list::AppListView* view_; // Owned by native widget. 107 app_list::AppListView* view_; // Owned by native widget.
106 app_list::test::AppListTestViewDelegate* delegate_; // Owned by |view_|; 108 app_list::test::AppListTestViewDelegate* delegate_; // Owned by |view_|;
107 109
108 DISALLOW_COPY_AND_ASSIGN(AppListViewTestContext); 110 DISALLOW_COPY_AND_ASSIGN(AppListViewTestContext);
109 }; 111 };
110 112
111 // Extend the regular AppListTestViewDelegate to communicate back to the test 113 // Extend the regular AppListTestViewDelegate to communicate back to the test
112 // context. Note the test context doesn't simply inherit this, because the 114 // context. Note the test context doesn't simply inherit this, because the
113 // delegate is owned by the view. 115 // delegate is owned by the view.
114 class UnitTestViewDelegate : public app_list::test::AppListTestViewDelegate { 116 class UnitTestViewDelegate : public app_list::test::AppListTestViewDelegate {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 default: 148 default:
147 NOTREACHED(); 149 NOTREACHED();
148 break; 150 break;
149 } 151 }
150 152
151 delegate_ = new UnitTestViewDelegate(this); 153 delegate_ = new UnitTestViewDelegate(this);
152 view_ = new app_list::AppListView(delegate_); 154 view_ = new app_list::AppListView(delegate_);
153 155
154 // Initialize centered around a point that ensures the window is wholly shown. 156 // Initialize centered around a point that ensures the window is wholly shown.
155 view_->InitAsBubbleAtFixedLocation(parent, 157 view_->InitAsBubbleAtFixedLocation(parent,
156 &pagination_model_,
157 gfx::Point(300, 300), 158 gfx::Point(300, 300),
158 views::BubbleBorder::FLOAT, 159 views::BubbleBorder::FLOAT,
159 false /* border_accepts_events */); 160 false /* border_accepts_events */);
160 } 161 }
161 162
162 AppListViewTestContext::~AppListViewTestContext() { 163 AppListViewTestContext::~AppListViewTestContext() {
163 // The view observes the PaginationModel which is about to get destroyed, so 164 // The view observes the PaginationModel which is about to get destroyed, so
164 // if the view is not already deleted by the time this destructor is called, 165 // if the view is not already deleted by the time this destructor is called,
165 // there will be problems. 166 // there will be problems.
166 EXPECT_FALSE(view_); 167 EXPECT_FALSE(view_);
(...skipping 18 matching lines...) Expand all
185 186
186 void AppListViewTestContext::Close() { 187 void AppListViewTestContext::Close() {
187 view_->GetWidget()->Close(); 188 view_->GetWidget()->Close();
188 run_loop_.reset(new base::RunLoop); 189 run_loop_.reset(new base::RunLoop);
189 run_loop_->Run(); 190 run_loop_->Run();
190 191
191 // |view_| should have been deleted and set to NULL via ViewClosing(). 192 // |view_| should have been deleted and set to NULL via ViewClosing().
192 EXPECT_FALSE(view_); 193 EXPECT_FALSE(view_);
193 } 194 }
194 195
196 PaginationModel* AppListViewTestContext::GetPaginationModel() {
197 return view_->GetAppsPaginationModel();
198 }
199
195 void AppListViewTestContext::RunDisplayTest() { 200 void AppListViewTestContext::RunDisplayTest() {
196 EXPECT_FALSE(view_->GetWidget()->IsVisible()); 201 EXPECT_FALSE(view_->GetWidget()->IsVisible());
197 EXPECT_EQ(-1, pagination_model_.total_pages()); 202 EXPECT_EQ(-1, GetPaginationModel()->total_pages());
198 delegate_->GetTestModel()->PopulateApps(kInitialItems); 203 delegate_->GetTestModel()->PopulateApps(kInitialItems);
199 204
200 Show(); 205 Show();
201 if (is_landscape()) 206 if (is_landscape())
202 EXPECT_EQ(2, pagination_model_.total_pages()); 207 EXPECT_EQ(2, GetPaginationModel()->total_pages());
203 else 208 else
204 EXPECT_EQ(3, pagination_model_.total_pages()); 209 EXPECT_EQ(3, GetPaginationModel()->total_pages());
205 EXPECT_EQ(0, pagination_model_.selected_page()); 210 EXPECT_EQ(0, GetPaginationModel()->selected_page());
206 211
207 // Checks on the main view. 212 // Checks on the main view.
208 AppListMainView* main_view = view_->app_list_main_view(); 213 AppListMainView* main_view = view_->app_list_main_view();
209 EXPECT_NO_FATAL_FAILURE(CheckView(main_view)); 214 EXPECT_NO_FATAL_FAILURE(CheckView(main_view));
210 EXPECT_NO_FATAL_FAILURE(CheckView(main_view->search_box_view())); 215 EXPECT_NO_FATAL_FAILURE(CheckView(main_view->search_box_view()));
211 EXPECT_NO_FATAL_FAILURE(CheckView(main_view->contents_view())); 216 EXPECT_NO_FATAL_FAILURE(CheckView(main_view->contents_view()));
212 217
213 Close(); 218 Close();
214 } 219 }
215 220
216 void AppListViewTestContext::RunReshowWithOpenFolderTest() { 221 void AppListViewTestContext::RunReshowWithOpenFolderTest() {
217 EXPECT_FALSE(view_->GetWidget()->IsVisible()); 222 EXPECT_FALSE(view_->GetWidget()->IsVisible());
218 EXPECT_EQ(-1, pagination_model_.total_pages()); 223 EXPECT_EQ(-1, GetPaginationModel()->total_pages());
219 224
220 AppListTestModel* model = delegate_->GetTestModel(); 225 AppListTestModel* model = delegate_->GetTestModel();
221 model->PopulateApps(kInitialItems); 226 model->PopulateApps(kInitialItems);
222 const std::string folder_id = 227 const std::string folder_id =
223 model->MergeItems(model->top_level_item_list()->item_at(0)->id(), 228 model->MergeItems(model->top_level_item_list()->item_at(0)->id(),
224 model->top_level_item_list()->item_at(1)->id()); 229 model->top_level_item_list()->item_at(1)->id());
225 230
226 AppListFolderItem* folder_item = model->FindFolderItem(folder_id); 231 AppListFolderItem* folder_item = model->FindFolderItem(folder_id);
227 EXPECT_TRUE(folder_item); 232 EXPECT_TRUE(folder_item);
228 233
(...skipping 23 matching lines...) Expand all
252 // The main grid view should be showing after a reshow. 257 // The main grid view should be showing after a reshow.
253 EXPECT_NO_FATAL_FAILURE(CheckView(main_view)); 258 EXPECT_NO_FATAL_FAILURE(CheckView(main_view));
254 EXPECT_NO_FATAL_FAILURE(CheckView(container_view->apps_grid_view())); 259 EXPECT_NO_FATAL_FAILURE(CheckView(container_view->apps_grid_view()));
255 EXPECT_FALSE(container_view->app_list_folder_view()->visible()); 260 EXPECT_FALSE(container_view->app_list_folder_view()->visible());
256 261
257 Close(); 262 Close();
258 } 263 }
259 264
260 void AppListViewTestContext::RunStartPageTest() { 265 void AppListViewTestContext::RunStartPageTest() {
261 EXPECT_FALSE(view_->GetWidget()->IsVisible()); 266 EXPECT_FALSE(view_->GetWidget()->IsVisible());
262 EXPECT_EQ(-1, pagination_model_.total_pages()); 267 EXPECT_EQ(-1, GetPaginationModel()->total_pages());
263 AppListTestModel* model = delegate_->GetTestModel(); 268 AppListTestModel* model = delegate_->GetTestModel();
264 model->PopulateApps(3); 269 model->PopulateApps(3);
265 270
266 Show(); 271 Show();
267 272
268 AppListMainView* main_view = view_->app_list_main_view(); 273 AppListMainView* main_view = view_->app_list_main_view();
269 StartPageView* start_page_view = 274 StartPageView* start_page_view =
270 main_view->contents_view()->start_page_view(); 275 main_view->contents_view()->start_page_view();
271 // Checks on the main view. 276 // Checks on the main view.
272 EXPECT_NO_FATAL_FAILURE(CheckView(main_view)); 277 EXPECT_NO_FATAL_FAILURE(CheckView(main_view));
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 INSTANTIATE_TEST_CASE_P(AppListViewTestAuraInstance, 422 INSTANTIATE_TEST_CASE_P(AppListViewTestAuraInstance,
418 AppListViewTestAura, 423 AppListViewTestAura,
419 ::testing::Range<int>(TEST_TYPE_START, TEST_TYPE_END)); 424 ::testing::Range<int>(TEST_TYPE_START, TEST_TYPE_END));
420 425
421 INSTANTIATE_TEST_CASE_P(AppListViewTestDesktopInstance, 426 INSTANTIATE_TEST_CASE_P(AppListViewTestDesktopInstance,
422 AppListViewTestDesktop, 427 AppListViewTestDesktop,
423 ::testing::Range<int>(TEST_TYPE_START, TEST_TYPE_END)); 428 ::testing::Range<int>(TEST_TYPE_START, TEST_TYPE_END));
424 429
425 } // namespace test 430 } // namespace test
426 } // namespace app_list 431 } // namespace app_list
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698