OLD | NEW |
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2016 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 <vector> | 5 #include <vector> |
6 | 6 |
7 #include "base/time/time.h" | 7 #include "base/time/time.h" |
8 #include "net/cookies/cookie_store.h" | 8 #include "net/cookies/cookie_store.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "net/cookies/canonical_cookie.h" | 10 #include "net/cookies/canonical_cookie.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 // BuildCookieLine doesn't reorder the list, it relies on the caller to do so. | 55 // BuildCookieLine doesn't reorder the list, it relies on the caller to do so. |
56 cookies.push_back(CanonicalCookie::Create( | 56 cookies.push_back(CanonicalCookie::Create( |
57 url, "F=G", now - base::TimeDelta::FromSeconds(1), options)); | 57 url, "F=G", now - base::TimeDelta::FromSeconds(1), options)); |
58 MatchCookieLineToVector("A=B; C; D=E; F=G", cookies); | 58 MatchCookieLineToVector("A=B; C; D=E; F=G", cookies); |
59 // BuildCookieLine doesn't deduplicate. | 59 // BuildCookieLine doesn't deduplicate. |
60 cookies.push_back(CanonicalCookie::Create( | 60 cookies.push_back(CanonicalCookie::Create( |
61 url, "D=E", now - base::TimeDelta::FromSeconds(2), options)); | 61 url, "D=E", now - base::TimeDelta::FromSeconds(2), options)); |
62 MatchCookieLineToVector("A=B; C; D=E; F=G; D=E", cookies); | 62 MatchCookieLineToVector("A=B; C; D=E; F=G; D=E", cookies); |
63 } | 63 } |
64 | 64 |
| 65 TEST(CookieStoreBaseTest, CreatePredicateForHostCookies) { |
| 66 GURL url("http://www.example.com/"); |
| 67 GURL url2("https://www.example.com/"); |
| 68 GURL url3("https://www.google.com/"); |
| 69 |
| 70 CookieOptions options; |
| 71 CookieStore::CookiePredicate predicate = |
| 72 CookieStore::CreatePredicateForHostCookies(url); |
| 73 |
| 74 base::Time now = base::Time::Now(); |
| 75 std::vector<scoped_ptr<CanonicalCookie>> valid_cookies; |
| 76 valid_cookies.push_back(CanonicalCookie::Create(url, "A=B", now, options)); |
| 77 valid_cookies.push_back(CanonicalCookie::Create(url, "C=F", now, options)); |
| 78 // We should match a different scheme with the same host. |
| 79 valid_cookies.push_back(CanonicalCookie::Create(url2, "A=B", now, options)); |
| 80 |
| 81 std::vector<scoped_ptr<CanonicalCookie>> invalid_cookies; |
| 82 // We don't match domain cookies. |
| 83 invalid_cookies.push_back( |
| 84 CanonicalCookie::Create(url2, "A=B;domain=.example.com", now, options)); |
| 85 invalid_cookies.push_back(CanonicalCookie::Create(url3, "A=B", now, options)); |
| 86 |
| 87 for (const auto& cookie : valid_cookies) { |
| 88 EXPECT_TRUE(predicate.Run(*cookie)) << cookie->DebugString(); |
| 89 } |
| 90 for (const auto& cookie : invalid_cookies) { |
| 91 EXPECT_FALSE(predicate.Run(*cookie)) << cookie->DebugString(); |
| 92 } |
| 93 } |
| 94 |
65 } // namespace net | 95 } // namespace net |
OLD | NEW |