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 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 std::string widevine_fsid = | 274 std::string widevine_fsid = |
275 CreateFileSystem(kWidevineCdmPluginId, kOrigin2); | 275 CreateFileSystem(kWidevineCdmPluginId, kOrigin2); |
276 storage::FileSystemURL widevine_file1 = | 276 storage::FileSystemURL widevine_file1 = |
277 CreateFile(kOrigin2, widevine_fsid, "bar1"); | 277 CreateFile(kOrigin2, widevine_fsid, "bar1"); |
278 storage::FileSystemURL widevine_file2 = | 278 storage::FileSystemURL widevine_file2 = |
279 CreateFile(kOrigin2, widevine_fsid, "bar2"); | 279 CreateFile(kOrigin2, widevine_fsid, "bar2"); |
280 SetFileTimestamp(widevine_file1, now); | 280 SetFileTimestamp(widevine_file1, now); |
281 SetFileTimestamp(widevine_file2, sixty_days_ago); | 281 SetFileTimestamp(widevine_file2, sixty_days_ago); |
282 } | 282 } |
283 | 283 |
| 284 void DeleteClearKeyTestData() { DeleteFile(clearkey_file_); } |
| 285 |
284 // Returns true, if the given origin exists in a PluginPrivateFileSystem. | 286 // Returns true, if the given origin exists in a PluginPrivateFileSystem. |
285 bool DataExistsForOrigin(const GURL& origin) { | 287 bool DataExistsForOrigin(const GURL& origin) { |
286 AwaitCompletionHelper await_completion; | 288 AwaitCompletionHelper await_completion; |
287 bool data_exists_for_origin = false; | 289 bool data_exists_for_origin = false; |
288 filesystem_context_->default_file_task_runner()->PostTask( | 290 filesystem_context_->default_file_task_runner()->PostTask( |
289 FROM_HERE, base::Bind(&RemovePluginPrivateDataTester:: | 291 FROM_HERE, base::Bind(&RemovePluginPrivateDataTester:: |
290 CheckIfDataExistsForOriginOnFileTaskRunner, | 292 CheckIfDataExistsForOriginOnFileTaskRunner, |
291 base::Unretained(this), origin, | 293 base::Unretained(this), origin, |
292 &data_exists_for_origin, &await_completion)); | 294 &data_exists_for_origin, &await_completion)); |
293 await_completion.BlockUntilNotified(); | 295 await_completion.BlockUntilNotified(); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 operation_context->set_allowed_bytes_growth( | 356 operation_context->set_allowed_bytes_growth( |
355 storage::QuotaManager::kNoLimit); | 357 storage::QuotaManager::kNoLimit); |
356 file_util->EnsureFileExists( | 358 file_util->EnsureFileExists( |
357 std::move(operation_context), file_url, | 359 std::move(operation_context), file_url, |
358 base::Bind(&RemovePluginPrivateDataTester::OnFileCreated, | 360 base::Bind(&RemovePluginPrivateDataTester::OnFileCreated, |
359 base::Unretained(this), &await_completion)); | 361 base::Unretained(this), &await_completion)); |
360 await_completion.BlockUntilNotified(); | 362 await_completion.BlockUntilNotified(); |
361 return file_url; | 363 return file_url; |
362 } | 364 } |
363 | 365 |
| 366 void DeleteFile(storage::FileSystemURL file_url) { |
| 367 AwaitCompletionHelper await_completion; |
| 368 storage::AsyncFileUtil* file_util = filesystem_context_->GetAsyncFileUtil( |
| 369 storage::kFileSystemTypePluginPrivate); |
| 370 std::unique_ptr<storage::FileSystemOperationContext> operation_context = |
| 371 base::MakeUnique<storage::FileSystemOperationContext>( |
| 372 filesystem_context_); |
| 373 file_util->DeleteFile( |
| 374 std::move(operation_context), file_url, |
| 375 base::Bind(&RemovePluginPrivateDataTester::OnFileDeleted, |
| 376 base::Unretained(this), &await_completion)); |
| 377 await_completion.BlockUntilNotified(); |
| 378 } |
| 379 |
364 // Sets the last_access_time and last_modified_time to |time_stamp| on the | 380 // Sets the last_access_time and last_modified_time to |time_stamp| on the |
365 // file specified by |file_url|. The file must already exist. | 381 // file specified by |file_url|. The file must already exist. |
366 void SetFileTimestamp(const storage::FileSystemURL& file_url, | 382 void SetFileTimestamp(const storage::FileSystemURL& file_url, |
367 const base::Time& time_stamp) { | 383 const base::Time& time_stamp) { |
368 AwaitCompletionHelper await_completion; | 384 AwaitCompletionHelper await_completion; |
369 storage::AsyncFileUtil* file_util = filesystem_context_->GetAsyncFileUtil( | 385 storage::AsyncFileUtil* file_util = filesystem_context_->GetAsyncFileUtil( |
370 storage::kFileSystemTypePluginPrivate); | 386 storage::kFileSystemTypePluginPrivate); |
371 std::unique_ptr<storage::FileSystemOperationContext> operation_context = | 387 std::unique_ptr<storage::FileSystemOperationContext> operation_context = |
372 base::MakeUnique<storage::FileSystemOperationContext>( | 388 base::MakeUnique<storage::FileSystemOperationContext>( |
373 filesystem_context_); | 389 filesystem_context_); |
(...skipping 11 matching lines...) Expand all Loading... |
385 } | 401 } |
386 | 402 |
387 void OnFileCreated(AwaitCompletionHelper* await_completion, | 403 void OnFileCreated(AwaitCompletionHelper* await_completion, |
388 base::File::Error result, | 404 base::File::Error result, |
389 bool created) { | 405 bool created) { |
390 EXPECT_EQ(base::File::FILE_OK, result) << base::File::ErrorToString(result); | 406 EXPECT_EQ(base::File::FILE_OK, result) << base::File::ErrorToString(result); |
391 EXPECT_TRUE(created); | 407 EXPECT_TRUE(created); |
392 await_completion->Notify(); | 408 await_completion->Notify(); |
393 } | 409 } |
394 | 410 |
| 411 void OnFileDeleted(AwaitCompletionHelper* await_completion, |
| 412 base::File::Error result) { |
| 413 EXPECT_EQ(base::File::FILE_OK, result) << base::File::ErrorToString(result); |
| 414 await_completion->Notify(); |
| 415 } |
| 416 |
395 void OnFileTouched(AwaitCompletionHelper* await_completion, | 417 void OnFileTouched(AwaitCompletionHelper* await_completion, |
396 base::File::Error result) { | 418 base::File::Error result) { |
397 EXPECT_EQ(base::File::FILE_OK, result) << base::File::ErrorToString(result); | 419 EXPECT_EQ(base::File::FILE_OK, result) << base::File::ErrorToString(result); |
398 await_completion->Notify(); | 420 await_completion->Notify(); |
399 } | 421 } |
400 | 422 |
401 void OnFileOpened(base::File* file_result, | 423 void OnFileOpened(base::File* file_result, |
402 AwaitCompletionHelper* await_completion, | 424 AwaitCompletionHelper* await_completion, |
403 base::File file, | 425 base::File file, |
404 const base::Closure& on_close_callback) { | 426 const base::Closure& on_close_callback) { |
(...skipping 21 matching lines...) Expand all Loading... |
426 // AwaitCompletionHelper and MessageLoop don't work on a | 448 // AwaitCompletionHelper and MessageLoop don't work on a |
427 // SequencedTaskRunner, so post a task on the IO thread. | 449 // SequencedTaskRunner, so post a task on the IO thread. |
428 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 450 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
429 base::Bind(&AwaitCompletionHelper::Notify, | 451 base::Bind(&AwaitCompletionHelper::Notify, |
430 base::Unretained(await_completion))); | 452 base::Unretained(await_completion))); |
431 } | 453 } |
432 | 454 |
433 // We don't own this pointer. | 455 // We don't own this pointer. |
434 storage::FileSystemContext* filesystem_context_; | 456 storage::FileSystemContext* filesystem_context_; |
435 | 457 |
436 // Keep track of the URL for the ClearKey file so that it can be written to. | 458 // Keep track of the URL for the ClearKey file so that it can be written to |
| 459 // or deleted. |
437 storage::FileSystemURL clearkey_file_; | 460 storage::FileSystemURL clearkey_file_; |
438 | 461 |
439 DISALLOW_COPY_AND_ASSIGN(RemovePluginPrivateDataTester); | 462 DISALLOW_COPY_AND_ASSIGN(RemovePluginPrivateDataTester); |
440 }; | 463 }; |
441 #endif // BUILDFLAG(ENABLE_PLUGINS) | 464 #endif // BUILDFLAG(ENABLE_PLUGINS) |
442 | 465 |
443 bool IsWebSafeSchemeForTest(const std::string& scheme) { | 466 bool IsWebSafeSchemeForTest(const std::string& scheme) { |
444 return scheme == "http"; | 467 return scheme == "http"; |
445 } | 468 } |
446 | 469 |
(...skipping 839 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1286 EXPECT_FALSE(tester.DataExistsForOrigin(kOrigin1)); | 1309 EXPECT_FALSE(tester.DataExistsForOrigin(kOrigin1)); |
1287 EXPECT_FALSE(tester.DataExistsForOrigin(kOrigin2)); | 1310 EXPECT_FALSE(tester.DataExistsForOrigin(kOrigin2)); |
1288 | 1311 |
1289 const char more_data[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; | 1312 const char more_data[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; |
1290 EXPECT_EQ(static_cast<int>(arraysize(more_data)), | 1313 EXPECT_EQ(static_cast<int>(arraysize(more_data)), |
1291 file.WriteAtCurrentPos(more_data, arraysize(more_data))); | 1314 file.WriteAtCurrentPos(more_data, arraysize(more_data))); |
1292 | 1315 |
1293 base::File file2 = tester.OpenClearKeyFileForWrite(); | 1316 base::File file2 = tester.OpenClearKeyFileForWrite(); |
1294 EXPECT_FALSE(file2.IsValid()); | 1317 EXPECT_FALSE(file2.IsValid()); |
1295 } | 1318 } |
| 1319 |
| 1320 TEST_F(StoragePartitionImplTest, RemovePluginPrivateDataAfterDeletion) { |
| 1321 StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>( |
| 1322 BrowserContext::GetDefaultStoragePartition(browser_context())); |
| 1323 |
| 1324 RemovePluginPrivateDataTester tester(partition->GetFileSystemContext()); |
| 1325 tester.AddPluginPrivateTestData(); |
| 1326 EXPECT_TRUE(tester.DataExistsForOrigin(kOrigin1)); |
| 1327 EXPECT_TRUE(tester.DataExistsForOrigin(kOrigin2)); |
| 1328 |
| 1329 // Delete the single file saved for |kOrigin1|. This does not remove the |
| 1330 // origin from the list of Origins. However, ClearPluginPrivateData() will |
| 1331 // remove it. |
| 1332 tester.DeleteClearKeyTestData(); |
| 1333 EXPECT_TRUE(tester.DataExistsForOrigin(kOrigin1)); |
| 1334 EXPECT_TRUE(tester.DataExistsForOrigin(kOrigin2)); |
| 1335 |
| 1336 base::RunLoop run_loop; |
| 1337 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 1338 FROM_HERE, base::Bind(&ClearPluginPrivateData, partition, GURL(), |
| 1339 base::Time(), base::Time::Max(), &run_loop)); |
| 1340 run_loop.Run(); |
| 1341 |
| 1342 EXPECT_FALSE(tester.DataExistsForOrigin(kOrigin1)); |
| 1343 EXPECT_FALSE(tester.DataExistsForOrigin(kOrigin2)); |
| 1344 } |
1296 #endif // BUILDFLAG(ENABLE_PLUGINS) | 1345 #endif // BUILDFLAG(ENABLE_PLUGINS) |
1297 | 1346 |
1298 TEST(StoragePartitionImplStaticTest, CreatePredicateForHostCookies) { | 1347 TEST(StoragePartitionImplStaticTest, CreatePredicateForHostCookies) { |
1299 GURL url("http://www.example.com/"); | 1348 GURL url("http://www.example.com/"); |
1300 GURL url2("https://www.example.com/"); | 1349 GURL url2("https://www.example.com/"); |
1301 GURL url3("https://www.google.com/"); | 1350 GURL url3("https://www.google.com/"); |
1302 | 1351 |
1303 net::CookieOptions options; | 1352 net::CookieOptions options; |
1304 net::CookieStore::CookiePredicate predicate = | 1353 net::CookieStore::CookiePredicate predicate = |
1305 StoragePartitionImpl::CreatePredicateForHostCookies(url); | 1354 StoragePartitionImpl::CreatePredicateForHostCookies(url); |
(...skipping 11 matching lines...) Expand all Loading... |
1317 CanonicalCookie::Create(url2, "A=B;domain=.example.com", now, options)); | 1366 CanonicalCookie::Create(url2, "A=B;domain=.example.com", now, options)); |
1318 invalid_cookies.push_back(CanonicalCookie::Create(url3, "A=B", now, options)); | 1367 invalid_cookies.push_back(CanonicalCookie::Create(url3, "A=B", now, options)); |
1319 | 1368 |
1320 for (const auto& cookie : valid_cookies) | 1369 for (const auto& cookie : valid_cookies) |
1321 EXPECT_TRUE(predicate.Run(*cookie)) << cookie->DebugString(); | 1370 EXPECT_TRUE(predicate.Run(*cookie)) << cookie->DebugString(); |
1322 for (const auto& cookie : invalid_cookies) | 1371 for (const auto& cookie : invalid_cookies) |
1323 EXPECT_FALSE(predicate.Run(*cookie)) << cookie->DebugString(); | 1372 EXPECT_FALSE(predicate.Run(*cookie)) << cookie->DebugString(); |
1324 } | 1373 } |
1325 | 1374 |
1326 } // namespace content | 1375 } // namespace content |
OLD | NEW |