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

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

Issue 10890049: app_list: Touch scroll and animation improvement. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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/pagination_model.cc ('k') | ui/app_list/search_result_view.cc » ('j') | 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/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 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 MessageLoop::current()->Run(); 183 MessageLoop::current()->Run();
184 EXPECT_EQ(1, observer_.transition_start_count()); 184 EXPECT_EQ(1, observer_.transition_start_count());
185 EXPECT_EQ(1, observer_.transition_end_count()); 185 EXPECT_EQ(1, observer_.transition_end_count());
186 EXPECT_EQ(1, observer_.selection_count()); 186 EXPECT_EQ(1, observer_.selection_count());
187 EXPECT_EQ(std::string("1"), observer_.selected_pages()); 187 EXPECT_EQ(std::string("1"), observer_.selected_pages());
188 188
189 // More than two transitions and only the first and last would happen. 189 // More than two transitions and only the first and last would happen.
190 SetStartPageAndExpects(kStartPage, 2, 0, 0); 190 SetStartPageAndExpects(kStartPage, 2, 0, 0);
191 pagination_.SelectPage(1, true /* animate */); 191 pagination_.SelectPage(1, true /* animate */);
192 pagination_.SelectPage(3, true /* animate */); // Ignored 192 pagination_.SelectPage(3, true /* animate */); // Ignored
193 pagination_.SelectPage(0, true /* animate */); // Ignored 193 pagination_.SelectPage(4, true /* animate */); // Ignored
194 pagination_.SelectPage(2, true /* animate */); 194 pagination_.SelectPage(2, true /* animate */);
195 MessageLoop::current()->Run(); 195 MessageLoop::current()->Run();
196 EXPECT_EQ(2, observer_.transition_start_count()); 196 EXPECT_EQ(2, observer_.transition_start_count());
197 EXPECT_EQ(2, observer_.transition_end_count()); 197 EXPECT_EQ(2, observer_.transition_end_count());
198 EXPECT_EQ(2, observer_.selection_count()); 198 EXPECT_EQ(2, observer_.selection_count());
199 EXPECT_EQ(std::string("1 2"), observer_.selected_pages()); 199 EXPECT_EQ(std::string("1 2"), observer_.selected_pages());
200
201 // Multiple transitions with one transition that goes back to the original
202 // and followed by a new transition. Two transitions would happen. The first
203 // one will be reversed by the kStart transition and the second one will be
204 // finished.
205 SetStartPageAndExpects(kStartPage, 1, 0, 0);
206 pagination_.SelectPage(1, true /* animate */);
207 pagination_.SelectPage(2, true /* animate */); // Ignored
208 pagination_.SelectPage(kStartPage, true /* animate */);
209 pagination_.SelectPage(3, true /* animate */);
210 MessageLoop::current()->Run();
211 EXPECT_EQ(std::string("3"), observer_.selected_pages());
200 } 212 }
201 213
202 TEST_F(PaginationModelTest, SimpleScroll) { 214 TEST_F(PaginationModelTest, SimpleScroll) {
203 const int kStartPage = 2; 215 const int kStartPage = 2;
204 216
205 // Scroll to the next page (negative delta) and end at more than 0.5 217 // Scroll to the next page (negative delta) and finish it.
206 SetStartPageAndExpects(kStartPage, 1, 0, 0); 218 SetStartPageAndExpects(kStartPage, 1, 0, 0);
207 pagination_.StartScroll(); 219 pagination_.StartScroll();
208 pagination_.UpdateScroll(-0.1); 220 pagination_.UpdateScroll(-0.1);
209 EXPECT_EQ(kStartPage + 1, pagination_.transition().target_page); 221 EXPECT_EQ(kStartPage + 1, pagination_.transition().target_page);
210 pagination_.UpdateScroll(-0.5); 222 pagination_.EndScroll(false); // Finish transition
211 pagination_.EndScroll();
212 // More than 0.5 transition will be finished with a page select.
213 EXPECT_GT(pagination_.transition().progress, 0.5);
214 MessageLoop::current()->Run(); 223 MessageLoop::current()->Run();
215 EXPECT_EQ(1, observer_.selection_count()); 224 EXPECT_EQ(1, observer_.selection_count());
216 225
217 // Scroll to the previous page (positive delta) and end at more than 0.5 226 // Scroll to the previous page (positive delta) and finish it.
218 SetStartPageAndExpects(kStartPage, 1, 0, 0); 227 SetStartPageAndExpects(kStartPage, 1, 0, 0);
219 pagination_.StartScroll(); 228 pagination_.StartScroll();
220 pagination_.UpdateScroll(0.1); 229 pagination_.UpdateScroll(0.1);
221 EXPECT_EQ(kStartPage - 1, pagination_.transition().target_page); 230 EXPECT_EQ(kStartPage - 1, pagination_.transition().target_page);
222 pagination_.UpdateScroll(0.5); 231 pagination_.EndScroll(false); // Finish transition
223 pagination_.EndScroll();
224 // More than 0.5 transition will be finished with a page select.
225 EXPECT_GT(pagination_.transition().progress, 0.5);
226 MessageLoop::current()->Run(); 232 MessageLoop::current()->Run();
227 EXPECT_EQ(1, observer_.selection_count()); 233 EXPECT_EQ(1, observer_.selection_count());
228 234
229 // Scroll to the next page (negative delta) and end at less than 0.5 235 // Scroll to the next page (negative delta) and cancel it.
230 SetStartPageAndExpects(kStartPage, 0, 1, 0); 236 SetStartPageAndExpects(kStartPage, 0, 1, 0);
231 pagination_.StartScroll(); 237 pagination_.StartScroll();
232 pagination_.UpdateScroll(-0.1); 238 pagination_.UpdateScroll(-0.1);
233 EXPECT_EQ(kStartPage + 1, pagination_.transition().target_page); 239 EXPECT_EQ(kStartPage + 1, pagination_.transition().target_page);
234 pagination_.EndScroll(); 240 pagination_.EndScroll(true); // Cancel transition
235 // Less than 0.5 transition will be reverted with no page select.
236 EXPECT_LT(pagination_.transition().progress, 0.5);
237 MessageLoop::current()->Run(); 241 MessageLoop::current()->Run();
238 EXPECT_EQ(0, observer_.selection_count()); 242 EXPECT_EQ(0, observer_.selection_count());
239 243
240 // Scroll to the previous page (position delta) and end at less than 0.5 244 // Scroll to the previous page (position delta) and cancel it.
241 SetStartPageAndExpects(kStartPage, 0, 1, 0); 245 SetStartPageAndExpects(kStartPage, 0, 1, 0);
242 pagination_.StartScroll(); 246 pagination_.StartScroll();
243 pagination_.UpdateScroll(0.1); 247 pagination_.UpdateScroll(0.1);
244 EXPECT_EQ(kStartPage - 1, pagination_.transition().target_page); 248 EXPECT_EQ(kStartPage - 1, pagination_.transition().target_page);
245 pagination_.EndScroll(); 249 pagination_.EndScroll(true); // Cancel transition
246 // Less than 0.5 transition will be reverted with no page select.
247 EXPECT_LT(pagination_.transition().progress, 0.5);
248 MessageLoop::current()->Run(); 250 MessageLoop::current()->Run();
249 EXPECT_EQ(0, observer_.selection_count()); 251 EXPECT_EQ(0, observer_.selection_count());
250 } 252 }
251 253
252 TEST_F(PaginationModelTest, ScrollWithTransition) { 254 TEST_F(PaginationModelTest, ScrollWithTransition) {
253 const int kStartPage = 2; 255 const int kStartPage = 2;
254 256
255 // Scroll to the next page (negative delta) with a transition in the same 257 // Scroll to the next page (negative delta) with a transition in the same
256 // direction. 258 // direction.
257 SetStartPageAndExpects(kStartPage, 1, 0, 0); 259 SetStartPageAndExpects(kStartPage, 1, 0, 0);
258 pagination_.SetTransition(PaginationModel::Transition(kStartPage + 1, 0.5)); 260 pagination_.SetTransition(PaginationModel::Transition(kStartPage + 1, 0.5));
259 pagination_.StartScroll(); 261 pagination_.StartScroll();
260 pagination_.UpdateScroll(-0.1); 262 pagination_.UpdateScroll(-0.1);
261 EXPECT_EQ(kStartPage + 1, pagination_.transition().target_page); 263 EXPECT_EQ(kStartPage + 1, pagination_.transition().target_page);
262 EXPECT_EQ(0.6, pagination_.transition().progress); 264 EXPECT_EQ(0.6, pagination_.transition().progress);
263 pagination_.EndScroll(); 265 pagination_.EndScroll(false);
264 MessageLoop::current()->Run(); 266 MessageLoop::current()->Run();
265 EXPECT_EQ(1, observer_.selection_count()); 267 EXPECT_EQ(1, observer_.selection_count());
266 268
267 // Scroll to the next page (negative delta) with a transition in a different 269 // Scroll to the next page (negative delta) with a transition in a different
268 // direction. 270 // direction.
269 SetStartPageAndExpects(kStartPage, 0, 1, 0); 271 SetStartPageAndExpects(kStartPage, 0, 1, 0);
270 pagination_.SetTransition(PaginationModel::Transition(kStartPage - 1, 0.5)); 272 pagination_.SetTransition(PaginationModel::Transition(kStartPage - 1, 0.5));
271 pagination_.StartScroll(); 273 pagination_.StartScroll();
272 pagination_.UpdateScroll(-0.1); 274 pagination_.UpdateScroll(-0.1);
273 EXPECT_EQ(kStartPage - 1, pagination_.transition().target_page); 275 EXPECT_EQ(kStartPage - 1, pagination_.transition().target_page);
274 EXPECT_EQ(0.4, pagination_.transition().progress); 276 EXPECT_EQ(0.4, pagination_.transition().progress);
275 pagination_.EndScroll(); 277 pagination_.EndScroll(true);
276 MessageLoop::current()->Run();
277 EXPECT_EQ(0, observer_.selection_count());
278 278
279 // Scroll to the previous page (positive delta) with a transition in the same 279 // Scroll to the previous page (positive delta) with a transition in the same
280 // direction. 280 // direction.
281 SetStartPageAndExpects(kStartPage, 1, 0, 0); 281 SetStartPageAndExpects(kStartPage, 1, 0, 0);
282 pagination_.SetTransition(PaginationModel::Transition(kStartPage - 1, 0.5)); 282 pagination_.SetTransition(PaginationModel::Transition(kStartPage - 1, 0.5));
283 pagination_.StartScroll(); 283 pagination_.StartScroll();
284 pagination_.UpdateScroll(0.1); 284 pagination_.UpdateScroll(0.1);
285 EXPECT_EQ(kStartPage - 1, pagination_.transition().target_page); 285 EXPECT_EQ(kStartPage - 1, pagination_.transition().target_page);
286 EXPECT_EQ(0.6, pagination_.transition().progress); 286 EXPECT_EQ(0.6, pagination_.transition().progress);
287 pagination_.EndScroll(); 287 pagination_.EndScroll(false);
288 MessageLoop::current()->Run(); 288 MessageLoop::current()->Run();
289 EXPECT_EQ(1, observer_.selection_count()); 289 EXPECT_EQ(1, observer_.selection_count());
290 290
291 // Scroll to the previous page (positive delta) with a transition in a 291 // Scroll to the previous page (positive delta) with a transition in a
292 // different direction. 292 // different direction.
293 SetStartPageAndExpects(kStartPage, 0, 1, 0); 293 SetStartPageAndExpects(kStartPage, 0, 1, 0);
294 pagination_.SetTransition(PaginationModel::Transition(kStartPage + 1, 0.5)); 294 pagination_.SetTransition(PaginationModel::Transition(kStartPage + 1, 0.5));
295 pagination_.StartScroll(); 295 pagination_.StartScroll();
296 pagination_.UpdateScroll(0.1); 296 pagination_.UpdateScroll(0.1);
297 EXPECT_EQ(kStartPage + 1, pagination_.transition().target_page); 297 EXPECT_EQ(kStartPage + 1, pagination_.transition().target_page);
298 EXPECT_EQ(0.4, pagination_.transition().progress); 298 EXPECT_EQ(0.4, pagination_.transition().progress);
299 pagination_.EndScroll(); 299 pagination_.EndScroll(true);
300 MessageLoop::current()->Run();
301 EXPECT_EQ(0, observer_.selection_count());
302 } 300 }
303 301
304 TEST_F(PaginationModelTest, LongScroll) { 302 TEST_F(PaginationModelTest, LongScroll) {
305 const int kStartPage = 2; 303 const int kStartPage = 2;
306 304
307 // Scroll to the next page (negative delta) with a transition in the same 305 // Scroll to the next page (negative delta) with a transition in the same
308 // direction. And scroll enough to change page twice. 306 // direction. And scroll enough to change page twice.
309 SetStartPageAndExpects(kStartPage, 2, 0, 0); 307 SetStartPageAndExpects(kStartPage, 2, 0, 0);
310 pagination_.SetTransition(PaginationModel::Transition(kStartPage + 1, 0.5)); 308 pagination_.SetTransition(PaginationModel::Transition(kStartPage + 1, 0.5));
311 pagination_.StartScroll(); 309 pagination_.StartScroll();
312 pagination_.UpdateScroll(-0.1); 310 pagination_.UpdateScroll(-0.1);
313 EXPECT_EQ(kStartPage + 1, pagination_.transition().target_page); 311 EXPECT_EQ(kStartPage + 1, pagination_.transition().target_page);
314 EXPECT_EQ(0.6, pagination_.transition().progress); 312 EXPECT_EQ(0.6, pagination_.transition().progress);
315 pagination_.UpdateScroll(-0.5); 313 pagination_.UpdateScroll(-0.5);
316 EXPECT_EQ(1, observer_.selection_count()); 314 EXPECT_EQ(1, observer_.selection_count());
317 pagination_.UpdateScroll(-0.5); 315 pagination_.UpdateScroll(-0.5);
318 EXPECT_EQ(kStartPage + 2, pagination_.transition().target_page); 316 EXPECT_EQ(kStartPage + 2, pagination_.transition().target_page);
319 pagination_.EndScroll(); 317 pagination_.EndScroll(false);
320 MessageLoop::current()->Run(); 318 MessageLoop::current()->Run();
321 EXPECT_EQ(2, observer_.selection_count()); 319 EXPECT_EQ(2, observer_.selection_count());
322 320
323 // Scroll to the next page (negative delta) with a transition in a different 321 // Scroll to the next page (negative delta) with a transition in a different
324 // direction. And scroll enough to revert it and switch page once. 322 // direction. And scroll enough to revert it and switch page once.
325 SetStartPageAndExpects(kStartPage, 1, 0, 0); 323 SetStartPageAndExpects(kStartPage, 1, 0, 0);
326 pagination_.SetTransition(PaginationModel::Transition(kStartPage - 1, 0.5)); 324 pagination_.SetTransition(PaginationModel::Transition(kStartPage - 1, 0.5));
327 pagination_.StartScroll(); 325 pagination_.StartScroll();
328 pagination_.UpdateScroll(-0.1); 326 pagination_.UpdateScroll(-0.1);
329 EXPECT_EQ(kStartPage - 1, pagination_.transition().target_page); 327 EXPECT_EQ(kStartPage - 1, pagination_.transition().target_page);
330 EXPECT_EQ(0.4, pagination_.transition().progress); 328 EXPECT_EQ(0.4, pagination_.transition().progress);
331 pagination_.UpdateScroll(-0.5); // This clears the transition. 329 pagination_.UpdateScroll(-0.5); // This clears the transition.
332 pagination_.UpdateScroll(-0.5); // This starts a new transition. 330 pagination_.UpdateScroll(-0.5); // This starts a new transition.
333 EXPECT_EQ(kStartPage + 1, pagination_.transition().target_page); 331 EXPECT_EQ(kStartPage + 1, pagination_.transition().target_page);
334 pagination_.EndScroll(); 332 pagination_.EndScroll(false);
335 MessageLoop::current()->Run(); 333 MessageLoop::current()->Run();
336 EXPECT_EQ(1, observer_.selection_count()); 334 EXPECT_EQ(1, observer_.selection_count());
337 335
338 // Similar cases as above but in the opposite direction. 336 // Similar cases as above but in the opposite direction.
339 // Scroll to the previous page (positive delta) with a transition in the same 337 // Scroll to the previous page (positive delta) with a transition in the same
340 // direction. And scroll enough to change page twice. 338 // direction. And scroll enough to change page twice.
341 SetStartPageAndExpects(kStartPage, 2, 0, 0); 339 SetStartPageAndExpects(kStartPage, 2, 0, 0);
342 pagination_.SetTransition(PaginationModel::Transition(kStartPage - 1, 0.5)); 340 pagination_.SetTransition(PaginationModel::Transition(kStartPage - 1, 0.5));
343 pagination_.StartScroll(); 341 pagination_.StartScroll();
344 pagination_.UpdateScroll(0.1); 342 pagination_.UpdateScroll(0.1);
345 EXPECT_EQ(kStartPage - 1, pagination_.transition().target_page); 343 EXPECT_EQ(kStartPage - 1, pagination_.transition().target_page);
346 EXPECT_EQ(0.6, pagination_.transition().progress); 344 EXPECT_EQ(0.6, pagination_.transition().progress);
347 pagination_.UpdateScroll(0.5); 345 pagination_.UpdateScroll(0.5);
348 EXPECT_EQ(1, observer_.selection_count()); 346 EXPECT_EQ(1, observer_.selection_count());
349 pagination_.UpdateScroll(0.5); 347 pagination_.UpdateScroll(0.5);
350 EXPECT_EQ(kStartPage - 2, pagination_.transition().target_page); 348 EXPECT_EQ(kStartPage - 2, pagination_.transition().target_page);
351 pagination_.EndScroll(); 349 pagination_.EndScroll(false);
352 MessageLoop::current()->Run(); 350 MessageLoop::current()->Run();
353 EXPECT_EQ(2, observer_.selection_count()); 351 EXPECT_EQ(2, observer_.selection_count());
354 352
355 // Scroll to the previous page (positive delta) with a transition in a 353 // Scroll to the previous page (positive delta) with a transition in a
356 // different direction. And scroll enough to revert it and switch page once. 354 // different direction. And scroll enough to revert it and switch page once.
357 SetStartPageAndExpects(kStartPage, 1, 0, 0); 355 SetStartPageAndExpects(kStartPage, 1, 0, 0);
358 pagination_.SetTransition(PaginationModel::Transition(kStartPage + 1, 0.5)); 356 pagination_.SetTransition(PaginationModel::Transition(kStartPage + 1, 0.5));
359 pagination_.StartScroll(); 357 pagination_.StartScroll();
360 pagination_.UpdateScroll(0.1); 358 pagination_.UpdateScroll(0.1);
361 EXPECT_EQ(kStartPage + 1, pagination_.transition().target_page); 359 EXPECT_EQ(kStartPage + 1, pagination_.transition().target_page);
362 EXPECT_EQ(0.4, pagination_.transition().progress); 360 EXPECT_EQ(0.4, pagination_.transition().progress);
363 pagination_.UpdateScroll(0.5); // This clears the transition. 361 pagination_.UpdateScroll(0.5); // This clears the transition.
364 pagination_.UpdateScroll(0.5); // This starts a new transition. 362 pagination_.UpdateScroll(0.5); // This starts a new transition.
365 EXPECT_EQ(kStartPage - 1, pagination_.transition().target_page); 363 EXPECT_EQ(kStartPage - 1, pagination_.transition().target_page);
366 pagination_.EndScroll(); 364 pagination_.EndScroll(false);
367 MessageLoop::current()->Run(); 365 MessageLoop::current()->Run();
368 EXPECT_EQ(1, observer_.selection_count()); 366 EXPECT_EQ(1, observer_.selection_count());
369 } 367 }
370 368
371 TEST_F(PaginationModelTest, SelectedPageIsLost) { 369 TEST_F(PaginationModelTest, SelectedPageIsLost) {
372 pagination_.SetTotalPages(2); 370 pagination_.SetTotalPages(2);
373 // The selected page is set to 0 once the total number of pages are set. 371 // The selected page is set to 0 once the total number of pages are set.
374 EXPECT_EQ(0, pagination_.selected_page()); 372 EXPECT_EQ(0, pagination_.selected_page());
375 373
376 pagination_.SelectPage(1, false /* animate */); 374 pagination_.SelectPage(1, false /* animate */);
377 EXPECT_EQ(1, pagination_.selected_page()); 375 EXPECT_EQ(1, pagination_.selected_page());
378 376
379 // The selected page is unchanged if it's still valid. 377 // The selected page is unchanged if it's still valid.
380 pagination_.SetTotalPages(3); 378 pagination_.SetTotalPages(3);
381 EXPECT_EQ(1, pagination_.selected_page()); 379 EXPECT_EQ(1, pagination_.selected_page());
382 pagination_.SetTotalPages(2); 380 pagination_.SetTotalPages(2);
383 EXPECT_EQ(1, pagination_.selected_page()); 381 EXPECT_EQ(1, pagination_.selected_page());
384 382
385 // But if the currently selected_page exceeds the total number of pages, 383 // But if the currently selected_page exceeds the total number of pages,
386 // it automatically switches to the last page. 384 // it automatically switches to the last page.
387 pagination_.SetTotalPages(1); 385 pagination_.SetTotalPages(1);
388 EXPECT_EQ(0, pagination_.selected_page()); 386 EXPECT_EQ(0, pagination_.selected_page());
389 } 387 }
390 388
391 } // namespace test 389 } // namespace test
392 } // namespace app_list 390 } // namespace app_list
OLDNEW
« no previous file with comments | « ui/app_list/pagination_model.cc ('k') | ui/app_list/search_result_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698