OLD | NEW |
---|---|
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 "components/history/core/browser/expire_history_backend.h" | 5 #include "components/history/core/browser/expire_history_backend.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <memory> | 10 #include <memory> |
11 #include <string> | 11 #include <string> |
12 #include <utility> | 12 #include <utility> |
13 | 13 |
14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
15 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
16 #include "base/files/file_util.h" | 16 #include "base/files/file_util.h" |
17 #include "base/files/scoped_temp_dir.h" | 17 #include "base/files/scoped_temp_dir.h" |
18 #include "base/macros.h" | 18 #include "base/macros.h" |
19 #include "base/run_loop.h" | 19 #include "base/run_loop.h" |
20 #include "base/scoped_observer.h" | 20 #include "base/scoped_observer.h" |
21 #include "base/strings/string16.h" | 21 #include "base/strings/string16.h" |
22 #include "base/strings/utf_string_conversions.h" | 22 #include "base/strings/utf_string_conversions.h" |
23 #include "base/test/scoped_feature_list.h" | |
23 #include "base/test/scoped_task_environment.h" | 24 #include "base/test/scoped_task_environment.h" |
24 #include "components/history/core/browser/history_backend_client.h" | 25 #include "components/history/core/browser/history_backend_client.h" |
25 #include "components/history/core/browser/history_backend_notifier.h" | 26 #include "components/history/core/browser/history_backend_notifier.h" |
26 #include "components/history/core/browser/history_constants.h" | 27 #include "components/history/core/browser/history_constants.h" |
27 #include "components/history/core/browser/history_database.h" | 28 #include "components/history/core/browser/history_database.h" |
28 #include "components/history/core/browser/thumbnail_database.h" | 29 #include "components/history/core/browser/thumbnail_database.h" |
29 #include "components/history/core/browser/top_sites.h" | 30 #include "components/history/core/browser/top_sites.h" |
30 #include "components/history/core/browser/top_sites_impl.h" | 31 #include "components/history/core/browser/top_sites_impl.h" |
31 #include "components/history/core/browser/top_sites_observer.h" | 32 #include "components/history/core/browser/top_sites_observer.h" |
32 #include "components/history/core/common/thumbnail_score.h" | 33 #include "components/history/core/common/thumbnail_score.h" |
(...skipping 851 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
884 | 885 |
885 // Verify that the early expiration threshold was updated, since there are no | 886 // Verify that the early expiration threshold was updated, since there are no |
886 // AUTO_SUBFRAME visits in the given time range. | 887 // AUTO_SUBFRAME visits in the given time range. |
887 EXPECT_TRUE(now <= main_db_->GetEarlyExpirationThreshold()); | 888 EXPECT_TRUE(now <= main_db_->GetEarlyExpirationThreshold()); |
888 | 889 |
889 // Now, read all visits and verify that there's at least one. | 890 // Now, read all visits and verify that there's at least one. |
890 EXPECT_TRUE(all->Read(now, main_db_.get(), &visits, 1)); | 891 EXPECT_TRUE(all->Read(now, main_db_.get(), &visits, 1)); |
891 EXPECT_EQ(1U, visits.size()); | 892 EXPECT_EQ(1U, visits.size()); |
892 } | 893 } |
893 | 894 |
895 // Test that ClearOldOnDemandFavicons() deletes favicons associated only to | |
896 // unstarred page URLs. | |
897 TEST_F(ExpireHistoryTest, ClearOldOnDemandFaviconsDoesDeleteUnstarred) { | |
898 base::test::ScopedFeatureList feature_list; | |
899 feature_list.InitAndEnableFeature(internal::kClearOldOnDemandFavicons); | |
900 | |
901 // The blob does not encode any real bitmap, obviously. | |
902 const unsigned char kBlob1[] = "0"; | |
903 std::vector<unsigned char> data(kBlob1, kBlob1 + sizeof(kBlob1)); | |
904 scoped_refptr<base::RefCountedBytes> favicon(new base::RefCountedBytes(data)); | |
pkotwicz
2017/07/10 19:50:19
Aside: There is a RefCountedBytes() constructor wi
jkrcal
2017/07/11 13:19:34
Done.
| |
905 | |
906 // Icon: old and not bookmarked case. | |
907 GURL url("http://google.com/favicon.ico"); | |
908 favicon_base::FaviconID icon_id = thumb_db_->AddFavicon( | |
909 url, favicon_base::FAVICON, favicon, FaviconBitmapType::ON_DEMAND, | |
910 base::Time::Now() - base::TimeDelta::FromDays(100), gfx::Size()); | |
911 ASSERT_NE(0, icon_id); | |
912 GURL page_url("http://google.com/"); | |
913 ASSERT_NE(0, thumb_db_->AddIconMapping(page_url, icon_id)); | |
914 | |
915 expirer_.ClearOldOnDemandFavicons(base::Time::Now() - | |
916 base::TimeDelta::FromDays(90)); | |
917 | |
918 // The icon gets deleted. | |
919 EXPECT_FALSE(thumb_db_->GetIconMappingsForPageURL(page_url, nullptr)); | |
920 EXPECT_FALSE(thumb_db_->GetFaviconHeader(icon_id, nullptr, nullptr)); | |
921 EXPECT_FALSE(thumb_db_->GetFaviconBitmaps(icon_id, nullptr)); | |
922 } | |
923 | |
924 // Test that ClearOldOnDemandFavicons() deletes favicons associated to at least | |
925 // one starred page URL. | |
926 TEST_F(ExpireHistoryTest, ClearOldOnDemandFaviconsDoesNotDeleteStarred) { | |
927 base::test::ScopedFeatureList feature_list; | |
928 feature_list.InitAndEnableFeature(internal::kClearOldOnDemandFavicons); | |
929 | |
930 // The blob does not encode any real bitmap, obviously. | |
931 const unsigned char kBlob1[] = "0"; | |
932 std::vector<unsigned char> data(kBlob1, kBlob1 + sizeof(kBlob1)); | |
933 scoped_refptr<base::RefCountedBytes> favicon(new base::RefCountedBytes(data)); | |
934 | |
935 // Icon: old but bookmarked case. | |
936 GURL url("http://google.com/favicon.ico"); | |
937 favicon_base::FaviconID icon_id = thumb_db_->AddFavicon( | |
938 url, favicon_base::FAVICON, favicon, FaviconBitmapType::ON_DEMAND, | |
939 base::Time::Now() - base::TimeDelta::FromDays(100), gfx::Size()); | |
940 ASSERT_NE(0, icon_id); | |
941 GURL page_url1("http://google.com/1"); | |
942 ASSERT_NE(0, thumb_db_->AddIconMapping(page_url1, icon_id)); | |
943 StarURL(page_url1); | |
944 GURL page_url2("http://google.com/2"); | |
945 ASSERT_NE(0, thumb_db_->AddIconMapping(page_url2, icon_id)); | |
946 | |
947 expirer_.ClearOldOnDemandFavicons(base::Time::Now() - | |
948 base::TimeDelta::FromDays(90)); | |
949 | |
950 // Nothing gets deleted. | |
951 EXPECT_TRUE(thumb_db_->GetFaviconHeader(icon_id, nullptr, nullptr)); | |
952 std::vector<FaviconBitmap> favicon_bitmaps; | |
953 EXPECT_TRUE(thumb_db_->GetFaviconBitmaps(icon_id, &favicon_bitmaps)); | |
954 EXPECT_EQ(1u, favicon_bitmaps.size()); | |
955 std::vector<IconMapping> icon_mapping; | |
956 EXPECT_TRUE(thumb_db_->GetIconMappingsForPageURL(page_url1, &icon_mapping)); | |
957 EXPECT_TRUE(thumb_db_->GetIconMappingsForPageURL(page_url2, &icon_mapping)); | |
958 EXPECT_EQ(2u, icon_mapping.size()); | |
959 EXPECT_EQ(icon_id, icon_mapping[0].icon_id); | |
960 EXPECT_EQ(icon_id, icon_mapping[1].icon_id); | |
961 } | |
962 | |
894 // TODO(brettw) add some visits with no URL to make sure everything is updated | 963 // TODO(brettw) add some visits with no URL to make sure everything is updated |
895 // properly. Have the visits also refer to nonexistent FTS rows. | 964 // properly. Have the visits also refer to nonexistent FTS rows. |
896 // | 965 // |
897 // Maybe also refer to invalid favicons. | 966 // Maybe also refer to invalid favicons. |
898 | 967 |
899 } // namespace history | 968 } // namespace history |
OLD | NEW |