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

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: Fix tests and bugs. 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* PaginationModel() const;
xiyuan 2014/05/30 15:47:47 nit: accessor should be named in lower case, like
Matt Giuca 2014/06/02 07:11:23 const: done. lowercase: My reading of the style gu
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::PaginationModel() const {
197 return view_->app_list_main_view()
198 ->contents_view()
199 ->apps_container_view()
200 ->apps_grid_view()
201 ->GetPaginationModel();
202 }
203
195 void AppListViewTestContext::RunDisplayTest() { 204 void AppListViewTestContext::RunDisplayTest() {
196 EXPECT_FALSE(view_->GetWidget()->IsVisible()); 205 EXPECT_FALSE(view_->GetWidget()->IsVisible());
197 EXPECT_EQ(-1, pagination_model_.total_pages()); 206 EXPECT_EQ(-1, PaginationModel()->total_pages());
198 delegate_->GetTestModel()->PopulateApps(kInitialItems); 207 delegate_->GetTestModel()->PopulateApps(kInitialItems);
199 208
200 Show(); 209 Show();
201 if (is_landscape()) 210 if (is_landscape())
202 EXPECT_EQ(2, pagination_model_.total_pages()); 211 EXPECT_EQ(2, PaginationModel()->total_pages());
203 else 212 else
204 EXPECT_EQ(3, pagination_model_.total_pages()); 213 EXPECT_EQ(3, PaginationModel()->total_pages());
205 EXPECT_EQ(0, pagination_model_.selected_page()); 214 EXPECT_EQ(0, PaginationModel()->selected_page());
206 215
207 // Checks on the main view. 216 // Checks on the main view.
208 AppListMainView* main_view = view_->app_list_main_view(); 217 AppListMainView* main_view = view_->app_list_main_view();
209 EXPECT_NO_FATAL_FAILURE(CheckView(main_view)); 218 EXPECT_NO_FATAL_FAILURE(CheckView(main_view));
210 EXPECT_NO_FATAL_FAILURE(CheckView(main_view->search_box_view())); 219 EXPECT_NO_FATAL_FAILURE(CheckView(main_view->search_box_view()));
211 EXPECT_NO_FATAL_FAILURE(CheckView(main_view->contents_view())); 220 EXPECT_NO_FATAL_FAILURE(CheckView(main_view->contents_view()));
212 221
213 Close(); 222 Close();
214 } 223 }
215 224
216 void AppListViewTestContext::RunReshowWithOpenFolderTest() { 225 void AppListViewTestContext::RunReshowWithOpenFolderTest() {
217 EXPECT_FALSE(view_->GetWidget()->IsVisible()); 226 EXPECT_FALSE(view_->GetWidget()->IsVisible());
218 EXPECT_EQ(-1, pagination_model_.total_pages()); 227 EXPECT_EQ(-1, PaginationModel()->total_pages());
219 228
220 AppListTestModel* model = delegate_->GetTestModel(); 229 AppListTestModel* model = delegate_->GetTestModel();
221 model->PopulateApps(kInitialItems); 230 model->PopulateApps(kInitialItems);
222 const std::string folder_id = 231 const std::string folder_id =
223 model->MergeItems(model->top_level_item_list()->item_at(0)->id(), 232 model->MergeItems(model->top_level_item_list()->item_at(0)->id(),
224 model->top_level_item_list()->item_at(1)->id()); 233 model->top_level_item_list()->item_at(1)->id());
225 234
226 AppListFolderItem* folder_item = model->FindFolderItem(folder_id); 235 AppListFolderItem* folder_item = model->FindFolderItem(folder_id);
227 EXPECT_TRUE(folder_item); 236 EXPECT_TRUE(folder_item);
228 237
(...skipping 23 matching lines...) Expand all
252 // The main grid view should be showing after a reshow. 261 // The main grid view should be showing after a reshow.
253 EXPECT_NO_FATAL_FAILURE(CheckView(main_view)); 262 EXPECT_NO_FATAL_FAILURE(CheckView(main_view));
254 EXPECT_NO_FATAL_FAILURE(CheckView(container_view->apps_grid_view())); 263 EXPECT_NO_FATAL_FAILURE(CheckView(container_view->apps_grid_view()));
255 EXPECT_FALSE(container_view->app_list_folder_view()->visible()); 264 EXPECT_FALSE(container_view->app_list_folder_view()->visible());
256 265
257 Close(); 266 Close();
258 } 267 }
259 268
260 void AppListViewTestContext::RunStartPageTest() { 269 void AppListViewTestContext::RunStartPageTest() {
261 EXPECT_FALSE(view_->GetWidget()->IsVisible()); 270 EXPECT_FALSE(view_->GetWidget()->IsVisible());
262 EXPECT_EQ(-1, pagination_model_.total_pages()); 271 EXPECT_EQ(-1, PaginationModel()->total_pages());
263 AppListTestModel* model = delegate_->GetTestModel(); 272 AppListTestModel* model = delegate_->GetTestModel();
264 model->PopulateApps(3); 273 model->PopulateApps(3);
265 274
266 Show(); 275 Show();
267 276
268 AppListMainView* main_view = view_->app_list_main_view(); 277 AppListMainView* main_view = view_->app_list_main_view();
269 StartPageView* start_page_view = 278 StartPageView* start_page_view =
270 main_view->contents_view()->start_page_view(); 279 main_view->contents_view()->start_page_view();
271 // Checks on the main view. 280 // Checks on the main view.
272 EXPECT_NO_FATAL_FAILURE(CheckView(main_view)); 281 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, 426 INSTANTIATE_TEST_CASE_P(AppListViewTestAuraInstance,
418 AppListViewTestAura, 427 AppListViewTestAura,
419 ::testing::Range<int>(TEST_TYPE_START, TEST_TYPE_END)); 428 ::testing::Range<int>(TEST_TYPE_START, TEST_TYPE_END));
420 429
421 INSTANTIATE_TEST_CASE_P(AppListViewTestDesktopInstance, 430 INSTANTIATE_TEST_CASE_P(AppListViewTestDesktopInstance,
422 AppListViewTestDesktop, 431 AppListViewTestDesktop,
423 ::testing::Range<int>(TEST_TYPE_START, TEST_TYPE_END)); 432 ::testing::Range<int>(TEST_TYPE_START, TEST_TYPE_END));
424 433
425 } // namespace test 434 } // namespace test
426 } // namespace app_list 435 } // namespace app_list
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698