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

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

Issue 1121213002: [chrome/browser/net] Replace MessageLoopProxy usage with ThreadTaskRunnerHandle (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed Review Comments Created 5 years, 7 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/files/file_util.h" 6 #include "base/files/file_util.h"
7 #include "base/files/scoped_temp_dir.h" 7 #include "base/files/scoped_temp_dir.h"
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_vector.h" 9 #include "base/memory/scoped_vector.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "base/run_loop.h" 11 #include "base/run_loop.h"
12 #include "base/single_thread_task_runner.h"
12 #include "base/stl_util.h" 13 #include "base/stl_util.h"
13 #include "base/thread_task_runner_handle.h" 14 #include "base/thread_task_runner_handle.h"
14 #include "base/time/time.h" 15 #include "base/time/time.h"
15 #include "chrome/browser/net/quota_policy_channel_id_store.h" 16 #include "chrome/browser/net/quota_policy_channel_id_store.h"
16 #include "content/public/test/mock_special_storage_policy.h" 17 #include "content/public/test/mock_special_storage_policy.h"
17 #include "content/public/test/test_browser_thread_bundle.h" 18 #include "content/public/test/test_browser_thread_bundle.h"
18 #include "net/base/test_data_directory.h" 19 #include "net/base/test_data_directory.h"
19 #include "net/cookies/cookie_util.h" 20 #include "net/cookies/cookie_util.h"
20 #include "net/ssl/ssl_client_cert_type.h" 21 #include "net/ssl/ssl_client_cert_type.h"
21 #include "net/test/cert_test_util.h" 22 #include "net/test/cert_test_util.h"
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 108
108 ScopedVector<net::DefaultChannelIDStore::ChannelID> channel_ids; 109 ScopedVector<net::DefaultChannelIDStore::ChannelID> channel_ids;
109 // Replace the store effectively destroying the current one and forcing it 110 // Replace the store effectively destroying the current one and forcing it
110 // to write its data to disk. Then we can see if after loading it again it 111 // to write its data to disk. Then we can see if after loading it again it
111 // is still there. 112 // is still there.
112 store_ = NULL; 113 store_ = NULL;
113 // Make sure we wait until the destructor has run. 114 // Make sure we wait until the destructor has run.
114 base::RunLoop().RunUntilIdle(); 115 base::RunLoop().RunUntilIdle();
115 store_ = new QuotaPolicyChannelIDStore( 116 store_ = new QuotaPolicyChannelIDStore(
116 temp_dir_.path().Append(kTestChannelIDFilename), 117 temp_dir_.path().Append(kTestChannelIDFilename),
117 base::MessageLoopProxy::current(), 118 base::ThreadTaskRunnerHandle::Get(),
118 NULL); 119 NULL);
119 120
120 // Reload and test for persistence 121 // Reload and test for persistence
121 Load(&channel_ids); 122 Load(&channel_ids);
122 ASSERT_EQ(2U, channel_ids.size()); 123 ASSERT_EQ(2U, channel_ids.size());
123 net::DefaultChannelIDStore::ChannelID* goog_channel_id; 124 net::DefaultChannelIDStore::ChannelID* goog_channel_id;
124 net::DefaultChannelIDStore::ChannelID* foo_channel_id; 125 net::DefaultChannelIDStore::ChannelID* foo_channel_id;
125 if (channel_ids[0]->server_identifier() == "google.com") { 126 if (channel_ids[0]->server_identifier() == "google.com") {
126 goog_channel_id = channel_ids[0]; 127 goog_channel_id = channel_ids[0];
127 foo_channel_id = channel_ids[1]; 128 foo_channel_id = channel_ids[1];
(...skipping 14 matching lines...) Expand all
142 143
143 // Now delete the channel ID and check persistence again. 144 // Now delete the channel ID and check persistence again.
144 store_->DeleteChannelID(*channel_ids[0]); 145 store_->DeleteChannelID(*channel_ids[0]);
145 store_->DeleteChannelID(*channel_ids[1]); 146 store_->DeleteChannelID(*channel_ids[1]);
146 store_ = NULL; 147 store_ = NULL;
147 // Make sure we wait until the destructor has run. 148 // Make sure we wait until the destructor has run.
148 base::RunLoop().RunUntilIdle(); 149 base::RunLoop().RunUntilIdle();
149 channel_ids.clear(); 150 channel_ids.clear();
150 store_ = new QuotaPolicyChannelIDStore( 151 store_ = new QuotaPolicyChannelIDStore(
151 temp_dir_.path().Append(kTestChannelIDFilename), 152 temp_dir_.path().Append(kTestChannelIDFilename),
152 base::MessageLoopProxy::current(), 153 base::ThreadTaskRunnerHandle::Get(),
153 NULL); 154 NULL);
154 155
155 // Reload and check if the channel ID has been removed. 156 // Reload and check if the channel ID has been removed.
156 Load(&channel_ids); 157 Load(&channel_ids);
157 ASSERT_EQ(0U, channel_ids.size()); 158 ASSERT_EQ(0U, channel_ids.size());
158 } 159 }
159 160
160 // Test if data is stored as expected in the QuotaPolicy database. 161 // Test if data is stored as expected in the QuotaPolicy database.
161 TEST_F(QuotaPolicyChannelIDStoreTest, TestPolicy) { 162 TEST_F(QuotaPolicyChannelIDStoreTest, TestPolicy) {
162 store_->AddChannelID( 163 store_->AddChannelID(
(...skipping 11 matching lines...) Expand all
174 // Make sure we wait until the destructor has run. 175 // Make sure we wait until the destructor has run.
175 base::RunLoop().RunUntilIdle(); 176 base::RunLoop().RunUntilIdle();
176 // Specify storage policy that makes "nonpersistent.com" session only. 177 // Specify storage policy that makes "nonpersistent.com" session only.
177 scoped_refptr<content::MockSpecialStoragePolicy> storage_policy = 178 scoped_refptr<content::MockSpecialStoragePolicy> storage_policy =
178 new content::MockSpecialStoragePolicy(); 179 new content::MockSpecialStoragePolicy();
179 storage_policy->AddSessionOnly( 180 storage_policy->AddSessionOnly(
180 net::cookie_util::CookieOriginToURL("nonpersistent.com", true)); 181 net::cookie_util::CookieOriginToURL("nonpersistent.com", true));
181 // Reload store, it should still have both channel IDs. 182 // Reload store, it should still have both channel IDs.
182 store_ = new QuotaPolicyChannelIDStore( 183 store_ = new QuotaPolicyChannelIDStore(
183 temp_dir_.path().Append(kTestChannelIDFilename), 184 temp_dir_.path().Append(kTestChannelIDFilename),
184 base::MessageLoopProxy::current(), 185 base::ThreadTaskRunnerHandle::Get(),
185 storage_policy); 186 storage_policy);
186 Load(&channel_ids); 187 Load(&channel_ids);
187 ASSERT_EQ(2U, channel_ids.size()); 188 ASSERT_EQ(2U, channel_ids.size());
188 189
189 // Add another two channel IDs before closing the store. Because additions are 190 // Add another two channel IDs before closing the store. Because additions are
190 // delayed and committed to disk in batches, these will not be committed until 191 // delayed and committed to disk in batches, these will not be committed until
191 // the store is destroyed, which is after the policy is applied. The pending 192 // the store is destroyed, which is after the policy is applied. The pending
192 // operation pruning logic should prevent the "nonpersistent.com" ID from 193 // operation pruning logic should prevent the "nonpersistent.com" ID from
193 // being committed to disk. 194 // being committed to disk.
194 store_->AddChannelID(net::DefaultChannelIDStore::ChannelID( 195 store_->AddChannelID(net::DefaultChannelIDStore::ChannelID(
195 "nonpersistent.com", base::Time::FromInternalValue(5), 196 "nonpersistent.com", base::Time::FromInternalValue(5),
196 base::Time::FromInternalValue(6), "e", "f")); 197 base::Time::FromInternalValue(6), "e", "f"));
197 store_->AddChannelID(net::DefaultChannelIDStore::ChannelID( 198 store_->AddChannelID(net::DefaultChannelIDStore::ChannelID(
198 "persistent.com", base::Time::FromInternalValue(7), 199 "persistent.com", base::Time::FromInternalValue(7),
199 base::Time::FromInternalValue(8), "g", "h")); 200 base::Time::FromInternalValue(8), "g", "h"));
200 201
201 // Now close the store, and the nonpersistent.com channel IDs should be 202 // Now close the store, and the nonpersistent.com channel IDs should be
202 // deleted according to policy. 203 // deleted according to policy.
203 store_ = NULL; 204 store_ = NULL;
204 // Make sure we wait until the destructor has run. 205 // Make sure we wait until the destructor has run.
205 base::RunLoop().RunUntilIdle(); 206 base::RunLoop().RunUntilIdle();
206 channel_ids.clear(); 207 channel_ids.clear();
207 store_ = new QuotaPolicyChannelIDStore( 208 store_ = new QuotaPolicyChannelIDStore(
208 temp_dir_.path().Append(kTestChannelIDFilename), 209 temp_dir_.path().Append(kTestChannelIDFilename),
209 base::MessageLoopProxy::current(), 210 base::ThreadTaskRunnerHandle::Get(),
210 NULL); 211 NULL);
211 212
212 // Reload and check that the nonpersistent.com channel IDs have been removed. 213 // Reload and check that the nonpersistent.com channel IDs have been removed.
213 Load(&channel_ids); 214 Load(&channel_ids);
214 ASSERT_EQ(2U, channel_ids.size()); 215 ASSERT_EQ(2U, channel_ids.size());
215 for (const auto& id : channel_ids) { 216 for (const auto& id : channel_ids) {
216 ASSERT_NE("nonpersistent.com", id->server_identifier()); 217 ASSERT_NE("nonpersistent.com", id->server_identifier());
217 } 218 }
218 } 219 }
OLDNEW
« no previous file with comments | « chrome/browser/net/nss_context.cc ('k') | chrome/browser/net/utility_process_mojo_proxy_resolver_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698