Index: content/browser/storage_partition_impl_unittest.cc |
diff --git a/content/browser/storage_partition_impl_unittest.cc b/content/browser/storage_partition_impl_unittest.cc |
index e4b790967b284bb02f743cdb696c7123c4fff752..22f0185fee2e586b6d9ee7dea5cf15c8f7710135 100644 |
--- a/content/browser/storage_partition_impl_unittest.cc |
+++ b/content/browser/storage_partition_impl_unittest.cc |
@@ -23,12 +23,15 @@ |
#include "content/public/test/test_browser_thread.h" |
#include "content/public/test/test_browser_thread_bundle.h" |
#include "net/base/test_completion_callback.h" |
+#include "net/cookies/canonical_cookie.h" |
#include "net/cookies/cookie_store.h" |
#include "net/url_request/url_request_context.h" |
#include "net/url_request/url_request_context_getter.h" |
#include "storage/browser/quota/quota_manager.h" |
#include "testing/gtest/include/gtest/gtest.h" |
+using net::CanonicalCookie; |
+ |
namespace content { |
namespace { |
@@ -919,4 +922,32 @@ TEST_F(StoragePartitionImplTest, RemoveLocalStorageForLastWeek) { |
EXPECT_TRUE(tester.DOMStorageExistsForOrigin(kOrigin3)); |
} |
+TEST(StoragePartitionImplStaticTest, CreatePredicateForHostCookies) { |
+ GURL url("http://www.example.com/"); |
+ GURL url2("https://www.example.com/"); |
+ GURL url3("https://www.google.com/"); |
+ |
+ net::CookieOptions options; |
+ net::CookieStore::CookiePredicate predicate = |
+ StoragePartitionImpl::CreatePredicateForHostCookies(url); |
+ |
+ base::Time now = base::Time::Now(); |
+ std::vector<scoped_ptr<CanonicalCookie>> valid_cookies; |
+ valid_cookies.push_back(CanonicalCookie::Create(url, "A=B", now, options)); |
+ valid_cookies.push_back(CanonicalCookie::Create(url, "C=F", now, options)); |
+ // We should match a different scheme with the same host. |
+ valid_cookies.push_back(CanonicalCookie::Create(url2, "A=B", now, options)); |
+ |
+ std::vector<scoped_ptr<CanonicalCookie>> invalid_cookies; |
+ // We don't match domain cookies. |
+ invalid_cookies.push_back( |
+ CanonicalCookie::Create(url2, "A=B;domain=.example.com", now, options)); |
+ invalid_cookies.push_back(CanonicalCookie::Create(url3, "A=B", now, options)); |
+ |
+ for (const auto& cookie : valid_cookies) |
+ EXPECT_TRUE(predicate.Run(*cookie)) << cookie->DebugString(); |
+ for (const auto& cookie : invalid_cookies) |
+ EXPECT_FALSE(predicate.Run(*cookie)) << cookie->DebugString(); |
+} |
+ |
} // namespace content |