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

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

Issue 14061025: ui: Use base::MessageLoop. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 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 (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/pagination_model.h" 5 #include "ui/app_list/pagination_model.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 } 61 }
62 62
63 // PaginationModelObserver overrides: 63 // PaginationModelObserver overrides:
64 virtual void TotalPagesChanged() OVERRIDE {} 64 virtual void TotalPagesChanged() OVERRIDE {}
65 virtual void SelectedPageChanged(int old_selected, 65 virtual void SelectedPageChanged(int old_selected,
66 int new_selected) OVERRIDE { 66 int new_selected) OVERRIDE {
67 AppendSelectedPage(new_selected); 67 AppendSelectedPage(new_selected);
68 ++selection_count_; 68 ++selection_count_;
69 if (expected_page_selection_ && 69 if (expected_page_selection_ &&
70 selection_count_ == expected_page_selection_) { 70 selection_count_ == expected_page_selection_) {
71 MessageLoop::current()->Quit(); 71 base::MessageLoop::current()->Quit();
72 } 72 }
73 } 73 }
74 virtual void TransitionChanged() OVERRIDE { 74 virtual void TransitionChanged() OVERRIDE {
75 if (transition_page_ == -1 || 75 if (transition_page_ == -1 ||
76 model_->transition().target_page == transition_page_) { 76 model_->transition().target_page == transition_page_) {
77 if (model_->transition().progress == 0) 77 if (model_->transition().progress == 0)
78 ++transition_start_count_; 78 ++transition_start_count_;
79 if (model_->transition().progress == 1) 79 if (model_->transition().progress == 1)
80 ++transition_end_count_; 80 ++transition_end_count_;
81 } 81 }
82 82
83 if ((expected_transition_start_ && 83 if ((expected_transition_start_ &&
84 transition_start_count_ == expected_transition_start_) || 84 transition_start_count_ == expected_transition_start_) ||
85 (expected_transition_end_ && 85 (expected_transition_end_ &&
86 transition_end_count_ == expected_transition_end_)) { 86 transition_end_count_ == expected_transition_end_)) {
87 MessageLoop::current()->Quit(); 87 base::MessageLoop::current()->Quit();
88 } 88 }
89 } 89 }
90 90
91 PaginationModel* model_; 91 PaginationModel* model_;
92 92
93 int expected_page_selection_; 93 int expected_page_selection_;
94 int expected_transition_start_; 94 int expected_transition_start_;
95 int expected_transition_end_; 95 int expected_transition_end_;
96 96
97 int selection_count_; 97 int selection_count_;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 observer_.Reset(); 134 observer_.Reset();
135 observer_.set_expected_page_selection(expected_selection); 135 observer_.set_expected_page_selection(expected_selection);
136 observer_.set_expected_transition_start(expected_transition_start); 136 observer_.set_expected_transition_start(expected_transition_start);
137 observer_.set_expected_transition_end(expected_transition_end); 137 observer_.set_expected_transition_end(expected_transition_end);
138 } 138 }
139 139
140 PaginationModel pagination_; 140 PaginationModel pagination_;
141 TestPaginationModelObserver observer_; 141 TestPaginationModelObserver observer_;
142 142
143 private: 143 private:
144 MessageLoopForUI message_loop_; 144 base::MessageLoopForUI message_loop_;
145 145
146 DISALLOW_COPY_AND_ASSIGN(PaginationModelTest); 146 DISALLOW_COPY_AND_ASSIGN(PaginationModelTest);
147 }; 147 };
148 148
149 TEST_F(PaginationModelTest, SelectPage) { 149 TEST_F(PaginationModelTest, SelectPage) {
150 pagination_.SelectPage(2, false /* animate */); 150 pagination_.SelectPage(2, false /* animate */);
151 pagination_.SelectPage(4, false /* animate */); 151 pagination_.SelectPage(4, false /* animate */);
152 pagination_.SelectPage(3, false /* animate */); 152 pagination_.SelectPage(3, false /* animate */);
153 pagination_.SelectPage(1, false /* animate */); 153 pagination_.SelectPage(1, false /* animate */);
154 154
155 EXPECT_EQ(0, observer_.transition_start_count()); 155 EXPECT_EQ(0, observer_.transition_start_count());
156 EXPECT_EQ(0, observer_.transition_end_count()); 156 EXPECT_EQ(0, observer_.transition_end_count());
157 EXPECT_EQ(4, observer_.selection_count()); 157 EXPECT_EQ(4, observer_.selection_count());
158 EXPECT_EQ(std::string("2 4 3 1"), observer_.selected_pages()); 158 EXPECT_EQ(std::string("2 4 3 1"), observer_.selected_pages());
159 159
160 // Nothing happens if select the same page. 160 // Nothing happens if select the same page.
161 pagination_.SelectPage(1, false /* animate */); 161 pagination_.SelectPage(1, false /* animate */);
162 EXPECT_EQ(4, observer_.selection_count()); 162 EXPECT_EQ(4, observer_.selection_count());
163 EXPECT_EQ(std::string("2 4 3 1"), observer_.selected_pages()); 163 EXPECT_EQ(std::string("2 4 3 1"), observer_.selected_pages());
164 } 164 }
165 165
166 TEST_F(PaginationModelTest, SelectPageAnimated) { 166 TEST_F(PaginationModelTest, SelectPageAnimated) {
167 const int kStartPage = 0; 167 const int kStartPage = 0;
168 168
169 // One transition. 169 // One transition.
170 SetStartPageAndExpects(kStartPage, 1, 0, 0); 170 SetStartPageAndExpects(kStartPage, 1, 0, 0);
171 pagination_.SelectPage(1, true /* animate */); 171 pagination_.SelectPage(1, true /* animate */);
172 MessageLoop::current()->Run(); 172 base::MessageLoop::current()->Run();
173 EXPECT_EQ(1, observer_.transition_start_count()); 173 EXPECT_EQ(1, observer_.transition_start_count());
174 EXPECT_EQ(1, observer_.transition_end_count()); 174 EXPECT_EQ(1, observer_.transition_end_count());
175 EXPECT_EQ(1, observer_.selection_count()); 175 EXPECT_EQ(1, observer_.selection_count());
176 EXPECT_EQ(std::string("1"), observer_.selected_pages()); 176 EXPECT_EQ(std::string("1"), observer_.selected_pages());
177 177
178 // Two transitions in a row. 178 // Two transitions in a row.
179 SetStartPageAndExpects(kStartPage, 2, 0, 0); 179 SetStartPageAndExpects(kStartPage, 2, 0, 0);
180 pagination_.SelectPage(1, true /* animate */); 180 pagination_.SelectPage(1, true /* animate */);
181 pagination_.SelectPage(3, true /* animate */); 181 pagination_.SelectPage(3, true /* animate */);
182 MessageLoop::current()->Run(); 182 base::MessageLoop::current()->Run();
183 EXPECT_EQ(2, observer_.transition_start_count()); 183 EXPECT_EQ(2, observer_.transition_start_count());
184 EXPECT_EQ(2, observer_.transition_end_count()); 184 EXPECT_EQ(2, observer_.transition_end_count());
185 EXPECT_EQ(2, observer_.selection_count()); 185 EXPECT_EQ(2, observer_.selection_count());
186 EXPECT_EQ(std::string("1 3"), observer_.selected_pages()); 186 EXPECT_EQ(std::string("1 3"), observer_.selected_pages());
187 187
188 // Transition to same page twice and only one should happen. 188 // Transition to same page twice and only one should happen.
189 SetStartPageAndExpects(kStartPage, 1, 0, 0); 189 SetStartPageAndExpects(kStartPage, 1, 0, 0);
190 pagination_.SelectPage(1, true /* animate */); 190 pagination_.SelectPage(1, true /* animate */);
191 pagination_.SelectPage(1, true /* animate */); // Ignored. 191 pagination_.SelectPage(1, true /* animate */); // Ignored.
192 MessageLoop::current()->Run(); 192 base::MessageLoop::current()->Run();
193 EXPECT_EQ(1, observer_.transition_start_count()); 193 EXPECT_EQ(1, observer_.transition_start_count());
194 EXPECT_EQ(1, observer_.transition_end_count()); 194 EXPECT_EQ(1, observer_.transition_end_count());
195 EXPECT_EQ(1, observer_.selection_count()); 195 EXPECT_EQ(1, observer_.selection_count());
196 EXPECT_EQ(std::string("1"), observer_.selected_pages()); 196 EXPECT_EQ(std::string("1"), observer_.selected_pages());
197 197
198 // More than two transitions and only the first and last would happen. 198 // More than two transitions and only the first and last would happen.
199 SetStartPageAndExpects(kStartPage, 2, 0, 0); 199 SetStartPageAndExpects(kStartPage, 2, 0, 0);
200 pagination_.SelectPage(1, true /* animate */); 200 pagination_.SelectPage(1, true /* animate */);
201 pagination_.SelectPage(3, true /* animate */); // Ignored 201 pagination_.SelectPage(3, true /* animate */); // Ignored
202 pagination_.SelectPage(4, true /* animate */); // Ignored 202 pagination_.SelectPage(4, true /* animate */); // Ignored
203 pagination_.SelectPage(2, true /* animate */); 203 pagination_.SelectPage(2, true /* animate */);
204 MessageLoop::current()->Run(); 204 base::MessageLoop::current()->Run();
205 EXPECT_EQ(2, observer_.transition_start_count()); 205 EXPECT_EQ(2, observer_.transition_start_count());
206 EXPECT_EQ(2, observer_.transition_end_count()); 206 EXPECT_EQ(2, observer_.transition_end_count());
207 EXPECT_EQ(2, observer_.selection_count()); 207 EXPECT_EQ(2, observer_.selection_count());
208 EXPECT_EQ(std::string("1 2"), observer_.selected_pages()); 208 EXPECT_EQ(std::string("1 2"), observer_.selected_pages());
209 209
210 // Multiple transitions with one transition that goes back to the original 210 // Multiple transitions with one transition that goes back to the original
211 // and followed by a new transition. Two transitions would happen. The first 211 // and followed by a new transition. Two transitions would happen. The first
212 // one will be reversed by the kStart transition and the second one will be 212 // one will be reversed by the kStart transition and the second one will be
213 // finished. 213 // finished.
214 SetStartPageAndExpects(kStartPage, 1, 0, 0); 214 SetStartPageAndExpects(kStartPage, 1, 0, 0);
215 pagination_.SelectPage(1, true /* animate */); 215 pagination_.SelectPage(1, true /* animate */);
216 pagination_.SelectPage(2, true /* animate */); // Ignored 216 pagination_.SelectPage(2, true /* animate */); // Ignored
217 pagination_.SelectPage(kStartPage, true /* animate */); 217 pagination_.SelectPage(kStartPage, true /* animate */);
218 pagination_.SelectPage(3, true /* animate */); 218 pagination_.SelectPage(3, true /* animate */);
219 MessageLoop::current()->Run(); 219 base::MessageLoop::current()->Run();
220 EXPECT_EQ(std::string("3"), observer_.selected_pages()); 220 EXPECT_EQ(std::string("3"), observer_.selected_pages());
221 } 221 }
222 222
223 TEST_F(PaginationModelTest, SimpleScroll) { 223 TEST_F(PaginationModelTest, SimpleScroll) {
224 const int kStartPage = 2; 224 const int kStartPage = 2;
225 225
226 // Scroll to the next page (negative delta) and finish it. 226 // Scroll to the next page (negative delta) and finish it.
227 SetStartPageAndExpects(kStartPage, 1, 0, 0); 227 SetStartPageAndExpects(kStartPage, 1, 0, 0);
228 pagination_.StartScroll(); 228 pagination_.StartScroll();
229 pagination_.UpdateScroll(-0.1); 229 pagination_.UpdateScroll(-0.1);
230 EXPECT_EQ(kStartPage + 1, pagination_.transition().target_page); 230 EXPECT_EQ(kStartPage + 1, pagination_.transition().target_page);
231 pagination_.EndScroll(false); // Finish transition 231 pagination_.EndScroll(false); // Finish transition
232 MessageLoop::current()->Run(); 232 base::MessageLoop::current()->Run();
233 EXPECT_EQ(1, observer_.selection_count()); 233 EXPECT_EQ(1, observer_.selection_count());
234 234
235 // Scroll to the previous page (positive delta) and finish it. 235 // Scroll to the previous page (positive delta) and finish it.
236 SetStartPageAndExpects(kStartPage, 1, 0, 0); 236 SetStartPageAndExpects(kStartPage, 1, 0, 0);
237 pagination_.StartScroll(); 237 pagination_.StartScroll();
238 pagination_.UpdateScroll(0.1); 238 pagination_.UpdateScroll(0.1);
239 EXPECT_EQ(kStartPage - 1, pagination_.transition().target_page); 239 EXPECT_EQ(kStartPage - 1, pagination_.transition().target_page);
240 pagination_.EndScroll(false); // Finish transition 240 pagination_.EndScroll(false); // Finish transition
241 MessageLoop::current()->Run(); 241 base::MessageLoop::current()->Run();
242 EXPECT_EQ(1, observer_.selection_count()); 242 EXPECT_EQ(1, observer_.selection_count());
243 243
244 // Scroll to the next page (negative delta) and cancel it. 244 // Scroll to the next page (negative delta) and cancel it.
245 SetStartPageAndExpects(kStartPage, 0, 1, 0); 245 SetStartPageAndExpects(kStartPage, 0, 1, 0);
246 pagination_.StartScroll(); 246 pagination_.StartScroll();
247 pagination_.UpdateScroll(-0.1); 247 pagination_.UpdateScroll(-0.1);
248 EXPECT_EQ(kStartPage + 1, pagination_.transition().target_page); 248 EXPECT_EQ(kStartPage + 1, pagination_.transition().target_page);
249 pagination_.EndScroll(true); // Cancel transition 249 pagination_.EndScroll(true); // Cancel transition
250 MessageLoop::current()->Run(); 250 base::MessageLoop::current()->Run();
251 EXPECT_EQ(0, observer_.selection_count()); 251 EXPECT_EQ(0, observer_.selection_count());
252 252
253 // Scroll to the previous page (position delta) and cancel it. 253 // Scroll to the previous page (position delta) and cancel it.
254 SetStartPageAndExpects(kStartPage, 0, 1, 0); 254 SetStartPageAndExpects(kStartPage, 0, 1, 0);
255 pagination_.StartScroll(); 255 pagination_.StartScroll();
256 pagination_.UpdateScroll(0.1); 256 pagination_.UpdateScroll(0.1);
257 EXPECT_EQ(kStartPage - 1, pagination_.transition().target_page); 257 EXPECT_EQ(kStartPage - 1, pagination_.transition().target_page);
258 pagination_.EndScroll(true); // Cancel transition 258 pagination_.EndScroll(true); // Cancel transition
259 MessageLoop::current()->Run(); 259 base::MessageLoop::current()->Run();
260 EXPECT_EQ(0, observer_.selection_count()); 260 EXPECT_EQ(0, observer_.selection_count());
261 } 261 }
262 262
263 TEST_F(PaginationModelTest, ScrollWithTransition) { 263 TEST_F(PaginationModelTest, ScrollWithTransition) {
264 const int kStartPage = 2; 264 const int kStartPage = 2;
265 265
266 // Scroll to the next page (negative delta) with a transition in the same 266 // Scroll to the next page (negative delta) with a transition in the same
267 // direction. 267 // direction.
268 SetStartPageAndExpects(kStartPage, 1, 0, 0); 268 SetStartPageAndExpects(kStartPage, 1, 0, 0);
269 pagination_.SetTransition(PaginationModel::Transition(kStartPage + 1, 0.5)); 269 pagination_.SetTransition(PaginationModel::Transition(kStartPage + 1, 0.5));
270 pagination_.StartScroll(); 270 pagination_.StartScroll();
271 pagination_.UpdateScroll(-0.1); 271 pagination_.UpdateScroll(-0.1);
272 EXPECT_EQ(kStartPage + 1, pagination_.transition().target_page); 272 EXPECT_EQ(kStartPage + 1, pagination_.transition().target_page);
273 EXPECT_EQ(0.6, pagination_.transition().progress); 273 EXPECT_EQ(0.6, pagination_.transition().progress);
274 pagination_.EndScroll(false); 274 pagination_.EndScroll(false);
275 MessageLoop::current()->Run(); 275 base::MessageLoop::current()->Run();
276 EXPECT_EQ(1, observer_.selection_count()); 276 EXPECT_EQ(1, observer_.selection_count());
277 277
278 // Scroll to the next page (negative delta) with a transition in a different 278 // Scroll to the next page (negative delta) with a transition in a different
279 // direction. 279 // direction.
280 SetStartPageAndExpects(kStartPage, 0, 1, 0); 280 SetStartPageAndExpects(kStartPage, 0, 1, 0);
281 pagination_.SetTransition(PaginationModel::Transition(kStartPage - 1, 0.5)); 281 pagination_.SetTransition(PaginationModel::Transition(kStartPage - 1, 0.5));
282 pagination_.StartScroll(); 282 pagination_.StartScroll();
283 pagination_.UpdateScroll(-0.1); 283 pagination_.UpdateScroll(-0.1);
284 EXPECT_EQ(kStartPage - 1, pagination_.transition().target_page); 284 EXPECT_EQ(kStartPage - 1, pagination_.transition().target_page);
285 EXPECT_EQ(0.4, pagination_.transition().progress); 285 EXPECT_EQ(0.4, pagination_.transition().progress);
286 pagination_.EndScroll(true); 286 pagination_.EndScroll(true);
287 287
288 // Scroll to the previous page (positive delta) with a transition in the same 288 // Scroll to the previous page (positive delta) with a transition in the same
289 // direction. 289 // direction.
290 SetStartPageAndExpects(kStartPage, 1, 0, 0); 290 SetStartPageAndExpects(kStartPage, 1, 0, 0);
291 pagination_.SetTransition(PaginationModel::Transition(kStartPage - 1, 0.5)); 291 pagination_.SetTransition(PaginationModel::Transition(kStartPage - 1, 0.5));
292 pagination_.StartScroll(); 292 pagination_.StartScroll();
293 pagination_.UpdateScroll(0.1); 293 pagination_.UpdateScroll(0.1);
294 EXPECT_EQ(kStartPage - 1, pagination_.transition().target_page); 294 EXPECT_EQ(kStartPage - 1, pagination_.transition().target_page);
295 EXPECT_EQ(0.6, pagination_.transition().progress); 295 EXPECT_EQ(0.6, pagination_.transition().progress);
296 pagination_.EndScroll(false); 296 pagination_.EndScroll(false);
297 MessageLoop::current()->Run(); 297 base::MessageLoop::current()->Run();
298 EXPECT_EQ(1, observer_.selection_count()); 298 EXPECT_EQ(1, observer_.selection_count());
299 299
300 // Scroll to the previous page (positive delta) with a transition in a 300 // Scroll to the previous page (positive delta) with a transition in a
301 // different direction. 301 // different direction.
302 SetStartPageAndExpects(kStartPage, 0, 1, 0); 302 SetStartPageAndExpects(kStartPage, 0, 1, 0);
303 pagination_.SetTransition(PaginationModel::Transition(kStartPage + 1, 0.5)); 303 pagination_.SetTransition(PaginationModel::Transition(kStartPage + 1, 0.5));
304 pagination_.StartScroll(); 304 pagination_.StartScroll();
305 pagination_.UpdateScroll(0.1); 305 pagination_.UpdateScroll(0.1);
306 EXPECT_EQ(kStartPage + 1, pagination_.transition().target_page); 306 EXPECT_EQ(kStartPage + 1, pagination_.transition().target_page);
307 EXPECT_EQ(0.4, pagination_.transition().progress); 307 EXPECT_EQ(0.4, pagination_.transition().progress);
308 pagination_.EndScroll(true); 308 pagination_.EndScroll(true);
309 } 309 }
310 310
311 TEST_F(PaginationModelTest, LongScroll) { 311 TEST_F(PaginationModelTest, LongScroll) {
312 const int kStartPage = 2; 312 const int kStartPage = 2;
313 313
314 // Scroll to the next page (negative delta) with a transition in the same 314 // Scroll to the next page (negative delta) with a transition in the same
315 // direction. And scroll enough to change page twice. 315 // direction. And scroll enough to change page twice.
316 SetStartPageAndExpects(kStartPage, 2, 0, 0); 316 SetStartPageAndExpects(kStartPage, 2, 0, 0);
317 pagination_.SetTransition(PaginationModel::Transition(kStartPage + 1, 0.5)); 317 pagination_.SetTransition(PaginationModel::Transition(kStartPage + 1, 0.5));
318 pagination_.StartScroll(); 318 pagination_.StartScroll();
319 pagination_.UpdateScroll(-0.1); 319 pagination_.UpdateScroll(-0.1);
320 EXPECT_EQ(kStartPage + 1, pagination_.transition().target_page); 320 EXPECT_EQ(kStartPage + 1, pagination_.transition().target_page);
321 EXPECT_EQ(0.6, pagination_.transition().progress); 321 EXPECT_EQ(0.6, pagination_.transition().progress);
322 pagination_.UpdateScroll(-0.5); 322 pagination_.UpdateScroll(-0.5);
323 EXPECT_EQ(1, observer_.selection_count()); 323 EXPECT_EQ(1, observer_.selection_count());
324 pagination_.UpdateScroll(-0.5); 324 pagination_.UpdateScroll(-0.5);
325 EXPECT_EQ(kStartPage + 2, pagination_.transition().target_page); 325 EXPECT_EQ(kStartPage + 2, pagination_.transition().target_page);
326 pagination_.EndScroll(false); 326 pagination_.EndScroll(false);
327 MessageLoop::current()->Run(); 327 base::MessageLoop::current()->Run();
328 EXPECT_EQ(2, observer_.selection_count()); 328 EXPECT_EQ(2, observer_.selection_count());
329 329
330 // Scroll to the next page (negative delta) with a transition in a different 330 // Scroll to the next page (negative delta) with a transition in a different
331 // direction. And scroll enough to revert it and switch page once. 331 // direction. And scroll enough to revert it and switch page once.
332 SetStartPageAndExpects(kStartPage, 1, 0, 0); 332 SetStartPageAndExpects(kStartPage, 1, 0, 0);
333 pagination_.SetTransition(PaginationModel::Transition(kStartPage - 1, 0.5)); 333 pagination_.SetTransition(PaginationModel::Transition(kStartPage - 1, 0.5));
334 pagination_.StartScroll(); 334 pagination_.StartScroll();
335 pagination_.UpdateScroll(-0.1); 335 pagination_.UpdateScroll(-0.1);
336 EXPECT_EQ(kStartPage - 1, pagination_.transition().target_page); 336 EXPECT_EQ(kStartPage - 1, pagination_.transition().target_page);
337 EXPECT_EQ(0.4, pagination_.transition().progress); 337 EXPECT_EQ(0.4, pagination_.transition().progress);
338 pagination_.UpdateScroll(-0.5); // This clears the transition. 338 pagination_.UpdateScroll(-0.5); // This clears the transition.
339 pagination_.UpdateScroll(-0.5); // This starts a new transition. 339 pagination_.UpdateScroll(-0.5); // This starts a new transition.
340 EXPECT_EQ(kStartPage + 1, pagination_.transition().target_page); 340 EXPECT_EQ(kStartPage + 1, pagination_.transition().target_page);
341 pagination_.EndScroll(false); 341 pagination_.EndScroll(false);
342 MessageLoop::current()->Run(); 342 base::MessageLoop::current()->Run();
343 EXPECT_EQ(1, observer_.selection_count()); 343 EXPECT_EQ(1, observer_.selection_count());
344 344
345 // Similar cases as above but in the opposite direction. 345 // Similar cases as above but in the opposite direction.
346 // Scroll to the previous page (positive delta) with a transition in the same 346 // Scroll to the previous page (positive delta) with a transition in the same
347 // direction. And scroll enough to change page twice. 347 // direction. And scroll enough to change page twice.
348 SetStartPageAndExpects(kStartPage, 2, 0, 0); 348 SetStartPageAndExpects(kStartPage, 2, 0, 0);
349 pagination_.SetTransition(PaginationModel::Transition(kStartPage - 1, 0.5)); 349 pagination_.SetTransition(PaginationModel::Transition(kStartPage - 1, 0.5));
350 pagination_.StartScroll(); 350 pagination_.StartScroll();
351 pagination_.UpdateScroll(0.1); 351 pagination_.UpdateScroll(0.1);
352 EXPECT_EQ(kStartPage - 1, pagination_.transition().target_page); 352 EXPECT_EQ(kStartPage - 1, pagination_.transition().target_page);
353 EXPECT_EQ(0.6, pagination_.transition().progress); 353 EXPECT_EQ(0.6, pagination_.transition().progress);
354 pagination_.UpdateScroll(0.5); 354 pagination_.UpdateScroll(0.5);
355 EXPECT_EQ(1, observer_.selection_count()); 355 EXPECT_EQ(1, observer_.selection_count());
356 pagination_.UpdateScroll(0.5); 356 pagination_.UpdateScroll(0.5);
357 EXPECT_EQ(kStartPage - 2, pagination_.transition().target_page); 357 EXPECT_EQ(kStartPage - 2, pagination_.transition().target_page);
358 pagination_.EndScroll(false); 358 pagination_.EndScroll(false);
359 MessageLoop::current()->Run(); 359 base::MessageLoop::current()->Run();
360 EXPECT_EQ(2, observer_.selection_count()); 360 EXPECT_EQ(2, observer_.selection_count());
361 361
362 // Scroll to the previous page (positive delta) with a transition in a 362 // Scroll to the previous page (positive delta) with a transition in a
363 // different direction. And scroll enough to revert it and switch page once. 363 // different direction. And scroll enough to revert it and switch page once.
364 SetStartPageAndExpects(kStartPage, 1, 0, 0); 364 SetStartPageAndExpects(kStartPage, 1, 0, 0);
365 pagination_.SetTransition(PaginationModel::Transition(kStartPage + 1, 0.5)); 365 pagination_.SetTransition(PaginationModel::Transition(kStartPage + 1, 0.5));
366 pagination_.StartScroll(); 366 pagination_.StartScroll();
367 pagination_.UpdateScroll(0.1); 367 pagination_.UpdateScroll(0.1);
368 EXPECT_EQ(kStartPage + 1, pagination_.transition().target_page); 368 EXPECT_EQ(kStartPage + 1, pagination_.transition().target_page);
369 EXPECT_EQ(0.4, pagination_.transition().progress); 369 EXPECT_EQ(0.4, pagination_.transition().progress);
370 pagination_.UpdateScroll(0.5); // This clears the transition. 370 pagination_.UpdateScroll(0.5); // This clears the transition.
371 pagination_.UpdateScroll(0.5); // This starts a new transition. 371 pagination_.UpdateScroll(0.5); // This starts a new transition.
372 EXPECT_EQ(kStartPage - 1, pagination_.transition().target_page); 372 EXPECT_EQ(kStartPage - 1, pagination_.transition().target_page);
373 pagination_.EndScroll(false); 373 pagination_.EndScroll(false);
374 MessageLoop::current()->Run(); 374 base::MessageLoop::current()->Run();
375 EXPECT_EQ(1, observer_.selection_count()); 375 EXPECT_EQ(1, observer_.selection_count());
376 } 376 }
377 377
378 TEST_F(PaginationModelTest, FireTransitionZero) { 378 TEST_F(PaginationModelTest, FireTransitionZero) {
379 const int kStartPage = 2; 379 const int kStartPage = 2;
380 380
381 // Scroll to next page then revert the scroll and make sure transition 381 // Scroll to next page then revert the scroll and make sure transition
382 // progress 0 is fired when previous scroll is cleared. 382 // progress 0 is fired when previous scroll is cleared.
383 SetStartPageAndExpects(kStartPage, 0, 0, 0); 383 SetStartPageAndExpects(kStartPage, 0, 0, 0);
384 pagination_.StartScroll(); 384 pagination_.StartScroll();
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 EXPECT_EQ(1, pagination_.selected_page()); 421 EXPECT_EQ(1, pagination_.selected_page());
422 422
423 // But if the currently selected_page exceeds the total number of pages, 423 // But if the currently selected_page exceeds the total number of pages,
424 // it automatically switches to the last page. 424 // it automatically switches to the last page.
425 pagination_.SetTotalPages(1); 425 pagination_.SetTotalPages(1);
426 EXPECT_EQ(0, pagination_.selected_page()); 426 EXPECT_EQ(0, pagination_.selected_page());
427 } 427 }
428 428
429 } // namespace test 429 } // namespace test
430 } // namespace app_list 430 } // namespace app_list
OLDNEW
« no previous file with comments | « ui/app_list/cocoa/test/apps_grid_controller_test_helper.mm ('k') | ui/app_list/views/apps_grid_view_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698