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" |
11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
12 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
13 #include "base/threading/thread.h" | 13 #include "base/threading/thread.h" |
14 #include "base/threading/thread_task_runner_handle.h" | 14 #include "base/threading/thread_task_runner_handle.h" |
15 #include "content/browser/browser_thread_impl.h" | 15 #include "content/browser/browser_thread_impl.h" |
16 #include "content/browser/gpu/shader_disk_cache.h" | 16 #include "content/browser/gpu/shader_disk_cache.h" |
17 #include "content/browser/quota/mock_quota_manager.h" | 17 #include "content/browser/quota/mock_quota_manager.h" |
18 #include "content/browser/storage_partition_impl.h" | 18 #include "content/browser/storage_partition_impl.h" |
19 #include "content/public/browser/local_storage_usage_info.h" | 19 #include "content/public/browser/local_storage_usage_info.h" |
20 #include "content/public/browser/storage_partition.h" | 20 #include "content/public/browser/storage_partition.h" |
21 #include "content/public/test/mock_special_storage_policy.h" | 21 #include "content/public/test/mock_special_storage_policy.h" |
22 #include "content/public/test/test_browser_context.h" | 22 #include "content/public/test/test_browser_context.h" |
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 "ppapi/features/features.h" |
30 #include "storage/browser/quota/quota_manager.h" | 31 #include "storage/browser/quota/quota_manager.h" |
31 #include "testing/gtest/include/gtest/gtest.h" | 32 #include "testing/gtest/include/gtest/gtest.h" |
32 | 33 |
33 #if defined(ENABLE_PLUGINS) | 34 #if BUILDFLAG(ENABLE_PLUGINS) |
34 #include "ppapi/shared_impl/ppapi_constants.h" | 35 #include "ppapi/shared_impl/ppapi_constants.h" |
35 #include "storage/browser/fileapi/async_file_util.h" | 36 #include "storage/browser/fileapi/async_file_util.h" |
36 #include "storage/browser/fileapi/file_system_context.h" | 37 #include "storage/browser/fileapi/file_system_context.h" |
37 #include "storage/browser/fileapi/file_system_operation_context.h" | 38 #include "storage/browser/fileapi/file_system_operation_context.h" |
38 #include "storage/browser/fileapi/isolated_context.h" | 39 #include "storage/browser/fileapi/isolated_context.h" |
39 #include "storage/common/fileapi/file_system_util.h" | 40 #include "storage/common/fileapi/file_system_util.h" |
40 #endif // defined(ENABLE_PLUGINS) | 41 #endif // BUILDFLAG(ENABLE_PLUGINS) |
41 | 42 |
42 using net::CanonicalCookie; | 43 using net::CanonicalCookie; |
43 | 44 |
44 namespace content { | 45 namespace content { |
45 namespace { | 46 namespace { |
46 | 47 |
47 const int kDefaultClientId = 42; | 48 const int kDefaultClientId = 42; |
48 const char kCacheKey[] = "key"; | 49 const char kCacheKey[] = "key"; |
49 const char kCacheValue[] = "cached value"; | 50 const char kCacheValue[] = "cached value"; |
50 | 51 |
51 const char kTestOrigin1[] = "http://host1:1/"; | 52 const char kTestOrigin1[] = "http://host1:1/"; |
52 const char kTestOrigin2[] = "http://host2:1/"; | 53 const char kTestOrigin2[] = "http://host2:1/"; |
53 const char kTestOrigin3[] = "http://host3:1/"; | 54 const char kTestOrigin3[] = "http://host3:1/"; |
54 const char kTestOriginDevTools[] = "chrome-devtools://abcdefghijklmnopqrstuvw/"; | 55 const char kTestOriginDevTools[] = "chrome-devtools://abcdefghijklmnopqrstuvw/"; |
55 | 56 |
56 #if defined(ENABLE_PLUGINS) | 57 #if BUILDFLAG(ENABLE_PLUGINS) |
57 const char kWidevineCdmPluginId[] = "application_x-ppapi-widevine-cdm"; | 58 const char kWidevineCdmPluginId[] = "application_x-ppapi-widevine-cdm"; |
58 const char kClearKeyCdmPluginId[] = "application_x-ppapi-clearkey-cdm"; | 59 const char kClearKeyCdmPluginId[] = "application_x-ppapi-clearkey-cdm"; |
59 #endif // defined(ENABLE_PLUGINS) | 60 #endif // BUILDFLAG(ENABLE_PLUGINS) |
60 | 61 |
61 const GURL kOrigin1(kTestOrigin1); | 62 const GURL kOrigin1(kTestOrigin1); |
62 const GURL kOrigin2(kTestOrigin2); | 63 const GURL kOrigin2(kTestOrigin2); |
63 const GURL kOrigin3(kTestOrigin3); | 64 const GURL kOrigin3(kTestOrigin3); |
64 const GURL kOriginDevTools(kTestOriginDevTools); | 65 const GURL kOriginDevTools(kTestOriginDevTools); |
65 | 66 |
66 const base::FilePath::CharType kDomStorageOrigin1[] = | 67 const base::FilePath::CharType kDomStorageOrigin1[] = |
67 FILE_PATH_LITERAL("http_host1_1.localstorage"); | 68 FILE_PATH_LITERAL("http_host1_1.localstorage"); |
68 | 69 |
69 const base::FilePath::CharType kDomStorageOrigin2[] = | 70 const base::FilePath::CharType kDomStorageOrigin2[] = |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 TestBrowserContext* profile_; | 239 TestBrowserContext* profile_; |
239 content::DOMStorageContext* dom_storage_context_; | 240 content::DOMStorageContext* dom_storage_context_; |
240 | 241 |
241 std::vector<content::LocalStorageUsageInfo> infos_; | 242 std::vector<content::LocalStorageUsageInfo> infos_; |
242 | 243 |
243 AwaitCompletionHelper await_completion_; | 244 AwaitCompletionHelper await_completion_; |
244 | 245 |
245 DISALLOW_COPY_AND_ASSIGN(RemoveLocalStorageTester); | 246 DISALLOW_COPY_AND_ASSIGN(RemoveLocalStorageTester); |
246 }; | 247 }; |
247 | 248 |
248 #if defined(ENABLE_PLUGINS) | 249 #if BUILDFLAG(ENABLE_PLUGINS) |
249 class RemovePluginPrivateDataTester { | 250 class RemovePluginPrivateDataTester { |
250 public: | 251 public: |
251 explicit RemovePluginPrivateDataTester( | 252 explicit RemovePluginPrivateDataTester( |
252 storage::FileSystemContext* filesystem_context) | 253 storage::FileSystemContext* filesystem_context) |
253 : filesystem_context_(filesystem_context) {} | 254 : filesystem_context_(filesystem_context) {} |
254 | 255 |
255 // Add some files to the PluginPrivateFileSystem. They are created as follows: | 256 // Add some files to the PluginPrivateFileSystem. They are created as follows: |
256 // kOrigin1 - ClearKey - 1 file - timestamp 10 days ago | 257 // kOrigin1 - ClearKey - 1 file - timestamp 10 days ago |
257 // kOrigin2 - Widevine - 2 files - timestamps now and 60 days ago | 258 // kOrigin2 - Widevine - 2 files - timestamps now and 60 days ago |
258 void AddPluginPrivateTestData() { | 259 void AddPluginPrivateTestData() { |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
429 } | 430 } |
430 | 431 |
431 // We don't own this pointer. | 432 // We don't own this pointer. |
432 storage::FileSystemContext* filesystem_context_; | 433 storage::FileSystemContext* filesystem_context_; |
433 | 434 |
434 // Keep track of the URL for the ClearKey file so that it can be written to. | 435 // Keep track of the URL for the ClearKey file so that it can be written to. |
435 storage::FileSystemURL clearkey_file_; | 436 storage::FileSystemURL clearkey_file_; |
436 | 437 |
437 DISALLOW_COPY_AND_ASSIGN(RemovePluginPrivateDataTester); | 438 DISALLOW_COPY_AND_ASSIGN(RemovePluginPrivateDataTester); |
438 }; | 439 }; |
439 #endif // defined(ENABLE_PLUGINS) | 440 #endif // BUILDFLAG(ENABLE_PLUGINS) |
440 | 441 |
441 bool IsWebSafeSchemeForTest(const std::string& scheme) { | 442 bool IsWebSafeSchemeForTest(const std::string& scheme) { |
442 return scheme == "http"; | 443 return scheme == "http"; |
443 } | 444 } |
444 | 445 |
445 bool DoesOriginMatchForUnprotectedWeb( | 446 bool DoesOriginMatchForUnprotectedWeb( |
446 const GURL& origin, | 447 const GURL& origin, |
447 storage::SpecialStoragePolicy* special_storage_policy) { | 448 storage::SpecialStoragePolicy* special_storage_policy) { |
448 if (IsWebSafeSchemeForTest(origin.scheme())) | 449 if (IsWebSafeSchemeForTest(origin.scheme())) |
449 return !special_storage_policy->IsStorageProtected(origin.GetOrigin()); | 450 return !special_storage_policy->IsStorageProtected(origin.GetOrigin()); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
544 void ClearData(content::StoragePartition* partition, | 545 void ClearData(content::StoragePartition* partition, |
545 base::RunLoop* run_loop) { | 546 base::RunLoop* run_loop) { |
546 base::Time time; | 547 base::Time time; |
547 partition->ClearData( | 548 partition->ClearData( |
548 StoragePartition::REMOVE_DATA_MASK_SHADER_CACHE, | 549 StoragePartition::REMOVE_DATA_MASK_SHADER_CACHE, |
549 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, | 550 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, |
550 GURL(), StoragePartition::OriginMatcherFunction(), | 551 GURL(), StoragePartition::OriginMatcherFunction(), |
551 time, time, run_loop->QuitClosure()); | 552 time, time, run_loop->QuitClosure()); |
552 } | 553 } |
553 | 554 |
554 #if defined(ENABLE_PLUGINS) | 555 #if BUILDFLAG(ENABLE_PLUGINS) |
555 void ClearPluginPrivateData(content::StoragePartition* partition, | 556 void ClearPluginPrivateData(content::StoragePartition* partition, |
556 const GURL& storage_origin, | 557 const GURL& storage_origin, |
557 const base::Time delete_begin, | 558 const base::Time delete_begin, |
558 const base::Time delete_end, | 559 const base::Time delete_end, |
559 base::RunLoop* run_loop) { | 560 base::RunLoop* run_loop) { |
560 partition->ClearData( | 561 partition->ClearData( |
561 StoragePartitionImpl::REMOVE_DATA_MASK_PLUGIN_PRIVATE_DATA, | 562 StoragePartitionImpl::REMOVE_DATA_MASK_PLUGIN_PRIVATE_DATA, |
562 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, storage_origin, | 563 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, storage_origin, |
563 StoragePartition::OriginMatcherFunction(), delete_begin, delete_end, | 564 StoragePartition::OriginMatcherFunction(), delete_begin, delete_end, |
564 run_loop->QuitClosure()); | 565 run_loop->QuitClosure()); |
565 } | 566 } |
566 #endif // defined(ENABLE_PLUGINS) | 567 #endif // BUILDFLAG(ENABLE_PLUGINS) |
567 | 568 |
568 } // namespace | 569 } // namespace |
569 | 570 |
570 class StoragePartitionImplTest : public testing::Test { | 571 class StoragePartitionImplTest : public testing::Test { |
571 public: | 572 public: |
572 StoragePartitionImplTest() | 573 StoragePartitionImplTest() |
573 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), | 574 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), |
574 browser_context_(new TestBrowserContext()) {} | 575 browser_context_(new TestBrowserContext()) {} |
575 | 576 |
576 MockQuotaManager* GetMockManager() { | 577 MockQuotaManager* GetMockManager() { |
(...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1190 base::Bind(&DoesOriginMatchForBothProtectedAndUnprotectedWeb), | 1191 base::Bind(&DoesOriginMatchForBothProtectedAndUnprotectedWeb), |
1191 &run_loop)); | 1192 &run_loop)); |
1192 run_loop.Run(); | 1193 run_loop.Run(); |
1193 | 1194 |
1194 // kOrigin1 and kOrigin2 do not have age more than a week. | 1195 // kOrigin1 and kOrigin2 do not have age more than a week. |
1195 EXPECT_FALSE(tester.DOMStorageExistsForOrigin(kOrigin1)); | 1196 EXPECT_FALSE(tester.DOMStorageExistsForOrigin(kOrigin1)); |
1196 EXPECT_FALSE(tester.DOMStorageExistsForOrigin(kOrigin2)); | 1197 EXPECT_FALSE(tester.DOMStorageExistsForOrigin(kOrigin2)); |
1197 EXPECT_TRUE(tester.DOMStorageExistsForOrigin(kOrigin3)); | 1198 EXPECT_TRUE(tester.DOMStorageExistsForOrigin(kOrigin3)); |
1198 } | 1199 } |
1199 | 1200 |
1200 #if defined(ENABLE_PLUGINS) | 1201 #if BUILDFLAG(ENABLE_PLUGINS) |
1201 TEST_F(StoragePartitionImplTest, RemovePluginPrivateDataForever) { | 1202 TEST_F(StoragePartitionImplTest, RemovePluginPrivateDataForever) { |
1202 StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>( | 1203 StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>( |
1203 BrowserContext::GetDefaultStoragePartition(browser_context())); | 1204 BrowserContext::GetDefaultStoragePartition(browser_context())); |
1204 | 1205 |
1205 RemovePluginPrivateDataTester tester(partition->GetFileSystemContext()); | 1206 RemovePluginPrivateDataTester tester(partition->GetFileSystemContext()); |
1206 tester.AddPluginPrivateTestData(); | 1207 tester.AddPluginPrivateTestData(); |
1207 EXPECT_TRUE(tester.DataExistsForOrigin(kOrigin1)); | 1208 EXPECT_TRUE(tester.DataExistsForOrigin(kOrigin1)); |
1208 EXPECT_TRUE(tester.DataExistsForOrigin(kOrigin2)); | 1209 EXPECT_TRUE(tester.DataExistsForOrigin(kOrigin2)); |
1209 | 1210 |
1210 base::RunLoop run_loop; | 1211 base::RunLoop run_loop; |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1284 EXPECT_FALSE(tester.DataExistsForOrigin(kOrigin1)); | 1285 EXPECT_FALSE(tester.DataExistsForOrigin(kOrigin1)); |
1285 EXPECT_FALSE(tester.DataExistsForOrigin(kOrigin2)); | 1286 EXPECT_FALSE(tester.DataExistsForOrigin(kOrigin2)); |
1286 | 1287 |
1287 const char more_data[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; | 1288 const char more_data[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; |
1288 EXPECT_EQ(static_cast<int>(arraysize(more_data)), | 1289 EXPECT_EQ(static_cast<int>(arraysize(more_data)), |
1289 file.WriteAtCurrentPos(more_data, arraysize(more_data))); | 1290 file.WriteAtCurrentPos(more_data, arraysize(more_data))); |
1290 | 1291 |
1291 base::File file2 = tester.OpenClearKeyFileForWrite(); | 1292 base::File file2 = tester.OpenClearKeyFileForWrite(); |
1292 EXPECT_FALSE(file2.IsValid()); | 1293 EXPECT_FALSE(file2.IsValid()); |
1293 } | 1294 } |
1294 #endif // defined(ENABLE_PLUGINS) | 1295 #endif // BUILDFLAG(ENABLE_PLUGINS) |
1295 | 1296 |
1296 TEST(StoragePartitionImplStaticTest, CreatePredicateForHostCookies) { | 1297 TEST(StoragePartitionImplStaticTest, CreatePredicateForHostCookies) { |
1297 GURL url("http://www.example.com/"); | 1298 GURL url("http://www.example.com/"); |
1298 GURL url2("https://www.example.com/"); | 1299 GURL url2("https://www.example.com/"); |
1299 GURL url3("https://www.google.com/"); | 1300 GURL url3("https://www.google.com/"); |
1300 | 1301 |
1301 net::CookieOptions options; | 1302 net::CookieOptions options; |
1302 net::CookieStore::CookiePredicate predicate = | 1303 net::CookieStore::CookiePredicate predicate = |
1303 StoragePartitionImpl::CreatePredicateForHostCookies(url); | 1304 StoragePartitionImpl::CreatePredicateForHostCookies(url); |
1304 | 1305 |
(...skipping 10 matching lines...) Expand all Loading... |
1315 CanonicalCookie::Create(url2, "A=B;domain=.example.com", now, options)); | 1316 CanonicalCookie::Create(url2, "A=B;domain=.example.com", now, options)); |
1316 invalid_cookies.push_back(CanonicalCookie::Create(url3, "A=B", now, options)); | 1317 invalid_cookies.push_back(CanonicalCookie::Create(url3, "A=B", now, options)); |
1317 | 1318 |
1318 for (const auto& cookie : valid_cookies) | 1319 for (const auto& cookie : valid_cookies) |
1319 EXPECT_TRUE(predicate.Run(*cookie)) << cookie->DebugString(); | 1320 EXPECT_TRUE(predicate.Run(*cookie)) << cookie->DebugString(); |
1320 for (const auto& cookie : invalid_cookies) | 1321 for (const auto& cookie : invalid_cookies) |
1321 EXPECT_FALSE(predicate.Run(*cookie)) << cookie->DebugString(); | 1322 EXPECT_FALSE(predicate.Run(*cookie)) << cookie->DebugString(); |
1322 } | 1323 } |
1323 | 1324 |
1324 } // namespace content | 1325 } // namespace content |
OLD | NEW |