Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(403)

Side by Side Diff: content/browser/storage_partition_impl_unittest.cc

Issue 1844243002: [CookieStore] Upgrading host-based deleting to predicate-based deleting. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix IOS Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/thread_task_runner_handle.h" 13 #include "base/thread_task_runner_handle.h"
14 #include "base/threading/thread.h" 14 #include "base/threading/thread.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/cookie_store.h" 27 #include "net/cookies/cookie_store.h"
27 #include "net/url_request/url_request_context.h" 28 #include "net/url_request/url_request_context.h"
28 #include "net/url_request/url_request_context_getter.h" 29 #include "net/url_request/url_request_context_getter.h"
29 #include "storage/browser/quota/quota_manager.h" 30 #include "storage/browser/quota/quota_manager.h"
30 #include "testing/gtest/include/gtest/gtest.h" 31 #include "testing/gtest/include/gtest/gtest.h"
31 32
33 using net::CanonicalCookie;
34
32 namespace content { 35 namespace content {
33 namespace { 36 namespace {
34 37
35 const int kDefaultClientId = 42; 38 const int kDefaultClientId = 42;
36 const char kCacheKey[] = "key"; 39 const char kCacheKey[] = "key";
37 const char kCacheValue[] = "cached value"; 40 const char kCacheValue[] = "cached value";
38 41
39 const char kTestOrigin1[] = "http://host1:1/"; 42 const char kTestOrigin1[] = "http://host1:1/";
40 const char kTestOrigin2[] = "http://host2:1/"; 43 const char kTestOrigin2[] = "http://host2:1/";
41 const char kTestOrigin3[] = "http://host3:1/"; 44 const char kTestOrigin3[] = "http://host3:1/";
(...skipping 870 matching lines...) Expand 10 before | Expand all | Expand 10 after
912 base::Bind(&DoesOriginMatchForBothProtectedAndUnprotectedWeb), 915 base::Bind(&DoesOriginMatchForBothProtectedAndUnprotectedWeb),
913 &run_loop)); 916 &run_loop));
914 run_loop.Run(); 917 run_loop.Run();
915 918
916 // kOrigin1 and kOrigin2 do not have age more than a week. 919 // kOrigin1 and kOrigin2 do not have age more than a week.
917 EXPECT_FALSE(tester.DOMStorageExistsForOrigin(kOrigin1)); 920 EXPECT_FALSE(tester.DOMStorageExistsForOrigin(kOrigin1));
918 EXPECT_FALSE(tester.DOMStorageExistsForOrigin(kOrigin2)); 921 EXPECT_FALSE(tester.DOMStorageExistsForOrigin(kOrigin2));
919 EXPECT_TRUE(tester.DOMStorageExistsForOrigin(kOrigin3)); 922 EXPECT_TRUE(tester.DOMStorageExistsForOrigin(kOrigin3));
920 } 923 }
921 924
925 TEST(StoragePartitionImplStaticTest, CreatePredicateForHostCookies) {
926 GURL url("http://www.example.com/");
927 GURL url2("https://www.example.com/");
928 GURL url3("https://www.google.com/");
929
930 net::CookieOptions options;
931 net::CookieStore::CookiePredicate predicate =
932 StoragePartitionImpl::CreatePredicateForHostCookies(url);
933
934 base::Time now = base::Time::Now();
935 std::vector<scoped_ptr<CanonicalCookie>> valid_cookies;
936 valid_cookies.push_back(CanonicalCookie::Create(url, "A=B", now, options));
937 valid_cookies.push_back(CanonicalCookie::Create(url, "C=F", now, options));
938 // We should match a different scheme with the same host.
939 valid_cookies.push_back(CanonicalCookie::Create(url2, "A=B", now, options));
940
941 std::vector<scoped_ptr<CanonicalCookie>> invalid_cookies;
942 // We don't match domain cookies.
943 invalid_cookies.push_back(
944 CanonicalCookie::Create(url2, "A=B;domain=.example.com", now, options));
945 invalid_cookies.push_back(CanonicalCookie::Create(url3, "A=B", now, options));
946
947 for (const auto& cookie : valid_cookies)
948 EXPECT_TRUE(predicate.Run(*cookie)) << cookie->DebugString();
949 for (const auto& cookie : invalid_cookies)
950 EXPECT_FALSE(predicate.Run(*cookie)) << cookie->DebugString();
951 }
952
922 } // namespace content 953 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698