| 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" |
| (...skipping 837 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 848 RunUntilIdle(); | 848 RunUntilIdle(); |
| 849 EXPECT_EQ(3U, page_added_count()); | 849 EXPECT_EQ(3U, page_added_count()); |
| 850 EXPECT_EQ(1U, model_removed_count()); | 850 EXPECT_EQ(1U, model_removed_count()); |
| 851 ASSERT_EQ(2U, GetAllPages().size()); | 851 ASSERT_EQ(2U, GetAllPages().size()); |
| 852 const OfflinePageItem* downloads_page = FindPageForOfflineId(offline_id); | 852 const OfflinePageItem* downloads_page = FindPageForOfflineId(offline_id); |
| 853 EXPECT_EQ(kTestPageUrlWithSegment, downloads_page->url); | 853 EXPECT_EQ(kTestPageUrlWithSegment, downloads_page->url); |
| 854 EXPECT_EQ(client_id, downloads_page->client_id); | 854 EXPECT_EQ(client_id, downloads_page->client_id); |
| 855 EXPECT_EQ(offline_id, downloads_page->offline_id); | 855 EXPECT_EQ(offline_id, downloads_page->offline_id); |
| 856 } | 856 } |
| 857 | 857 |
| 858 // Checks that a closing tab doesn't trigger the creation of a snapshot. And |
| 859 // also that if the closure is reverted, a snapshot is saved upon the next hide |
| 860 // event. |
| 861 TEST_F(RecentTabHelperTest, NoSaveIfTabIsClosing) { |
| 862 // Navigates and fully load then close and hide the tab. No snapshots are |
| 863 // expected. |
| 864 NavigateAndCommit(kTestPageUrl); |
| 865 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame(); |
| 866 FastForwardSnapshotController(); |
| 867 // Note: These two next calls are always expected to happen in this order. |
| 868 recent_tab_helper()->WillCloseTab(); |
| 869 recent_tab_helper()->WasHidden(); |
| 870 RunUntilIdle(); |
| 871 EXPECT_EQ(0U, page_added_count()); |
| 872 EXPECT_EQ(0U, model_removed_count()); |
| 873 ASSERT_EQ(0U, GetAllPages().size()); |
| 874 |
| 875 // Simulates the page being restored and shown again, then hidden. At this |
| 876 // moment a snapshot should be created. |
| 877 recent_tab_helper()->WasShown(); |
| 878 recent_tab_helper()->WasHidden(); |
| 879 RunUntilIdle(); |
| 880 EXPECT_EQ(1U, page_added_count()); |
| 881 EXPECT_EQ(0U, model_removed_count()); |
| 882 ASSERT_EQ(1U, GetAllPages().size()); |
| 883 } |
| 884 |
| 858 } // namespace offline_pages | 885 } // namespace offline_pages |
| OLD | NEW |