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

Side by Side Diff: chrome/browser/android/offline_pages/recent_tab_helper_unittest.cc

Issue 2571633003: Simple improvements to RecentTabHelperTest. (Closed)
Patch Set: Created 4 years 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "chrome/browser/android/offline_pages/recent_tab_helper.h" 5 #include "chrome/browser/android/offline_pages/recent_tab_helper.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "base/strings/string16.h" 9 #include "base/strings/string16.h"
10 #include "base/test/scoped_feature_list.h" 10 #include "base/test/scoped_feature_list.h"
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 } 239 }
240 240
241 // Loads a page and verifies that a snapshot is created. 241 // Loads a page and verifies that a snapshot is created.
242 TEST_F(RecentTabHelperTest, SimpleCapture) { 242 TEST_F(RecentTabHelperTest, SimpleCapture) {
243 NavigateAndCommit(kTestPageUrl); 243 NavigateAndCommit(kTestPageUrl);
244 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame(); 244 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame();
245 FastForwardSnapshotController(); 245 FastForwardSnapshotController();
246 RunUntilIdle(); 246 RunUntilIdle();
247 EXPECT_TRUE(model()->is_loaded()); 247 EXPECT_TRUE(model()->is_loaded());
248 GetAllPages(); 248 GetAllPages();
249 EXPECT_EQ(1U, all_pages().size()); 249 ASSERT_EQ(1U, all_pages().size());
250 EXPECT_EQ(kTestPageUrl, all_pages()[0].url); 250 EXPECT_EQ(kTestPageUrl, all_pages()[0].url);
251 } 251 }
252 252
253 // Checks that WebContents with no tab IDs are properly ignored. 253 // Checks that WebContents with no tab IDs are properly ignored.
254 TEST_F(RecentTabHelperTest, NoTabIdNoCapture) { 254 TEST_F(RecentTabHelperTest, NoTabIdNoCapture) {
255 // Create delegate that returns 'false' as TabId retrieval result. 255 // Create delegate that returns 'false' as TabId retrieval result.
256 recent_tab_helper()->SetDelegate(base::MakeUnique<TestDelegate>( 256 recent_tab_helper()->SetDelegate(base::MakeUnique<TestDelegate>(
257 this, task_runner(), kTabId, false)); 257 this, task_runner(), kTabId, false));
258 258
259 NavigateAndCommit(kTestPageUrl); 259 NavigateAndCommit(kTestPageUrl);
260 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame(); 260 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame();
261 FastForwardSnapshotController(); 261 FastForwardSnapshotController();
262 RunUntilIdle(); 262 RunUntilIdle();
263 EXPECT_TRUE(model()->is_loaded()); 263 EXPECT_TRUE(model()->is_loaded());
264 GetAllPages(); 264 GetAllPages();
265 // No page should be captured. 265 // No page should be captured.
266 EXPECT_EQ(0U, all_pages().size()); 266 ASSERT_EQ(0U, all_pages().size());
267 } 267 }
268 268
269 // Triggers two snapshot captures during a single page load. Should end up with 269 // Triggers two snapshot captures during a single page load. Should end up with
270 // one offline page (the 2nd snapshot should be kept). 270 // one offline page (the 2nd snapshot should be kept).
271 TEST_F(RecentTabHelperTest, TwoCapturesSamePageLoad) { 271 TEST_F(RecentTabHelperTest, TwoCapturesSamePageLoad) {
272 NavigateAndCommit(kTestPageUrl); 272 NavigateAndCommit(kTestPageUrl);
273 // Triggers snapshot after a time delay. 273 // Triggers snapshot after a time delay.
274 recent_tab_helper()->DocumentAvailableInMainFrame(); 274 recent_tab_helper()->DocumentAvailableInMainFrame();
275 RunUntilIdle(); 275 RunUntilIdle();
276 EXPECT_TRUE(model()->is_loaded()); 276 EXPECT_TRUE(model()->is_loaded());
277 EXPECT_EQ(0U, page_added_count()); 277 EXPECT_EQ(0U, page_added_count());
278 // Move the snapshot controller's time forward so it gets past timeouts. 278 // Move the snapshot controller's time forward so it gets past timeouts.
279 FastForwardSnapshotController(); 279 FastForwardSnapshotController();
280 RunUntilIdle(); 280 RunUntilIdle();
281 EXPECT_EQ(1U, page_added_count()); 281 EXPECT_EQ(1U, page_added_count());
282 EXPECT_EQ(0U, model_removed_count()); 282 EXPECT_EQ(0U, model_removed_count());
283 GetAllPages(); 283 GetAllPages();
284 EXPECT_EQ(1U, all_pages().size()); 284 ASSERT_EQ(1U, all_pages().size());
285 EXPECT_EQ(kTestPageUrl, all_pages()[0].url); 285 EXPECT_EQ(kTestPageUrl, all_pages()[0].url);
286 int64_t first_offline_id = all_pages()[0].offline_id; 286 int64_t first_offline_id = all_pages()[0].offline_id;
287 287
288 // Triggers snapshot after a time delay. 288 // Triggers snapshot after a time delay.
289 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame(); 289 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame();
290 // Move the snapshot controller's time forward so it gets past timeouts. 290 // Move the snapshot controller's time forward so it gets past timeouts.
291 FastForwardSnapshotController(); 291 FastForwardSnapshotController();
292 RunUntilIdle(); 292 RunUntilIdle();
293 EXPECT_EQ(2U, page_added_count()); 293 EXPECT_EQ(2U, page_added_count());
294 EXPECT_EQ(1U, model_removed_count()); 294 EXPECT_EQ(1U, model_removed_count());
295 // the same page should be simply overridden. 295 // the same page should be simply overridden.
296 GetAllPages(); 296 GetAllPages();
297 EXPECT_EQ(1U, all_pages().size()); 297 ASSERT_EQ(1U, all_pages().size());
298 EXPECT_EQ(kTestPageUrl, all_pages()[0].url); 298 EXPECT_EQ(kTestPageUrl, all_pages()[0].url);
299 EXPECT_NE(first_offline_id, all_pages()[0].offline_id); 299 EXPECT_NE(first_offline_id, all_pages()[0].offline_id);
300 } 300 }
301 301
302 // Triggers two snapshot captures during a single page load, where the 2nd one 302 // Triggers two snapshot captures during a single page load, where the 2nd one
303 // fails. Should end up with one offline page (the 1st, successful snapshot 303 // fails. Should end up with one offline page (the 1st, successful snapshot
304 // should be kept). 304 // should be kept).
305 // TODO(carlosk): re-enable once https://crbug.com/655697 is fixed, again. 305 // TODO(carlosk): re-enable once https://crbug.com/655697 is fixed, again.
306 TEST_F(RecentTabHelperTest, DISABLED_TwoCapturesSamePageLoadSecondFails) { 306 TEST_F(RecentTabHelperTest, DISABLED_TwoCapturesSamePageLoadSecondFails) {
307 NavigateAndCommit(kTestPageUrl); 307 NavigateAndCommit(kTestPageUrl);
308 // Triggers snapshot after a time delay. 308 // Triggers snapshot after a time delay.
309 recent_tab_helper()->DocumentAvailableInMainFrame(); 309 recent_tab_helper()->DocumentAvailableInMainFrame();
310 RunUntilIdle(); 310 RunUntilIdle();
311 EXPECT_TRUE(model()->is_loaded()); 311 EXPECT_TRUE(model()->is_loaded());
312 EXPECT_EQ(0U, page_added_count()); 312 EXPECT_EQ(0U, page_added_count());
313 // Move the snapshot controller's time forward so it gets past timeouts. 313 // Move the snapshot controller's time forward so it gets past timeouts.
314 FastForwardSnapshotController(); 314 FastForwardSnapshotController();
315 RunUntilIdle(); 315 RunUntilIdle();
316 EXPECT_EQ(1U, page_added_count()); 316 EXPECT_EQ(1U, page_added_count());
317 EXPECT_EQ(0U, model_removed_count()); 317 EXPECT_EQ(0U, model_removed_count());
318 GetAllPages(); 318 GetAllPages();
319 EXPECT_EQ(1U, all_pages().size()); 319 ASSERT_EQ(1U, all_pages().size());
320 EXPECT_EQ(kTestPageUrl, all_pages()[0].url); 320 EXPECT_EQ(kTestPageUrl, all_pages()[0].url);
321 int64_t first_offline_id = all_pages()[0].offline_id; 321 int64_t first_offline_id = all_pages()[0].offline_id;
322 322
323 // Sets a new delegate that will make the second snapshot fail. 323 // Sets a new delegate that will make the second snapshot fail.
324 TestDelegate* failing_delegate = 324 TestDelegate* failing_delegate =
325 new TestDelegate(this, task_runner(), kTabId, true); 325 new TestDelegate(this, task_runner(), kTabId, true);
326 failing_delegate->set_archive_size(-1); 326 failing_delegate->set_archive_size(-1);
327 failing_delegate->set_archive_result( 327 failing_delegate->set_archive_result(
328 offline_pages::OfflinePageArchiver::ArchiverResult:: 328 offline_pages::OfflinePageArchiver::ArchiverResult::
329 ERROR_ARCHIVE_CREATION_FAILED); 329 ERROR_ARCHIVE_CREATION_FAILED);
330 recent_tab_helper()->SetDelegate( 330 recent_tab_helper()->SetDelegate(
331 std::unique_ptr<TestDelegate>(failing_delegate)); 331 std::unique_ptr<TestDelegate>(failing_delegate));
332 332
333 // Triggers snapshot after a time delay. 333 // Triggers snapshot after a time delay.
334 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame(); 334 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame();
335 // Move the snapshot controller's time forward so it gets past timeouts. 335 // Move the snapshot controller's time forward so it gets past timeouts.
336 FastForwardSnapshotController(); 336 FastForwardSnapshotController();
337 RunUntilIdle(); 337 RunUntilIdle();
338 EXPECT_EQ(1U, page_added_count()); 338 EXPECT_EQ(1U, page_added_count());
339 EXPECT_EQ(0U, model_removed_count()); 339 EXPECT_EQ(0U, model_removed_count());
340 // The exact same page should still be available. 340 // The exact same page should still be available.
341 GetAllPages(); 341 GetAllPages();
342 EXPECT_EQ(1U, all_pages().size()); 342 ASSERT_EQ(1U, all_pages().size());
343 EXPECT_EQ(kTestPageUrl, all_pages()[0].url); 343 EXPECT_EQ(kTestPageUrl, all_pages()[0].url);
344 EXPECT_EQ(first_offline_id, all_pages()[0].offline_id); 344 EXPECT_EQ(first_offline_id, all_pages()[0].offline_id);
345 } 345 }
346 346
347 // Triggers two snapshot captures for two different page loads for the same URL. 347 // Triggers two snapshot captures for two different page loads for the same URL.
348 // Should end up with one offline page (snapshot from the 2nd load). 348 // Should end up with one offline page (snapshot from the 2nd load).
349 TEST_F(RecentTabHelperTest, TwoCapturesDifferentPageLoadsSameUrl) { 349 TEST_F(RecentTabHelperTest, TwoCapturesDifferentPageLoadsSameUrl) {
350 NavigateAndCommit(kTestPageUrl); 350 NavigateAndCommit(kTestPageUrl);
351 // Triggers snapshot after a time delay. 351 // Triggers snapshot after a time delay.
352 recent_tab_helper()->DocumentAvailableInMainFrame(); 352 recent_tab_helper()->DocumentAvailableInMainFrame();
353 RunUntilIdle(); 353 RunUntilIdle();
354 EXPECT_TRUE(model()->is_loaded()); 354 EXPECT_TRUE(model()->is_loaded());
355 EXPECT_EQ(0U, page_added_count()); 355 EXPECT_EQ(0U, page_added_count());
356 // Move the snapshot controller's time forward so it gets past timeouts. 356 // Move the snapshot controller's time forward so it gets past timeouts.
357 FastForwardSnapshotController(); 357 FastForwardSnapshotController();
358 RunUntilIdle(); 358 RunUntilIdle();
359 EXPECT_EQ(1U, page_added_count()); 359 EXPECT_EQ(1U, page_added_count());
360 EXPECT_EQ(0U, model_removed_count()); 360 EXPECT_EQ(0U, model_removed_count());
361 GetAllPages(); 361 GetAllPages();
362 EXPECT_EQ(1U, all_pages().size()); 362 ASSERT_EQ(1U, all_pages().size());
363 EXPECT_EQ(kTestPageUrl, all_pages()[0].url); 363 EXPECT_EQ(kTestPageUrl, all_pages()[0].url);
364 int64_t first_offline_id = all_pages()[0].offline_id; 364 int64_t first_offline_id = all_pages()[0].offline_id;
365 365
366 NavigateAndCommit(kTestPageUrl); 366 NavigateAndCommit(kTestPageUrl);
367 // Triggers snapshot after a time delay. 367 // Triggers snapshot after a time delay.
368 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame(); 368 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame();
369 // Move the snapshot controller's time forward so it gets past timeouts. 369 // Move the snapshot controller's time forward so it gets past timeouts.
370 FastForwardSnapshotController(); 370 FastForwardSnapshotController();
371 RunUntilIdle(); 371 RunUntilIdle();
372 EXPECT_EQ(2U, page_added_count()); 372 EXPECT_EQ(2U, page_added_count());
373 EXPECT_EQ(1U, model_removed_count()); 373 EXPECT_EQ(1U, model_removed_count());
374 // the same page should be simply overridden. 374 // the same page should be simply overridden.
375 GetAllPages(); 375 GetAllPages();
376 EXPECT_EQ(1U, all_pages().size()); 376 ASSERT_EQ(1U, all_pages().size());
377 EXPECT_EQ(kTestPageUrl, all_pages()[0].url); 377 EXPECT_EQ(kTestPageUrl, all_pages()[0].url);
378 EXPECT_NE(first_offline_id, all_pages()[0].offline_id); 378 EXPECT_NE(first_offline_id, all_pages()[0].offline_id);
379 } 379 }
380 380
381 // Triggers two snapshot captures for two different page loads for the same URL, 381 // Triggers two snapshot captures for two different page loads for the same URL,
382 // where the 2nd one fails. Should end up with no offline pages (privacy driven 382 // where the 2nd one fails. Should end up with no offline pages (privacy driven
383 // decision). 383 // decision).
384 TEST_F(RecentTabHelperTest, TwoCapturesDifferentPageLoadsSameUrlSecondFails) { 384 TEST_F(RecentTabHelperTest, TwoCapturesDifferentPageLoadsSameUrlSecondFails) {
385 NavigateAndCommit(kTestPageUrl); 385 NavigateAndCommit(kTestPageUrl);
386 // Triggers snapshot after a time delay. 386 // Triggers snapshot after a time delay.
387 recent_tab_helper()->DocumentAvailableInMainFrame(); 387 recent_tab_helper()->DocumentAvailableInMainFrame();
388 RunUntilIdle(); 388 RunUntilIdle();
389 EXPECT_TRUE(model()->is_loaded()); 389 EXPECT_TRUE(model()->is_loaded());
390 EXPECT_EQ(0U, page_added_count()); 390 EXPECT_EQ(0U, page_added_count());
391 // Move the snapshot controller's time forward so it gets past timeouts. 391 // Move the snapshot controller's time forward so it gets past timeouts.
392 FastForwardSnapshotController(); 392 FastForwardSnapshotController();
393 RunUntilIdle(); 393 RunUntilIdle();
394 EXPECT_EQ(1U, page_added_count()); 394 EXPECT_EQ(1U, page_added_count());
395 EXPECT_EQ(0U, model_removed_count()); 395 EXPECT_EQ(0U, model_removed_count());
396 GetAllPages(); 396 GetAllPages();
397 EXPECT_EQ(1U, all_pages().size()); 397 ASSERT_EQ(1U, all_pages().size());
398 EXPECT_EQ(kTestPageUrl, all_pages()[0].url); 398 EXPECT_EQ(kTestPageUrl, all_pages()[0].url);
399 399
400 // Sets a new delegate that will make the second snapshot fail. 400 // Sets a new delegate that will make the second snapshot fail.
401 TestDelegate* failing_delegate = 401 TestDelegate* failing_delegate =
402 new TestDelegate(this, task_runner(), kTabId, true); 402 new TestDelegate(this, task_runner(), kTabId, true);
403 failing_delegate->set_archive_size(-1); 403 failing_delegate->set_archive_size(-1);
404 failing_delegate->set_archive_result( 404 failing_delegate->set_archive_result(
405 offline_pages::OfflinePageArchiver::ArchiverResult:: 405 offline_pages::OfflinePageArchiver::ArchiverResult::
406 ERROR_ARCHIVE_CREATION_FAILED); 406 ERROR_ARCHIVE_CREATION_FAILED);
407 recent_tab_helper()->SetDelegate( 407 recent_tab_helper()->SetDelegate(
408 std::unique_ptr<TestDelegate>(failing_delegate)); 408 std::unique_ptr<TestDelegate>(failing_delegate));
409 409
410 NavigateAndCommit(kTestPageUrl); 410 NavigateAndCommit(kTestPageUrl);
411 // Triggers snapshot after a time delay. 411 // Triggers snapshot after a time delay.
412 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame(); 412 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame();
413 // Move the snapshot controller's time forward so it gets past timeouts. 413 // Move the snapshot controller's time forward so it gets past timeouts.
414 FastForwardSnapshotController(); 414 FastForwardSnapshotController();
415 RunUntilIdle(); 415 RunUntilIdle();
416 EXPECT_EQ(1U, page_added_count()); 416 EXPECT_EQ(1U, page_added_count());
417 EXPECT_EQ(1U, model_removed_count()); 417 EXPECT_EQ(1U, model_removed_count());
418 // the same page should be simply overridden. 418 // the same page should be simply overridden.
419 GetAllPages(); 419 GetAllPages();
420 EXPECT_EQ(0U, all_pages().size()); 420 ASSERT_EQ(0U, all_pages().size());
421 } 421 }
422 422
423 // Triggers two snapshot captures for two different page loads and URLs. Should 423 // Triggers two snapshot captures for two different page loads and URLs. Should
424 // end up with one offline page. 424 // end up with one offline page.
425 TEST_F(RecentTabHelperTest, TwoCapturesDifferentPageLoadsAndUrls) { 425 TEST_F(RecentTabHelperTest, TwoCapturesDifferentPageLoadsAndUrls) {
426 NavigateAndCommit(kTestPageUrl); 426 NavigateAndCommit(kTestPageUrl);
427 // Triggers snapshot after a time delay. 427 // Triggers snapshot after a time delay.
428 recent_tab_helper()->DocumentAvailableInMainFrame(); 428 recent_tab_helper()->DocumentAvailableInMainFrame();
429 RunUntilIdle(); 429 RunUntilIdle();
430 EXPECT_TRUE(model()->is_loaded()); 430 EXPECT_TRUE(model()->is_loaded());
431 EXPECT_EQ(0U, page_added_count()); 431 EXPECT_EQ(0U, page_added_count());
432 // Move the snapshot controller's time forward so it gets past timeouts. 432 // Move the snapshot controller's time forward so it gets past timeouts.
433 FastForwardSnapshotController(); 433 FastForwardSnapshotController();
434 RunUntilIdle(); 434 RunUntilIdle();
435 EXPECT_EQ(1U, page_added_count()); 435 EXPECT_EQ(1U, page_added_count());
436 EXPECT_EQ(0U, model_removed_count()); 436 EXPECT_EQ(0U, model_removed_count());
437 GetAllPages(); 437 GetAllPages();
438 EXPECT_EQ(1U, all_pages().size()); 438 ASSERT_EQ(1U, all_pages().size());
439 EXPECT_EQ(kTestPageUrl, all_pages()[0].url); 439 EXPECT_EQ(kTestPageUrl, all_pages()[0].url);
440 440
441 NavigateAndCommit(kTestPageUrlOther); 441 NavigateAndCommit(kTestPageUrlOther);
442 // Triggers snapshot after a time delay. 442 // Triggers snapshot after a time delay.
443 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame(); 443 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame();
444 // Move the snapshot controller's time forward so it gets past timeouts. 444 // Move the snapshot controller's time forward so it gets past timeouts.
445 FastForwardSnapshotController(); 445 FastForwardSnapshotController();
446 RunUntilIdle(); 446 RunUntilIdle();
447 EXPECT_EQ(2U, page_added_count()); 447 EXPECT_EQ(2U, page_added_count());
448 EXPECT_EQ(1U, model_removed_count()); 448 EXPECT_EQ(1U, model_removed_count());
449 // the same page should be simply overridden. 449 // the same page should be simply overridden.
450 GetAllPages(); 450 GetAllPages();
451 EXPECT_EQ(1U, all_pages().size()); 451 ASSERT_EQ(1U, all_pages().size());
452 EXPECT_EQ(kTestPageUrlOther, all_pages()[0].url); 452 EXPECT_EQ(kTestPageUrlOther, all_pages()[0].url);
453 } 453 }
454 454
455 // Triggers two snapshot captures via the download after a page was loaded page 455 // Triggers two snapshot captures via the download after a page was loaded page
456 // and saved twice by last_n. Should end up with three offline pages: two from 456 // and saved twice by last_n. Should end up with three offline pages: two from
457 // downloads (which shouldn't replace each other) and one from last_n. 457 // downloads (which shouldn't replace each other) and one from last_n.
458 TEST_F(RecentTabHelperTest, TwoDownloadCapturesInARowSamePage) { 458 TEST_F(RecentTabHelperTest, TwoDownloadCapturesInARowSamePage) {
459 NavigateAndCommit(kTestPageUrl); 459 NavigateAndCommit(kTestPageUrl);
460 // Executes a regular load with snapshots taken by last_n. 460 // Executes a regular load with snapshots taken by last_n.
461 recent_tab_helper()->DocumentAvailableInMainFrame(); 461 recent_tab_helper()->DocumentAvailableInMainFrame();
462 RunUntilIdle(); 462 RunUntilIdle();
463 EXPECT_TRUE(model()->is_loaded());
fgorski 2016/12/14 16:05:29 this is probably not needed, and Justin is working
carlosk 2016/12/14 17:52:22 Done.
463 FastForwardSnapshotController(); 464 FastForwardSnapshotController();
464 RunUntilIdle(); 465 RunUntilIdle();
465 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame(); 466 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame();
466 FastForwardSnapshotController(); 467 FastForwardSnapshotController();
467 RunUntilIdle(); 468 RunUntilIdle();
468 // Checks that two last_n snapshots were created but only one was kept. 469 // Checks that two last_n snapshots were created but only one was kept.
469 EXPECT_EQ(2U, page_added_count()); 470 EXPECT_EQ(2U, page_added_count());
470 EXPECT_EQ(1U, model_removed_count()); 471 EXPECT_EQ(1U, model_removed_count());
471 GetAllPages(); 472 GetAllPages();
472 EXPECT_EQ(1U, all_pages().size()); 473 ASSERT_EQ(1U, all_pages().size());
473 EXPECT_EQ(kTestPageUrl, all_pages()[0].url); 474 EXPECT_EQ(kTestPageUrl, all_pages()[0].url);
474 int64_t first_offline_id = all_pages()[0].offline_id; 475 int64_t first_offline_id = all_pages()[0].offline_id;
475 476
476 // Request the 1st offline download. 477 // Request the 1st offline download.
477 const int64_t second_offline_id = first_offline_id + 1; 478 const int64_t second_offline_id = first_offline_id + 1;
478 recent_tab_helper()->ObserveAndDownloadCurrentPage( 479 recent_tab_helper()->ObserveAndDownloadCurrentPage(
479 ClientId("download", "id2"), second_offline_id); 480 ClientId("download", "id2"), second_offline_id);
480 RunUntilIdle(); 481 RunUntilIdle();
481 GetAllPages(); 482 GetAllPages();
482 // Checks that both the previous last_n and download snapshots are present. 483 // Checks that both the previous last_n and download snapshots are present.
(...skipping 25 matching lines...) Expand all
508 509
509 // Simulates an error (disconnection) during the load of a page. Should end up 510 // Simulates an error (disconnection) during the load of a page. Should end up
510 // with no offline pages. 511 // with no offline pages.
511 TEST_F(RecentTabHelperTest, NoCaptureOnErrorPage) { 512 TEST_F(RecentTabHelperTest, NoCaptureOnErrorPage) {
512 FailLoad(kTestPageUrl); 513 FailLoad(kTestPageUrl);
513 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame(); 514 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame();
514 FastForwardSnapshotController(); 515 FastForwardSnapshotController();
515 RunUntilIdle(); 516 RunUntilIdle();
516 EXPECT_TRUE(model()->is_loaded()); 517 EXPECT_TRUE(model()->is_loaded());
517 GetAllPages(); 518 GetAllPages();
518 EXPECT_EQ(0U, all_pages().size()); 519 ASSERT_EQ(0U, all_pages().size());
519 } 520 }
520 521
521 // Checks that no snapshots are created if the Offline Page Cache feature is 522 // Checks that no snapshots are created if the Offline Page Cache feature is
522 // disabled. 523 // disabled.
523 TEST_F(RecentTabHelperTest, FeatureNotEnabled) { 524 TEST_F(RecentTabHelperTest, FeatureNotEnabled) {
524 base::test::ScopedFeatureList scoped_feature_list; 525 base::test::ScopedFeatureList scoped_feature_list;
525 scoped_feature_list.Init(); 526 scoped_feature_list.Init();
526 NavigateAndCommit(kTestPageUrl); 527 NavigateAndCommit(kTestPageUrl);
527 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame(); 528 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame();
528 FastForwardSnapshotController(); 529 FastForwardSnapshotController();
529 RunUntilIdle(); 530 RunUntilIdle();
530 EXPECT_TRUE(model()->is_loaded()); 531 EXPECT_TRUE(model()->is_loaded());
531 GetAllPages(); 532 GetAllPages();
532 // No page should be captured. 533 // No page should be captured.
533 EXPECT_EQ(0U, all_pages().size()); 534 ASSERT_EQ(0U, all_pages().size());
534 } 535 }
535 536
536 // Simulates a download request to offline the current page. Should end up with 537 // Simulates a download request to offline the current page. Should end up with
537 // one offline pages. 538 // one offline pages.
538 TEST_F(RecentTabHelperTest, DISABLED_DownloadRequest) { 539 TEST_F(RecentTabHelperTest, DownloadRequest) {
539 NavigateAndCommit(kTestPageUrl); 540 NavigateAndCommit(kTestPageUrl);
540 recent_tab_helper()->ObserveAndDownloadCurrentPage( 541 recent_tab_helper()->ObserveAndDownloadCurrentPage(
541 ClientId("download", "id1"), 153L); 542 ClientId("download", "id1"), 153L);
542 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame(); 543 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame();
544 FastForwardSnapshotController();
543 RunUntilIdle(); 545 RunUntilIdle();
544 EXPECT_TRUE(model()->is_loaded()); 546 EXPECT_TRUE(model()->is_loaded());
545 GetAllPages(); 547 GetAllPages();
546 EXPECT_EQ(1U, all_pages().size()); 548 ASSERT_EQ(1U, all_pages().size());
547 const OfflinePageItem& page = all_pages()[0]; 549 const OfflinePageItem& page = all_pages()[0];
548 EXPECT_EQ(kTestPageUrl, page.url); 550 EXPECT_EQ(kTestPageUrl, page.url);
549 EXPECT_EQ("download", page.client_id.name_space); 551 EXPECT_EQ("download", page.client_id.name_space);
550 EXPECT_EQ("id1", page.client_id.id); 552 EXPECT_EQ("id1", page.client_id.id);
551 EXPECT_EQ(153L, page.offline_id); 553 EXPECT_EQ(153L, page.offline_id);
552 } 554 }
553 555
554 } // namespace offline_pages 556 } // namespace offline_pages
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698