OLD | NEW |
---|---|
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" |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
107 | 107 |
108 ScopedVector<net::DefaultChannelIDStore::ChannelID> channel_ids; | 108 ScopedVector<net::DefaultChannelIDStore::ChannelID> channel_ids; |
109 // Replace the store effectively destroying the current one and forcing it | 109 // 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 | 110 // to write its data to disk. Then we can see if after loading it again it |
111 // is still there. | 111 // is still there. |
112 store_ = NULL; | 112 store_ = NULL; |
113 // Make sure we wait until the destructor has run. | 113 // Make sure we wait until the destructor has run. |
114 base::RunLoop().RunUntilIdle(); | 114 base::RunLoop().RunUntilIdle(); |
115 store_ = new QuotaPolicyChannelIDStore( | 115 store_ = new QuotaPolicyChannelIDStore( |
116 temp_dir_.path().Append(kTestChannelIDFilename), | 116 temp_dir_.path().Append(kTestChannelIDFilename), |
117 base::MessageLoopProxy::current(), | 117 base::ThreadTaskRunnerHandle::Get(), |
Ryan Sleevi
2015/05/04 18:11:27
IWYU: If you're going to change this, you need to
Pranay
2015/05/05 04:18:38
Done.
| |
118 NULL); | 118 NULL); |
119 | 119 |
120 // Reload and test for persistence | 120 // Reload and test for persistence |
121 Load(&channel_ids); | 121 Load(&channel_ids); |
122 ASSERT_EQ(2U, channel_ids.size()); | 122 ASSERT_EQ(2U, channel_ids.size()); |
123 net::DefaultChannelIDStore::ChannelID* goog_channel_id; | 123 net::DefaultChannelIDStore::ChannelID* goog_channel_id; |
124 net::DefaultChannelIDStore::ChannelID* foo_channel_id; | 124 net::DefaultChannelIDStore::ChannelID* foo_channel_id; |
125 if (channel_ids[0]->server_identifier() == "google.com") { | 125 if (channel_ids[0]->server_identifier() == "google.com") { |
126 goog_channel_id = channel_ids[0]; | 126 goog_channel_id = channel_ids[0]; |
127 foo_channel_id = channel_ids[1]; | 127 foo_channel_id = channel_ids[1]; |
(...skipping 14 matching lines...) Expand all Loading... | |
142 | 142 |
143 // Now delete the channel ID and check persistence again. | 143 // Now delete the channel ID and check persistence again. |
144 store_->DeleteChannelID(*channel_ids[0]); | 144 store_->DeleteChannelID(*channel_ids[0]); |
145 store_->DeleteChannelID(*channel_ids[1]); | 145 store_->DeleteChannelID(*channel_ids[1]); |
146 store_ = NULL; | 146 store_ = NULL; |
147 // Make sure we wait until the destructor has run. | 147 // Make sure we wait until the destructor has run. |
148 base::RunLoop().RunUntilIdle(); | 148 base::RunLoop().RunUntilIdle(); |
149 channel_ids.clear(); | 149 channel_ids.clear(); |
150 store_ = new QuotaPolicyChannelIDStore( | 150 store_ = new QuotaPolicyChannelIDStore( |
151 temp_dir_.path().Append(kTestChannelIDFilename), | 151 temp_dir_.path().Append(kTestChannelIDFilename), |
152 base::MessageLoopProxy::current(), | 152 base::ThreadTaskRunnerHandle::Get(), |
153 NULL); | 153 NULL); |
154 | 154 |
155 // Reload and check if the channel ID has been removed. | 155 // Reload and check if the channel ID has been removed. |
156 Load(&channel_ids); | 156 Load(&channel_ids); |
157 ASSERT_EQ(0U, channel_ids.size()); | 157 ASSERT_EQ(0U, channel_ids.size()); |
158 } | 158 } |
159 | 159 |
160 // Test if data is stored as expected in the QuotaPolicy database. | 160 // Test if data is stored as expected in the QuotaPolicy database. |
161 TEST_F(QuotaPolicyChannelIDStoreTest, TestPolicy) { | 161 TEST_F(QuotaPolicyChannelIDStoreTest, TestPolicy) { |
162 store_->AddChannelID( | 162 store_->AddChannelID( |
(...skipping 11 matching lines...) Expand all Loading... | |
174 // Make sure we wait until the destructor has run. | 174 // Make sure we wait until the destructor has run. |
175 base::RunLoop().RunUntilIdle(); | 175 base::RunLoop().RunUntilIdle(); |
176 // Specify storage policy that makes "nonpersistent.com" session only. | 176 // Specify storage policy that makes "nonpersistent.com" session only. |
177 scoped_refptr<content::MockSpecialStoragePolicy> storage_policy = | 177 scoped_refptr<content::MockSpecialStoragePolicy> storage_policy = |
178 new content::MockSpecialStoragePolicy(); | 178 new content::MockSpecialStoragePolicy(); |
179 storage_policy->AddSessionOnly( | 179 storage_policy->AddSessionOnly( |
180 net::cookie_util::CookieOriginToURL("nonpersistent.com", true)); | 180 net::cookie_util::CookieOriginToURL("nonpersistent.com", true)); |
181 // Reload store, it should still have both channel IDs. | 181 // Reload store, it should still have both channel IDs. |
182 store_ = new QuotaPolicyChannelIDStore( | 182 store_ = new QuotaPolicyChannelIDStore( |
183 temp_dir_.path().Append(kTestChannelIDFilename), | 183 temp_dir_.path().Append(kTestChannelIDFilename), |
184 base::MessageLoopProxy::current(), | 184 base::ThreadTaskRunnerHandle::Get(), |
185 storage_policy); | 185 storage_policy); |
186 Load(&channel_ids); | 186 Load(&channel_ids); |
187 ASSERT_EQ(2U, channel_ids.size()); | 187 ASSERT_EQ(2U, channel_ids.size()); |
188 | 188 |
189 // Add another two channel IDs before closing the store. Because additions are | 189 // 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 | 190 // 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 | 191 // the store is destroyed, which is after the policy is applied. The pending |
192 // operation pruning logic should prevent the "nonpersistent.com" ID from | 192 // operation pruning logic should prevent the "nonpersistent.com" ID from |
193 // being committed to disk. | 193 // being committed to disk. |
194 store_->AddChannelID(net::DefaultChannelIDStore::ChannelID( | 194 store_->AddChannelID(net::DefaultChannelIDStore::ChannelID( |
195 "nonpersistent.com", base::Time::FromInternalValue(5), | 195 "nonpersistent.com", base::Time::FromInternalValue(5), |
196 base::Time::FromInternalValue(6), "e", "f")); | 196 base::Time::FromInternalValue(6), "e", "f")); |
197 store_->AddChannelID(net::DefaultChannelIDStore::ChannelID( | 197 store_->AddChannelID(net::DefaultChannelIDStore::ChannelID( |
198 "persistent.com", base::Time::FromInternalValue(7), | 198 "persistent.com", base::Time::FromInternalValue(7), |
199 base::Time::FromInternalValue(8), "g", "h")); | 199 base::Time::FromInternalValue(8), "g", "h")); |
200 | 200 |
201 // Now close the store, and the nonpersistent.com channel IDs should be | 201 // Now close the store, and the nonpersistent.com channel IDs should be |
202 // deleted according to policy. | 202 // deleted according to policy. |
203 store_ = NULL; | 203 store_ = NULL; |
204 // Make sure we wait until the destructor has run. | 204 // Make sure we wait until the destructor has run. |
205 base::RunLoop().RunUntilIdle(); | 205 base::RunLoop().RunUntilIdle(); |
206 channel_ids.clear(); | 206 channel_ids.clear(); |
207 store_ = new QuotaPolicyChannelIDStore( | 207 store_ = new QuotaPolicyChannelIDStore( |
208 temp_dir_.path().Append(kTestChannelIDFilename), | 208 temp_dir_.path().Append(kTestChannelIDFilename), |
209 base::MessageLoopProxy::current(), | 209 base::ThreadTaskRunnerHandle::Get(), |
210 NULL); | 210 NULL); |
211 | 211 |
212 // Reload and check that the nonpersistent.com channel IDs have been removed. | 212 // Reload and check that the nonpersistent.com channel IDs have been removed. |
213 Load(&channel_ids); | 213 Load(&channel_ids); |
214 ASSERT_EQ(2U, channel_ids.size()); | 214 ASSERT_EQ(2U, channel_ids.size()); |
215 for (const auto& id : channel_ids) { | 215 for (const auto& id : channel_ids) { |
216 ASSERT_NE("nonpersistent.com", id->server_identifier()); | 216 ASSERT_NE("nonpersistent.com", id->server_identifier()); |
217 } | 217 } |
218 } | 218 } |
OLD | NEW |