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

Side by Side Diff: components/precache/core/precache_url_table_unittest.cc

Issue 2364873004: Add Precache.CacheStatus.NonPrefetch.FromPrecache. (Closed)
Patch Set: Add const. Created 4 years, 2 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 | « components/precache/core/precache_url_table.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/precache/core/precache_url_table.h" 5 #include "components/precache/core/precache_url_table.h"
6 6
7 #include <map> 7 #include <map>
8 #include <memory> 8 #include <memory>
9 #include <set> 9 #include <set>
10 10
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "base/time/time.h" 12 #include "base/time/time.h"
13 #include "sql/connection.h" 13 #include "sql/connection.h"
14 #include "sql/statement.h" 14 #include "sql/statement.h"
15 #include "testing/gmock/include/gmock/gmock.h" 15 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
17 17
18 namespace precache { 18 namespace precache {
19 19
20 void PrintTo(const PrecacheURLInfo& url_info, ::std::ostream* os) {
21 *os << "{" << url_info.was_precached << ", " << url_info.is_precached << ", "
22 << url_info.was_used << "}";
23 }
24
20 namespace { 25 namespace {
21 26
22 class PrecacheURLTableTest : public testing::Test { 27 class PrecacheURLTableTest : public testing::Test {
23 public: 28 public:
24 PrecacheURLTableTest() {} 29 PrecacheURLTableTest() {}
25 ~PrecacheURLTableTest() override {} 30 ~PrecacheURLTableTest() override {}
26 31
27 protected: 32 protected:
28 void SetUp() override { 33 void SetUp() override {
29 precache_url_table_.reset(new PrecacheURLTable()); 34 precache_url_table_.reset(new PrecacheURLTable());
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 precache_url_table_->SetURLAsNotPrecached(GURL("http://deleted.com")); 78 precache_url_table_->SetURLAsNotPrecached(GURL("http://deleted.com"));
74 79
75 std::map<GURL, base::Time> expected_map; 80 std::map<GURL, base::Time> expected_map;
76 expected_map[GURL("http://stays.com")] = kStaysTime; 81 expected_map[GURL("http://stays.com")] = kStaysTime;
77 82
78 std::map<GURL, base::Time> actual_map; 83 std::map<GURL, base::Time> actual_map;
79 precache_url_table_->GetAllDataForTesting(&actual_map); 84 precache_url_table_->GetAllDataForTesting(&actual_map);
80 EXPECT_EQ(expected_map, actual_map); 85 EXPECT_EQ(expected_map, actual_map);
81 } 86 }
82 87
83 TEST_F(PrecacheURLTableTest, IsURLPrecached) { 88 TEST_F(PrecacheURLTableTest, GetURLInfo) {
84 EXPECT_FALSE(precache_url_table_->IsURLPrecached(GURL("http://url.com"))); 89 const GURL url("http://url.com");
85 90
86 precache_url_table_->AddURL(GURL("http://url.com"), 1, true, 91 EXPECT_EQ((PrecacheURLInfo{false, false, false}),
87 base::Time::FromInternalValue(100)); 92 precache_url_table_->GetURLInfo(url));
88 93
89 EXPECT_TRUE(precache_url_table_->IsURLPrecached(GURL("http://url.com"))); 94 precache_url_table_->AddURL(url, 1, true, base::Time::FromInternalValue(100));
90 95
91 precache_url_table_->SetURLAsNotPrecached(GURL("http://url.com")); 96 EXPECT_EQ((PrecacheURLInfo{true, true, false}),
97 precache_url_table_->GetURLInfo(url));
92 98
93 EXPECT_FALSE(precache_url_table_->IsURLPrecached(GURL("http://url.com"))); 99 precache_url_table_->SetPrecachedURLAsUsed(url);
100
101 EXPECT_EQ((PrecacheURLInfo{true, false, true}),
102 precache_url_table_->GetURLInfo(url));
103
104 precache_url_table_->AddURL(url, 1, true, base::Time::FromInternalValue(100));
105
106 EXPECT_EQ((PrecacheURLInfo{true, true, false}),
107 precache_url_table_->GetURLInfo(url));
108
109 precache_url_table_->SetURLAsNotPrecached(url);
110
111 EXPECT_EQ((PrecacheURLInfo{true, false, false}),
112 precache_url_table_->GetURLInfo(url));
94 } 113 }
95 114
96 TEST_F(PrecacheURLTableTest, DeleteAllPrecachedBefore) { 115 TEST_F(PrecacheURLTableTest, DeleteAllPrecachedBefore) {
97 const base::Time kOldTime = base::Time::FromInternalValue(10); 116 const base::Time kOldTime = base::Time::FromInternalValue(10);
98 const base::Time kBeforeTime = base::Time::FromInternalValue(20); 117 const base::Time kBeforeTime = base::Time::FromInternalValue(20);
99 const base::Time kEndTime = base::Time::FromInternalValue(30); 118 const base::Time kEndTime = base::Time::FromInternalValue(30);
100 const base::Time kAfterTime = base::Time::FromInternalValue(40); 119 const base::Time kAfterTime = base::Time::FromInternalValue(40);
101 120
102 precache_url_table_->AddURL(GURL("http://old.com"), 1, true, kOldTime); 121 precache_url_table_->AddURL(GURL("http://old.com"), 1, true, kOldTime);
103 precache_url_table_->AddURL(GURL("http://before.com"), 1, true, kBeforeTime); 122 precache_url_table_->AddURL(GURL("http://before.com"), 1, true, kBeforeTime);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 EXPECT_EQ(0, statement.ColumnInt(2)); 170 EXPECT_EQ(0, statement.ColumnInt(2));
152 EXPECT_EQ(1, statement.ColumnInt(3)); 171 EXPECT_EQ(1, statement.ColumnInt(3));
153 } 172 }
154 EXPECT_THAT(std::set<std::string>(begin(old_urls), end(old_urls)), 173 EXPECT_THAT(std::set<std::string>(begin(old_urls), end(old_urls)),
155 ::testing::ContainerEq(actual_urls)); 174 ::testing::ContainerEq(actual_urls));
156 } 175 }
157 176
158 } // namespace 177 } // namespace
159 178
160 } // namespace precache 179 } // namespace precache
OLDNEW
« no previous file with comments | « components/precache/core/precache_url_table.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698