| OLD | NEW |
| 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/strings/string_number_conversions.h" |
| 11 #include "base/test/scoped_feature_list.h" | 11 #include "base/test/scoped_feature_list.h" |
| 12 #include "base/test/test_mock_time_task_runner.h" | 12 #include "base/test/test_mock_time_task_runner.h" |
| 13 #include "base/threading/thread_task_runner_handle.h" | 13 #include "base/threading/thread_task_runner_handle.h" |
| 14 #include "chrome/browser/android/offline_pages/offline_page_model_factory.h" | 14 #include "chrome/browser/android/offline_pages/offline_page_model_factory.h" |
| 15 #include "chrome/browser/android/offline_pages/request_coordinator_factory.h" | 15 #include "chrome/browser/android/offline_pages/request_coordinator_factory.h" |
| 16 #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
" |
| 17 #include "chrome/browser/android/offline_pages/test_request_coordinator_builder.
h" | 17 #include "chrome/browser/android/offline_pages/test_request_coordinator_builder.
h" |
| 18 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 18 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 19 #include "components/offline_pages/core/client_namespace_constants.h" | 19 #include "components/offline_pages/core/client_namespace_constants.h" |
| 20 #include "components/offline_pages/core/offline_page_feature.h" | 20 #include "components/offline_pages/core/offline_page_feature.h" |
| 21 #include "components/offline_pages/core/offline_page_item.h" | 21 #include "components/offline_pages/core/offline_page_item.h" |
| 22 #include "components/offline_pages/core/offline_page_model.h" | 22 #include "components/offline_pages/core/offline_page_model.h" |
| 23 #include "components/offline_pages/core/offline_page_test_archiver.h" | 23 #include "components/offline_pages/core/offline_page_test_archiver.h" |
| 24 #include "content/public/browser/navigation_entry.h" | 24 #include "content/public/browser/navigation_entry.h" |
| 25 #include "content/public/browser/navigation_handle.h" | 25 #include "content/public/browser/navigation_handle.h" |
| 26 #include "content/public/browser/reload_type.h" |
| 26 #include "content/public/browser/web_contents.h" | 27 #include "content/public/browser/web_contents.h" |
| 27 #include "content/public/common/referrer.h" | 28 #include "content/public/common/referrer.h" |
| 28 #include "content/public/test/web_contents_tester.h" | 29 #include "content/public/test/web_contents_tester.h" |
| 29 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
| 30 | 31 |
| 31 namespace offline_pages { | 32 namespace offline_pages { |
| 32 | 33 |
| 33 namespace { | 34 namespace { |
| 34 const GURL kTestPageUrl("http://mystery.site/foo.html"); | 35 const GURL kTestPageUrl("http://mystery.site/foo.html"); |
| 35 const GURL kTestPageUrlOther("http://crazy.site/foo_other.html"); | 36 const GURL kTestPageUrlOther("http://crazy.site/foo_other.html"); |
| (...skipping 812 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 848 RunUntilIdle(); | 849 RunUntilIdle(); |
| 849 EXPECT_EQ(3U, page_added_count()); | 850 EXPECT_EQ(3U, page_added_count()); |
| 850 EXPECT_EQ(1U, model_removed_count()); | 851 EXPECT_EQ(1U, model_removed_count()); |
| 851 ASSERT_EQ(2U, GetAllPages().size()); | 852 ASSERT_EQ(2U, GetAllPages().size()); |
| 852 const OfflinePageItem* downloads_page = FindPageForOfflineId(offline_id); | 853 const OfflinePageItem* downloads_page = FindPageForOfflineId(offline_id); |
| 853 EXPECT_EQ(kTestPageUrlWithSegment, downloads_page->url); | 854 EXPECT_EQ(kTestPageUrlWithSegment, downloads_page->url); |
| 854 EXPECT_EQ(client_id, downloads_page->client_id); | 855 EXPECT_EQ(client_id, downloads_page->client_id); |
| 855 EXPECT_EQ(offline_id, downloads_page->offline_id); | 856 EXPECT_EQ(offline_id, downloads_page->offline_id); |
| 856 } | 857 } |
| 857 | 858 |
| 859 // Tests that a page reloaded is tracked as an actual load and properly saved. |
| 860 TEST_F(RecentTabHelperTest, ReloadIsTrackedAsNavigationAndSavedOnlyUponLoad) { |
| 861 // Navigates and load fully then hide the tab so that a snapshot is created. |
| 862 NavigateAndCommit(kTestPageUrl); |
| 863 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame(); |
| 864 FastForwardSnapshotController(); |
| 865 recent_tab_helper()->WasHidden(); |
| 866 RunUntilIdle(); |
| 867 ASSERT_EQ(1U, GetAllPages().size()); |
| 868 |
| 869 // Starts a reload and hides the tab. No new snapshot should be saved. |
| 870 controller().Reload(content::ReloadType::NORMAL, false); |
| 871 content::WebContentsTester* web_contents_tester = |
| 872 content::WebContentsTester::For(web_contents()); |
| 873 web_contents_tester->CommitPendingNavigation(); |
| 874 recent_tab_helper()->WasHidden(); |
| 875 RunUntilIdle(); |
| 876 EXPECT_EQ(1U, page_added_count()); |
| 877 EXPECT_EQ(0U, model_removed_count()); |
| 878 ASSERT_EQ(1U, GetAllPages().size()); |
| 879 |
| 880 // Finish loading and hide the tab. A new snapshot should be created. |
| 881 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame(); |
| 882 FastForwardSnapshotController(); |
| 883 recent_tab_helper()->WasHidden(); |
| 884 RunUntilIdle(); |
| 885 EXPECT_EQ(2U, page_added_count()); |
| 886 EXPECT_EQ(1U, model_removed_count()); |
| 887 ASSERT_EQ(1U, GetAllPages().size()); |
| 888 } |
| 889 |
| 858 } // namespace offline_pages | 890 } // namespace offline_pages |
| OLD | NEW |