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

Side by Side Diff: net/base/cookie_monster_unittest.cc

Issue 3070001: Fixes targeting the unique creation times invariant in the CookieMonster: (Closed)
Patch Set: Made creation times in perftest unique. Created 10 years, 4 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 (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 <time.h> 5 #include <time.h>
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/platform_thread.h" 10 #include "base/platform_thread.h"
11 #include "base/ref_counted.h" 11 #include "base/ref_counted.h"
12 #include "base/scoped_ptr.h" 12 #include "base/scoped_ptr.h"
13 #include "base/string_util.h" 13 #include "base/string_util.h"
14 #include "base/time.h" 14 #include "base/time.h"
15 #include "googleurl/src/gurl.h" 15 #include "googleurl/src/gurl.h"
16 #include "net/base/cookie_monster.h" 16 #include "net/base/cookie_monster.h"
17 #include "net/base/cookie_monster_store_test.h" // For CookieStore Mock
17 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
18 19
20 namespace net {
21
19 using base::Time; 22 using base::Time;
20 using base::TimeDelta; 23 using base::TimeDelta;
21 24
22 namespace { 25 namespace {
23 26
24 class ParsedCookieTest : public testing::Test { }; 27 class ParsedCookieTest : public testing::Test { };
25 class CookieMonsterTest : public testing::Test { }; 28 class CookieMonsterTest : public testing::Test { };
26 29
27 // Describes a call to one of the 3 functions of PersistentCookieStore.
28 struct CookieStoreCommand {
29 enum Type {
30 ADD,
31 UPDATE_ACCESS_TIME,
32 REMOVE,
33 };
34
35 CookieStoreCommand(Type type,
36 const std::string& key,
37 const net::CookieMonster::CanonicalCookie& cookie)
38 : type(type), key(key), cookie(cookie) {}
39
40 Type type;
41 std::string key; // Only applicable to the ADD command.
42 net::CookieMonster::CanonicalCookie cookie;
43 };
44
45 // Implementation of PersistentCookieStore that captures the
46 // received commands and saves them to a list.
47 // The result of calls to Load() can be configured using SetLoadExpectation().
48 class MockPersistentCookieStore
49 : public net::CookieMonster::PersistentCookieStore {
50 public:
51 typedef std::vector<CookieStoreCommand> CommandList;
52
53 MockPersistentCookieStore() : load_return_value_(true) {
54 }
55
56 virtual bool Load(
57 std::vector<net::CookieMonster::KeyedCanonicalCookie>* out_cookies) {
58 bool ok = load_return_value_;
59 if (ok)
60 *out_cookies = load_result_;
61 return ok;
62 }
63
64 virtual void AddCookie(const std::string& key,
65 const net::CookieMonster::CanonicalCookie& cookie) {
66 commands_.push_back(
67 CookieStoreCommand(CookieStoreCommand::ADD, key, cookie));
68 }
69
70 virtual void UpdateCookieAccessTime(
71 const net::CookieMonster::CanonicalCookie& cookie) {
72 commands_.push_back(CookieStoreCommand(
73 CookieStoreCommand::UPDATE_ACCESS_TIME, std::string(), cookie));
74 }
75
76 virtual void DeleteCookie(
77 const net::CookieMonster::CanonicalCookie& cookie) {
78 commands_.push_back(
79 CookieStoreCommand(CookieStoreCommand::REMOVE, std::string(), cookie));
80 }
81
82 void SetLoadExpectation(
83 bool return_value,
84 const std::vector<net::CookieMonster::KeyedCanonicalCookie>& result) {
85 load_return_value_ = return_value;
86 load_result_ = result;
87 }
88
89 const CommandList& commands() const {
90 return commands_;
91 }
92
93 private:
94 CommandList commands_;
95
96 // Deferred result to use when Load() is called.
97 bool load_return_value_;
98 std::vector<net::CookieMonster::KeyedCanonicalCookie> load_result_;
99
100 DISALLOW_COPY_AND_ASSIGN(MockPersistentCookieStore);
101 };
102
103 // Mock for CookieMonster::Delegate
104 class MockCookieMonsterDelegate : public net::CookieMonster::Delegate {
105 public:
106 typedef std::pair<net::CookieMonster::CanonicalCookie, bool>
107 CookieNotification;
108
109 MockCookieMonsterDelegate() {}
110
111 virtual void OnCookieChanged(
112 const net::CookieMonster::CanonicalCookie& cookie,
113 bool removed) {
114 CookieNotification notification(cookie, removed);
115 changes_.push_back(notification);
116 }
117
118 const std::vector<CookieNotification>& changes() const { return changes_; }
119
120 void reset() { changes_.clear(); }
121
122 private:
123 virtual ~MockCookieMonsterDelegate() {}
124
125 std::vector<CookieNotification> changes_;
126
127 DISALLOW_COPY_AND_ASSIGN(MockCookieMonsterDelegate);
128 };
129
130 // Helper to build a list of KeyedCanonicalCookies.
131 void AddKeyedCookieToList(
132 const std::string& key,
133 const std::string& cookie_line,
134 const Time& creation_time,
135 std::vector<net::CookieMonster::KeyedCanonicalCookie>* out_list) {
136
137 // Parse the cookie line.
138 net::CookieMonster::ParsedCookie pc(cookie_line);
139 EXPECT_TRUE(pc.IsValid());
140
141 // This helper is simplistic in interpreting a parsed cookie, in order to
142 // avoid duplicated CookieMonster's CanonPath() and CanonExpiration()
143 // functions. Would be nice to export them, and re-use here.
144 EXPECT_FALSE(pc.HasMaxAge());
145 EXPECT_TRUE(pc.HasPath());
146 Time cookie_expires = pc.HasExpires() ?
147 net::CookieMonster::ParseCookieTime(pc.Expires()) : Time();
148 std::string cookie_path = pc.Path();
149
150 scoped_ptr<net::CookieMonster::CanonicalCookie> cookie(
151 new net::CookieMonster::CanonicalCookie(
152 pc.Name(), pc.Value(), key, cookie_path,
153 pc.IsSecure(), pc.IsHttpOnly(),
154 creation_time, creation_time,
155 !cookie_expires.is_null(),
156 cookie_expires));
157
158 out_list->push_back(
159 net::CookieMonster::KeyedCanonicalCookie(
160 key, cookie.release()));
161 }
162
163 // Helper for DeleteAllForHost test; repopulates CM with same layout 30 // Helper for DeleteAllForHost test; repopulates CM with same layout
164 // each time. 31 // each time.
165 const char* kTopLevelDomainPlus1 = "http://www.harvard.edu"; 32 const char* kTopLevelDomainPlus1 = "http://www.harvard.edu";
166 const char* kTopLevelDomainPlus2 = "http://www.math.harvard.edu"; 33 const char* kTopLevelDomainPlus2 = "http://www.math.harvard.edu";
167 const char* kTopLevelDomainPlus2Secure = "https://www.math.harvard.edu"; 34 const char* kTopLevelDomainPlus2Secure = "https://www.math.harvard.edu";
168 const char* kTopLevelDomainPlus3 = 35 const char* kTopLevelDomainPlus3 =
169 "http://www.bourbaki.math.harvard.edu"; 36 "http://www.bourbaki.math.harvard.edu";
170 const char* kOtherDomain = "http://www.mit.edu"; 37 const char* kOtherDomain = "http://www.mit.edu";
171 38
172 void PopulateCmForDeleteAllForHost(scoped_refptr<net::CookieMonster> cm) { 39 void PopulateCmForDeleteAllForHost(scoped_refptr<net::CookieMonster> cm) {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 EXPECT_TRUE(cm->SetCookieWithDetails(url_top_level_domain_plus_2, 107 EXPECT_TRUE(cm->SetCookieWithDetails(url_top_level_domain_plus_2,
241 "host_path_2", "X", 108 "host_path_2", "X",
242 "", "/dir1/dir2", 109 "", "/dir1/dir2",
243 base::Time(), false, false)); 110 base::Time(), false, false));
244 111
245 EXPECT_EQ(13U, cm->GetAllCookies().size()); 112 EXPECT_EQ(13U, cm->GetAllCookies().size());
246 } 113 }
247 114
248 } // namespace 115 } // namespace
249 116
250
251 TEST(ParsedCookieTest, TestBasic) { 117 TEST(ParsedCookieTest, TestBasic) {
252 net::CookieMonster::ParsedCookie pc("a=b"); 118 net::CookieMonster::ParsedCookie pc("a=b");
253 EXPECT_TRUE(pc.IsValid()); 119 EXPECT_TRUE(pc.IsValid());
254 EXPECT_FALSE(pc.IsSecure()); 120 EXPECT_FALSE(pc.IsSecure());
255 EXPECT_EQ("a", pc.Name()); 121 EXPECT_EQ("a", pc.Name());
256 EXPECT_EQ("b", pc.Value()); 122 EXPECT_EQ("b", pc.Value());
257 } 123 }
258 124
259 TEST(ParsedCookieTest, TestQuoted) { 125 TEST(ParsedCookieTest, TestQuoted) {
260 // These are some quoting cases which the major browsers all 126 // These are some quoting cases which the major browsers all
(...skipping 1222 matching lines...) Expand 10 before | Expand all | Expand 10 after
1483 // duplicate cookie (both from the in-memory cache, and from the backing store). 1349 // duplicate cookie (both from the in-memory cache, and from the backing store).
1484 // 1350 //
1485 // This is a regression test for: http://crbug.com/17855. 1351 // This is a regression test for: http://crbug.com/17855.
1486 TEST(CookieMonsterTest, DontImportDuplicateCookies) { 1352 TEST(CookieMonsterTest, DontImportDuplicateCookies) {
1487 GURL url_google("http://www.google.com/"); 1353 GURL url_google("http://www.google.com/");
1488 1354
1489 scoped_refptr<MockPersistentCookieStore> store( 1355 scoped_refptr<MockPersistentCookieStore> store(
1490 new MockPersistentCookieStore); 1356 new MockPersistentCookieStore);
1491 1357
1492 // We will fill some initial cookies into the PersistentCookieStore, 1358 // We will fill some initial cookies into the PersistentCookieStore,
1493 // to simulate a database with 4 duplicates. 1359 // to simulate a database with 4 duplicates. Note that we need to
1360 // be careful not to have any duplicate creation times at all (as it's a
1361 // violation of a CookieMonster invariant) even if Time::Now() doesn't
1362 // move between calls.
1494 std::vector<net::CookieMonster::KeyedCanonicalCookie> initial_cookies; 1363 std::vector<net::CookieMonster::KeyedCanonicalCookie> initial_cookies;
1495 1364
1496 // Insert 4 cookies with name "X" on path "/", with varying creation 1365 // Insert 4 cookies with name "X" on path "/", with varying creation
1497 // dates. We expect only the most recent one to be preserved following 1366 // dates. We expect only the most recent one to be preserved following
1498 // the import. 1367 // the import.
1499 1368
1500 AddKeyedCookieToList("www.google.com", 1369 AddKeyedCookieToList("www.google.com",
1501 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", 1370 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT",
1502 Time::Now() + TimeDelta::FromDays(3), 1371 Time::Now() + TimeDelta::FromDays(3),
1503 &initial_cookies); 1372 &initial_cookies);
(...skipping 18 matching lines...) Expand all
1522 // dates. We expect only the most recent one to be preserved the import. 1391 // dates. We expect only the most recent one to be preserved the import.
1523 1392
1524 // ===> This one is the WINNER (biggest creation time). <==== 1393 // ===> This one is the WINNER (biggest creation time). <====
1525 AddKeyedCookieToList("www.google.com", 1394 AddKeyedCookieToList("www.google.com",
1526 "X=a1; path=/2; expires=Mon, 18-Apr-22 22:50:14 GMT", 1395 "X=a1; path=/2; expires=Mon, 18-Apr-22 22:50:14 GMT",
1527 Time::Now() + TimeDelta::FromDays(9), 1396 Time::Now() + TimeDelta::FromDays(9),
1528 &initial_cookies); 1397 &initial_cookies);
1529 1398
1530 AddKeyedCookieToList("www.google.com", 1399 AddKeyedCookieToList("www.google.com",
1531 "X=a2; path=/2; expires=Mon, 18-Apr-22 22:50:14 GMT", 1400 "X=a2; path=/2; expires=Mon, 18-Apr-22 22:50:14 GMT",
1532 Time::Now() + TimeDelta::FromDays(1), 1401 Time::Now() + TimeDelta::FromDays(2),
1533 &initial_cookies); 1402 &initial_cookies);
1534 1403
1535 // Insert 1 cookie with name "Y" on path "/". 1404 // Insert 1 cookie with name "Y" on path "/".
1536 AddKeyedCookieToList("www.google.com", 1405 AddKeyedCookieToList("www.google.com",
1537 "Y=a; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", 1406 "Y=a; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT",
1538 Time::Now() + TimeDelta::FromDays(9), 1407 Time::Now() + TimeDelta::FromDays(10),
1539 &initial_cookies); 1408 &initial_cookies);
1540 1409
1541 // Inject our initial cookies into the mock PersistentCookieStore. 1410 // Inject our initial cookies into the mock PersistentCookieStore.
1542 store->SetLoadExpectation(true, initial_cookies); 1411 store->SetLoadExpectation(true, initial_cookies);
1543 1412
1544 scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(store, NULL)); 1413 scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(store, NULL));
1545 1414
1546 // Verify that duplicates were not imported for path "/". 1415 // Verify that duplicates were not imported for path "/".
1547 // (If this had failed, GetCookies() would have also returned X=1, X=2, X=4). 1416 // (If this had failed, GetCookies() would have also returned X=1, X=2, X=4).
1548 EXPECT_EQ("X=3; Y=a", cm->GetCookies(GURL("http://www.google.com/"))); 1417 EXPECT_EQ("X=3; Y=a", cm->GetCookies(GURL("http://www.google.com/")));
1549 1418
1550 // Verify that same-named cookie on a different path ("/x2") didn't get 1419 // Verify that same-named cookie on a different path ("/x2") didn't get
1551 // messed up. 1420 // messed up.
1552 EXPECT_EQ("X=a1; X=3; Y=a", 1421 EXPECT_EQ("X=a1; X=3; Y=a",
1553 cm->GetCookies(GURL("http://www.google.com/2/x"))); 1422 cm->GetCookies(GURL("http://www.google.com/2/x")));
1554 1423
1555 // Verify that the PersistentCookieStore was told to kill its 4 duplicates. 1424 // Verify that the PersistentCookieStore was told to kill its 4 duplicates.
1556 ASSERT_EQ(4u, store->commands().size()); 1425 ASSERT_EQ(4u, store->commands().size());
1557 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[0].type); 1426 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[0].type);
1558 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[1].type); 1427 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[1].type);
1559 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[2].type); 1428 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[2].type);
1560 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[3].type); 1429 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[3].type);
1561 } 1430 }
1562 1431
1432 // Tests importing from a persistent cookie store that contains cookies
1433 // with duplicate creation times. This situation should be handled by
1434 // dropping the cookies before insertion/visibility to user.
1435 //
1436 // This is a regression test for: http://crbug.com/43188.
1437 TEST(CookieMonsterTest, DontImportDuplicateCreationTimes) {
1438 GURL url_google("http://www.google.com/");
1439
1440 scoped_refptr<MockPersistentCookieStore> store(
1441 new MockPersistentCookieStore);
1442
1443 Time now(Time::Now());
1444 Time earlier(now - TimeDelta::FromDays(1));
1445
1446 // Insert 8 cookies, four with the current time as creation times, and
1447 // four with the earlier time as creation times. We should only get
1448 // two cookies remaining, but which two (other than that there should
1449 // be one from each set) will be random.
1450 std::vector<net::CookieMonster::KeyedCanonicalCookie> initial_cookies;
1451 AddKeyedCookieToList("www.google.com",
1452 "X=1; path=/",
1453 now,
1454 &initial_cookies);
1455 AddKeyedCookieToList("www.google.com",
1456 "X=2; path=/",
1457 now,
1458 &initial_cookies);
1459 AddKeyedCookieToList("www.google.com",
1460 "X=3; path=/",
1461 now,
1462 &initial_cookies);
1463 AddKeyedCookieToList("www.google.com",
1464 "X=4; path=/",
1465 now,
1466 &initial_cookies);
1467
1468 AddKeyedCookieToList("www.google.com",
1469 "Y=1; path=/",
1470 earlier,
1471 &initial_cookies);
1472 AddKeyedCookieToList("www.google.com",
1473 "Y=2; path=/",
1474 earlier,
1475 &initial_cookies);
1476 AddKeyedCookieToList("www.google.com",
1477 "Y=3; path=/",
1478 earlier,
1479 &initial_cookies);
1480 AddKeyedCookieToList("www.google.com",
1481 "Y=4; path=/",
1482 earlier,
1483 &initial_cookies);
1484
1485 // Inject our initial cookies into the mock PersistentCookieStore.
1486 store->SetLoadExpectation(true, initial_cookies);
1487
1488 scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(store, NULL));
1489
1490 net::CookieMonster::CookieList list(cm->GetAllCookies());
1491 EXPECT_EQ(2U, list.size());
1492 // Confirm that we have one of each.
1493 std::string name1(list[0].Name());
1494 std::string name2(list[1].Name());
1495 EXPECT_TRUE(name1 == "X" || name2 == "X");
1496 EXPECT_TRUE(name1 == "Y" || name2 == "Y");
1497 EXPECT_NE(name1, name2);
1498 }
1499
1563 TEST(CookieMonsterTest, Delegate) { 1500 TEST(CookieMonsterTest, Delegate) {
1564 GURL url_google(kUrlGoogle); 1501 GURL url_google(kUrlGoogle);
1565 1502
1566 scoped_refptr<MockPersistentCookieStore> store( 1503 scoped_refptr<MockPersistentCookieStore> store(
1567 new MockPersistentCookieStore); 1504 new MockPersistentCookieStore);
1568 scoped_refptr<MockCookieMonsterDelegate> delegate( 1505 scoped_refptr<MockCookieMonsterDelegate> delegate(
1569 new MockCookieMonsterDelegate); 1506 new MockCookieMonsterDelegate);
1570 scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(store, delegate)); 1507 scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(store, delegate));
1571 1508
1572 EXPECT_TRUE(cm->SetCookie(url_google, "A=B")); 1509 EXPECT_TRUE(cm->SetCookie(url_google, "A=B"));
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
1708 EXPECT_EQ("E", it->Name()); 1645 EXPECT_EQ("E", it->Name());
1709 EXPECT_EQ("F", it->Value()); 1646 EXPECT_EQ("F", it->Value());
1710 EXPECT_EQ("/", it->Path()); 1647 EXPECT_EQ("/", it->Path());
1711 EXPECT_EQ("www.google.izzle", it->Domain()); 1648 EXPECT_EQ("www.google.izzle", it->Domain());
1712 EXPECT_TRUE(it->IsSecure()); 1649 EXPECT_TRUE(it->IsSecure());
1713 EXPECT_FALSE(it->IsHttpOnly()); 1650 EXPECT_FALSE(it->IsHttpOnly());
1714 1651
1715 ASSERT_TRUE(++it == cookies.end()); 1652 ASSERT_TRUE(++it == cookies.end());
1716 } 1653 }
1717 1654
1718
1719
1720 TEST(CookieMonsterTest, DeleteAllForHost) { 1655 TEST(CookieMonsterTest, DeleteAllForHost) {
1721 scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(NULL, NULL)); 1656 scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(NULL, NULL));
1722 1657
1723 // Test probes: 1658 // Test probes:
1724 // * Non-secure URL, mid-level (http://w.c.b.a) 1659 // * Non-secure URL, mid-level (http://w.c.b.a)
1725 // * Secure URL, mid-level (https://w.c.b.a) 1660 // * Secure URL, mid-level (https://w.c.b.a)
1726 // * URL with path, mid-level (https:/w.c.b.a/dir1/xx) 1661 // * URL with path, mid-level (https:/w.c.b.a/dir1/xx)
1727 // All three tests should nuke only the midlevel host cookie, 1662 // All three tests should nuke only the midlevel host cookie,
1728 // the http_only cookie, the host secure cookie, and the two host 1663 // the http_only cookie, the host secure cookie, and the two host
1729 // path cookies. http_only, secure, and paths are ignored by 1664 // path cookies. http_only, secure, and paths are ignored by
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1772 EXPECT_EQ("dom_1=X; dom_2=X; dom_3=X; host_3=X", 1707 EXPECT_EQ("dom_1=X; dom_2=X; dom_3=X; host_3=X",
1773 cm->GetCookies(GURL(kTopLevelDomainPlus3))); 1708 cm->GetCookies(GURL(kTopLevelDomainPlus3)));
1774 EXPECT_EQ("dom_1=X; dom_2=X; sec_dom=X", 1709 EXPECT_EQ("dom_1=X; dom_2=X; sec_dom=X",
1775 cm->GetCookies(GURL(kTopLevelDomainPlus2Secure))); 1710 cm->GetCookies(GURL(kTopLevelDomainPlus2Secure)));
1776 EXPECT_EQ("dom_1=X; host_1=X", cm->GetCookies(GURL(kTopLevelDomainPlus1))); 1711 EXPECT_EQ("dom_1=X; host_1=X", cm->GetCookies(GURL(kTopLevelDomainPlus1)));
1777 EXPECT_EQ("dom_path_2=X; dom_path_1=X; dom_1=X; dom_2=X; sec_dom=X", 1712 EXPECT_EQ("dom_path_2=X; dom_path_1=X; dom_1=X; dom_2=X; sec_dom=X",
1778 cm->GetCookies(GURL(kTopLevelDomainPlus2Secure + 1713 cm->GetCookies(GURL(kTopLevelDomainPlus2Secure +
1779 std::string("/dir1/dir2/xxx")))); 1714 std::string("/dir1/dir2/xxx"))));
1780 1715
1781 } 1716 }
1717
1718 TEST(CookieMonsterTest, UniqueCreationTime) {
1719 scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(NULL, NULL));
1720 GURL url_google(kUrlGoogle);
1721 net::CookieOptions options;
1722
1723 // Add in three cookies through every public interface to the
1724 // CookieMonster and confirm that none of them have duplicate
1725 // creation times.
1726
1727 // SetCookieWithCreationTime and SetCookieWithCreationTimeAndOptions
1728 // are not included as they aren't going to be public for very much
1729 // longer.
1730
1731 // SetCookie, SetCookies, SetCookiesWithOptions,
1732 // SetCookieWithOptions, SetCookieWithDetails
1733
1734 cm->SetCookie(url_google, "SetCookie1=A");
1735 cm->SetCookie(url_google, "SetCookie2=A");
1736 cm->SetCookie(url_google, "SetCookie3=A");
1737
1738 {
1739 std::vector<std::string> cookie_lines;
1740 cookie_lines.push_back("setCookies1=A");
1741 cookie_lines.push_back("setCookies2=A");
1742 cookie_lines.push_back("setCookies4=A");
1743 cm->SetCookies(url_google, cookie_lines);
1744 }
1745
1746 {
1747 std::vector<std::string> cookie_lines;
1748 cookie_lines.push_back("setCookiesWithOptions1=A");
1749 cookie_lines.push_back("setCookiesWithOptions2=A");
1750 cookie_lines.push_back("setCookiesWithOptions3=A");
1751
1752 cm->SetCookiesWithOptions(url_google, cookie_lines, options);
1753 }
1754
1755 cm->SetCookieWithOptions(url_google, "setCookieWithOptions1=A", options);
1756 cm->SetCookieWithOptions(url_google, "setCookieWithOptions2=A", options);
1757 cm->SetCookieWithOptions(url_google, "setCookieWithOptions3=A", options);
1758
1759 cm->SetCookieWithDetails(url_google, "setCookieWithDetails1", "A",
1760 ".google.com", "/", Time(), false, false);
1761 cm->SetCookieWithDetails(url_google, "setCookieWithDetails2", "A",
1762 ".google.com", "/", Time(), false, false);
1763 cm->SetCookieWithDetails(url_google, "setCookieWithDetails3", "A",
1764 ".google.com", "/", Time(), false, false);
1765
1766 // Now we check
1767 net::CookieMonster::CookieList cookie_list(cm->GetAllCookies());
1768 typedef std::map<int64, net::CookieMonster::CanonicalCookie> TimeCookieMap;
1769 TimeCookieMap check_map;
1770 for (net::CookieMonster::CookieList::const_iterator it = cookie_list.begin();
1771 it != cookie_list.end(); it++) {
1772 const int64 creation_date = it->CreationDate().ToInternalValue();
1773 TimeCookieMap::const_iterator
1774 existing_cookie_it(check_map.find(creation_date));
1775 EXPECT_TRUE(existing_cookie_it == check_map.end())
1776 << "Cookie " << it->Name() << " has same creation date ("
1777 << it->CreationDate().ToInternalValue()
1778 << ") as previously entered cookie "
1779 << existing_cookie_it->second.Name();
1780
1781 if (existing_cookie_it == check_map.end()) {
1782 check_map.insert(TimeCookieMap::value_type(
1783 it->CreationDate().ToInternalValue(), *it));
1784 }
1785 }
1786 }
1787
1788 } // namespace
OLDNEW
« net/base/cookie_monster.cc ('K') | « net/base/cookie_monster_store_test.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698