Chromium Code Reviews| 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 #include "storage/common/fileapi/file_system_util.h" | |
| 40 #endif // defined(ENABLE_PLUGINS) | |
| 41 | |
| 33 using net::CanonicalCookie; | 42 using net::CanonicalCookie; |
| 34 | 43 |
| 35 namespace content { | 44 namespace content { |
| 36 namespace { | 45 namespace { |
| 37 | 46 |
| 38 const int kDefaultClientId = 42; | 47 const int kDefaultClientId = 42; |
| 39 const char kCacheKey[] = "key"; | 48 const char kCacheKey[] = "key"; |
| 40 const char kCacheValue[] = "cached value"; | 49 const char kCacheValue[] = "cached value"; |
| 41 | 50 |
| 42 const char kTestOrigin1[] = "http://host1:1/"; | 51 const char kTestOrigin1[] = "http://host1:1/"; |
| 43 const char kTestOrigin2[] = "http://host2:1/"; | 52 const char kTestOrigin2[] = "http://host2:1/"; |
| 44 const char kTestOrigin3[] = "http://host3:1/"; | 53 const char kTestOrigin3[] = "http://host3:1/"; |
| 45 const char kTestOriginDevTools[] = "chrome-devtools://abcdefghijklmnopqrstuvw/"; | 54 const char kTestOriginDevTools[] = "chrome-devtools://abcdefghijklmnopqrstuvw/"; |
| 46 | 55 |
| 56 #if defined(ENABLE_PLUGINS) | |
| 57 const char kWidevineCdmPluginId[] = "application_x-ppapi-widevine-cdm"; | |
| 58 const char kClearKeyCdmPluginId[] = "application_x-ppapi-clearkey-cdm"; | |
| 59 #endif // defined(ENABLE_PLUGINS) | |
| 60 | |
| 47 const GURL kOrigin1(kTestOrigin1); | 61 const GURL kOrigin1(kTestOrigin1); |
| 48 const GURL kOrigin2(kTestOrigin2); | 62 const GURL kOrigin2(kTestOrigin2); |
| 49 const GURL kOrigin3(kTestOrigin3); | 63 const GURL kOrigin3(kTestOrigin3); |
| 50 const GURL kOriginDevTools(kTestOriginDevTools); | 64 const GURL kOriginDevTools(kTestOriginDevTools); |
| 51 | 65 |
| 52 const base::FilePath::CharType kDomStorageOrigin1[] = | 66 const base::FilePath::CharType kDomStorageOrigin1[] = |
| 53 FILE_PATH_LITERAL("http_host1_1.localstorage"); | 67 FILE_PATH_LITERAL("http_host1_1.localstorage"); |
| 54 | 68 |
| 55 const base::FilePath::CharType kDomStorageOrigin2[] = | 69 const base::FilePath::CharType kDomStorageOrigin2[] = |
| 56 FILE_PATH_LITERAL("http_host2_1.localstorage"); | 70 FILE_PATH_LITERAL("http_host2_1.localstorage"); |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 224 TestBrowserContext* profile_; | 238 TestBrowserContext* profile_; |
| 225 content::DOMStorageContext* dom_storage_context_; | 239 content::DOMStorageContext* dom_storage_context_; |
| 226 | 240 |
| 227 std::vector<content::LocalStorageUsageInfo> infos_; | 241 std::vector<content::LocalStorageUsageInfo> infos_; |
| 228 | 242 |
| 229 AwaitCompletionHelper await_completion_; | 243 AwaitCompletionHelper await_completion_; |
| 230 | 244 |
| 231 DISALLOW_COPY_AND_ASSIGN(RemoveLocalStorageTester); | 245 DISALLOW_COPY_AND_ASSIGN(RemoveLocalStorageTester); |
| 232 }; | 246 }; |
| 233 | 247 |
| 248 #if defined(ENABLE_PLUGINS) | |
| 249 class RemovePluginPrivateDataTester { | |
| 250 public: | |
| 251 explicit RemovePluginPrivateDataTester( | |
| 252 storage::FileSystemContext* filesystem_context) | |
| 253 : filesystem_context_(filesystem_context) {} | |
| 254 | |
| 255 // Add some files to the PluginPrivateFileSystem. They are created as follows: | |
| 256 // kOrigin1 - ClearKey - 1 file - timestamp 10 days ago | |
| 257 // kOrigin2 - Widevine - 2 files - timestamps now and 60 days ago | |
| 258 void AddPluginPrivateTestData() { | |
| 259 base::Time now = base::Time::Now(); | |
| 260 base::Time ten_days_ago = now - base::TimeDelta::FromDays(10); | |
| 261 base::Time sixty_days_ago = now - base::TimeDelta::FromDays(60); | |
| 262 | |
| 263 // Create a PluginPrivateFileSystem for ClearKey and add a single file | |
| 264 // with a timestamp of 1 day ago. | |
| 265 std::string clearkey_fsid = | |
| 266 CreateFileSystem(kClearKeyCdmPluginId, kOrigin1); | |
| 267 clearkey_file_ = 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 // Opens the file created for ClearKey (in kOrigin1) for writing. Caller | |
| 296 // needs to verify if the file was opened or not. | |
| 297 base::File OpenClearKeyFileForWrite() { | |
| 298 AwaitCompletionHelper await_completion; | |
| 299 base::File file; | |
| 300 storage::AsyncFileUtil* async_file_util = | |
| 301 filesystem_context_->GetAsyncFileUtil( | |
| 302 storage::kFileSystemTypePluginPrivate); | |
| 303 std::unique_ptr<storage::FileSystemOperationContext> operation_context = | |
| 304 base::WrapUnique( | |
| 305 new storage::FileSystemOperationContext(filesystem_context_)); | |
| 306 async_file_util->CreateOrOpen( | |
| 307 std::move(operation_context), clearkey_file_, | |
| 308 base::File::FLAG_OPEN | base::File::FLAG_WRITE, | |
| 309 base::Bind(&RemovePluginPrivateDataTester::OnFileOpened, | |
| 310 base::Unretained(this), &file, &await_completion)); | |
| 311 await_completion.BlockUntilNotified(); | |
| 312 return file; | |
| 313 } | |
| 314 | |
| 315 private: | |
| 316 // Creates a PluginPrivateFileSystem for the |plugin_name| and |origin| | |
| 317 // provided. Returns the file system ID for the created | |
| 318 // PluginPrivateFileSystem. | |
| 319 std::string CreateFileSystem(const std::string& plugin_name, | |
| 320 const GURL& origin) { | |
| 321 AwaitCompletionHelper await_completion; | |
| 322 std::string fsid = storage::IsolatedContext::GetInstance() | |
| 323 ->RegisterFileSystemForVirtualPath( | |
| 324 storage::kFileSystemTypePluginPrivate, | |
| 325 ppapi::kPluginPrivateRootName, base::FilePath()); | |
| 326 EXPECT_TRUE(storage::ValidateIsolatedFileSystemId(fsid)); | |
| 327 filesystem_context_->OpenPluginPrivateFileSystem( | |
| 328 origin, storage::kFileSystemTypePluginPrivate, fsid, plugin_name, | |
| 329 storage::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, | |
| 330 base::Bind(&RemovePluginPrivateDataTester::OnFileSystemOpened, | |
| 331 base::Unretained(this), &await_completion)); | |
| 332 await_completion.BlockUntilNotified(); | |
| 333 return fsid; | |
| 334 } | |
| 335 | |
| 336 // Creates a file named |file_name| in the PluginPrivateFileSystem identified | |
| 337 // by |origin| and |fsid|. Returns the URL for the created file. The file | |
| 338 // must not already exist or the test will fail. | |
| 339 storage::FileSystemURL CreateFile(const GURL& origin, | |
| 340 const std::string& fsid, | |
| 341 const std::string& file_name) { | |
| 342 AwaitCompletionHelper await_completion; | |
| 343 std::string root = storage::GetIsolatedFileSystemRootURIString( | |
| 344 origin, fsid, ppapi::kPluginPrivateRootName); | |
| 345 storage::FileSystemURL file_url = | |
| 346 filesystem_context_->CrackURL(GURL(root + file_name)); | |
| 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 operation_context->set_allowed_bytes_growth( | |
| 353 storage::QuotaManager::kNoLimit); | |
| 354 file_util->EnsureFileExists( | |
| 355 std::move(operation_context), file_url, | |
| 356 base::Bind(&RemovePluginPrivateDataTester::OnFileCreated, | |
| 357 base::Unretained(this), &await_completion)); | |
| 358 await_completion.BlockUntilNotified(); | |
| 359 return file_url; | |
| 360 } | |
| 361 | |
| 362 // Sets the last_access_time and last_modified_time to |time_stamp| on the | |
| 363 // file specified by |file_url|. The file must already exist. | |
| 364 void SetFileTimestamp(const storage::FileSystemURL& file_url, | |
| 365 const base::Time& time_stamp) { | |
| 366 AwaitCompletionHelper await_completion; | |
| 367 storage::AsyncFileUtil* file_util = filesystem_context_->GetAsyncFileUtil( | |
| 368 storage::kFileSystemTypePluginPrivate); | |
| 369 std::unique_ptr<storage::FileSystemOperationContext> operation_context = | |
| 370 base::WrapUnique( | |
| 371 new storage::FileSystemOperationContext(filesystem_context_)); | |
| 372 file_util->Touch(std::move(operation_context), file_url, time_stamp, | |
| 373 time_stamp, | |
| 374 base::Bind(&RemovePluginPrivateDataTester::OnFileTouched, | |
| 375 base::Unretained(this), &await_completion)); | |
| 376 await_completion.BlockUntilNotified(); | |
| 377 } | |
| 378 | |
| 379 void OnFileSystemOpened(AwaitCompletionHelper* await_completion, | |
| 380 base::File::Error result) { | |
| 381 EXPECT_EQ(base::File::FILE_OK, result) << base::File::ErrorToString(result); | |
| 382 await_completion->Notify(); | |
| 383 } | |
| 384 | |
| 385 void OnFileCreated(AwaitCompletionHelper* await_completion, | |
| 386 base::File::Error result, | |
| 387 bool created) { | |
| 388 EXPECT_EQ(base::File::FILE_OK, result) << base::File::ErrorToString(result); | |
| 389 EXPECT_TRUE(created); | |
| 390 await_completion->Notify(); | |
| 391 } | |
| 392 | |
| 393 void OnFileTouched(AwaitCompletionHelper* await_completion, | |
| 394 base::File::Error result) { | |
| 395 EXPECT_EQ(base::File::FILE_OK, result) << base::File::ErrorToString(result); | |
| 396 await_completion->Notify(); | |
| 397 } | |
| 398 | |
| 399 void OnFileOpened(base::File* file_result, | |
| 400 AwaitCompletionHelper* await_completion, | |
| 401 base::File file, | |
| 402 const base::Closure& on_close_callback) { | |
| 403 *file_result = std::move(file); | |
| 404 await_completion->Notify(); | |
| 405 } | |
| 406 | |
| 407 // If |origin| exists in the PluginPrivateFileSystem, set | |
| 408 // |data_exists_for_origin| to true, false otherwise. | |
| 409 void CheckIfDataExistsForOriginOnFileTaskRunner( | |
| 410 const GURL& origin, | |
| 411 bool* data_exists_for_origin, | |
| 412 AwaitCompletionHelper* await_completion) { | |
| 413 storage::FileSystemBackend* backend = | |
| 414 filesystem_context_->GetFileSystemBackend( | |
| 415 storage::kFileSystemTypePluginPrivate); | |
| 416 storage::FileSystemQuotaUtil* quota_util = backend->GetQuotaUtil(); | |
| 417 | |
| 418 // Determine the set of origins used. | |
| 419 std::set<GURL> origins; | |
| 420 quota_util->GetOriginsForTypeOnFileTaskRunner( | |
| 421 storage::kFileSystemTypePluginPrivate, &origins); | |
| 422 *data_exists_for_origin = origins.find(origin) != origins.end(); | |
| 423 | |
| 424 // AwaitCompletionHelper and MessageLoop don't work on a | |
| 425 // SequencedTaskRunner, so post a task on the IO thread. | |
| 426 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | |
| 427 base::Bind(&AwaitCompletionHelper::Notify, | |
| 428 base::Unretained(await_completion))); | |
| 429 } | |
| 430 | |
| 431 // We don't own this pointer. | |
| 432 storage::FileSystemContext* filesystem_context_; | |
| 433 | |
| 434 // Keep track of the URL for the ClearKey file so that it can be written to. | |
| 435 storage::FileSystemURL clearkey_file_; | |
| 436 | |
| 437 DISALLOW_COPY_AND_ASSIGN(RemovePluginPrivateDataTester); | |
| 438 }; | |
| 439 #endif // defined(ENABLE_PLUGINS) | |
| 440 | |
| 234 bool IsWebSafeSchemeForTest(const std::string& scheme) { | 441 bool IsWebSafeSchemeForTest(const std::string& scheme) { |
| 235 return scheme == "http"; | 442 return scheme == "http"; |
| 236 } | 443 } |
| 237 | 444 |
| 238 bool DoesOriginMatchForUnprotectedWeb( | 445 bool DoesOriginMatchForUnprotectedWeb( |
| 239 const GURL& origin, | 446 const GURL& origin, |
| 240 storage::SpecialStoragePolicy* special_storage_policy) { | 447 storage::SpecialStoragePolicy* special_storage_policy) { |
| 241 if (IsWebSafeSchemeForTest(origin.scheme())) | 448 if (IsWebSafeSchemeForTest(origin.scheme())) |
| 242 return !special_storage_policy->IsStorageProtected(origin.GetOrigin()); | 449 return !special_storage_policy->IsStorageProtected(origin.GetOrigin()); |
| 243 | 450 |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 337 void ClearData(content::StoragePartition* partition, | 544 void ClearData(content::StoragePartition* partition, |
| 338 base::RunLoop* run_loop) { | 545 base::RunLoop* run_loop) { |
| 339 base::Time time; | 546 base::Time time; |
| 340 partition->ClearData( | 547 partition->ClearData( |
| 341 StoragePartition::REMOVE_DATA_MASK_SHADER_CACHE, | 548 StoragePartition::REMOVE_DATA_MASK_SHADER_CACHE, |
| 342 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, | 549 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, |
| 343 GURL(), StoragePartition::OriginMatcherFunction(), | 550 GURL(), StoragePartition::OriginMatcherFunction(), |
| 344 time, time, run_loop->QuitClosure()); | 551 time, time, run_loop->QuitClosure()); |
| 345 } | 552 } |
| 346 | 553 |
| 554 #if defined(ENABLE_PLUGINS) | |
| 555 void ClearPluginPrivateData(content::StoragePartition* partition, | |
| 556 const GURL& storage_origin, | |
| 557 const base::Time delete_begin, | |
| 558 const base::Time delete_end, | |
| 559 base::RunLoop* run_loop) { | |
| 560 partition->ClearData( | |
| 561 StoragePartitionImpl::REMOVE_DATA_MASK_PLUGIN_PRIVATE_DATA, | |
| 562 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, storage_origin, | |
| 563 StoragePartition::OriginMatcherFunction(), delete_begin, delete_end, | |
| 564 run_loop->QuitClosure()); | |
| 565 } | |
| 566 #endif // defined(ENABLE_PLUGINS) | |
| 567 | |
| 347 } // namespace | 568 } // namespace |
| 348 | 569 |
| 349 class StoragePartitionImplTest : public testing::Test { | 570 class StoragePartitionImplTest : public testing::Test { |
| 350 public: | 571 public: |
| 351 StoragePartitionImplTest() | 572 StoragePartitionImplTest() |
| 352 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), | 573 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), |
| 353 browser_context_(new TestBrowserContext()) { | 574 browser_context_(new TestBrowserContext()) {} |
| 354 } | |
| 355 | 575 |
| 356 MockQuotaManager* GetMockManager() { | 576 MockQuotaManager* GetMockManager() { |
| 357 if (!quota_manager_.get()) { | 577 if (!quota_manager_.get()) { |
| 358 quota_manager_ = new MockQuotaManager( | 578 quota_manager_ = new MockQuotaManager( |
| 359 browser_context_->IsOffTheRecord(), | 579 browser_context_->IsOffTheRecord(), |
| 360 browser_context_->GetPath(), | 580 browser_context_->GetPath(), |
| 361 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO).get(), | 581 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO).get(), |
| 362 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB).get(), | 582 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB).get(), |
| 363 browser_context_->GetSpecialStoragePolicy()); | 583 browser_context_->GetSpecialStoragePolicy()); |
| 364 } | 584 } |
| (...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 968 base::Bind(&DoesOriginMatchForBothProtectedAndUnprotectedWeb), | 1188 base::Bind(&DoesOriginMatchForBothProtectedAndUnprotectedWeb), |
| 969 &run_loop)); | 1189 &run_loop)); |
| 970 run_loop.Run(); | 1190 run_loop.Run(); |
| 971 | 1191 |
| 972 // kOrigin1 and kOrigin2 do not have age more than a week. | 1192 // kOrigin1 and kOrigin2 do not have age more than a week. |
| 973 EXPECT_FALSE(tester.DOMStorageExistsForOrigin(kOrigin1)); | 1193 EXPECT_FALSE(tester.DOMStorageExistsForOrigin(kOrigin1)); |
| 974 EXPECT_FALSE(tester.DOMStorageExistsForOrigin(kOrigin2)); | 1194 EXPECT_FALSE(tester.DOMStorageExistsForOrigin(kOrigin2)); |
| 975 EXPECT_TRUE(tester.DOMStorageExistsForOrigin(kOrigin3)); | 1195 EXPECT_TRUE(tester.DOMStorageExistsForOrigin(kOrigin3)); |
| 976 } | 1196 } |
| 977 | 1197 |
| 1198 #if defined(ENABLE_PLUGINS) | |
| 1199 TEST_F(StoragePartitionImplTest, RemovePluginPrivateDataForever) { | |
| 1200 StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>( | |
| 1201 BrowserContext::GetDefaultStoragePartition(browser_context())); | |
| 1202 | |
| 1203 RemovePluginPrivateDataTester tester(partition->GetFileSystemContext()); | |
| 1204 tester.AddPluginPrivateTestData(); | |
| 1205 EXPECT_TRUE(tester.DataExistsForOrigin(kOrigin1)); | |
| 1206 EXPECT_TRUE(tester.DataExistsForOrigin(kOrigin2)); | |
| 1207 | |
| 1208 base::RunLoop run_loop; | |
| 1209 base::ThreadTaskRunnerHandle::Get()->PostTask( | |
| 1210 FROM_HERE, base::Bind(&ClearPluginPrivateData, partition, GURL(), | |
| 1211 base::Time(), base::Time::Max(), &run_loop)); | |
| 1212 run_loop.Run(); | |
| 1213 | |
| 1214 EXPECT_FALSE(tester.DataExistsForOrigin(kOrigin1)); | |
| 1215 EXPECT_FALSE(tester.DataExistsForOrigin(kOrigin2)); | |
| 1216 } | |
| 1217 | |
| 1218 TEST_F(StoragePartitionImplTest, RemovePluginPrivateDataLastWeek) { | |
| 1219 StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>( | |
| 1220 BrowserContext::GetDefaultStoragePartition(browser_context())); | |
| 1221 base::Time a_week_ago = base::Time::Now() - base::TimeDelta::FromDays(7); | |
| 1222 | |
| 1223 RemovePluginPrivateDataTester tester(partition->GetFileSystemContext()); | |
| 1224 tester.AddPluginPrivateTestData(); | |
| 1225 EXPECT_TRUE(tester.DataExistsForOrigin(kOrigin1)); | |
| 1226 EXPECT_TRUE(tester.DataExistsForOrigin(kOrigin2)); | |
| 1227 | |
| 1228 base::RunLoop run_loop; | |
| 1229 base::ThreadTaskRunnerHandle::Get()->PostTask( | |
| 1230 FROM_HERE, base::Bind(&ClearPluginPrivateData, partition, GURL(), | |
| 1231 a_week_ago, base::Time::Max(), &run_loop)); | |
| 1232 run_loop.Run(); | |
| 1233 | |
| 1234 // Origin1 has 1 file from 10 days ago, so it should remain around. | |
| 1235 // Origin2 has a current file, so it should be removed (even though the | |
| 1236 // second file is much older). | |
| 1237 EXPECT_TRUE(tester.DataExistsForOrigin(kOrigin1)); | |
| 1238 EXPECT_FALSE(tester.DataExistsForOrigin(kOrigin2)); | |
| 1239 } | |
| 1240 | |
| 1241 TEST_F(StoragePartitionImplTest, RemovePluginPrivateDataForOrigin) { | |
| 1242 StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>( | |
| 1243 BrowserContext::GetDefaultStoragePartition(browser_context())); | |
| 1244 | |
| 1245 RemovePluginPrivateDataTester tester(partition->GetFileSystemContext()); | |
| 1246 tester.AddPluginPrivateTestData(); | |
| 1247 EXPECT_TRUE(tester.DataExistsForOrigin(kOrigin1)); | |
| 1248 EXPECT_TRUE(tester.DataExistsForOrigin(kOrigin2)); | |
| 1249 | |
| 1250 base::RunLoop run_loop; | |
| 1251 base::ThreadTaskRunnerHandle::Get()->PostTask( | |
| 1252 FROM_HERE, base::Bind(&ClearPluginPrivateData, partition, kOrigin1, | |
| 1253 base::Time(), base::Time::Max(), &run_loop)); | |
| 1254 run_loop.Run(); | |
| 1255 | |
| 1256 // Only Origin1 should be deleted. | |
| 1257 EXPECT_FALSE(tester.DataExistsForOrigin(kOrigin1)); | |
| 1258 EXPECT_TRUE(tester.DataExistsForOrigin(kOrigin2)); | |
| 1259 } | |
| 1260 | |
| 1261 TEST_F(StoragePartitionImplTest, RemovePluginPrivateDataWhileWriting) { | |
| 1262 StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>( | |
| 1263 BrowserContext::GetDefaultStoragePartition(browser_context())); | |
| 1264 | |
| 1265 RemovePluginPrivateDataTester tester(partition->GetFileSystemContext()); | |
| 1266 tester.AddPluginPrivateTestData(); | |
| 1267 EXPECT_TRUE(tester.DataExistsForOrigin(kOrigin1)); | |
| 1268 EXPECT_TRUE(tester.DataExistsForOrigin(kOrigin2)); | |
| 1269 | |
| 1270 const char test_data[] = {0, 1, 2, 3, 4, 5}; | |
| 1271 base::File file = tester.OpenClearKeyFileForWrite(); | |
| 1272 EXPECT_TRUE(file.IsValid()); | |
| 1273 EXPECT_EQ(static_cast<int>(arraysize(test_data)), | |
| 1274 file.Write(0, test_data, arraysize(test_data))); | |
| 1275 | |
| 1276 base::RunLoop run_loop; | |
| 1277 base::ThreadTaskRunnerHandle::Get()->PostTask( | |
| 1278 FROM_HERE, base::Bind(&ClearPluginPrivateData, partition, GURL(), | |
| 1279 base::Time(), base::Time::Max(), &run_loop)); | |
| 1280 run_loop.Run(); | |
|
xhwang
2016/06/02 23:51:45
This will finish all the deletion steps then quit
jrummell
2016/06/08 23:44:08
The test does different things on different OSes (
nhiroki
2016/06/09 15:59:48
Yes. Each operation is independent and able to fin
| |
| 1281 | |
| 1282 EXPECT_FALSE(tester.DataExistsForOrigin(kOrigin1)); | |
| 1283 EXPECT_FALSE(tester.DataExistsForOrigin(kOrigin2)); | |
| 1284 | |
| 1285 const char more_data[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; | |
| 1286 EXPECT_EQ(static_cast<int>(arraysize(more_data)), | |
| 1287 file.WriteAtCurrentPos(more_data, arraysize(more_data))); | |
| 1288 | |
| 1289 base::File file2 = tester.OpenClearKeyFileForWrite(); | |
| 1290 EXPECT_FALSE(file2.IsValid()); | |
| 1291 } | |
| 1292 #endif // defined(ENABLE_PLUGINS) | |
| 1293 | |
| 978 TEST(StoragePartitionImplStaticTest, CreatePredicateForHostCookies) { | 1294 TEST(StoragePartitionImplStaticTest, CreatePredicateForHostCookies) { |
| 979 GURL url("http://www.example.com/"); | 1295 GURL url("http://www.example.com/"); |
| 980 GURL url2("https://www.example.com/"); | 1296 GURL url2("https://www.example.com/"); |
| 981 GURL url3("https://www.google.com/"); | 1297 GURL url3("https://www.google.com/"); |
| 982 | 1298 |
| 983 net::CookieOptions options; | 1299 net::CookieOptions options; |
| 984 net::CookieStore::CookiePredicate predicate = | 1300 net::CookieStore::CookiePredicate predicate = |
| 985 StoragePartitionImpl::CreatePredicateForHostCookies(url); | 1301 StoragePartitionImpl::CreatePredicateForHostCookies(url); |
| 986 | 1302 |
| 987 base::Time now = base::Time::Now(); | 1303 base::Time now = base::Time::Now(); |
| 988 std::vector<std::unique_ptr<CanonicalCookie>> valid_cookies; | 1304 std::vector<std::unique_ptr<CanonicalCookie>> valid_cookies; |
| 989 valid_cookies.push_back(CanonicalCookie::Create(url, "A=B", now, options)); | 1305 valid_cookies.push_back(CanonicalCookie::Create(url, "A=B", now, options)); |
| 990 valid_cookies.push_back(CanonicalCookie::Create(url, "C=F", now, options)); | 1306 valid_cookies.push_back(CanonicalCookie::Create(url, "C=F", now, options)); |
| 991 // We should match a different scheme with the same host. | 1307 // We should match a different scheme with the same host. |
| 992 valid_cookies.push_back(CanonicalCookie::Create(url2, "A=B", now, options)); | 1308 valid_cookies.push_back(CanonicalCookie::Create(url2, "A=B", now, options)); |
| 993 | 1309 |
| 994 std::vector<std::unique_ptr<CanonicalCookie>> invalid_cookies; | 1310 std::vector<std::unique_ptr<CanonicalCookie>> invalid_cookies; |
| 995 // We don't match domain cookies. | 1311 // We don't match domain cookies. |
| 996 invalid_cookies.push_back( | 1312 invalid_cookies.push_back( |
| 997 CanonicalCookie::Create(url2, "A=B;domain=.example.com", now, options)); | 1313 CanonicalCookie::Create(url2, "A=B;domain=.example.com", now, options)); |
| 998 invalid_cookies.push_back(CanonicalCookie::Create(url3, "A=B", now, options)); | 1314 invalid_cookies.push_back(CanonicalCookie::Create(url3, "A=B", now, options)); |
| 999 | 1315 |
| 1000 for (const auto& cookie : valid_cookies) | 1316 for (const auto& cookie : valid_cookies) |
| 1001 EXPECT_TRUE(predicate.Run(*cookie)) << cookie->DebugString(); | 1317 EXPECT_TRUE(predicate.Run(*cookie)) << cookie->DebugString(); |
| 1002 for (const auto& cookie : invalid_cookies) | 1318 for (const auto& cookie : invalid_cookies) |
| 1003 EXPECT_FALSE(predicate.Run(*cookie)) << cookie->DebugString(); | 1319 EXPECT_FALSE(predicate.Run(*cookie)) << cookie->DebugString(); |
| 1004 } | 1320 } |
| 1005 | 1321 |
| 1006 } // namespace content | 1322 } // namespace content |
| OLD | NEW |