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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 ASSERT_STREQ("a", goog_channel_id->private_key().c_str()); | 133 ASSERT_STREQ("a", goog_channel_id->private_key().c_str()); |
134 ASSERT_STREQ("b", goog_channel_id->cert().c_str()); | 134 ASSERT_STREQ("b", goog_channel_id->cert().c_str()); |
135 ASSERT_EQ(1, goog_channel_id->creation_time().ToInternalValue()); | 135 ASSERT_EQ(1, goog_channel_id->creation_time().ToInternalValue()); |
136 ASSERT_EQ(2, goog_channel_id->expiration_time().ToInternalValue()); | 136 ASSERT_EQ(2, goog_channel_id->expiration_time().ToInternalValue()); |
137 ASSERT_EQ("foo.com", foo_channel_id->server_identifier()); | 137 ASSERT_EQ("foo.com", foo_channel_id->server_identifier()); |
138 ASSERT_STREQ("c", foo_channel_id->private_key().c_str()); | 138 ASSERT_STREQ("c", foo_channel_id->private_key().c_str()); |
139 ASSERT_STREQ("d", foo_channel_id->cert().c_str()); | 139 ASSERT_STREQ("d", foo_channel_id->cert().c_str()); |
140 ASSERT_EQ(3, foo_channel_id->creation_time().ToInternalValue()); | 140 ASSERT_EQ(3, foo_channel_id->creation_time().ToInternalValue()); |
141 ASSERT_EQ(4, foo_channel_id->expiration_time().ToInternalValue()); | 141 ASSERT_EQ(4, foo_channel_id->expiration_time().ToInternalValue()); |
142 | 142 |
143 // Now delete the cert 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::MessageLoopProxy::current(), |
153 NULL); | 153 NULL); |
154 | 154 |
155 // Reload and check if the cert 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( |
163 net::DefaultChannelIDStore::ChannelID("foo.com", | 163 net::DefaultChannelIDStore::ChannelID("nonpersistent.com", |
164 base::Time::FromInternalValue(3), | 164 base::Time::FromInternalValue(3), |
165 base::Time::FromInternalValue(4), | 165 base::Time::FromInternalValue(4), |
166 "c", | 166 "c", |
167 "d")); | 167 "d")); |
168 | 168 |
169 ScopedVector<net::DefaultChannelIDStore::ChannelID> channel_ids; | 169 ScopedVector<net::DefaultChannelIDStore::ChannelID> channel_ids; |
170 // Replace the store effectively destroying the current one and forcing it | 170 // Replace the store effectively destroying the current one and forcing it |
171 // to write its data to disk. Then we can see if after loading it again it | 171 // to write its data to disk. Then we can see if after loading it again it |
172 // is still there. | 172 // is still there. |
173 store_ = NULL; | 173 store_ = NULL; |
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 "foo.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("foo.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::MessageLoopProxy::current(), |
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 // Now close the store, and "foo.com" should be deleted according to policy. | 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 |
| 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 |
| 193 // being committed to disk. |
| 194 store_->AddChannelID(net::DefaultChannelIDStore::ChannelID( |
| 195 "nonpersistent.com", base::Time::FromInternalValue(5), |
| 196 base::Time::FromInternalValue(6), "e", "f")); |
| 197 store_->AddChannelID(net::DefaultChannelIDStore::ChannelID( |
| 198 "persistent.com", base::Time::FromInternalValue(7), |
| 199 base::Time::FromInternalValue(8), "g", "h")); |
| 200 |
| 201 // Now close the store, and the nonpersistent.com channel IDs should be |
| 202 // deleted according to policy. |
190 store_ = NULL; | 203 store_ = NULL; |
191 // Make sure we wait until the destructor has run. | 204 // Make sure we wait until the destructor has run. |
192 base::RunLoop().RunUntilIdle(); | 205 base::RunLoop().RunUntilIdle(); |
193 channel_ids.clear(); | 206 channel_ids.clear(); |
194 store_ = new QuotaPolicyChannelIDStore( | 207 store_ = new QuotaPolicyChannelIDStore( |
195 temp_dir_.path().Append(kTestChannelIDFilename), | 208 temp_dir_.path().Append(kTestChannelIDFilename), |
196 base::MessageLoopProxy::current(), | 209 base::MessageLoopProxy::current(), |
197 NULL); | 210 NULL); |
198 | 211 |
199 // Reload and check that the "foo.com" cert has been removed. | 212 // Reload and check that the nonpersistent.com channel IDs have been removed. |
200 Load(&channel_ids); | 213 Load(&channel_ids); |
201 ASSERT_EQ(1U, channel_ids.size()); | 214 ASSERT_EQ(2U, channel_ids.size()); |
202 ASSERT_EQ("google.com", channel_ids[0]->server_identifier()); | 215 for (const auto& id : channel_ids) { |
| 216 ASSERT_NE("nonpersistent.com", id->server_identifier()); |
| 217 } |
203 } | 218 } |
OLD | NEW |