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

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

Issue 2655673005: RecentTabHelper won't accept overlapping requests from Downloads anymore. (Closed)
Patch Set: Minor changes from addressing dewittj@ comments. Created 3 years, 10 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
« no previous file with comments | « chrome/browser/android/offline_pages/recent_tab_helper.cc ('k') | 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/strings/string_number_conversions.h"
10 #include "base/test/scoped_feature_list.h" 11 #include "base/test/scoped_feature_list.h"
11 #include "base/test/test_mock_time_task_runner.h" 12 #include "base/test/test_mock_time_task_runner.h"
12 #include "base/threading/thread_task_runner_handle.h" 13 #include "base/threading/thread_task_runner_handle.h"
13 #include "chrome/browser/android/offline_pages/offline_page_model_factory.h" 14 #include "chrome/browser/android/offline_pages/offline_page_model_factory.h"
14 #include "chrome/browser/android/offline_pages/request_coordinator_factory.h" 15 #include "chrome/browser/android/offline_pages/request_coordinator_factory.h"
15 #include "chrome/browser/android/offline_pages/test_offline_page_model_builder.h " 16 #include "chrome/browser/android/offline_pages/test_offline_page_model_builder.h "
16 #include "chrome/browser/android/offline_pages/test_request_coordinator_builder. h" 17 #include "chrome/browser/android/offline_pages/test_request_coordinator_builder. h"
17 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 18 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
18 #include "components/offline_pages/core/client_namespace_constants.h" 19 #include "components/offline_pages/core/client_namespace_constants.h"
19 #include "components/offline_pages/core/offline_page_feature.h" 20 #include "components/offline_pages/core/offline_page_feature.h"
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 // Moves forward the snapshot controller's task runner. 91 // Moves forward the snapshot controller's task runner.
91 void FastForwardSnapshotController(); 92 void FastForwardSnapshotController();
92 93
93 // Navigates to the URL and commit as if it has been typed in the address bar. 94 // Navigates to the URL and commit as if it has been typed in the address bar.
94 // Note: we need this to simulate navigations to the same URL that more like a 95 // Note: we need this to simulate navigations to the same URL that more like a
95 // reload and not same page. NavigateAndCommit simulates a click on a link 96 // reload and not same page. NavigateAndCommit simulates a click on a link
96 // and when reusing the same URL that will be considered a same page 97 // and when reusing the same URL that will be considered a same page
97 // navigation. 98 // navigation.
98 void NavigateAndCommitTyped(const GURL& url); 99 void NavigateAndCommitTyped(const GURL& url);
99 100
101 ClientId NewDownloadClientId();
102
100 RecentTabHelper* recent_tab_helper() const { return recent_tab_helper_; } 103 RecentTabHelper* recent_tab_helper() const { return recent_tab_helper_; }
101 104
102 OfflinePageModel* model() const { return model_; } 105 OfflinePageModel* model() const { return model_; }
103 106
104 // Returns a OfflinePageItem pointer from |all_pages| that matches the 107 // Returns a OfflinePageItem pointer from |all_pages| that matches the
105 // provided |offline_id|. If a match is not found returns nullptr. 108 // provided |offline_id|. If a match is not found returns nullptr.
106 const OfflinePageItem* FindPageForOfflineId(int64_t offline_id) { 109 const OfflinePageItem* FindPageForOfflineId(int64_t offline_id) {
107 for (const OfflinePageItem& page : GetAllPages()) { 110 for (const OfflinePageItem& page : GetAllPages()) {
108 if (page.offline_id == offline_id) 111 if (page.offline_id == offline_id)
109 return &page; 112 return &page;
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 } 250 }
248 251
249 void RecentTabHelperTest::NavigateAndCommitTyped(const GURL& url) { 252 void RecentTabHelperTest::NavigateAndCommitTyped(const GURL& url) {
250 controller().LoadURL(url, content::Referrer(), ui::PAGE_TRANSITION_TYPED, 253 controller().LoadURL(url, content::Referrer(), ui::PAGE_TRANSITION_TYPED,
251 std::string()); 254 std::string());
252 content::WebContentsTester* web_contents_tester = 255 content::WebContentsTester* web_contents_tester =
253 content::WebContentsTester::For(web_contents()); 256 content::WebContentsTester::For(web_contents());
254 web_contents_tester->CommitPendingNavigation(); 257 web_contents_tester->CommitPendingNavigation();
255 } 258 }
256 259
260 ClientId RecentTabHelperTest::NewDownloadClientId() {
261 static int counter = 0;
262 return ClientId(kDownloadNamespace,
263 std::string("id") + base::IntToString(++counter));
264 }
265
257 // Checks the test setup. 266 // Checks the test setup.
258 TEST_F(RecentTabHelperTest, RecentTabHelperInstanceExists) { 267 TEST_F(RecentTabHelperTest, RecentTabHelperInstanceExists) {
259 base::test::ScopedFeatureList scoped_feature_list; 268 base::test::ScopedFeatureList scoped_feature_list;
260 scoped_feature_list.Init(); 269 scoped_feature_list.Init();
261 EXPECT_NE(nullptr, recent_tab_helper()); 270 EXPECT_NE(nullptr, recent_tab_helper());
262 } 271 }
263 272
264 // Fully loads a page then simulates the tab being hidden. Verifies that a 273 // Fully loads a page then simulates the tab being hidden. Verifies that a
265 // snapshot is created only when the latter happens. 274 // snapshot is created only when the latter happens.
266 TEST_F(RecentTabHelperTest, LastNCaptureAfterLoad) { 275 TEST_F(RecentTabHelperTest, LastNCaptureAfterLoad) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 // ignored from both last_n and downloads. 317 // ignored from both last_n and downloads.
309 TEST_F(RecentTabHelperTest, NoTabIdNoCapture) { 318 TEST_F(RecentTabHelperTest, NoTabIdNoCapture) {
310 // Create delegate that returns 'false' as TabId retrieval result. 319 // Create delegate that returns 'false' as TabId retrieval result.
311 recent_tab_helper()->SetDelegate(base::MakeUnique<TestDelegate>( 320 recent_tab_helper()->SetDelegate(base::MakeUnique<TestDelegate>(
312 this, task_runner(), kTabId, false)); 321 this, task_runner(), kTabId, false));
313 322
314 NavigateAndCommit(kTestPageUrl); 323 NavigateAndCommit(kTestPageUrl);
315 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame(); 324 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame();
316 FastForwardSnapshotController(); 325 FastForwardSnapshotController();
317 recent_tab_helper()->WasHidden(); 326 recent_tab_helper()->WasHidden();
318 recent_tab_helper()->ObserveAndDownloadCurrentPage( 327 recent_tab_helper()->ObserveAndDownloadCurrentPage(NewDownloadClientId(),
319 ClientId("download", "id2"), 123L); 328 123L);
320 RunUntilIdle(); 329 RunUntilIdle();
321 EXPECT_TRUE(model()->is_loaded()); 330 EXPECT_TRUE(model()->is_loaded());
322 // No page should be captured. 331 // No page should be captured.
323 EXPECT_EQ(0U, page_added_count()); 332 EXPECT_EQ(0U, page_added_count());
324 ASSERT_EQ(0U, GetAllPages().size()); 333 ASSERT_EQ(0U, GetAllPages().size());
325 } 334 }
326 335
327 // Triggers two last_n snapshot captures during a single page load. Should end 336 // Triggers two last_n snapshot captures during a single page load. Should end
328 // up with one snapshot, the 1st being replaced by the 2nd. 337 // up with one snapshot, the 1st being replaced by the 2nd.
329 TEST_F(RecentTabHelperTest, TwoCapturesSamePageLoad) { 338 TEST_F(RecentTabHelperTest, TwoCapturesSamePageLoad) {
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 recent_tab_helper()->WasHidden(); 534 recent_tab_helper()->WasHidden();
526 RunUntilIdle(); 535 RunUntilIdle();
527 EXPECT_EQ(2U, page_added_count()); 536 EXPECT_EQ(2U, page_added_count());
528 EXPECT_EQ(1U, model_removed_count()); 537 EXPECT_EQ(1U, model_removed_count());
529 ASSERT_EQ(1U, GetAllPages().size()); 538 ASSERT_EQ(1U, GetAllPages().size());
530 EXPECT_EQ(kTestPageUrl, GetAllPages()[0].url); 539 EXPECT_EQ(kTestPageUrl, GetAllPages()[0].url);
531 int64_t first_offline_id = GetAllPages()[0].offline_id; 540 int64_t first_offline_id = GetAllPages()[0].offline_id;
532 541
533 // First snapshot request by downloads. Two offline pages are expected. 542 // First snapshot request by downloads. Two offline pages are expected.
534 const int64_t second_offline_id = first_offline_id + 1; 543 const int64_t second_offline_id = first_offline_id + 1;
535 const ClientId second_client_id("download", "id2"); 544 const ClientId second_client_id = NewDownloadClientId();
536 recent_tab_helper()->ObserveAndDownloadCurrentPage(second_client_id, 545 recent_tab_helper()->ObserveAndDownloadCurrentPage(second_client_id,
537 second_offline_id); 546 second_offline_id);
538 RunUntilIdle(); 547 RunUntilIdle();
539 EXPECT_EQ(3U, page_added_count()); 548 EXPECT_EQ(3U, page_added_count());
540 EXPECT_EQ(1U, model_removed_count()); 549 EXPECT_EQ(1U, model_removed_count());
541 ASSERT_EQ(2U, GetAllPages().size()); 550 ASSERT_EQ(2U, GetAllPages().size());
542 EXPECT_NE(nullptr, FindPageForOfflineId(first_offline_id)); 551 EXPECT_NE(nullptr, FindPageForOfflineId(first_offline_id));
543 const OfflinePageItem* second_page = FindPageForOfflineId(second_offline_id); 552 const OfflinePageItem* second_page = FindPageForOfflineId(second_offline_id);
544 ASSERT_NE(nullptr, second_page); 553 ASSERT_NE(nullptr, second_page);
545 EXPECT_EQ(kTestPageUrl, second_page->url); 554 EXPECT_EQ(kTestPageUrl, second_page->url);
546 EXPECT_EQ(second_client_id, second_page->client_id); 555 EXPECT_EQ(second_client_id, second_page->client_id);
547 556
548 // Second snapshot request by downloads. Three offline pages are expected. 557 // Second snapshot request by downloads. Three offline pages are expected.
549 const int64_t third_offline_id = first_offline_id + 2; 558 const int64_t third_offline_id = first_offline_id + 2;
550 const ClientId third_client_id("download", "id2"); 559 const ClientId third_client_id = NewDownloadClientId();
551 recent_tab_helper()->ObserveAndDownloadCurrentPage(third_client_id, 560 recent_tab_helper()->ObserveAndDownloadCurrentPage(third_client_id,
552 third_offline_id); 561 third_offline_id);
553 RunUntilIdle(); 562 RunUntilIdle();
554 EXPECT_EQ(4U, page_added_count()); 563 EXPECT_EQ(4U, page_added_count());
555 EXPECT_EQ(1U, model_removed_count()); 564 EXPECT_EQ(1U, model_removed_count());
556 ASSERT_EQ(3U, GetAllPages().size()); 565 ASSERT_EQ(3U, GetAllPages().size());
557 EXPECT_NE(nullptr, FindPageForOfflineId(first_offline_id)); 566 EXPECT_NE(nullptr, FindPageForOfflineId(first_offline_id));
558 EXPECT_NE(nullptr, FindPageForOfflineId(second_offline_id)); 567 EXPECT_NE(nullptr, FindPageForOfflineId(second_offline_id));
559 const OfflinePageItem* third_page = FindPageForOfflineId(third_offline_id); 568 const OfflinePageItem* third_page = FindPageForOfflineId(third_offline_id);
560 ASSERT_NE(nullptr, third_page); 569 ASSERT_NE(nullptr, third_page);
561 EXPECT_EQ(kTestPageUrl, third_page->url); 570 EXPECT_EQ(kTestPageUrl, third_page->url);
562 EXPECT_EQ(third_client_id, third_page->client_id); 571 EXPECT_EQ(third_client_id, third_page->client_id);
563 } 572 }
564 573
565 // Simulates an error (disconnection) during the load of a page. Should end up 574 // Simulates an error (disconnection) during the load of a page. Should end up
566 // with no offline pages for any requester. 575 // with no offline pages for any requester.
567 TEST_F(RecentTabHelperTest, NoCaptureOnErrorPage) { 576 TEST_F(RecentTabHelperTest, NoCaptureOnErrorPage) {
568 FailLoad(kTestPageUrl); 577 FailLoad(kTestPageUrl);
569 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame(); 578 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame();
570 FastForwardSnapshotController(); 579 FastForwardSnapshotController();
571 recent_tab_helper()->WasHidden(); 580 recent_tab_helper()->WasHidden();
572 recent_tab_helper()->ObserveAndDownloadCurrentPage( 581 recent_tab_helper()->ObserveAndDownloadCurrentPage(NewDownloadClientId(),
573 ClientId("download", "id1"), 123L); 582 123L);
574 RunUntilIdle(); 583 RunUntilIdle();
575 EXPECT_TRUE(model()->is_loaded()); 584 EXPECT_TRUE(model()->is_loaded());
576 ASSERT_EQ(0U, GetAllPages().size()); 585 ASSERT_EQ(0U, GetAllPages().size());
577 } 586 }
578 587
579 // Checks that last_n snapshots are not created if the feature is disabled. 588 // Checks that last_n snapshots are not created if the feature is disabled.
580 // Download requests should still work. 589 // Download requests should still work.
581 TEST_F(RecentTabHelperTest, LastNFeatureNotEnabled) { 590 TEST_F(RecentTabHelperTest, LastNFeatureNotEnabled) {
582 base::test::ScopedFeatureList scoped_feature_list; 591 base::test::ScopedFeatureList scoped_feature_list;
583 scoped_feature_list.Init(); 592 scoped_feature_list.Init();
584 NavigateAndCommit(kTestPageUrl); 593 NavigateAndCommit(kTestPageUrl);
585 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame(); 594 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame();
586 FastForwardSnapshotController(); 595 FastForwardSnapshotController();
587 recent_tab_helper()->WasHidden(); 596 recent_tab_helper()->WasHidden();
588 RunUntilIdle(); 597 RunUntilIdle();
589 EXPECT_TRUE(model()->is_loaded()); 598 EXPECT_TRUE(model()->is_loaded());
590 // No page should be captured. 599 // No page should be captured.
591 ASSERT_EQ(0U, GetAllPages().size()); 600 ASSERT_EQ(0U, GetAllPages().size());
592 601
593 recent_tab_helper()->ObserveAndDownloadCurrentPage( 602 recent_tab_helper()->ObserveAndDownloadCurrentPage(NewDownloadClientId(),
594 ClientId("download", "id1"), 123L); 603 123L);
595 RunUntilIdle(); 604 RunUntilIdle();
596 // No page should be captured. 605 // No page should be captured.
597 ASSERT_EQ(1U, GetAllPages().size()); 606 ASSERT_EQ(1U, GetAllPages().size());
598 } 607 }
599 608
600 // Simulates a download request to offline the current page made early during 609 // Simulates a download request to offline the current page made early during
601 // loading. Should execute two captures but only the final one is kept. 610 // loading. Should execute two captures but only the final one is kept.
602 TEST_F(RecentTabHelperTest, DownloadRequestEarlyInLoad) { 611 TEST_F(RecentTabHelperTest, DownloadRequestEarlyInLoad) {
603 // Commit the navigation and request the snapshot from downloads. No captures 612 // Commit the navigation and request the snapshot from downloads. No captures
604 // so far. 613 // so far.
605 NavigateAndCommit(kTestPageUrl); 614 NavigateAndCommit(kTestPageUrl);
606 const ClientId client_id("download", "id1"); 615 const ClientId client_id = NewDownloadClientId();
607 recent_tab_helper()->ObserveAndDownloadCurrentPage(client_id, 153L); 616 recent_tab_helper()->ObserveAndDownloadCurrentPage(client_id, 153L);
608 FastForwardSnapshotController(); 617 FastForwardSnapshotController();
609 RunUntilIdle(); 618 RunUntilIdle();
610 EXPECT_TRUE(model()->is_loaded()); 619 EXPECT_TRUE(model()->is_loaded());
611 ASSERT_EQ(0U, GetAllPages().size()); 620 ASSERT_EQ(0U, GetAllPages().size());
612 621
613 // Minimally load the page. First capture should occur. 622 // Minimally load the page. First capture should occur.
614 recent_tab_helper()->DocumentAvailableInMainFrame(); 623 recent_tab_helper()->DocumentAvailableInMainFrame();
615 FastForwardSnapshotController(); 624 FastForwardSnapshotController();
616 RunUntilIdle(); 625 RunUntilIdle();
(...skipping 20 matching lines...) Expand all
637 // is minimally loaded. Should execute two captures but only the final one is 646 // is minimally loaded. Should execute two captures but only the final one is
638 // kept. 647 // kept.
639 TEST_F(RecentTabHelperTest, DownloadRequestLaterInLoad) { 648 TEST_F(RecentTabHelperTest, DownloadRequestLaterInLoad) {
640 NavigateAndCommit(kTestPageUrl); 649 NavigateAndCommit(kTestPageUrl);
641 recent_tab_helper()->DocumentAvailableInMainFrame(); 650 recent_tab_helper()->DocumentAvailableInMainFrame();
642 FastForwardSnapshotController(); 651 FastForwardSnapshotController();
643 RunUntilIdle(); 652 RunUntilIdle();
644 EXPECT_TRUE(model()->is_loaded()); 653 EXPECT_TRUE(model()->is_loaded());
645 ASSERT_EQ(0U, GetAllPages().size()); 654 ASSERT_EQ(0U, GetAllPages().size());
646 655
647 const ClientId client_id("download", "id1"); 656 const ClientId client_id = NewDownloadClientId();
648 recent_tab_helper()->ObserveAndDownloadCurrentPage(client_id, 153L); 657 recent_tab_helper()->ObserveAndDownloadCurrentPage(client_id, 153L);
649 RunUntilIdle(); 658 RunUntilIdle();
650 ASSERT_EQ(1U, GetAllPages().size()); 659 ASSERT_EQ(1U, GetAllPages().size());
651 const OfflinePageItem& page = GetAllPages()[0]; 660 const OfflinePageItem& page = GetAllPages()[0];
652 EXPECT_EQ(kTestPageUrl, page.url); 661 EXPECT_EQ(kTestPageUrl, page.url);
653 EXPECT_EQ(client_id, page.client_id); 662 EXPECT_EQ(client_id, page.client_id);
654 EXPECT_EQ(153L, page.offline_id); 663 EXPECT_EQ(153L, page.offline_id);
655 664
656 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame(); 665 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame();
657 FastForwardSnapshotController(); 666 FastForwardSnapshotController();
658 RunUntilIdle(); 667 RunUntilIdle();
659 EXPECT_EQ(2U, page_added_count()); 668 EXPECT_EQ(2U, page_added_count());
660 EXPECT_EQ(1U, model_removed_count()); 669 EXPECT_EQ(1U, model_removed_count());
661 ASSERT_EQ(1U, GetAllPages().size()); 670 ASSERT_EQ(1U, GetAllPages().size());
662 } 671 }
663 672
664 // Simulates a download request to offline the current page made after loading 673 // Simulates a download request to offline the current page made after loading
665 // is completed. Should end up with one offline pages. 674 // is completed. Should end up with one offline pages.
666 TEST_F(RecentTabHelperTest, DownloadRequestAfterFullyLoad) { 675 TEST_F(RecentTabHelperTest, DownloadRequestAfterFullyLoad) {
667 NavigateAndCommit(kTestPageUrl); 676 NavigateAndCommit(kTestPageUrl);
668 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame(); 677 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame();
669 FastForwardSnapshotController(); 678 FastForwardSnapshotController();
670 RunUntilIdle(); 679 RunUntilIdle();
671 EXPECT_TRUE(model()->is_loaded()); 680 EXPECT_TRUE(model()->is_loaded());
672 ASSERT_EQ(0U, GetAllPages().size()); 681 ASSERT_EQ(0U, GetAllPages().size());
673 682
674 const ClientId client_id("download", "id1"); 683 const ClientId client_id = NewDownloadClientId();
675 recent_tab_helper()->ObserveAndDownloadCurrentPage(client_id, 153L); 684 recent_tab_helper()->ObserveAndDownloadCurrentPage(client_id, 153L);
676 RunUntilIdle(); 685 RunUntilIdle();
677 ASSERT_EQ(1U, GetAllPages().size()); 686 ASSERT_EQ(1U, GetAllPages().size());
678 const OfflinePageItem& page = GetAllPages()[0]; 687 const OfflinePageItem& page = GetAllPages()[0];
679 EXPECT_EQ(kTestPageUrl, page.url); 688 EXPECT_EQ(kTestPageUrl, page.url);
680 EXPECT_EQ(client_id, page.client_id); 689 EXPECT_EQ(client_id, page.client_id);
681 EXPECT_EQ(153L, page.offline_id); 690 EXPECT_EQ(153L, page.offline_id);
682 } 691 }
683 692
684 // Simulates requests coming from last_n and downloads at the same time for a 693 // Simulates requests coming from last_n and downloads at the same time for a
685 // fully loaded page. 694 // fully loaded page.
686 TEST_F(RecentTabHelperTest, SimultaneousCapturesFromLastNAndDownloads) { 695 TEST_F(RecentTabHelperTest, SimultaneousCapturesFromLastNAndDownloads) {
687 NavigateAndCommit(kTestPageUrl); 696 NavigateAndCommit(kTestPageUrl);
688 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame(); 697 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame();
689 FastForwardSnapshotController(); 698 FastForwardSnapshotController();
690 recent_tab_helper()->WasHidden(); 699 recent_tab_helper()->WasHidden();
691 const int64_t download_offline_id = 153L; 700 const int64_t download_offline_id = 153L;
692 const ClientId download_client_id("download", "id1"); 701 const ClientId download_client_id = NewDownloadClientId();
693 recent_tab_helper()->ObserveAndDownloadCurrentPage(download_client_id, 702 recent_tab_helper()->ObserveAndDownloadCurrentPage(download_client_id,
694 download_offline_id); 703 download_offline_id);
695 RunUntilIdle(); 704 RunUntilIdle();
696 ASSERT_EQ(2U, GetAllPages().size()); 705 ASSERT_EQ(2U, GetAllPages().size());
697 706
698 const OfflinePageItem* downloads_page = 707 const OfflinePageItem* downloads_page =
699 FindPageForOfflineId(download_offline_id); 708 FindPageForOfflineId(download_offline_id);
700 ASSERT_TRUE(downloads_page); 709 ASSERT_TRUE(downloads_page);
701 EXPECT_EQ(kTestPageUrl, downloads_page->url); 710 EXPECT_EQ(kTestPageUrl, downloads_page->url);
702 EXPECT_EQ(download_client_id, downloads_page->client_id); 711 EXPECT_EQ(download_client_id, downloads_page->client_id);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
735 EXPECT_EQ(1U, model_removed_count()); 744 EXPECT_EQ(1U, model_removed_count());
736 ASSERT_EQ(1U, GetAllPages().size()); 745 ASSERT_EQ(1U, GetAllPages().size());
737 746
738 recent_tab_helper()->WasHidden(); 747 recent_tab_helper()->WasHidden();
739 RunUntilIdle(); 748 RunUntilIdle();
740 EXPECT_EQ(2U, page_added_count()); 749 EXPECT_EQ(2U, page_added_count());
741 EXPECT_EQ(1U, model_removed_count()); 750 EXPECT_EQ(1U, model_removed_count());
742 ASSERT_EQ(1U, GetAllPages().size()); 751 ASSERT_EQ(1U, GetAllPages().size());
743 } 752 }
744 753
754 // Simulates multiple download requests and verifies that overlapping requests
755 // are ignored.
756 TEST_F(RecentTabHelperTest, OverlappingDownloadRequestsAreIgnored) {
757 // Navigates and commits then make two download snapshot requests.
758 NavigateAndCommit(kTestPageUrl);
759 const ClientId client_id_1 = NewDownloadClientId();
760 const int64_t offline_id_1 = 153L;
761 recent_tab_helper()->ObserveAndDownloadCurrentPage(client_id_1, offline_id_1);
762 recent_tab_helper()->ObserveAndDownloadCurrentPage(NewDownloadClientId(),
763 351L);
764
765 // Finish loading the page. Only the first request should be executed.
766 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame();
767 FastForwardSnapshotController();
768 RunUntilIdle();
769 EXPECT_EQ(1U, page_added_count());
770 EXPECT_EQ(0U, model_removed_count());
771 ASSERT_EQ(1U, GetAllPages().size());
772 const OfflinePageItem& fist_page = GetAllPages()[0];
773 EXPECT_EQ(client_id_1, fist_page.client_id);
774 EXPECT_EQ(offline_id_1, fist_page.offline_id);
775
776 // Make two additional download snapshot requests. Again only the first should
777 // generate a snapshot.
778 const ClientId client_id_3 = NewDownloadClientId();
779 const int64_t offline_id_3 = 789L;
780 recent_tab_helper()->ObserveAndDownloadCurrentPage(client_id_3, offline_id_3);
781 recent_tab_helper()->ObserveAndDownloadCurrentPage(NewDownloadClientId(),
782 987L);
783 RunUntilIdle();
784 EXPECT_EQ(2U, page_added_count());
785 EXPECT_EQ(0U, model_removed_count());
786 ASSERT_EQ(2U, GetAllPages().size());
787 const OfflinePageItem* second_page = FindPageForOfflineId(offline_id_3);
788 ASSERT_TRUE(second_page);
789 EXPECT_EQ(client_id_3, second_page->client_id);
790 EXPECT_EQ(offline_id_3, second_page->offline_id);
791 }
792
745 } // namespace offline_pages 793 } // namespace offline_pages
OLDNEW
« no previous file with comments | « chrome/browser/android/offline_pages/recent_tab_helper.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698