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

Side by Side Diff: net/disk_cache/simple/simple_index_unittest.cc

Issue 1545233002: Convert Pass()→std::move() in //net (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 12 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "net/disk_cache/simple/simple_index.h"
6
5 #include <algorithm> 7 #include <algorithm>
6 #include <functional> 8 #include <functional>
9 #include <utility>
7 10
8 #include "base/files/scoped_temp_dir.h" 11 #include "base/files/scoped_temp_dir.h"
9 #include "base/hash.h" 12 #include "base/hash.h"
10 #include "base/logging.h" 13 #include "base/logging.h"
11 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
12 #include "base/pickle.h" 15 #include "base/pickle.h"
13 #include "base/sha1.h" 16 #include "base/sha1.h"
14 #include "base/strings/stringprintf.h" 17 #include "base/strings/stringprintf.h"
15 #include "base/task_runner.h" 18 #include "base/task_runner.h"
16 #include "base/threading/platform_thread.h" 19 #include "base/threading/platform_thread.h"
17 #include "base/time/time.h" 20 #include "base/time/time.h"
18 #include "net/base/cache_type.h" 21 #include "net/base/cache_type.h"
19 #include "net/disk_cache/simple/simple_index.h"
20 #include "net/disk_cache/simple/simple_index_delegate.h" 22 #include "net/disk_cache/simple/simple_index_delegate.h"
21 #include "net/disk_cache/simple/simple_index_file.h" 23 #include "net/disk_cache/simple/simple_index_file.h"
22 #include "net/disk_cache/simple/simple_test_util.h" 24 #include "net/disk_cache/simple/simple_test_util.h"
23 #include "net/disk_cache/simple/simple_util.h" 25 #include "net/disk_cache/simple/simple_util.h"
24 #include "testing/gtest/include/gtest/gtest.h" 26 #include "testing/gtest/include/gtest/gtest.h"
25 27
26 namespace disk_cache { 28 namespace disk_cache {
27 namespace { 29 namespace {
28 30
29 const base::Time kTestLastUsedTime = 31 const base::Time kTestLastUsedTime =
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 101
100 static uint64_t HashesInitializer(size_t hash_index) { 102 static uint64_t HashesInitializer(size_t hash_index) {
101 return disk_cache::simple_util::GetEntryHashKey( 103 return disk_cache::simple_util::GetEntryHashKey(
102 base::StringPrintf("key%d", static_cast<int>(hash_index))); 104 base::StringPrintf("key%d", static_cast<int>(hash_index)));
103 } 105 }
104 106
105 void SetUp() override { 107 void SetUp() override {
106 scoped_ptr<MockSimpleIndexFile> index_file(new MockSimpleIndexFile()); 108 scoped_ptr<MockSimpleIndexFile> index_file(new MockSimpleIndexFile());
107 index_file_ = index_file->AsWeakPtr(); 109 index_file_ = index_file->AsWeakPtr();
108 index_.reset( 110 index_.reset(
109 new SimpleIndex(NULL, this, net::DISK_CACHE, index_file.Pass())); 111 new SimpleIndex(NULL, this, net::DISK_CACHE, std::move(index_file)));
110 112
111 index_->Initialize(base::Time()); 113 index_->Initialize(base::Time());
112 } 114 }
113 115
114 void WaitForTimeChange() { 116 void WaitForTimeChange() {
115 const base::Time initial_time = base::Time::Now(); 117 const base::Time initial_time = base::Time::Now();
116 do { 118 do {
117 base::PlatformThread::YieldCurrentThread(); 119 base::PlatformThread::YieldCurrentThread();
118 } while (base::Time::Now() - 120 } while (base::Time::Now() -
119 initial_time < base::TimeDelta::FromSeconds(1)); 121 initial_time < base::TimeDelta::FromSeconds(1));
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 index()->Insert(hashes_.at<2>()); 202 index()->Insert(hashes_.at<2>());
201 index()->UpdateEntrySize(hashes_.at<2>(), 2); 203 index()->UpdateEntrySize(hashes_.at<2>(), 2);
202 index()->Insert(hashes_.at<3>()); 204 index()->Insert(hashes_.at<3>());
203 index()->UpdateEntrySize(hashes_.at<3>(), 3); 205 index()->UpdateEntrySize(hashes_.at<3>(), 3);
204 index()->Insert(hashes_.at<4>()); 206 index()->Insert(hashes_.at<4>());
205 index()->UpdateEntrySize(hashes_.at<4>(), 4); 207 index()->UpdateEntrySize(hashes_.at<4>(), 4);
206 EXPECT_EQ(9U, index()->cache_size_); 208 EXPECT_EQ(9U, index()->cache_size_);
207 { 209 {
208 scoped_ptr<SimpleIndexLoadResult> result(new SimpleIndexLoadResult()); 210 scoped_ptr<SimpleIndexLoadResult> result(new SimpleIndexLoadResult());
209 result->did_load = true; 211 result->did_load = true;
210 index()->MergeInitializingSet(result.Pass()); 212 index()->MergeInitializingSet(std::move(result));
211 } 213 }
212 EXPECT_EQ(9U, index()->cache_size_); 214 EXPECT_EQ(9U, index()->cache_size_);
213 { 215 {
214 scoped_ptr<SimpleIndexLoadResult> result(new SimpleIndexLoadResult()); 216 scoped_ptr<SimpleIndexLoadResult> result(new SimpleIndexLoadResult());
215 result->did_load = true; 217 result->did_load = true;
216 const uint64_t new_hash_key = hashes_.at<11>(); 218 const uint64_t new_hash_key = hashes_.at<11>();
217 result->entries.insert( 219 result->entries.insert(
218 std::make_pair(new_hash_key, EntryMetadata(base::Time::Now(), 11))); 220 std::make_pair(new_hash_key, EntryMetadata(base::Time::Now(), 11)));
219 const uint64_t redundant_hash_key = hashes_.at<4>(); 221 const uint64_t redundant_hash_key = hashes_.at<4>();
220 result->entries.insert(std::make_pair(redundant_hash_key, 222 result->entries.insert(std::make_pair(redundant_hash_key,
221 EntryMetadata(base::Time::Now(), 4))); 223 EntryMetadata(base::Time::Now(), 4)));
222 index()->MergeInitializingSet(result.Pass()); 224 index()->MergeInitializingSet(std::move(result));
223 } 225 }
224 EXPECT_EQ(2U + 3U + 4U + 11U, index()->cache_size_); 226 EXPECT_EQ(2U + 3U + 4U + 11U, index()->cache_size_);
225 } 227 }
226 228
227 // State of index changes as expected with an insert and a remove. 229 // State of index changes as expected with an insert and a remove.
228 TEST_F(SimpleIndexTest, BasicInsertRemove) { 230 TEST_F(SimpleIndexTest, BasicInsertRemove) {
229 // Confirm blank state. 231 // Confirm blank state.
230 EntryMetadata metadata; 232 EntryMetadata metadata;
231 EXPECT_EQ(base::Time(), metadata.GetLastUsedTime()); 233 EXPECT_EQ(base::Time(), metadata.GetLastUsedTime());
232 EXPECT_EQ(0U, metadata.GetEntrySize()); 234 EXPECT_EQ(0U, metadata.GetEntrySize());
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 WaitForTimeChange(); 619 WaitForTimeChange();
618 EXPECT_EQ(expected_trigger, index()->write_to_disk_timer_.desired_run_time()); 620 EXPECT_EQ(expected_trigger, index()->write_to_disk_timer_.desired_run_time());
619 index()->Insert(hashes_.at<2>()); 621 index()->Insert(hashes_.at<2>());
620 index()->UpdateEntrySize(hashes_.at<2>(), 40); 622 index()->UpdateEntrySize(hashes_.at<2>(), 40);
621 EXPECT_TRUE(index()->write_to_disk_timer_.IsRunning()); 623 EXPECT_TRUE(index()->write_to_disk_timer_.IsRunning());
622 EXPECT_LT(expected_trigger, index()->write_to_disk_timer_.desired_run_time()); 624 EXPECT_LT(expected_trigger, index()->write_to_disk_timer_.desired_run_time());
623 index()->write_to_disk_timer_.Stop(); 625 index()->write_to_disk_timer_.Stop();
624 } 626 }
625 627
626 } // namespace disk_cache 628 } // namespace disk_cache
OLDNEW
« no previous file with comments | « net/disk_cache/simple/simple_index_file.cc ('k') | net/disk_cache/simple/simple_net_log_parameters.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698