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

Side by Side Diff: chrome/browser/net/quota_policy_channel_id_store_unittest.cc

Issue 2095523002: Make //crypto factories return std::unique_ptr<>s (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix comment Created 4 years, 6 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/net/quota_policy_channel_id_store.h" 5 #include "chrome/browser/net/quota_policy_channel_id_store.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
11 #include "base/files/scoped_temp_dir.h" 11 #include "base/files/scoped_temp_dir.h"
12 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
davidben 2016/06/23 03:09:35 No longer used, I think.
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_vector.h" 14 #include "base/memory/scoped_vector.h"
15 #include "base/message_loop/message_loop.h" 15 #include "base/message_loop/message_loop.h"
16 #include "base/run_loop.h" 16 #include "base/run_loop.h"
17 #include "base/single_thread_task_runner.h" 17 #include "base/single_thread_task_runner.h"
18 #include "base/stl_util.h" 18 #include "base/stl_util.h"
19 #include "base/threading/thread_task_runner_handle.h" 19 #include "base/threading/thread_task_runner_handle.h"
20 #include "base/time/time.h" 20 #include "base/time/time.h"
21 #include "content/public/test/mock_special_storage_policy.h" 21 #include "content/public/test/mock_special_storage_policy.h"
22 #include "content/public/test/test_browser_thread_bundle.h" 22 #include "content/public/test/test_browser_thread_bundle.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 channel_ids_; 77 channel_ids_;
78 base::MessageLoop loop_; 78 base::MessageLoop loop_;
79 }; 79 };
80 80
81 // Test if data is stored as expected in the QuotaPolicy database. 81 // Test if data is stored as expected in the QuotaPolicy database.
82 TEST_F(QuotaPolicyChannelIDStoreTest, TestPersistence) { 82 TEST_F(QuotaPolicyChannelIDStoreTest, TestPersistence) {
83 std::unique_ptr<crypto::ECPrivateKey> goog_key( 83 std::unique_ptr<crypto::ECPrivateKey> goog_key(
84 crypto::ECPrivateKey::Create()); 84 crypto::ECPrivateKey::Create());
85 std::unique_ptr<crypto::ECPrivateKey> foo_key(crypto::ECPrivateKey::Create()); 85 std::unique_ptr<crypto::ECPrivateKey> foo_key(crypto::ECPrivateKey::Create());
86 store_->AddChannelID(net::DefaultChannelIDStore::ChannelID( 86 store_->AddChannelID(net::DefaultChannelIDStore::ChannelID(
87 "google.com", base::Time::FromInternalValue(1), 87 "google.com", base::Time::FromInternalValue(1), goog_key->Copy()));
88 base::WrapUnique(goog_key->Copy())));
89 store_->AddChannelID(net::DefaultChannelIDStore::ChannelID( 88 store_->AddChannelID(net::DefaultChannelIDStore::ChannelID(
90 "foo.com", base::Time::FromInternalValue(3), 89 "foo.com", base::Time::FromInternalValue(3), foo_key->Copy()));
91 base::WrapUnique(foo_key->Copy())));
92 90
93 std::vector<std::unique_ptr<net::DefaultChannelIDStore::ChannelID>> 91 std::vector<std::unique_ptr<net::DefaultChannelIDStore::ChannelID>>
94 channel_ids; 92 channel_ids;
95 // Replace the store effectively destroying the current one and forcing it 93 // Replace the store effectively destroying the current one and forcing it
96 // to write its data to disk. Then we can see if after loading it again it 94 // to write its data to disk. Then we can see if after loading it again it
97 // is still there. 95 // is still there.
98 store_ = NULL; 96 store_ = NULL;
99 // Make sure we wait until the destructor has run. 97 // Make sure we wait until the destructor has run.
100 base::RunLoop().RunUntilIdle(); 98 base::RunLoop().RunUntilIdle();
101 store_ = new QuotaPolicyChannelIDStore( 99 store_ = new QuotaPolicyChannelIDStore(
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 134
137 // Reload and check if the channel ID has been removed. 135 // Reload and check if the channel ID has been removed.
138 Load(&channel_ids); 136 Load(&channel_ids);
139 ASSERT_EQ(0U, channel_ids.size()); 137 ASSERT_EQ(0U, channel_ids.size());
140 } 138 }
141 139
142 // Test if data is stored as expected in the QuotaPolicy database. 140 // Test if data is stored as expected in the QuotaPolicy database.
143 TEST_F(QuotaPolicyChannelIDStoreTest, TestPolicy) { 141 TEST_F(QuotaPolicyChannelIDStoreTest, TestPolicy) {
144 store_->AddChannelID(net::DefaultChannelIDStore::ChannelID( 142 store_->AddChannelID(net::DefaultChannelIDStore::ChannelID(
145 "google.com", base::Time::FromInternalValue(1), 143 "google.com", base::Time::FromInternalValue(1),
146 base::WrapUnique(crypto::ECPrivateKey::Create()))); 144 crypto::ECPrivateKey::Create()));
147 store_->AddChannelID(net::DefaultChannelIDStore::ChannelID( 145 store_->AddChannelID(net::DefaultChannelIDStore::ChannelID(
148 "nonpersistent.com", base::Time::FromInternalValue(3), 146 "nonpersistent.com", base::Time::FromInternalValue(3),
149 base::WrapUnique(crypto::ECPrivateKey::Create()))); 147 crypto::ECPrivateKey::Create()));
150 148
151 std::vector<std::unique_ptr<net::DefaultChannelIDStore::ChannelID>> 149 std::vector<std::unique_ptr<net::DefaultChannelIDStore::ChannelID>>
152 channel_ids; 150 channel_ids;
153 // Replace the store effectively destroying the current one and forcing it 151 // Replace the store effectively destroying the current one and forcing it
154 // to write its data to disk. Then we can see if after loading it again it 152 // to write its data to disk. Then we can see if after loading it again it
155 // is still there. 153 // is still there.
156 store_ = NULL; 154 store_ = NULL;
157 // Make sure we wait until the destructor has run. 155 // Make sure we wait until the destructor has run.
158 base::RunLoop().RunUntilIdle(); 156 base::RunLoop().RunUntilIdle();
159 // Specify storage policy that makes "nonpersistent.com" session only. 157 // Specify storage policy that makes "nonpersistent.com" session only.
160 scoped_refptr<content::MockSpecialStoragePolicy> storage_policy = 158 scoped_refptr<content::MockSpecialStoragePolicy> storage_policy =
161 new content::MockSpecialStoragePolicy(); 159 new content::MockSpecialStoragePolicy();
162 storage_policy->AddSessionOnly( 160 storage_policy->AddSessionOnly(
163 net::cookie_util::CookieOriginToURL("nonpersistent.com", true)); 161 net::cookie_util::CookieOriginToURL("nonpersistent.com", true));
164 // Reload store, it should still have both channel IDs. 162 // Reload store, it should still have both channel IDs.
165 store_ = new QuotaPolicyChannelIDStore( 163 store_ = new QuotaPolicyChannelIDStore(
166 temp_dir_.path().Append(kTestChannelIDFilename), 164 temp_dir_.path().Append(kTestChannelIDFilename),
167 base::ThreadTaskRunnerHandle::Get(), 165 base::ThreadTaskRunnerHandle::Get(),
168 storage_policy); 166 storage_policy);
169 Load(&channel_ids); 167 Load(&channel_ids);
170 ASSERT_EQ(2U, channel_ids.size()); 168 ASSERT_EQ(2U, channel_ids.size());
171 169
172 // Add another two channel IDs before closing the store. Because additions are 170 // Add another two channel IDs before closing the store. Because additions are
173 // delayed and committed to disk in batches, these will not be committed until 171 // delayed and committed to disk in batches, these will not be committed until
174 // the store is destroyed, which is after the policy is applied. The pending 172 // the store is destroyed, which is after the policy is applied. The pending
175 // operation pruning logic should prevent the "nonpersistent.com" ID from 173 // operation pruning logic should prevent the "nonpersistent.com" ID from
176 // being committed to disk. 174 // being committed to disk.
177 store_->AddChannelID(net::DefaultChannelIDStore::ChannelID( 175 store_->AddChannelID(net::DefaultChannelIDStore::ChannelID(
178 "nonpersistent.com", base::Time::FromInternalValue(5), 176 "nonpersistent.com", base::Time::FromInternalValue(5),
179 base::WrapUnique(crypto::ECPrivateKey::Create()))); 177 crypto::ECPrivateKey::Create()));
180 store_->AddChannelID(net::DefaultChannelIDStore::ChannelID( 178 store_->AddChannelID(net::DefaultChannelIDStore::ChannelID(
181 "persistent.com", base::Time::FromInternalValue(7), 179 "persistent.com", base::Time::FromInternalValue(7),
182 base::WrapUnique(crypto::ECPrivateKey::Create()))); 180 crypto::ECPrivateKey::Create()));
183 181
184 // Now close the store, and the nonpersistent.com channel IDs should be 182 // Now close the store, and the nonpersistent.com channel IDs should be
185 // deleted according to policy. 183 // deleted according to policy.
186 store_ = NULL; 184 store_ = NULL;
187 // Make sure we wait until the destructor has run. 185 // Make sure we wait until the destructor has run.
188 base::RunLoop().RunUntilIdle(); 186 base::RunLoop().RunUntilIdle();
189 channel_ids.clear(); 187 channel_ids.clear();
190 store_ = new QuotaPolicyChannelIDStore( 188 store_ = new QuotaPolicyChannelIDStore(
191 temp_dir_.path().Append(kTestChannelIDFilename), 189 temp_dir_.path().Append(kTestChannelIDFilename),
192 base::ThreadTaskRunnerHandle::Get(), 190 base::ThreadTaskRunnerHandle::Get(),
193 NULL); 191 NULL);
194 192
195 // Reload and check that the nonpersistent.com channel IDs have been removed. 193 // Reload and check that the nonpersistent.com channel IDs have been removed.
196 Load(&channel_ids); 194 Load(&channel_ids);
197 ASSERT_EQ(2U, channel_ids.size()); 195 ASSERT_EQ(2U, channel_ids.size());
198 for (const auto& id : channel_ids) { 196 for (const auto& id : channel_ids) {
199 ASSERT_NE("nonpersistent.com", id->server_identifier()); 197 ASSERT_NE("nonpersistent.com", id->server_identifier());
200 } 198 }
201 } 199 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698