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 <stdint.h> | 5 #include <stdint.h> |
6 | 6 |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/time/time.h" | 8 #include "base/time/time.h" |
9 #include "components/precache/core/precache_session_table.h" | 9 #include "components/precache/core/precache_session_table.h" |
| 10 #include "components/precache/core/proto/quota.pb.h" |
10 #include "components/precache/core/proto/unfinished_work.pb.h" | 11 #include "components/precache/core/proto/unfinished_work.pb.h" |
11 #include "sql/connection.h" | 12 #include "sql/connection.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
13 #include "url/gurl.h" | 14 #include "url/gurl.h" |
14 | 15 |
15 namespace precache { | 16 namespace precache { |
16 | 17 |
17 namespace { | 18 namespace { |
18 | 19 |
19 class PrecacheSessionTableTest : public testing::Test { | 20 class PrecacheSessionTableTest : public testing::Test { |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 unfinished_work->add_top_host()->set_hostname("a.com"); | 147 unfinished_work->add_top_host()->set_hostname("a.com"); |
147 precache_session_table_->SaveUnfinishedWork(std::move(unfinished_work)); | 148 precache_session_table_->SaveUnfinishedWork(std::move(unfinished_work)); |
148 precache_session_table_->DeleteUnfinishedWork(); | 149 precache_session_table_->DeleteUnfinishedWork(); |
149 | 150 |
150 std::unique_ptr<PrecacheUnfinishedWork> unfinished_work2 = | 151 std::unique_ptr<PrecacheUnfinishedWork> unfinished_work2 = |
151 precache_session_table_->GetUnfinishedWork(); | 152 precache_session_table_->GetUnfinishedWork(); |
152 | 153 |
153 EXPECT_EQ(0, unfinished_work2->top_host_size()); | 154 EXPECT_EQ(0, unfinished_work2->top_host_size()); |
154 } | 155 } |
155 | 156 |
| 157 TEST_F(PrecacheSessionTableTest, SaveAndGetQuota) { |
| 158 // Initial quota, should have expired. |
| 159 EXPECT_LT(base::Time::FromInternalValue( |
| 160 precache_session_table_->GetQuota().start_time()), |
| 161 base::Time::Now()); |
| 162 |
| 163 PrecacheQuota quota; |
| 164 quota.set_start_time(base::Time::Now().ToInternalValue()); |
| 165 quota.set_remaining(1000U); |
| 166 |
| 167 PrecacheQuota expected_quota = quota; |
| 168 precache_session_table_->SaveQuota(quota); |
| 169 EXPECT_EQ(expected_quota.start_time(), |
| 170 precache_session_table_->GetQuota().start_time()); |
| 171 EXPECT_EQ(expected_quota.remaining(), |
| 172 precache_session_table_->GetQuota().remaining()); |
| 173 } |
| 174 |
156 } // namespace | 175 } // namespace |
157 | 176 |
158 } // namespace precache | 177 } // namespace precache |
OLD | NEW |