Chromium Code Reviews| 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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 153 NULL); | 153 NULL); |
| 154 | 154 |
| 155 // Reload and check if the cert has been removed. | 155 // Reload and check if the cert 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 |
| 190 // are delayed and committed to disk in batches, these will not be committed | |
| 191 // until the store is destroyed, which is after the policy is applied. The | |
| 192 // pending operation pruning logic should prevent the "nonpersistent.com" ID | |
| 193 // from being committed to disk. | |
| 194 store_->AddChannelID(net::DefaultChannelIDStore::ChannelID( | |
| 195 "nonpersistent.com", base::Time::FromInternalValue(5), | |
| 196 base::Time::FromInternalValue(6), "e", "f")); | |
|
Ryan Sleevi
2015/04/06 18:46:55
I'm not actually sure that this is valid / consist
rohitrao (ping after 24h)
2015/04/06 19:48:24
Ah, ok. I don't actually know what channel ids ar
| |
| 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 session-only IDs should be deleted according | |
| 202 // 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 proper IDs have been removed. |
|
mef
2015/04/06 20:17:44
maybe say 'proper (nonpersistent.com)'?
rohitrao (ping after 24h)
2015/04/07 14:21:37
Done.
| |
| 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 |