OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 | 7 |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "content/public/test/test_browser_thread.h" | 23 #include "content/public/test/test_browser_thread.h" |
24 #include "content/public/test/test_browser_thread_bundle.h" | 24 #include "content/public/test/test_browser_thread_bundle.h" |
25 #include "net/base/test_completion_callback.h" | 25 #include "net/base/test_completion_callback.h" |
26 #include "net/cookies/canonical_cookie.h" | 26 #include "net/cookies/canonical_cookie.h" |
27 #include "net/cookies/cookie_store.h" | 27 #include "net/cookies/cookie_store.h" |
28 #include "net/url_request/url_request_context.h" | 28 #include "net/url_request/url_request_context.h" |
29 #include "net/url_request/url_request_context_getter.h" | 29 #include "net/url_request/url_request_context_getter.h" |
30 #include "storage/browser/quota/quota_manager.h" | 30 #include "storage/browser/quota/quota_manager.h" |
31 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
32 | 32 |
| 33 #if defined(ENABLE_PLUGINS) |
| 34 #include "ppapi/shared_impl/ppapi_constants.h" |
| 35 #include "storage/browser/fileapi/async_file_util.h" |
| 36 #include "storage/browser/fileapi/file_system_context.h" |
| 37 #include "storage/browser/fileapi/file_system_operation_context.h" |
| 38 #include "storage/browser/fileapi/isolated_context.h" |
| 39 #endif // defined(ENABLE_PLUGINS) |
| 40 |
33 using net::CanonicalCookie; | 41 using net::CanonicalCookie; |
34 | 42 |
35 namespace content { | 43 namespace content { |
36 namespace { | 44 namespace { |
37 | 45 |
38 const int kDefaultClientId = 42; | 46 const int kDefaultClientId = 42; |
39 const char kCacheKey[] = "key"; | 47 const char kCacheKey[] = "key"; |
40 const char kCacheValue[] = "cached value"; | 48 const char kCacheValue[] = "cached value"; |
41 | 49 |
42 const char kTestOrigin1[] = "http://host1:1/"; | 50 const char kTestOrigin1[] = "http://host1:1/"; |
43 const char kTestOrigin2[] = "http://host2:1/"; | 51 const char kTestOrigin2[] = "http://host2:1/"; |
44 const char kTestOrigin3[] = "http://host3:1/"; | 52 const char kTestOrigin3[] = "http://host3:1/"; |
45 const char kTestOriginDevTools[] = "chrome-devtools://abcdefghijklmnopqrstuvw/"; | 53 const char kTestOriginDevTools[] = "chrome-devtools://abcdefghijklmnopqrstuvw/"; |
46 | 54 |
| 55 #if defined(ENABLE_PLUGINS) |
| 56 const char kWidevineCdmPluginId[] = "application_x-ppapi-widevine-cdm"; |
| 57 const char kClearKeyCdmPluginId[] = "application_x-ppapi-clearkey-cdm"; |
| 58 #endif // defined(ENABLE_PLUGINS) |
| 59 |
47 const GURL kOrigin1(kTestOrigin1); | 60 const GURL kOrigin1(kTestOrigin1); |
48 const GURL kOrigin2(kTestOrigin2); | 61 const GURL kOrigin2(kTestOrigin2); |
49 const GURL kOrigin3(kTestOrigin3); | 62 const GURL kOrigin3(kTestOrigin3); |
50 const GURL kOriginDevTools(kTestOriginDevTools); | 63 const GURL kOriginDevTools(kTestOriginDevTools); |
51 | 64 |
52 const base::FilePath::CharType kDomStorageOrigin1[] = | 65 const base::FilePath::CharType kDomStorageOrigin1[] = |
53 FILE_PATH_LITERAL("http_host1_1.localstorage"); | 66 FILE_PATH_LITERAL("http_host1_1.localstorage"); |
54 | 67 |
55 const base::FilePath::CharType kDomStorageOrigin2[] = | 68 const base::FilePath::CharType kDomStorageOrigin2[] = |
56 FILE_PATH_LITERAL("http_host2_1.localstorage"); | 69 FILE_PATH_LITERAL("http_host2_1.localstorage"); |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 TestBrowserContext* profile_; | 237 TestBrowserContext* profile_; |
225 content::DOMStorageContext* dom_storage_context_; | 238 content::DOMStorageContext* dom_storage_context_; |
226 | 239 |
227 std::vector<content::LocalStorageUsageInfo> infos_; | 240 std::vector<content::LocalStorageUsageInfo> infos_; |
228 | 241 |
229 AwaitCompletionHelper await_completion_; | 242 AwaitCompletionHelper await_completion_; |
230 | 243 |
231 DISALLOW_COPY_AND_ASSIGN(RemoveLocalStorageTester); | 244 DISALLOW_COPY_AND_ASSIGN(RemoveLocalStorageTester); |
232 }; | 245 }; |
233 | 246 |
| 247 #if defined(ENABLE_PLUGINS) |
| 248 class RemovePluginPrivateDataTester { |
| 249 public: |
| 250 explicit RemovePluginPrivateDataTester( |
| 251 storage::FileSystemContext* filesystem_context) |
| 252 : filesystem_context_(filesystem_context) {} |
| 253 |
| 254 // Add some files to the PluginPrivateFileSystem. They are created as follows: |
| 255 // kOrigin1 - ClearKey - 1 file - timestamp 10 days ago |
| 256 // kOrigin2 - Widevine - 2 files - timestamps now and 60 days ago |
| 257 void AddPluginPrivateTestData() { |
| 258 base::Time now = base::Time::Now(); |
| 259 base::Time ten_days_ago = now - base::TimeDelta::FromDays(10); |
| 260 base::Time sixty_days_ago = now - base::TimeDelta::FromDays(60); |
| 261 |
| 262 // Create a PluginPrivateFileSystem for ClearKey and add a single file |
| 263 // with a timestamp of 1 day ago. |
| 264 std::string clearkey_fsid = |
| 265 CreateFileSystem(kClearKeyCdmPluginId, kOrigin1); |
| 266 storage::FileSystemURL clearkey_file = |
| 267 CreateFile(kOrigin1, clearkey_fsid, "foo"); |
| 268 SetFileTimestamp(clearkey_file, ten_days_ago); |
| 269 |
| 270 // Create a second PluginPrivateFileSystem for Widevine and add two files |
| 271 // with different times. |
| 272 std::string widevine_fsid = |
| 273 CreateFileSystem(kWidevineCdmPluginId, kOrigin2); |
| 274 storage::FileSystemURL widevine_file1 = |
| 275 CreateFile(kOrigin2, widevine_fsid, "bar1"); |
| 276 storage::FileSystemURL widevine_file2 = |
| 277 CreateFile(kOrigin2, widevine_fsid, "bar2"); |
| 278 SetFileTimestamp(widevine_file1, now); |
| 279 SetFileTimestamp(widevine_file2, sixty_days_ago); |
| 280 } |
| 281 |
| 282 // Returns true, if the given origin exists in a PluginPrivateFileSystem. |
| 283 bool DataExistsForOrigin(const GURL& origin) { |
| 284 AwaitCompletionHelper await_completion; |
| 285 bool data_exists_for_origin = false; |
| 286 filesystem_context_->default_file_task_runner()->PostTask( |
| 287 FROM_HERE, base::Bind(&RemovePluginPrivateDataTester:: |
| 288 CheckIfDataExistsForOriginOnFileTaskRunner, |
| 289 base::Unretained(this), origin, |
| 290 &data_exists_for_origin, &await_completion)); |
| 291 await_completion.BlockUntilNotified(); |
| 292 return data_exists_for_origin; |
| 293 } |
| 294 |
| 295 private: |
| 296 // Creates a PluginPrivateFileSystem for the |plugin_name| and |origin| |
| 297 // provided. Returns the file system ID for the created |
| 298 // PluginPrivateFileSystem. |
| 299 std::string CreateFileSystem(const std::string& plugin_name, |
| 300 const GURL& origin) { |
| 301 AwaitCompletionHelper await_completion; |
| 302 std::string fsid = storage::IsolatedContext::GetInstance() |
| 303 ->RegisterFileSystemForVirtualPath( |
| 304 storage::kFileSystemTypePluginPrivate, |
| 305 ppapi::kPluginPrivateRootName, base::FilePath()); |
| 306 EXPECT_TRUE(storage::ValidateIsolatedFileSystemId(fsid)); |
| 307 filesystem_context_->OpenPluginPrivateFileSystem( |
| 308 origin, storage::kFileSystemTypePluginPrivate, fsid, plugin_name, |
| 309 storage::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, |
| 310 base::Bind(&RemovePluginPrivateDataTester::OnFileSystemOpened, |
| 311 base::Unretained(this), &await_completion)); |
| 312 await_completion.BlockUntilNotified(); |
| 313 return fsid; |
| 314 } |
| 315 |
| 316 // Creates a file named |file_name| in the PluginPrivateFileSystem identified |
| 317 // by |origin| and |fsid|. Returns the URL for the created file. The file |
| 318 // must not already exist or the test will fail. |
| 319 storage::FileSystemURL CreateFile(const GURL& origin, |
| 320 const std::string& fsid, |
| 321 const std::string& file_name) { |
| 322 AwaitCompletionHelper await_completion; |
| 323 std::string root = storage::GetIsolatedFileSystemRootURIString( |
| 324 origin, fsid, ppapi::kPluginPrivateRootName); |
| 325 storage::FileSystemURL file_url = |
| 326 filesystem_context_->CrackURL(GURL(root + file_name)); |
| 327 storage::AsyncFileUtil* file_util = filesystem_context_->GetAsyncFileUtil( |
| 328 storage::kFileSystemTypePluginPrivate); |
| 329 std::unique_ptr<storage::FileSystemOperationContext> operation_context = |
| 330 base::WrapUnique( |
| 331 new storage::FileSystemOperationContext(filesystem_context_)); |
| 332 operation_context->set_allowed_bytes_growth( |
| 333 storage::QuotaManager::kNoLimit); |
| 334 file_util->EnsureFileExists( |
| 335 std::move(operation_context), file_url, |
| 336 base::Bind(&RemovePluginPrivateDataTester::OnFileCreated, |
| 337 base::Unretained(this), &await_completion)); |
| 338 await_completion.BlockUntilNotified(); |
| 339 return file_url; |
| 340 } |
| 341 |
| 342 // Sets the last_access_time and last_modified_time to |time_stamp| on the |
| 343 // file specified by |file_url|. The file must already exist. |
| 344 void SetFileTimestamp(const storage::FileSystemURL& file_url, |
| 345 const base::Time& time_stamp) { |
| 346 AwaitCompletionHelper await_completion; |
| 347 storage::AsyncFileUtil* file_util = filesystem_context_->GetAsyncFileUtil( |
| 348 storage::kFileSystemTypePluginPrivate); |
| 349 std::unique_ptr<storage::FileSystemOperationContext> operation_context = |
| 350 base::WrapUnique( |
| 351 new storage::FileSystemOperationContext(filesystem_context_)); |
| 352 file_util->Touch(std::move(operation_context), file_url, time_stamp, |
| 353 time_stamp, |
| 354 base::Bind(&RemovePluginPrivateDataTester::OnFileTouched, |
| 355 base::Unretained(this), &await_completion)); |
| 356 await_completion.BlockUntilNotified(); |
| 357 } |
| 358 |
| 359 void OnFileSystemOpened(AwaitCompletionHelper* await_completion, |
| 360 base::File::Error result) { |
| 361 EXPECT_EQ(base::File::FILE_OK, result) << base::File::ErrorToString(result); |
| 362 await_completion->Notify(); |
| 363 } |
| 364 |
| 365 void OnFileCreated(AwaitCompletionHelper* await_completion, |
| 366 base::File::Error result, |
| 367 bool created) { |
| 368 EXPECT_EQ(base::File::FILE_OK, result) << base::File::ErrorToString(result); |
| 369 EXPECT_TRUE(created); |
| 370 await_completion->Notify(); |
| 371 } |
| 372 |
| 373 void OnFileTouched(AwaitCompletionHelper* await_completion, |
| 374 base::File::Error result) { |
| 375 EXPECT_EQ(base::File::FILE_OK, result) << base::File::ErrorToString(result); |
| 376 await_completion->Notify(); |
| 377 } |
| 378 |
| 379 // If |origin| exists in the PluginPrivateFileSystem, set |
| 380 // |data_exists_for_origin| to true, false otherwise. |
| 381 void CheckIfDataExistsForOriginOnFileTaskRunner( |
| 382 const GURL& origin, |
| 383 bool* data_exists_for_origin, |
| 384 AwaitCompletionHelper* await_completion) { |
| 385 storage::FileSystemBackend* backend = |
| 386 filesystem_context_->GetFileSystemBackend( |
| 387 storage::kFileSystemTypePluginPrivate); |
| 388 storage::FileSystemQuotaUtil* quota_util = backend->GetQuotaUtil(); |
| 389 |
| 390 // Determine the set of origins used. |
| 391 std::set<GURL> origins; |
| 392 quota_util->GetOriginsForTypeOnFileTaskRunner( |
| 393 storage::kFileSystemTypePluginPrivate, &origins); |
| 394 *data_exists_for_origin = origins.find(origin) != origins.end(); |
| 395 |
| 396 // AwaitCompletionHelper and MessageLoop don't work on a |
| 397 // SequencedTaskRunner, so post a task on the IO thread. |
| 398 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 399 base::Bind(&AwaitCompletionHelper::Notify, |
| 400 base::Unretained(await_completion))); |
| 401 } |
| 402 |
| 403 // We don't own this pointer. |
| 404 storage::FileSystemContext* filesystem_context_; |
| 405 |
| 406 DISALLOW_COPY_AND_ASSIGN(RemovePluginPrivateDataTester); |
| 407 }; |
| 408 #endif // defined(ENABLE_PLUGINS) |
| 409 |
234 bool IsWebSafeSchemeForTest(const std::string& scheme) { | 410 bool IsWebSafeSchemeForTest(const std::string& scheme) { |
235 return scheme == "http"; | 411 return scheme == "http"; |
236 } | 412 } |
237 | 413 |
238 bool DoesOriginMatchForUnprotectedWeb( | 414 bool DoesOriginMatchForUnprotectedWeb( |
239 const GURL& origin, | 415 const GURL& origin, |
240 storage::SpecialStoragePolicy* special_storage_policy) { | 416 storage::SpecialStoragePolicy* special_storage_policy) { |
241 if (IsWebSafeSchemeForTest(origin.scheme())) | 417 if (IsWebSafeSchemeForTest(origin.scheme())) |
242 return !special_storage_policy->IsStorageProtected(origin.GetOrigin()); | 418 return !special_storage_policy->IsStorageProtected(origin.GetOrigin()); |
243 | 419 |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 void ClearData(content::StoragePartition* partition, | 513 void ClearData(content::StoragePartition* partition, |
338 base::RunLoop* run_loop) { | 514 base::RunLoop* run_loop) { |
339 base::Time time; | 515 base::Time time; |
340 partition->ClearData( | 516 partition->ClearData( |
341 StoragePartition::REMOVE_DATA_MASK_SHADER_CACHE, | 517 StoragePartition::REMOVE_DATA_MASK_SHADER_CACHE, |
342 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, | 518 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, |
343 GURL(), StoragePartition::OriginMatcherFunction(), | 519 GURL(), StoragePartition::OriginMatcherFunction(), |
344 time, time, run_loop->QuitClosure()); | 520 time, time, run_loop->QuitClosure()); |
345 } | 521 } |
346 | 522 |
| 523 #if defined(ENABLE_PLUGINS) |
| 524 void ClearPluginPrivateData(content::StoragePartition* partition, |
| 525 const GURL& storage_origin, |
| 526 const base::Time delete_begin, |
| 527 const base::Time delete_end, |
| 528 base::RunLoop* run_loop) { |
| 529 partition->ClearData( |
| 530 StoragePartitionImpl::REMOVE_DATA_MASK_PLUGIN_PRIVATE_DATA, |
| 531 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, storage_origin, |
| 532 StoragePartition::OriginMatcherFunction(), delete_begin, delete_end, |
| 533 run_loop->QuitClosure()); |
| 534 } |
| 535 #endif // defined(ENABLE_PLUGINS) |
| 536 |
347 } // namespace | 537 } // namespace |
348 | 538 |
349 class StoragePartitionImplTest : public testing::Test { | 539 class StoragePartitionImplTest : public testing::Test { |
350 public: | 540 public: |
351 StoragePartitionImplTest() | 541 StoragePartitionImplTest() |
352 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), | 542 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), |
353 browser_context_(new TestBrowserContext()) { | 543 browser_context_(new TestBrowserContext()) {} |
354 } | |
355 | 544 |
356 MockQuotaManager* GetMockManager() { | 545 MockQuotaManager* GetMockManager() { |
357 if (!quota_manager_.get()) { | 546 if (!quota_manager_.get()) { |
358 quota_manager_ = new MockQuotaManager( | 547 quota_manager_ = new MockQuotaManager( |
359 browser_context_->IsOffTheRecord(), | 548 browser_context_->IsOffTheRecord(), |
360 browser_context_->GetPath(), | 549 browser_context_->GetPath(), |
361 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO).get(), | 550 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO).get(), |
362 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB).get(), | 551 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB).get(), |
363 browser_context_->GetSpecialStoragePolicy()); | 552 browser_context_->GetSpecialStoragePolicy()); |
364 } | 553 } |
(...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
968 base::Bind(&DoesOriginMatchForBothProtectedAndUnprotectedWeb), | 1157 base::Bind(&DoesOriginMatchForBothProtectedAndUnprotectedWeb), |
969 &run_loop)); | 1158 &run_loop)); |
970 run_loop.Run(); | 1159 run_loop.Run(); |
971 | 1160 |
972 // kOrigin1 and kOrigin2 do not have age more than a week. | 1161 // kOrigin1 and kOrigin2 do not have age more than a week. |
973 EXPECT_FALSE(tester.DOMStorageExistsForOrigin(kOrigin1)); | 1162 EXPECT_FALSE(tester.DOMStorageExistsForOrigin(kOrigin1)); |
974 EXPECT_FALSE(tester.DOMStorageExistsForOrigin(kOrigin2)); | 1163 EXPECT_FALSE(tester.DOMStorageExistsForOrigin(kOrigin2)); |
975 EXPECT_TRUE(tester.DOMStorageExistsForOrigin(kOrigin3)); | 1164 EXPECT_TRUE(tester.DOMStorageExistsForOrigin(kOrigin3)); |
976 } | 1165 } |
977 | 1166 |
| 1167 #if defined(ENABLE_PLUGINS) |
| 1168 TEST_F(StoragePartitionImplTest, RemovePluginPrivateDataForever) { |
| 1169 StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>( |
| 1170 BrowserContext::GetDefaultStoragePartition(browser_context())); |
| 1171 |
| 1172 RemovePluginPrivateDataTester tester(partition->GetFileSystemContext()); |
| 1173 tester.AddPluginPrivateTestData(); |
| 1174 EXPECT_TRUE(tester.DataExistsForOrigin(kOrigin1)); |
| 1175 EXPECT_TRUE(tester.DataExistsForOrigin(kOrigin2)); |
| 1176 |
| 1177 base::RunLoop run_loop; |
| 1178 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 1179 FROM_HERE, base::Bind(&ClearPluginPrivateData, partition, GURL(), |
| 1180 base::Time(), base::Time::Max(), &run_loop)); |
| 1181 run_loop.Run(); |
| 1182 |
| 1183 EXPECT_FALSE(tester.DataExistsForOrigin(kOrigin1)); |
| 1184 EXPECT_FALSE(tester.DataExistsForOrigin(kOrigin2)); |
| 1185 } |
| 1186 |
| 1187 TEST_F(StoragePartitionImplTest, RemovePluginPrivateDataLastWeek) { |
| 1188 StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>( |
| 1189 BrowserContext::GetDefaultStoragePartition(browser_context())); |
| 1190 base::Time a_week_ago = base::Time::Now() - base::TimeDelta::FromDays(7); |
| 1191 |
| 1192 RemovePluginPrivateDataTester tester(partition->GetFileSystemContext()); |
| 1193 tester.AddPluginPrivateTestData(); |
| 1194 EXPECT_TRUE(tester.DataExistsForOrigin(kOrigin1)); |
| 1195 EXPECT_TRUE(tester.DataExistsForOrigin(kOrigin2)); |
| 1196 |
| 1197 base::RunLoop run_loop; |
| 1198 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 1199 FROM_HERE, base::Bind(&ClearPluginPrivateData, partition, GURL(), |
| 1200 a_week_ago, base::Time::Max(), &run_loop)); |
| 1201 run_loop.Run(); |
| 1202 |
| 1203 // Origin1 has 1 file from 10 days ago, so it should remain around. |
| 1204 // Origin2 has a current file, so it should be removed (even though the |
| 1205 // second file is much older). |
| 1206 EXPECT_TRUE(tester.DataExistsForOrigin(kOrigin1)); |
| 1207 EXPECT_FALSE(tester.DataExistsForOrigin(kOrigin2)); |
| 1208 } |
| 1209 |
| 1210 TEST_F(StoragePartitionImplTest, RemovePluginPrivateDataForOrigin) { |
| 1211 StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>( |
| 1212 BrowserContext::GetDefaultStoragePartition(browser_context())); |
| 1213 |
| 1214 RemovePluginPrivateDataTester tester(partition->GetFileSystemContext()); |
| 1215 tester.AddPluginPrivateTestData(); |
| 1216 EXPECT_TRUE(tester.DataExistsForOrigin(kOrigin1)); |
| 1217 EXPECT_TRUE(tester.DataExistsForOrigin(kOrigin2)); |
| 1218 |
| 1219 base::RunLoop run_loop; |
| 1220 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 1221 FROM_HERE, base::Bind(&ClearPluginPrivateData, partition, kOrigin1, |
| 1222 base::Time(), base::Time::Max(), &run_loop)); |
| 1223 run_loop.Run(); |
| 1224 |
| 1225 // Only Origin1 should be deleted. |
| 1226 EXPECT_FALSE(tester.DataExistsForOrigin(kOrigin1)); |
| 1227 EXPECT_TRUE(tester.DataExistsForOrigin(kOrigin2)); |
| 1228 } |
| 1229 #endif // defined(ENABLE_PLUGINS) |
| 1230 |
978 TEST(StoragePartitionImplStaticTest, CreatePredicateForHostCookies) { | 1231 TEST(StoragePartitionImplStaticTest, CreatePredicateForHostCookies) { |
979 GURL url("http://www.example.com/"); | 1232 GURL url("http://www.example.com/"); |
980 GURL url2("https://www.example.com/"); | 1233 GURL url2("https://www.example.com/"); |
981 GURL url3("https://www.google.com/"); | 1234 GURL url3("https://www.google.com/"); |
982 | 1235 |
983 net::CookieOptions options; | 1236 net::CookieOptions options; |
984 net::CookieStore::CookiePredicate predicate = | 1237 net::CookieStore::CookiePredicate predicate = |
985 StoragePartitionImpl::CreatePredicateForHostCookies(url); | 1238 StoragePartitionImpl::CreatePredicateForHostCookies(url); |
986 | 1239 |
987 base::Time now = base::Time::Now(); | 1240 base::Time now = base::Time::Now(); |
988 std::vector<std::unique_ptr<CanonicalCookie>> valid_cookies; | 1241 std::vector<std::unique_ptr<CanonicalCookie>> valid_cookies; |
989 valid_cookies.push_back(CanonicalCookie::Create(url, "A=B", now, options)); | 1242 valid_cookies.push_back(CanonicalCookie::Create(url, "A=B", now, options)); |
990 valid_cookies.push_back(CanonicalCookie::Create(url, "C=F", now, options)); | 1243 valid_cookies.push_back(CanonicalCookie::Create(url, "C=F", now, options)); |
991 // We should match a different scheme with the same host. | 1244 // We should match a different scheme with the same host. |
992 valid_cookies.push_back(CanonicalCookie::Create(url2, "A=B", now, options)); | 1245 valid_cookies.push_back(CanonicalCookie::Create(url2, "A=B", now, options)); |
993 | 1246 |
994 std::vector<std::unique_ptr<CanonicalCookie>> invalid_cookies; | 1247 std::vector<std::unique_ptr<CanonicalCookie>> invalid_cookies; |
995 // We don't match domain cookies. | 1248 // We don't match domain cookies. |
996 invalid_cookies.push_back( | 1249 invalid_cookies.push_back( |
997 CanonicalCookie::Create(url2, "A=B;domain=.example.com", now, options)); | 1250 CanonicalCookie::Create(url2, "A=B;domain=.example.com", now, options)); |
998 invalid_cookies.push_back(CanonicalCookie::Create(url3, "A=B", now, options)); | 1251 invalid_cookies.push_back(CanonicalCookie::Create(url3, "A=B", now, options)); |
999 | 1252 |
1000 for (const auto& cookie : valid_cookies) | 1253 for (const auto& cookie : valid_cookies) |
1001 EXPECT_TRUE(predicate.Run(*cookie)) << cookie->DebugString(); | 1254 EXPECT_TRUE(predicate.Run(*cookie)) << cookie->DebugString(); |
1002 for (const auto& cookie : invalid_cookies) | 1255 for (const auto& cookie : invalid_cookies) |
1003 EXPECT_FALSE(predicate.Run(*cookie)) << cookie->DebugString(); | 1256 EXPECT_FALSE(predicate.Run(*cookie)) << cookie->DebugString(); |
1004 } | 1257 } |
1005 | 1258 |
1006 } // namespace content | 1259 } // namespace content |
OLD | NEW |