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

Side by Side Diff: net/cookies/cookie_store_unittest.h

Issue 1378273003: Decouple CookieMonsterTest from CookieStoreTest. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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
« no previous file with comments | « net/cookies/cookie_monster_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #ifndef NET_COOKIES_COOKIE_STORE_UNITTEST_H_ 5 #ifndef NET_COOKIES_COOKIE_STORE_UNITTEST_H_
6 #define NET_COOKIES_COOKIE_STORE_UNITTEST_H_ 6 #define NET_COOKIES_COOKIE_STORE_UNITTEST_H_
7 7
8 #include <set>
9 #include <string>
10 #include <vector>
11
8 #include "base/bind.h" 12 #include "base/bind.h"
9 #include "base/location.h" 13 #include "base/location.h"
10 #include "base/message_loop/message_loop.h" 14 #include "base/message_loop/message_loop.h"
11 #include "base/single_thread_task_runner.h" 15 #include "base/single_thread_task_runner.h"
16 #include "base/strings/string_split.h"
12 #include "base/strings/string_tokenizer.h" 17 #include "base/strings/string_tokenizer.h"
18 #include "base/strings/string_util.h"
13 #include "base/thread_task_runner_handle.h" 19 #include "base/thread_task_runner_handle.h"
14 #include "base/threading/thread.h" 20 #include "base/threading/thread.h"
15 #include "net/cookies/cookie_monster.h" 21 #include "net/cookies/cookie_monster.h"
16 #include "net/cookies/cookie_store.h" 22 #include "net/cookies/cookie_store.h"
17 #include "net/cookies/cookie_store_test_callbacks.h" 23 #include "net/cookies/cookie_store_test_callbacks.h"
18 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
19 #include "url/gurl.h" 25 #include "url/gurl.h"
20 26
21 #if defined(OS_IOS) 27 #if defined(OS_IOS)
22 #include "base/ios/ios_util.h" 28 #include "base/ios/ios_util.h"
23 #endif 29 #endif
24 30
25 // This file declares unittest templates that can be used to test common 31 // This file declares unittest templates that can be used to test common
26 // behavior of any CookieStore implementation. 32 // behavior of any CookieStore implementation.
27 // See cookie_monster_unittest.cc for an example of an implementation. 33 // See cookie_monster_unittest.cc for an example of an implementation.
28 34
29 namespace net { 35 namespace net {
30 36
31 using base::Thread; 37 using base::Thread;
32 38
33 const int kTimeout = 1000; 39 const int kTimeout = 1000;
34 40
35 const char kUrlFtp[] = "ftp://ftp.google.izzle/";
36 const char kUrlGoogle[] = "http://www.google.izzle";
37 const char kUrlGoogleFoo[] = "http://www.google.izzle/foo";
38 const char kUrlGoogleBar[] = "http://www.google.izzle/bar";
39 const char kUrlGoogleSecure[] = "https://www.google.izzle";
40 const char kUrlGoogleWebSocket[] = "ws://www.google.izzle";
41 const char kUrlGoogleWebSocketSecure[] = "wss://www.google.izzle";
42 const char kValidCookieLine[] = "A=B; path=/"; 41 const char kValidCookieLine[] = "A=B; path=/";
43 const char kValidDomainCookieLine[] = "A=B; path=/; domain=google.izzle";
44 42
45 // The CookieStoreTestTraits must have the following members: 43 // The CookieStoreTestTraits must have the following members:
46 // struct CookieStoreTestTraits { 44 // struct CookieStoreTestTraits {
47 // // Factory function. 45 // // Factory function.
48 // static scoped_refptr<CookieStore> Create(); 46 // static scoped_refptr<CookieStore> Create();
49 // 47 //
50 // // The cookie store is a CookieMonster. Only used to test 48 // // The cookie store is a CookieMonster. Only used to test
51 // // GetCookieMonster(). 49 // // GetCookieMonster().
52 // static const bool is_cookie_monster; 50 // static const bool is_cookie_monster;
53 // 51 //
(...skipping 16 matching lines...) Expand all
70 // static const bool has_path_prefix_bug; 68 // static const bool has_path_prefix_bug;
71 // 69 //
72 // // Time to wait between two cookie insertions to ensure that cookies have 70 // // Time to wait between two cookie insertions to ensure that cookies have
73 // // different creation times. 71 // // different creation times.
74 // static const int creation_time_granularity_in_ms; 72 // static const int creation_time_granularity_in_ms;
75 // }; 73 // };
76 74
77 template <class CookieStoreTestTraits> 75 template <class CookieStoreTestTraits>
78 class CookieStoreTest : public testing::Test { 76 class CookieStoreTest : public testing::Test {
79 protected: 77 protected:
78 class URLHelper {
79 public:
80 explicit URLHelper(const std::string& url_string) : url_(url_string) {
81 std::vector<std::string> parts = SplitString(
Mike West 2015/10/09 15:08:15 This constructor should be in a `.cc` file.
cmumford 2015/10/09 21:21:01 Done.
82 url_.host(), ".", base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL);
83 DCHECK_EQ(parts.size(), 3u);
84 parts.erase(parts.begin());
85 domain_ = base::JoinString(parts, ".");
Mike West 2015/10/09 15:08:16 I think you're trying to get the registerable doma
cmumford 2015/10/09 21:21:01 Done - thx for that pointer.
86 tld_ = parts[1];
Mike West 2015/10/09 15:08:16 This isn't how TLDs work. Consider `co.uk`, for ex
cmumford 2015/10/09 21:21:00 Yeah - I was only trying to satisfy the needs of t
87 }
88 const std::string& TLD() const { return tld_; }
89 const std::string& domain() const { return domain_; }
90 std::string host() const { return url_.host(); }
91 std::string spec() const { return url_.spec(); }
92 const GURL& url() const { return url_; }
93 const GURL AppendPath(const std::string& path) const {
94 return GURL(url_.spec() + path);
95 }
96 std::string Format(const std::string& format_string) const {
97 std::string new_string = format_string;
Mike West 2015/10/09 15:08:15 This should also be in a `.cc` file.
cmumford 2015/10/09 21:21:01 Done.
98 base::ReplaceSubstringsAfterOffset(&new_string, 0, "%D", domain());
99 base::ReplaceSubstringsAfterOffset(&new_string, 0, "%T", TLD());
100 return new_string;
101 }
102
103 private:
104 const GURL url_;
105 std::string tld_;
106 std::string domain_;
107 };
108
80 CookieStoreTest() 109 CookieStoreTest()
81 : url_google_(kUrlGoogle), 110 : http_www_google_("http://www.google.izzle"),
82 url_google_secure_(kUrlGoogleSecure), 111 https_www_google_("https://www.google.izzle"),
83 url_google_foo_(kUrlGoogleFoo), 112 ftp_google_("ftp://ftp.google.izzle/"),
84 url_google_bar_(kUrlGoogleBar) { 113 ws_www_google_("ws://www.google.izzle"),
114 wss_www_google_("wss://www.google.izzle"),
115 www_google_foo_("http://www.google.izzle/foo"),
116 www_google_bar_("http://www.google.izzle/bar") {
85 // This test may be used outside of the net test suite, and thus may not 117 // This test may be used outside of the net test suite, and thus may not
86 // have a message loop. 118 // have a message loop.
87 if (!base::MessageLoop::current()) 119 if (!base::MessageLoop::current())
88 message_loop_.reset(new base::MessageLoop); 120 message_loop_.reset(new base::MessageLoop);
89 weak_factory_.reset(new base::WeakPtrFactory<base::MessageLoop>( 121 weak_factory_.reset(new base::WeakPtrFactory<base::MessageLoop>(
90 base::MessageLoop::current())); 122 base::MessageLoop::current()));
91 } 123 }
92 124
93 // Helper methods for the asynchronous Cookie Store API that call the 125 // Helper methods for the asynchronous Cookie Store API that call the
94 // asynchronous method and then pump the loop until the callback is invoked, 126 // asynchronous method and then pump the loop until the callback is invoked,
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 while (!matched && base::Time::Now() <= polling_end_date) { 277 while (!matched && base::Time::Now() <= polling_end_date) {
246 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(10)); 278 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(10));
247 cookies = GetCookies(cs, url); 279 cookies = GetCookies(cs, url);
248 matched = (TokenizeCookieLine(line) == TokenizeCookieLine(cookies)); 280 matched = (TokenizeCookieLine(line) == TokenizeCookieLine(cookies));
249 } 281 }
250 282
251 EXPECT_TRUE(matched) << "\"" << cookies 283 EXPECT_TRUE(matched) << "\"" << cookies
252 << "\" does not match \"" << line << "\""; 284 << "\" does not match \"" << line << "\"";
253 } 285 }
254 286
255 GURL url_google_; 287 const URLHelper http_www_google_;
256 GURL url_google_secure_; 288 const URLHelper https_www_google_;
257 GURL url_google_foo_; 289 const URLHelper ftp_google_;
258 GURL url_google_bar_; 290 const URLHelper ws_www_google_;
291 const URLHelper wss_www_google_;
292 const URLHelper www_google_foo_;
293 const URLHelper www_google_bar_;
259 294
260 scoped_ptr<base::WeakPtrFactory<base::MessageLoop> > weak_factory_; 295 scoped_ptr<base::WeakPtrFactory<base::MessageLoop> > weak_factory_;
261 scoped_ptr<base::MessageLoop> message_loop_; 296 scoped_ptr<base::MessageLoop> message_loop_;
262 297
263 private: 298 private:
264 // Returns a set of strings of type "name=value". Fails in case of duplicate. 299 // Returns a set of strings of type "name=value". Fails in case of duplicate.
265 std::set<std::string> TokenizeCookieLine(const std::string& line) { 300 std::set<std::string> TokenizeCookieLine(const std::string& line) {
266 std::set<std::string> tokens; 301 std::set<std::string> tokens;
267 base::StringTokenizer tokenizer(line, " ;"); 302 base::StringTokenizer tokenizer(line, " ;");
268 while (tokenizer.GetNext()) 303 while (tokenizer.GetNext())
269 EXPECT_TRUE(tokens.insert(tokenizer.token()).second); 304 EXPECT_TRUE(tokens.insert(tokenizer.token()).second);
270 return tokens; 305 return tokens;
271 } 306 }
272 }; 307 };
273 308
274 TYPED_TEST_CASE_P(CookieStoreTest); 309 TYPED_TEST_CASE_P(CookieStoreTest);
275 310
276 TYPED_TEST_P(CookieStoreTest, TypeTest) { 311 TYPED_TEST_P(CookieStoreTest, TypeTest) {
277 scoped_refptr<CookieStore> cs(this->GetCookieStore()); 312 scoped_refptr<CookieStore> cs(this->GetCookieStore());
278 EXPECT_EQ(cs->GetCookieMonster(), 313 EXPECT_EQ(cs->GetCookieMonster(),
279 (TypeParam::is_cookie_monster) ? 314 (TypeParam::is_cookie_monster) ?
280 static_cast<CookieMonster*>(cs.get()) : NULL); 315 static_cast<CookieMonster*>(cs.get()) : NULL);
281 } 316 }
282 317
283 TYPED_TEST_P(CookieStoreTest, DomainTest) { 318 TYPED_TEST_P(CookieStoreTest, DomainTest) {
284 scoped_refptr<CookieStore> cs(this->GetCookieStore()); 319 scoped_refptr<CookieStore> cs(this->GetCookieStore());
285 EXPECT_TRUE(this->SetCookie(cs.get(), this->url_google_, "A=B")); 320 EXPECT_TRUE(this->SetCookie(cs.get(), this->http_www_google_.url(), "A=B"));
286 this->MatchCookieLines("A=B", this->GetCookies(cs.get(), this->url_google_)); 321 this->MatchCookieLines(
287 EXPECT_TRUE(this->SetCookie( 322 "A=B", this->GetCookies(cs.get(), this->http_www_google_.url()));
288 cs.get(), this->url_google_, "C=D; domain=.google.izzle")); 323 EXPECT_TRUE(
289 this->MatchCookieLines("A=B; C=D", 324 this->SetCookie(cs.get(), this->http_www_google_.url(),
290 this->GetCookies(cs.get(), this->url_google_)); 325 this->http_www_google_.Format("C=D; domain=.%D")));
326 this->MatchCookieLines(
327 "A=B; C=D", this->GetCookies(cs.get(), this->http_www_google_.url()));
291 328
292 // Verify that A=B was set as a host cookie rather than a domain 329 // Verify that A=B was set as a host cookie rather than a domain
293 // cookie -- should not be accessible from a sub sub-domain. 330 // cookie -- should not be accessible from a sub sub-domain.
294 this->MatchCookieLines( 331 this->MatchCookieLines(
295 "C=D", this->GetCookies(cs.get(), GURL("http://foo.www.google.izzle"))); 332 "C=D",
333 this->GetCookies(
334 cs.get(), GURL(this->http_www_google_.Format("http://foo.www.%D"))));
296 335
297 // Test and make sure we find domain cookies on the same domain. 336 // Test and make sure we find domain cookies on the same domain.
298 EXPECT_TRUE(this->SetCookie( 337 EXPECT_TRUE(
299 cs.get(), this->url_google_, "E=F; domain=.www.google.izzle")); 338 this->SetCookie(cs.get(), this->http_www_google_.url(),
300 this->MatchCookieLines("A=B; C=D; E=F", 339 this->http_www_google_.Format("E=F; domain=.www.%D")));
301 this->GetCookies(cs.get(), this->url_google_)); 340 this->MatchCookieLines(
341 "A=B; C=D; E=F",
342 this->GetCookies(cs.get(), this->http_www_google_.url()));
302 343
303 // Test setting a domain= that doesn't start w/ a dot, should 344 // Test setting a domain= that doesn't start w/ a dot, should
304 // treat it as a domain cookie, as if there was a pre-pended dot. 345 // treat it as a domain cookie, as if there was a pre-pended dot.
305 EXPECT_TRUE(this->SetCookie( 346 EXPECT_TRUE(
306 cs.get(), this->url_google_, "G=H; domain=www.google.izzle")); 347 this->SetCookie(cs.get(), this->http_www_google_.url(),
307 this->MatchCookieLines("A=B; C=D; E=F; G=H", 348 this->http_www_google_.Format("G=H; domain=www.%D")));
308 this->GetCookies(cs.get(), this->url_google_)); 349 this->MatchCookieLines(
350 "A=B; C=D; E=F; G=H",
351 this->GetCookies(cs.get(), this->http_www_google_.url()));
309 352
310 // Test domain enforcement, should fail on a sub-domain or something too deep. 353 // Test domain enforcement, should fail on a sub-domain or something too deep.
311 EXPECT_FALSE( 354 EXPECT_FALSE(
312 this->SetCookie(cs.get(), this->url_google_, "I=J; domain=.izzle")); 355 this->SetCookie(cs.get(), this->http_www_google_.url(),
313 this->MatchCookieLines(std::string(), 356 this->http_www_google_.Format("I=J; domain=.%T")));
314 this->GetCookies(cs.get(), GURL("http://a.izzle"))); 357 this->MatchCookieLines(
358 std::string(),
359 this->GetCookies(cs.get(),
360 GURL(this->http_www_google_.Format("http://a.%T"))));
315 EXPECT_FALSE(this->SetCookie( 361 EXPECT_FALSE(this->SetCookie(
316 cs.get(), this->url_google_, "K=L; domain=.bla.www.google.izzle")); 362 cs.get(), this->http_www_google_.url(),
363 this->http_www_google_.Format("K=L; domain=.bla.www.%D")));
317 this->MatchCookieLines( 364 this->MatchCookieLines(
318 "C=D; E=F; G=H", 365 "C=D; E=F; G=H",
319 this->GetCookies(cs.get(), GURL("http://bla.www.google.izzle"))); 366 this->GetCookies(
320 this->MatchCookieLines("A=B; C=D; E=F; G=H", 367 cs.get(), GURL(this->http_www_google_.Format("http://bla.www.%D"))));
321 this->GetCookies(cs.get(), this->url_google_)); 368 this->MatchCookieLines(
369 "A=B; C=D; E=F; G=H",
370 this->GetCookies(cs.get(), this->http_www_google_.url()));
322 } 371 }
323 372
324 // FireFox recognizes domains containing trailing periods as valid. 373 // FireFox recognizes domains containing trailing periods as valid.
325 // IE and Safari do not. Assert the expected policy here. 374 // IE and Safari do not. Assert the expected policy here.
326 TYPED_TEST_P(CookieStoreTest, DomainWithTrailingDotTest) { 375 TYPED_TEST_P(CookieStoreTest, DomainWithTrailingDotTest) {
327 scoped_refptr<CookieStore> cs(this->GetCookieStore()); 376 scoped_refptr<CookieStore> cs(this->GetCookieStore());
328 EXPECT_FALSE(this->SetCookie( 377 EXPECT_FALSE(this->SetCookie(cs.get(), this->http_www_google_.url(),
329 cs.get(), this->url_google_, "a=1; domain=.www.google.com.")); 378 "a=1; domain=.www.google.com."));
330 EXPECT_FALSE(this->SetCookie( 379 EXPECT_FALSE(this->SetCookie(cs.get(), this->http_www_google_.url(),
331 cs.get(), this->url_google_, "b=2; domain=.www.google.com..")); 380 "b=2; domain=.www.google.com.."));
332 this->MatchCookieLines(std::string(), 381 this->MatchCookieLines(
333 this->GetCookies(cs.get(), this->url_google_)); 382 std::string(), this->GetCookies(cs.get(), this->http_www_google_.url()));
334 } 383 }
335 384
336 // Test that cookies can bet set on higher level domains. 385 // Test that cookies can bet set on higher level domains.
337 // http://b/issue?id=896491 386 // http://b/issue?id=896491
338 TYPED_TEST_P(CookieStoreTest, ValidSubdomainTest) { 387 TYPED_TEST_P(CookieStoreTest, ValidSubdomainTest) {
339 scoped_refptr<CookieStore> cs(this->GetCookieStore()); 388 scoped_refptr<CookieStore> cs(this->GetCookieStore());
340 GURL url_abcd("http://a.b.c.d.com"); 389 GURL url_abcd("http://a.b.c.d.com");
341 GURL url_bcd("http://b.c.d.com"); 390 GURL url_bcd("http://b.c.d.com");
342 GURL url_cd("http://c.d.com"); 391 GURL url_cd("http://c.d.com");
343 GURL url_d("http://d.com"); 392 GURL url_d("http://d.com");
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
592 this->GetCookies(cs.get(), GURL("http://hopefully-no-cookies.com/"))); 641 this->GetCookies(cs.get(), GURL("http://hopefully-no-cookies.com/")));
593 this->MatchCookieLines(std::string(), 642 this->MatchCookieLines(std::string(),
594 this->GetCookies(cs.get(), GURL("http://.com/"))); 643 this->GetCookies(cs.get(), GURL("http://.com/")));
595 } 644 }
596 645
597 TYPED_TEST_P(CookieStoreTest, InvalidScheme) { 646 TYPED_TEST_P(CookieStoreTest, InvalidScheme) {
598 if (!TypeParam::filters_schemes) 647 if (!TypeParam::filters_schemes)
599 return; 648 return;
600 649
601 scoped_refptr<CookieStore> cs(this->GetCookieStore()); 650 scoped_refptr<CookieStore> cs(this->GetCookieStore());
602 EXPECT_FALSE(this->SetCookie(cs.get(), GURL(kUrlFtp), kValidCookieLine)); 651 EXPECT_FALSE(
652 this->SetCookie(cs.get(), this->ftp_google_.url(), kValidCookieLine));
603 } 653 }
604 654
605 TYPED_TEST_P(CookieStoreTest, InvalidScheme_Read) { 655 TYPED_TEST_P(CookieStoreTest, InvalidScheme_Read) {
606 if (!TypeParam::filters_schemes) 656 if (!TypeParam::filters_schemes)
607 return; 657 return;
608 658
659 const std::string kValidDomainCookieLine =
660 this->http_www_google_.Format("A=B; path=/; domain=%D");
661
609 scoped_refptr<CookieStore> cs(this->GetCookieStore()); 662 scoped_refptr<CookieStore> cs(this->GetCookieStore());
610 EXPECT_TRUE( 663 EXPECT_TRUE(this->SetCookie(cs.get(), this->http_www_google_.url(),
611 this->SetCookie(cs.get(), GURL(kUrlGoogle), kValidDomainCookieLine)); 664 kValidDomainCookieLine));
612 this->MatchCookieLines(std::string(), 665 this->MatchCookieLines(std::string(),
613 this->GetCookies(cs.get(), GURL(kUrlFtp))); 666 this->GetCookies(cs.get(), this->ftp_google_.url()));
614 } 667 }
615 668
616 TYPED_TEST_P(CookieStoreTest, PathTest) { 669 TYPED_TEST_P(CookieStoreTest, PathTest) {
617 scoped_refptr<CookieStore> cs(this->GetCookieStore()); 670 scoped_refptr<CookieStore> cs(this->GetCookieStore());
618 std::string url("http://www.google.izzle"); 671 std::string url("http://www.google.izzle");
619 EXPECT_TRUE(this->SetCookie(cs.get(), GURL(url), "A=B; path=/wee")); 672 EXPECT_TRUE(this->SetCookie(cs.get(), GURL(url), "A=B; path=/wee"));
620 this->MatchCookieLines("A=B", this->GetCookies(cs.get(), GURL(url + "/wee"))); 673 this->MatchCookieLines("A=B", this->GetCookies(cs.get(), GURL(url + "/wee")));
621 this->MatchCookieLines("A=B", 674 this->MatchCookieLines("A=B",
622 this->GetCookies(cs.get(), GURL(url + "/wee/"))); 675 this->GetCookies(cs.get(), GURL(url + "/wee/")));
623 this->MatchCookieLines("A=B", 676 this->MatchCookieLines("A=B",
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
664 717
665 TYPED_TEST_P(CookieStoreTest, HttpOnlyTest) { 718 TYPED_TEST_P(CookieStoreTest, HttpOnlyTest) {
666 if (!TypeParam::supports_http_only) 719 if (!TypeParam::supports_http_only)
667 return; 720 return;
668 721
669 scoped_refptr<CookieStore> cs(this->GetCookieStore()); 722 scoped_refptr<CookieStore> cs(this->GetCookieStore());
670 CookieOptions options; 723 CookieOptions options;
671 options.set_include_httponly(); 724 options.set_include_httponly();
672 725
673 // Create a httponly cookie. 726 // Create a httponly cookie.
674 EXPECT_TRUE(this->SetCookieWithOptions( 727 EXPECT_TRUE(this->SetCookieWithOptions(cs.get(), this->http_www_google_.url(),
675 cs.get(), this->url_google_, "A=B; httponly", options)); 728 "A=B; httponly", options));
676 729
677 // Check httponly read protection. 730 // Check httponly read protection.
678 this->MatchCookieLines(std::string(),
679 this->GetCookies(cs.get(), this->url_google_));
680 this->MatchCookieLines( 731 this->MatchCookieLines(
681 "A=B", this->GetCookiesWithOptions(cs.get(), this->url_google_, options)); 732 std::string(), this->GetCookies(cs.get(), this->http_www_google_.url()));
733 this->MatchCookieLines(
734 "A=B", this->GetCookiesWithOptions(cs.get(), this->http_www_google_.url(),
735 options));
682 736
683 // Check httponly overwrite protection. 737 // Check httponly overwrite protection.
684 EXPECT_FALSE(this->SetCookie(cs.get(), this->url_google_, "A=C")); 738 EXPECT_FALSE(this->SetCookie(cs.get(), this->http_www_google_.url(), "A=C"));
685 this->MatchCookieLines(std::string(),
686 this->GetCookies(cs.get(), this->url_google_));
687 this->MatchCookieLines( 739 this->MatchCookieLines(
688 "A=B", this->GetCookiesWithOptions(cs.get(), this->url_google_, options)); 740 std::string(), this->GetCookies(cs.get(), this->http_www_google_.url()));
689 EXPECT_TRUE( 741 this->MatchCookieLines(
690 this->SetCookieWithOptions(cs.get(), this->url_google_, "A=C", options)); 742 "A=B", this->GetCookiesWithOptions(cs.get(), this->http_www_google_.url(),
691 this->MatchCookieLines("A=C", this->GetCookies(cs.get(), this->url_google_)); 743 options));
744 EXPECT_TRUE(this->SetCookieWithOptions(cs.get(), this->http_www_google_.url(),
745 "A=C", options));
746 this->MatchCookieLines(
747 "A=C", this->GetCookies(cs.get(), this->http_www_google_.url()));
692 748
693 // Check httponly create protection. 749 // Check httponly create protection.
694 EXPECT_FALSE(this->SetCookie(cs.get(), this->url_google_, "B=A; httponly")); 750 EXPECT_FALSE(
751 this->SetCookie(cs.get(), this->http_www_google_.url(), "B=A; httponly"));
695 this->MatchCookieLines( 752 this->MatchCookieLines(
696 "A=C", this->GetCookiesWithOptions(cs.get(), this->url_google_, options)); 753 "A=C", this->GetCookiesWithOptions(cs.get(), this->http_www_google_.url(),
697 EXPECT_TRUE(this->SetCookieWithOptions( 754 options));
698 cs.get(), this->url_google_, "B=A; httponly", options)); 755 EXPECT_TRUE(this->SetCookieWithOptions(cs.get(), this->http_www_google_.url(),
756 "B=A; httponly", options));
757 this->MatchCookieLines("A=C; B=A",
758 this->GetCookiesWithOptions(
759 cs.get(), this->http_www_google_.url(), options));
699 this->MatchCookieLines( 760 this->MatchCookieLines(
700 "A=C; B=A", 761 "A=C", this->GetCookies(cs.get(), this->http_www_google_.url()));
701 this->GetCookiesWithOptions(cs.get(), this->url_google_, options));
702 this->MatchCookieLines("A=C", this->GetCookies(cs.get(), this->url_google_));
703 } 762 }
704 763
705 TYPED_TEST_P(CookieStoreTest, TestCookieDeletion) { 764 TYPED_TEST_P(CookieStoreTest, TestCookieDeletion) {
706 scoped_refptr<CookieStore> cs(this->GetCookieStore()); 765 scoped_refptr<CookieStore> cs(this->GetCookieStore());
707 766
708 // Create a session cookie. 767 // Create a session cookie.
709 EXPECT_TRUE(this->SetCookie(cs.get(), this->url_google_, kValidCookieLine)); 768 EXPECT_TRUE(this->SetCookie(cs.get(), this->http_www_google_.url(),
710 this->MatchCookieLines("A=B", this->GetCookies(cs.get(), this->url_google_)); 769 kValidCookieLine));
770 this->MatchCookieLines(
771 "A=B", this->GetCookies(cs.get(), this->http_www_google_.url()));
711 // Delete it via Max-Age. 772 // Delete it via Max-Age.
712 EXPECT_TRUE(this->SetCookie(cs.get(), 773 EXPECT_TRUE(this->SetCookie(cs.get(), this->http_www_google_.url(),
713 this->url_google_,
714 std::string(kValidCookieLine) + "; max-age=0")); 774 std::string(kValidCookieLine) + "; max-age=0"));
715 this->MatchCookieLineWithTimeout(cs.get(), this->url_google_, std::string()); 775 this->MatchCookieLineWithTimeout(cs.get(), this->http_www_google_.url(),
776 std::string());
716 777
717 // Create a session cookie. 778 // Create a session cookie.
718 EXPECT_TRUE(this->SetCookie(cs.get(), this->url_google_, kValidCookieLine)); 779 EXPECT_TRUE(this->SetCookie(cs.get(), this->http_www_google_.url(),
719 this->MatchCookieLines("A=B", this->GetCookies(cs.get(), this->url_google_)); 780 kValidCookieLine));
781 this->MatchCookieLines(
782 "A=B", this->GetCookies(cs.get(), this->http_www_google_.url()));
720 // Delete it via Expires. 783 // Delete it via Expires.
721 EXPECT_TRUE(this->SetCookie(cs.get(), 784 EXPECT_TRUE(this->SetCookie(cs.get(), this->http_www_google_.url(),
722 this->url_google_,
723 std::string(kValidCookieLine) + 785 std::string(kValidCookieLine) +
724 "; expires=Mon, 18-Apr-1977 22:50:13 GMT")); 786 "; expires=Mon, 18-Apr-1977 22:50:13 GMT"));
725 this->MatchCookieLines(std::string(), 787 this->MatchCookieLines(
726 this->GetCookies(cs.get(), this->url_google_)); 788 std::string(), this->GetCookies(cs.get(), this->http_www_google_.url()));
727 789
728 // Create a persistent cookie. 790 // Create a persistent cookie.
729 EXPECT_TRUE(this->SetCookie( 791 EXPECT_TRUE(this->SetCookie(
730 cs.get(), 792 cs.get(), this->http_www_google_.url(),
731 this->url_google_,
732 std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-22 22:50:13 GMT")); 793 std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-22 22:50:13 GMT"));
733 794
734 this->MatchCookieLines("A=B", this->GetCookies(cs.get(), this->url_google_)); 795 this->MatchCookieLines(
796 "A=B", this->GetCookies(cs.get(), this->http_www_google_.url()));
735 // Delete it via Max-Age. 797 // Delete it via Max-Age.
736 EXPECT_TRUE(this->SetCookie(cs.get(), 798 EXPECT_TRUE(this->SetCookie(cs.get(), this->http_www_google_.url(),
737 this->url_google_,
738 std::string(kValidCookieLine) + "; max-age=0")); 799 std::string(kValidCookieLine) + "; max-age=0"));
739 this->MatchCookieLineWithTimeout(cs.get(), this->url_google_, std::string()); 800 this->MatchCookieLineWithTimeout(cs.get(), this->http_www_google_.url(),
801 std::string());
740 802
741 // Create a persistent cookie. 803 // Create a persistent cookie.
742 EXPECT_TRUE(this->SetCookie( 804 EXPECT_TRUE(this->SetCookie(
743 cs.get(), 805 cs.get(), this->http_www_google_.url(),
744 this->url_google_,
745 std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-22 22:50:13 GMT")); 806 std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-22 22:50:13 GMT"));
746 this->MatchCookieLines("A=B", this->GetCookies(cs.get(), this->url_google_)); 807 this->MatchCookieLines(
808 "A=B", this->GetCookies(cs.get(), this->http_www_google_.url()));
747 // Delete it via Expires. 809 // Delete it via Expires.
748 EXPECT_TRUE(this->SetCookie(cs.get(), 810 EXPECT_TRUE(this->SetCookie(cs.get(), this->http_www_google_.url(),
749 this->url_google_,
750 std::string(kValidCookieLine) + 811 std::string(kValidCookieLine) +
751 "; expires=Mon, 18-Apr-1977 22:50:13 GMT")); 812 "; expires=Mon, 18-Apr-1977 22:50:13 GMT"));
752 this->MatchCookieLines(std::string(), 813 this->MatchCookieLines(
753 this->GetCookies(cs.get(), this->url_google_)); 814 std::string(), this->GetCookies(cs.get(), this->http_www_google_.url()));
754 815
755 // Create a persistent cookie. 816 // Create a persistent cookie.
756 EXPECT_TRUE(this->SetCookie( 817 EXPECT_TRUE(this->SetCookie(
757 cs.get(), 818 cs.get(), this->http_www_google_.url(),
758 this->url_google_,
759 std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-22 22:50:13 GMT")); 819 std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-22 22:50:13 GMT"));
760 this->MatchCookieLines("A=B", this->GetCookies(cs.get(), this->url_google_)); 820 this->MatchCookieLines(
821 "A=B", this->GetCookies(cs.get(), this->http_www_google_.url()));
761 // Check that it is not deleted with significant enough clock skew. 822 // Check that it is not deleted with significant enough clock skew.
762 base::Time server_time; 823 base::Time server_time;
763 EXPECT_TRUE(base::Time::FromString("Sun, 17-Apr-1977 22:50:13 GMT", 824 EXPECT_TRUE(base::Time::FromString("Sun, 17-Apr-1977 22:50:13 GMT",
764 &server_time)); 825 &server_time));
765 EXPECT_TRUE(this->SetCookieWithServerTime( 826 EXPECT_TRUE(this->SetCookieWithServerTime(
766 cs.get(), 827 cs.get(), this->http_www_google_.url(),
767 this->url_google_,
768 std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-1977 22:50:13 GMT", 828 std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-1977 22:50:13 GMT",
769 server_time)); 829 server_time));
770 this->MatchCookieLines("A=B", this->GetCookies(cs.get(), this->url_google_)); 830 this->MatchCookieLines(
831 "A=B", this->GetCookies(cs.get(), this->http_www_google_.url()));
771 832
772 // Create a persistent cookie. 833 // Create a persistent cookie.
773 EXPECT_TRUE(this->SetCookie( 834 EXPECT_TRUE(this->SetCookie(
774 cs.get(), 835 cs.get(), this->http_www_google_.url(),
775 this->url_google_,
776 std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-22 22:50:13 GMT")); 836 std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-22 22:50:13 GMT"));
777 this->MatchCookieLines("A=B", this->GetCookies(cs.get(), this->url_google_)); 837 this->MatchCookieLines(
838 "A=B", this->GetCookies(cs.get(), this->http_www_google_.url()));
778 // Delete it via Expires, with a unix epoch of 0. 839 // Delete it via Expires, with a unix epoch of 0.
779 EXPECT_TRUE(this->SetCookie(cs.get(), 840 EXPECT_TRUE(this->SetCookie(cs.get(), this->http_www_google_.url(),
780 this->url_google_,
781 std::string(kValidCookieLine) + 841 std::string(kValidCookieLine) +
782 "; expires=Thu, 1-Jan-1970 00:00:00 GMT")); 842 "; expires=Thu, 1-Jan-1970 00:00:00 GMT"));
783 this->MatchCookieLines(std::string(), 843 this->MatchCookieLines(
784 this->GetCookies(cs.get(), this->url_google_)); 844 std::string(), this->GetCookies(cs.get(), this->http_www_google_.url()));
785 } 845 }
786 846
787 TYPED_TEST_P(CookieStoreTest, TestDeleteAllCreatedBetween) { 847 TYPED_TEST_P(CookieStoreTest, TestDeleteAllCreatedBetween) {
788 scoped_refptr<CookieStore> cs(this->GetCookieStore()); 848 scoped_refptr<CookieStore> cs(this->GetCookieStore());
789 const base::Time last_month = base::Time::Now() - 849 const base::Time last_month = base::Time::Now() -
790 base::TimeDelta::FromDays(30); 850 base::TimeDelta::FromDays(30);
791 const base::Time last_minute = base::Time::Now() - 851 const base::Time last_minute = base::Time::Now() -
792 base::TimeDelta::FromMinutes(1); 852 base::TimeDelta::FromMinutes(1);
793 const base::Time next_minute = base::Time::Now() + 853 const base::Time next_minute = base::Time::Now() +
794 base::TimeDelta::FromMinutes(1); 854 base::TimeDelta::FromMinutes(1);
795 const base::Time next_month = base::Time::Now() + 855 const base::Time next_month = base::Time::Now() +
796 base::TimeDelta::FromDays(30); 856 base::TimeDelta::FromDays(30);
797 857
798 // Add a cookie. 858 // Add a cookie.
799 EXPECT_TRUE(this->SetCookie(cs.get(), this->url_google_, "A=B")); 859 EXPECT_TRUE(this->SetCookie(cs.get(), this->http_www_google_.url(), "A=B"));
800 // Check that the cookie is in the store. 860 // Check that the cookie is in the store.
801 this->MatchCookieLines("A=B", this->GetCookies(cs.get(), this->url_google_)); 861 this->MatchCookieLines(
862 "A=B", this->GetCookies(cs.get(), this->http_www_google_.url()));
802 863
803 // Remove cookies in empty intervals. 864 // Remove cookies in empty intervals.
804 EXPECT_EQ(0, this->DeleteCreatedBetween(cs.get(), last_month, last_minute)); 865 EXPECT_EQ(0, this->DeleteCreatedBetween(cs.get(), last_month, last_minute));
805 EXPECT_EQ(0, this->DeleteCreatedBetween(cs.get(), next_minute, next_month)); 866 EXPECT_EQ(0, this->DeleteCreatedBetween(cs.get(), next_minute, next_month));
806 // Check that the cookie is still there. 867 // Check that the cookie is still there.
807 this->MatchCookieLines("A=B", this->GetCookies(cs.get(), this->url_google_)); 868 this->MatchCookieLines(
869 "A=B", this->GetCookies(cs.get(), this->http_www_google_.url()));
808 870
809 // Remove the cookie with an interval defined by two dates. 871 // Remove the cookie with an interval defined by two dates.
810 EXPECT_EQ(1, this->DeleteCreatedBetween(cs.get(), last_minute, next_minute)); 872 EXPECT_EQ(1, this->DeleteCreatedBetween(cs.get(), last_minute, next_minute));
811 // Check that the cookie disappeared. 873 // Check that the cookie disappeared.
812 this->MatchCookieLines(std::string(), 874 this->MatchCookieLines(
813 this->GetCookies(cs.get(), this->url_google_)); 875 std::string(), this->GetCookies(cs.get(), this->http_www_google_.url()));
814 876
815 // Add another cookie. 877 // Add another cookie.
816 EXPECT_TRUE(this->SetCookie(cs.get(), this->url_google_, "C=D")); 878 EXPECT_TRUE(this->SetCookie(cs.get(), this->http_www_google_.url(), "C=D"));
817 // Check that the cookie is in the store. 879 // Check that the cookie is in the store.
818 this->MatchCookieLines("C=D", this->GetCookies(cs.get(), this->url_google_)); 880 this->MatchCookieLines(
881 "C=D", this->GetCookies(cs.get(), this->http_www_google_.url()));
819 882
820 // Remove the cookie with a null ending time. 883 // Remove the cookie with a null ending time.
821 EXPECT_EQ(1, this->DeleteCreatedBetween(cs.get(), last_minute, base::Time())); 884 EXPECT_EQ(1, this->DeleteCreatedBetween(cs.get(), last_minute, base::Time()));
822 // Check that the cookie disappeared. 885 // Check that the cookie disappeared.
823 this->MatchCookieLines(std::string(), 886 this->MatchCookieLines(
824 this->GetCookies(cs.get(), this->url_google_)); 887 std::string(), this->GetCookies(cs.get(), this->http_www_google_.url()));
825 } 888 }
826 889
827 TYPED_TEST_P(CookieStoreTest, TestDeleteAllCreatedBetweenForHost) { 890 TYPED_TEST_P(CookieStoreTest, TestDeleteAllCreatedBetweenForHost) {
828 scoped_refptr<CookieStore> cs(this->GetCookieStore()); 891 scoped_refptr<CookieStore> cs(this->GetCookieStore());
829 GURL url_not_google("http://www.notgoogle.com"); 892 GURL url_not_google("http://www.notgoogle.com");
830 base::Time now = base::Time::Now(); 893 base::Time now = base::Time::Now();
831 894
832 // These 3 cookies match the time range and host. 895 // These 3 cookies match the time range and host.
833 EXPECT_TRUE(this->SetCookie(cs.get(), this->url_google_, "A=B")); 896 EXPECT_TRUE(this->SetCookie(cs.get(), this->http_www_google_.url(), "A=B"));
834 EXPECT_TRUE(this->SetCookie(cs.get(), this->url_google_, "C=D")); 897 EXPECT_TRUE(this->SetCookie(cs.get(), this->http_www_google_.url(), "C=D"));
835 EXPECT_TRUE(this->SetCookie(cs.get(), this->url_google_, "Y=Z")); 898 EXPECT_TRUE(this->SetCookie(cs.get(), this->http_www_google_.url(), "Y=Z"));
836 899
837 // This cookie does not match host. 900 // This cookie does not match host.
838 EXPECT_TRUE(this->SetCookie(cs.get(), url_not_google, "E=F")); 901 EXPECT_TRUE(this->SetCookie(cs.get(), url_not_google, "E=F"));
839 902
840 // Delete cookies. 903 // Delete cookies.
841 EXPECT_EQ( 904 EXPECT_EQ(
842 3, // Deletes A=B, C=D, Y=Z 905 3, // Deletes A=B, C=D, Y=Z
843 this->DeleteAllCreatedBetweenForHost( 906 this->DeleteAllCreatedBetweenForHost(cs.get(), now, base::Time::Max(),
844 cs.get(), now, base::Time::Max(), this->url_google_)); 907 this->http_www_google_.url()));
845 } 908 }
846 909
847 TYPED_TEST_P(CookieStoreTest, TestSecure) { 910 TYPED_TEST_P(CookieStoreTest, TestSecure) {
848 scoped_refptr<CookieStore> cs(this->GetCookieStore()); 911 scoped_refptr<CookieStore> cs(this->GetCookieStore());
849 912
850 EXPECT_TRUE(this->SetCookie(cs.get(), this->url_google_, "A=B")); 913 EXPECT_TRUE(this->SetCookie(cs.get(), this->http_www_google_.url(), "A=B"));
851 this->MatchCookieLines("A=B",
852 this->GetCookies(cs.get(), this->url_google_));
853 this->MatchCookieLines( 914 this->MatchCookieLines(
854 "A=B", this->GetCookies(cs.get(), this->url_google_secure_)); 915 "A=B", this->GetCookies(cs.get(), this->http_www_google_.url()));
916 this->MatchCookieLines(
917 "A=B", this->GetCookies(cs.get(), this->https_www_google_.url()));
855 918
856 EXPECT_TRUE( 919 EXPECT_TRUE(this->SetCookie(cs.get(), this->https_www_google_.url(),
857 this->SetCookie(cs.get(), this->url_google_secure_, "A=B; secure")); 920 "A=B; secure"));
858 // The secure should overwrite the non-secure. 921 // The secure should overwrite the non-secure.
859 this->MatchCookieLines(std::string(), 922 this->MatchCookieLines(
860 this->GetCookies(cs.get(), this->url_google_)); 923 std::string(),
861 this->MatchCookieLines("A=B", 924 this->GetCookies(cs.get(), this->http_www_google_.url()));
862 this->GetCookies(cs.get(), this->url_google_secure_)); 925 this->MatchCookieLines(
926 "A=B", this->GetCookies(cs.get(), this->https_www_google_.url()));
863 927
864 EXPECT_TRUE( 928 EXPECT_TRUE(this->SetCookie(cs.get(), this->https_www_google_.url(),
865 this->SetCookie(cs.get(), this->url_google_secure_, "D=E; secure")); 929 "D=E; secure"));
866 this->MatchCookieLines(std::string(), 930 this->MatchCookieLines(
867 this->GetCookies(cs.get(), this->url_google_)); 931 std::string(),
868 this->MatchCookieLines("A=B; D=E", 932 this->GetCookies(cs.get(), this->http_www_google_.url()));
869 this->GetCookies(cs.get(), this->url_google_secure_)); 933 this->MatchCookieLines(
934 "A=B; D=E", this->GetCookies(cs.get(), this->https_www_google_.url()));
870 935
871 EXPECT_TRUE(this->SetCookie(cs.get(), this->url_google_secure_, "A=B")); 936 EXPECT_TRUE(
937 this->SetCookie(cs.get(), this->https_www_google_.url(), "A=B"));
872 // The non-secure should overwrite the secure. 938 // The non-secure should overwrite the secure.
873 this->MatchCookieLines("A=B", this->GetCookies(cs.get(), this->url_google_)); 939 this->MatchCookieLines(
874 this->MatchCookieLines("D=E; A=B", 940 "A=B", this->GetCookies(cs.get(), this->http_www_google_.url()));
875 this->GetCookies(cs.get(), this->url_google_secure_)); 941 this->MatchCookieLines(
942 "D=E; A=B", this->GetCookies(cs.get(), this->https_www_google_.url()));
876 } 943 }
877 944
878 static const int kLastAccessThresholdMilliseconds = 200; 945 static const int kLastAccessThresholdMilliseconds = 200;
879 946
880 // Formerly NetUtilTest.CookieTest back when we used wininet's cookie handling. 947 // Formerly NetUtilTest.CookieTest back when we used wininet's cookie handling.
881 TYPED_TEST_P(CookieStoreTest, NetUtilCookieTest) { 948 TYPED_TEST_P(CookieStoreTest, NetUtilCookieTest) {
882 const GURL test_url("http://mojo.jojo.google.izzle/"); 949 const GURL test_url("http://mojo.jojo.google.izzle/");
883 950
884 scoped_refptr<CookieStore> cs(this->GetCookieStore()); 951 scoped_refptr<CookieStore> cs(this->GetCookieStore());
885 952
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
986 EXPECT_TRUE(this->SetCookie( 1053 EXPECT_TRUE(this->SetCookie(
987 cs.get(), GURL("http://news.bbc.co.uk/midpath/x.html"), "g=10")); 1054 cs.get(), GURL("http://news.bbc.co.uk/midpath/x.html"), "g=10"));
988 EXPECT_EQ("d=1; a=4; e=1; b=1; c=1", 1055 EXPECT_EQ("d=1; a=4; e=1; b=1; c=1",
989 this->GetCookies(cs.get(), 1056 this->GetCookies(cs.get(),
990 GURL("http://d.c.b.a.google.com/aa/bb/cc/dd"))); 1057 GURL("http://d.c.b.a.google.com/aa/bb/cc/dd")));
991 } 1058 }
992 1059
993 TYPED_TEST_P(CookieStoreTest, DeleteSessionCookie) { 1060 TYPED_TEST_P(CookieStoreTest, DeleteSessionCookie) {
994 scoped_refptr<CookieStore> cs(this->GetCookieStore()); 1061 scoped_refptr<CookieStore> cs(this->GetCookieStore());
995 // Create a session cookie and a persistent cookie. 1062 // Create a session cookie and a persistent cookie.
1063 EXPECT_TRUE(this->SetCookie(cs.get(), this->http_www_google_.url(),
1064 std::string(kValidCookieLine)));
996 EXPECT_TRUE(this->SetCookie( 1065 EXPECT_TRUE(this->SetCookie(
997 cs.get(), this->url_google_, std::string(kValidCookieLine))); 1066 cs.get(), this->http_www_google_.url(),
998 EXPECT_TRUE(this->SetCookie(cs.get(), 1067 this->http_www_google_.Format("C=D; path=/; domain=%D;"
999 this->url_google_, 1068 "expires=Mon, 18-Apr-22 22:50:13 GMT")));
1000 "C=D; path=/; domain=google.izzle;" 1069 this->MatchCookieLines(
1001 "expires=Mon, 18-Apr-22 22:50:13 GMT")); 1070 "A=B; C=D", this->GetCookies(cs.get(), this->http_www_google_.url()));
1002 this->MatchCookieLines("A=B; C=D",
1003 this->GetCookies(cs.get(), this->url_google_));
1004 // Delete the session cookie. 1071 // Delete the session cookie.
1005 this->DeleteSessionCookies(cs.get()); 1072 this->DeleteSessionCookies(cs.get());
1006 // Check that the session cookie has been deleted but not the persistent one. 1073 // Check that the session cookie has been deleted but not the persistent one.
1007 EXPECT_EQ("C=D", this->GetCookies(cs.get(), this->url_google_)); 1074 EXPECT_EQ("C=D", this->GetCookies(cs.get(), this->http_www_google_.url()));
1008 } 1075 }
1009 1076
1010 REGISTER_TYPED_TEST_CASE_P(CookieStoreTest, 1077 REGISTER_TYPED_TEST_CASE_P(CookieStoreTest,
1011 TypeTest, 1078 TypeTest,
1012 DomainTest, 1079 DomainTest,
1013 DomainWithTrailingDotTest, 1080 DomainWithTrailingDotTest,
1014 ValidSubdomainTest, 1081 ValidSubdomainTest,
1015 InvalidDomainTest, 1082 InvalidDomainTest,
1016 DomainWithoutLeadingDotTest, 1083 DomainWithoutLeadingDotTest,
1017 CaseInsensitiveDomainTest, 1084 CaseInsensitiveDomainTest,
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
1103 Thread other_thread_; 1170 Thread other_thread_;
1104 }; 1171 };
1105 1172
1106 TYPED_TEST_CASE_P(MultiThreadedCookieStoreTest); 1173 TYPED_TEST_CASE_P(MultiThreadedCookieStoreTest);
1107 1174
1108 // TODO(ycxiao): Eventually, we will need to create a separate thread, create 1175 // TODO(ycxiao): Eventually, we will need to create a separate thread, create
1109 // the cookie store on that thread (or at least its store, i.e., the DB 1176 // the cookie store on that thread (or at least its store, i.e., the DB
1110 // thread). 1177 // thread).
1111 TYPED_TEST_P(MultiThreadedCookieStoreTest, ThreadCheckGetCookies) { 1178 TYPED_TEST_P(MultiThreadedCookieStoreTest, ThreadCheckGetCookies) {
1112 scoped_refptr<CookieStore> cs(this->GetCookieStore()); 1179 scoped_refptr<CookieStore> cs(this->GetCookieStore());
1113 EXPECT_TRUE(this->SetCookie(cs.get(), this->url_google_, "A=B")); 1180 EXPECT_TRUE(this->SetCookie(cs.get(), this->http_www_google_.url(), "A=B"));
1114 this->MatchCookieLines("A=B", this->GetCookies(cs.get(), this->url_google_)); 1181 this->MatchCookieLines(
1182 "A=B", this->GetCookies(cs.get(), this->http_www_google_.url()));
1115 StringResultCookieCallback callback(&this->other_thread_); 1183 StringResultCookieCallback callback(&this->other_thread_);
1116 base::Closure task = 1184 base::Closure task = base::Bind(
1117 base::Bind(&MultiThreadedCookieStoreTest<TypeParam>::GetCookiesTask, 1185 &MultiThreadedCookieStoreTest<TypeParam>::GetCookiesTask,
1118 base::Unretained(this), cs, this->url_google_, &callback); 1186 base::Unretained(this), cs, this->http_www_google_.url(), &callback);
1119 this->RunOnOtherThread(task); 1187 this->RunOnOtherThread(task);
1120 EXPECT_TRUE(callback.did_run()); 1188 EXPECT_TRUE(callback.did_run());
1121 EXPECT_EQ("A=B", callback.result()); 1189 EXPECT_EQ("A=B", callback.result());
1122 } 1190 }
1123 1191
1124 TYPED_TEST_P(MultiThreadedCookieStoreTest, ThreadCheckGetCookiesWithOptions) { 1192 TYPED_TEST_P(MultiThreadedCookieStoreTest, ThreadCheckGetCookiesWithOptions) {
1125 scoped_refptr<CookieStore> cs(this->GetCookieStore()); 1193 scoped_refptr<CookieStore> cs(this->GetCookieStore());
1126 CookieOptions options; 1194 CookieOptions options;
1127 if (!TypeParam::supports_http_only) 1195 if (!TypeParam::supports_http_only)
1128 options.set_include_httponly(); 1196 options.set_include_httponly();
1129 EXPECT_TRUE(this->SetCookie(cs.get(), this->url_google_, "A=B")); 1197 EXPECT_TRUE(this->SetCookie(cs.get(), this->http_www_google_.url(), "A=B"));
1130 this->MatchCookieLines( 1198 this->MatchCookieLines(
1131 "A=B", this->GetCookiesWithOptions(cs.get(), this->url_google_, options)); 1199 "A=B", this->GetCookiesWithOptions(cs.get(), this->http_www_google_.url(),
1200 options));
1132 StringResultCookieCallback callback(&this->other_thread_); 1201 StringResultCookieCallback callback(&this->other_thread_);
1133 base::Closure task = base::Bind( 1202 base::Closure task = base::Bind(
1134 &MultiThreadedCookieStoreTest<TypeParam>::GetCookiesWithOptionsTask, 1203 &MultiThreadedCookieStoreTest<TypeParam>::GetCookiesWithOptionsTask,
1135 base::Unretained(this), cs, this->url_google_, options, &callback); 1204 base::Unretained(this), cs, this->http_www_google_.url(), options,
1205 &callback);
1136 this->RunOnOtherThread(task); 1206 this->RunOnOtherThread(task);
1137 EXPECT_TRUE(callback.did_run()); 1207 EXPECT_TRUE(callback.did_run());
1138 EXPECT_EQ("A=B", callback.result()); 1208 EXPECT_EQ("A=B", callback.result());
1139 } 1209 }
1140 1210
1141 TYPED_TEST_P(MultiThreadedCookieStoreTest, ThreadCheckSetCookieWithOptions) { 1211 TYPED_TEST_P(MultiThreadedCookieStoreTest, ThreadCheckSetCookieWithOptions) {
1142 scoped_refptr<CookieStore> cs(this->GetCookieStore()); 1212 scoped_refptr<CookieStore> cs(this->GetCookieStore());
1143 CookieOptions options; 1213 CookieOptions options;
1144 if (!TypeParam::supports_http_only) 1214 if (!TypeParam::supports_http_only)
1145 options.set_include_httponly(); 1215 options.set_include_httponly();
1146 EXPECT_TRUE( 1216 EXPECT_TRUE(this->SetCookieWithOptions(cs.get(), this->http_www_google_.url(),
1147 this->SetCookieWithOptions(cs.get(), this->url_google_, "A=B", options)); 1217 "A=B", options));
1148 ResultSavingCookieCallback<bool> callback(&this->other_thread_); 1218 ResultSavingCookieCallback<bool> callback(&this->other_thread_);
1149 base::Closure task = base::Bind( 1219 base::Closure task = base::Bind(
1150 &MultiThreadedCookieStoreTest<TypeParam>::SetCookieWithOptionsTask, 1220 &MultiThreadedCookieStoreTest<TypeParam>::SetCookieWithOptionsTask,
1151 base::Unretained(this), cs, this->url_google_, "A=B", options, &callback); 1221 base::Unretained(this), cs, this->http_www_google_.url(), "A=B", options,
1222 &callback);
1152 this->RunOnOtherThread(task); 1223 this->RunOnOtherThread(task);
1153 EXPECT_TRUE(callback.did_run()); 1224 EXPECT_TRUE(callback.did_run());
1154 EXPECT_TRUE(callback.result()); 1225 EXPECT_TRUE(callback.result());
1155 } 1226 }
1156 1227
1157 TYPED_TEST_P(MultiThreadedCookieStoreTest, ThreadCheckDeleteCookie) { 1228 TYPED_TEST_P(MultiThreadedCookieStoreTest, ThreadCheckDeleteCookie) {
1158 scoped_refptr<CookieStore> cs(this->GetCookieStore()); 1229 scoped_refptr<CookieStore> cs(this->GetCookieStore());
1159 CookieOptions options; 1230 CookieOptions options;
1160 if (!TypeParam::supports_http_only) 1231 if (!TypeParam::supports_http_only)
1161 options.set_include_httponly(); 1232 options.set_include_httponly();
1162 EXPECT_TRUE( 1233 EXPECT_TRUE(this->SetCookieWithOptions(cs.get(), this->http_www_google_.url(),
1163 this->SetCookieWithOptions(cs.get(), this->url_google_, "A=B", options)); 1234 "A=B", options));
1164 this->DeleteCookie(cs.get(), this->url_google_, "A"); 1235 this->DeleteCookie(cs.get(), this->http_www_google_.url(), "A");
1165 EXPECT_TRUE( 1236 EXPECT_TRUE(this->SetCookieWithOptions(cs.get(), this->http_www_google_.url(),
1166 this->SetCookieWithOptions(cs.get(), this->url_google_, "A=B", options)); 1237 "A=B", options));
1167 NoResultCookieCallback callback(&this->other_thread_); 1238 NoResultCookieCallback callback(&this->other_thread_);
1168 base::Closure task = 1239 base::Closure task = base::Bind(
1169 base::Bind(&MultiThreadedCookieStoreTest<TypeParam>::DeleteCookieTask, 1240 &MultiThreadedCookieStoreTest<TypeParam>::DeleteCookieTask,
1170 base::Unretained(this), cs, this->url_google_, "A", &callback); 1241 base::Unretained(this), cs, this->http_www_google_.url(), "A", &callback);
1171 this->RunOnOtherThread(task); 1242 this->RunOnOtherThread(task);
1172 EXPECT_TRUE(callback.did_run()); 1243 EXPECT_TRUE(callback.did_run());
1173 } 1244 }
1174 1245
1175 TYPED_TEST_P(MultiThreadedCookieStoreTest, ThreadCheckDeleteSessionCookies) { 1246 TYPED_TEST_P(MultiThreadedCookieStoreTest, ThreadCheckDeleteSessionCookies) {
1176 scoped_refptr<CookieStore> cs(this->GetCookieStore()); 1247 scoped_refptr<CookieStore> cs(this->GetCookieStore());
1177 CookieOptions options; 1248 CookieOptions options;
1178 if (!TypeParam::supports_http_only) 1249 if (!TypeParam::supports_http_only)
1179 options.set_include_httponly(); 1250 options.set_include_httponly();
1180 EXPECT_TRUE( 1251 EXPECT_TRUE(this->SetCookieWithOptions(cs.get(), this->http_www_google_.url(),
1181 this->SetCookieWithOptions(cs.get(), this->url_google_, "A=B", options)); 1252 "A=B", options));
1182 EXPECT_TRUE( 1253 EXPECT_TRUE(this->SetCookieWithOptions(
1183 this->SetCookieWithOptions(cs.get(), 1254 cs.get(), this->http_www_google_.url(),
1184 this->url_google_, 1255 "B=C; expires=Mon, 18-Apr-22 22:50:13 GMT", options));
1185 "B=C; expires=Mon, 18-Apr-22 22:50:13 GMT",
1186 options));
1187 EXPECT_EQ(1, this->DeleteSessionCookies(cs.get())); 1256 EXPECT_EQ(1, this->DeleteSessionCookies(cs.get()));
1188 EXPECT_EQ(0, this->DeleteSessionCookies(cs.get())); 1257 EXPECT_EQ(0, this->DeleteSessionCookies(cs.get()));
1189 EXPECT_TRUE( 1258 EXPECT_TRUE(this->SetCookieWithOptions(cs.get(), this->http_www_google_.url(),
1190 this->SetCookieWithOptions(cs.get(), this->url_google_, "A=B", options)); 1259 "A=B", options));
1191 ResultSavingCookieCallback<int> callback(&this->other_thread_); 1260 ResultSavingCookieCallback<int> callback(&this->other_thread_);
1192 base::Closure task = base::Bind( 1261 base::Closure task = base::Bind(
1193 &MultiThreadedCookieStoreTest<TypeParam>::DeleteSessionCookiesTask, 1262 &MultiThreadedCookieStoreTest<TypeParam>::DeleteSessionCookiesTask,
1194 base::Unretained(this), cs, &callback); 1263 base::Unretained(this), cs, &callback);
1195 this->RunOnOtherThread(task); 1264 this->RunOnOtherThread(task);
1196 EXPECT_TRUE(callback.did_run()); 1265 EXPECT_TRUE(callback.did_run());
1197 EXPECT_EQ(1, callback.result()); 1266 EXPECT_EQ(1, callback.result());
1198 } 1267 }
1199 1268
1200 REGISTER_TYPED_TEST_CASE_P(MultiThreadedCookieStoreTest, 1269 REGISTER_TYPED_TEST_CASE_P(MultiThreadedCookieStoreTest,
1201 ThreadCheckGetCookies, 1270 ThreadCheckGetCookies,
1202 ThreadCheckGetCookiesWithOptions, 1271 ThreadCheckGetCookiesWithOptions,
1203 ThreadCheckSetCookieWithOptions, 1272 ThreadCheckSetCookieWithOptions,
1204 ThreadCheckDeleteCookie, 1273 ThreadCheckDeleteCookie,
1205 ThreadCheckDeleteSessionCookies); 1274 ThreadCheckDeleteSessionCookies);
1206 1275
1207 } // namespace net 1276 } // namespace net
1208 1277
1209 #endif // NET_COOKIES_COOKIE_STORE_UNITTEST_H_ 1278 #endif // NET_COOKIES_COOKIE_STORE_UNITTEST_H_
OLDNEW
« no previous file with comments | « net/cookies/cookie_monster_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698