OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "net/cookies/canonical_cookie.h" | 5 #include "net/cookies/canonical_cookie.h" |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "googleurl/src/gurl.h" | 8 #include "googleurl/src/gurl.h" |
9 #include "net/cookies/cookie_options.h" | 9 #include "net/cookies/cookie_options.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 CanonicalCookie cookie(url, "A", "2", "www.example.com", "/test", | 48 CanonicalCookie cookie(url, "A", "2", "www.example.com", "/test", |
49 current_time, base::Time(), current_time, false, | 49 current_time, base::Time(), current_time, false, |
50 false); | 50 false); |
51 EXPECT_EQ(url.GetOrigin().spec(), cookie.Source()); | 51 EXPECT_EQ(url.GetOrigin().spec(), cookie.Source()); |
52 EXPECT_EQ("A", cookie.Name()); | 52 EXPECT_EQ("A", cookie.Name()); |
53 EXPECT_EQ("2", cookie.Value()); | 53 EXPECT_EQ("2", cookie.Value()); |
54 EXPECT_EQ("www.example.com", cookie.Domain()); | 54 EXPECT_EQ("www.example.com", cookie.Domain()); |
55 EXPECT_EQ("/test", cookie.Path()); | 55 EXPECT_EQ("/test", cookie.Path()); |
56 EXPECT_FALSE(cookie.IsSecure()); | 56 EXPECT_FALSE(cookie.IsSecure()); |
57 | 57 |
58 CanonicalCookie cookie2(url, "A", "2", "", "", current_time, base::Time(), | 58 CanonicalCookie cookie2(url, |
59 current_time, false, false); | 59 "A", |
| 60 "2", |
| 61 std::string(), |
| 62 std::string(), |
| 63 current_time, |
| 64 base::Time(), |
| 65 current_time, |
| 66 false, |
| 67 false); |
60 EXPECT_EQ(url.GetOrigin().spec(), cookie.Source()); | 68 EXPECT_EQ(url.GetOrigin().spec(), cookie.Source()); |
61 EXPECT_EQ("A", cookie2.Name()); | 69 EXPECT_EQ("A", cookie2.Name()); |
62 EXPECT_EQ("2", cookie2.Value()); | 70 EXPECT_EQ("2", cookie2.Value()); |
63 EXPECT_EQ("", cookie2.Domain()); | 71 EXPECT_EQ("", cookie2.Domain()); |
64 EXPECT_EQ("", cookie2.Path()); | 72 EXPECT_EQ("", cookie2.Path()); |
65 EXPECT_FALSE(cookie2.IsSecure()); | 73 EXPECT_FALSE(cookie2.IsSecure()); |
66 | 74 |
67 } | 75 } |
68 | 76 |
69 TEST(CanonicalCookieTest, Create) { | 77 TEST(CanonicalCookieTest, Create) { |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 CookieOptions options; | 288 CookieOptions options; |
281 | 289 |
282 scoped_ptr<CanonicalCookie> cookie( | 290 scoped_ptr<CanonicalCookie> cookie( |
283 CanonicalCookie::Create(GURL("http://www.example.com"), | 291 CanonicalCookie::Create(GURL("http://www.example.com"), |
284 "A=2", creation_time, options)); | 292 "A=2", creation_time, options)); |
285 EXPECT_TRUE(cookie->IsOnPath("/")); | 293 EXPECT_TRUE(cookie->IsOnPath("/")); |
286 EXPECT_TRUE(cookie->IsOnPath("/test")); | 294 EXPECT_TRUE(cookie->IsOnPath("/test")); |
287 EXPECT_TRUE(cookie->IsOnPath("/test/bar.html")); | 295 EXPECT_TRUE(cookie->IsOnPath("/test/bar.html")); |
288 | 296 |
289 // Test the empty string edge case. | 297 // Test the empty string edge case. |
290 EXPECT_FALSE(cookie->IsOnPath("")); | 298 EXPECT_FALSE(cookie->IsOnPath(std::string())); |
291 | 299 |
292 cookie.reset( | 300 cookie.reset( |
293 CanonicalCookie::Create(GURL("http://www.example.com/test/foo.html"), | 301 CanonicalCookie::Create(GURL("http://www.example.com/test/foo.html"), |
294 "A=2", creation_time, options)); | 302 "A=2", creation_time, options)); |
295 EXPECT_FALSE(cookie->IsOnPath("/")); | 303 EXPECT_FALSE(cookie->IsOnPath("/")); |
296 EXPECT_TRUE(cookie->IsOnPath("/test")); | 304 EXPECT_TRUE(cookie->IsOnPath("/test")); |
297 EXPECT_TRUE(cookie->IsOnPath("/test/bar.html")); | 305 EXPECT_TRUE(cookie->IsOnPath("/test/bar.html")); |
298 EXPECT_TRUE(cookie->IsOnPath("/test/sample/bar.html")); | 306 EXPECT_TRUE(cookie->IsOnPath("/test/sample/bar.html")); |
299 } | 307 } |
300 | 308 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 options.set_include_httponly(); | 344 options.set_include_httponly(); |
337 cookie.reset( | 345 cookie.reset( |
338 CanonicalCookie::Create(url, "A=2; HttpOnly", creation_time, options)); | 346 CanonicalCookie::Create(url, "A=2; HttpOnly", creation_time, options)); |
339 EXPECT_TRUE(cookie->IsHttpOnly()); | 347 EXPECT_TRUE(cookie->IsHttpOnly()); |
340 EXPECT_TRUE(cookie->IncludeForRequestURL(url, options)); | 348 EXPECT_TRUE(cookie->IncludeForRequestURL(url, options)); |
341 options.set_exclude_httponly(); | 349 options.set_exclude_httponly(); |
342 EXPECT_FALSE(cookie->IncludeForRequestURL(url, options)); | 350 EXPECT_FALSE(cookie->IncludeForRequestURL(url, options)); |
343 } | 351 } |
344 | 352 |
345 } // namespace net | 353 } // namespace net |
OLD | NEW |