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/base/cookie_monster_store_test.cc

Issue 7860039: Re-land http://codereview.chromium.org/7831056/ and http://codereview.chromium.org/7833042/ . (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « net/base/cookie_monster_store_test.h ('k') | net/base/cookie_monster_unittest.cc » ('j') | 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/base/cookie_monster_store_test.h" 5 #include "net/base/cookie_monster_store_test.h"
6 6
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/stringprintf.h" 8 #include "base/stringprintf.h"
9 #include "base/time.h" 9 #include "base/time.h"
10 #include "googleurl/src/gurl.h" 10 #include "googleurl/src/gurl.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 12
13 namespace net { 13 namespace net {
14 14
15 MockPersistentCookieStore::MockPersistentCookieStore() 15 MockPersistentCookieStore::MockPersistentCookieStore()
16 : load_return_value_(true) { 16 : load_return_value_(true) {
17 } 17 }
18 18
19 MockPersistentCookieStore::~MockPersistentCookieStore() {} 19 MockPersistentCookieStore::~MockPersistentCookieStore() {}
20 20
21 void MockPersistentCookieStore::SetLoadExpectation( 21 void MockPersistentCookieStore::SetLoadExpectation(
22 bool return_value, 22 bool return_value,
23 const std::vector<CookieMonster::CanonicalCookie*>& result) { 23 const std::vector<CookieMonster::CanonicalCookie*>& result) {
24 load_return_value_ = return_value; 24 load_return_value_ = return_value;
25 load_result_ = result; 25 load_result_ = result;
26 } 26 }
27 27
28 bool MockPersistentCookieStore::Load( 28 bool MockPersistentCookieStore::Load(const LoadedCallback& loaded_callback) {
29 std::vector<CookieMonster::CanonicalCookie*>* out_cookies) {
30 bool ok = load_return_value_; 29 bool ok = load_return_value_;
31 if (ok) 30 std::vector<CookieMonster::CanonicalCookie*> out_cookies;
32 *out_cookies = load_result_; 31 if (ok) {
32 out_cookies = load_result_;
33 }
34 loaded_callback.Run(out_cookies);
33 return ok; 35 return ok;
34 } 36 }
35 37
36 void MockPersistentCookieStore::AddCookie( 38 void MockPersistentCookieStore::AddCookie(
37 const CookieMonster::CanonicalCookie& cookie) { 39 const CookieMonster::CanonicalCookie& cookie) {
38 commands_.push_back( 40 commands_.push_back(
39 CookieStoreCommand(CookieStoreCommand::ADD, cookie)); 41 CookieStoreCommand(CookieStoreCommand::ADD, cookie));
40 } 42 }
41 43
42 void MockPersistentCookieStore::UpdateCookieAccessTime( 44 void MockPersistentCookieStore::UpdateCookieAccessTime(
(...skipping 28 matching lines...) Expand all
71 changes_.push_back(notification); 73 changes_.push_back(notification);
72 } 74 }
73 75
74 MockCookieMonsterDelegate::~MockCookieMonsterDelegate() {} 76 MockCookieMonsterDelegate::~MockCookieMonsterDelegate() {}
75 77
76 void AddCookieToList( 78 void AddCookieToList(
77 const std::string& key, 79 const std::string& key,
78 const std::string& cookie_line, 80 const std::string& cookie_line,
79 const base::Time& creation_time, 81 const base::Time& creation_time,
80 std::vector<CookieMonster::CanonicalCookie*>* out_list) { 82 std::vector<CookieMonster::CanonicalCookie*>* out_list) {
83 scoped_ptr<CookieMonster::CanonicalCookie> cookie(
84 new CookieMonster::CanonicalCookie(
85 BuildCanonicalCookie(key, cookie_line, creation_time)));
86
87 out_list->push_back(cookie.release());
88 }
89
90 CookieMonster::CanonicalCookie BuildCanonicalCookie(
91 const std::string& key,
92 const std::string& cookie_line,
93 const base::Time& creation_time) {
81 94
82 // Parse the cookie line. 95 // Parse the cookie line.
83 CookieMonster::ParsedCookie pc(cookie_line); 96 CookieMonster::ParsedCookie pc(cookie_line);
84 EXPECT_TRUE(pc.IsValid()); 97 EXPECT_TRUE(pc.IsValid());
85 98
86 // This helper is simplistic in interpreting a parsed cookie, in order to 99 // This helper is simplistic in interpreting a parsed cookie, in order to
87 // avoid duplicated CookieMonster's CanonPath() and CanonExpiration() 100 // avoid duplicated CookieMonster's CanonPath() and CanonExpiration()
88 // functions. Would be nice to export them, and re-use here. 101 // functions. Would be nice to export them, and re-use here.
89 EXPECT_FALSE(pc.HasMaxAge()); 102 EXPECT_FALSE(pc.HasMaxAge());
90 EXPECT_TRUE(pc.HasPath()); 103 EXPECT_TRUE(pc.HasPath());
91 base::Time cookie_expires = pc.HasExpires() ? 104 base::Time cookie_expires = pc.HasExpires() ?
92 CookieMonster::ParseCookieTime(pc.Expires()) : base::Time(); 105 CookieMonster::ParseCookieTime(pc.Expires()) : base::Time();
93 std::string cookie_path = pc.Path(); 106 std::string cookie_path = pc.Path();
94 107
95 scoped_ptr<CookieMonster::CanonicalCookie> cookie( 108 return CookieMonster::CanonicalCookie(
96 new CookieMonster::CanonicalCookie( 109 GURL(), pc.Name(), pc.Value(), key, cookie_path,
97 GURL(), pc.Name(), pc.Value(), key, cookie_path, 110 pc.MACKey(), pc.MACAlgorithm(),
98 pc.MACKey(), pc.MACAlgorithm(), 111 creation_time, creation_time, cookie_expires,
99 creation_time, creation_time, cookie_expires, 112 pc.IsSecure(), pc.IsHttpOnly(),
100 pc.IsSecure(), pc.IsHttpOnly(), 113 !cookie_expires.is_null());
101 !cookie_expires.is_null()));
102
103 out_list->push_back(cookie.release());
104 } 114 }
105 115
106 MockSimplePersistentCookieStore::MockSimplePersistentCookieStore() {} 116 MockSimplePersistentCookieStore::MockSimplePersistentCookieStore() {}
107 117
108 MockSimplePersistentCookieStore::~MockSimplePersistentCookieStore() {} 118 MockSimplePersistentCookieStore::~MockSimplePersistentCookieStore() {}
109 119
110 bool MockSimplePersistentCookieStore::Load( 120 bool MockSimplePersistentCookieStore::Load(
111 std::vector<CookieMonster::CanonicalCookie*>* out_cookies) { 121 const LoadedCallback& loaded_callback) {
122 std::vector<CookieMonster::CanonicalCookie*> out_cookies;
112 for (CanonicalCookieMap::const_iterator it = cookies_.begin(); 123 for (CanonicalCookieMap::const_iterator it = cookies_.begin();
113 it != cookies_.end(); it++) 124 it != cookies_.end(); it++)
114 out_cookies->push_back( 125 out_cookies.push_back(
115 new CookieMonster::CanonicalCookie(it->second)); 126 new CookieMonster::CanonicalCookie(it->second));
127 loaded_callback.Run(out_cookies);
116 return true; 128 return true;
117 } 129 }
118 130
119 void MockSimplePersistentCookieStore::AddCookie( 131 void MockSimplePersistentCookieStore::AddCookie(
120 const CookieMonster::CanonicalCookie& cookie) { 132 const CookieMonster::CanonicalCookie& cookie) {
121 int64 creation_time = cookie.CreationDate().ToInternalValue(); 133 int64 creation_time = cookie.CreationDate().ToInternalValue();
122 EXPECT_TRUE(cookies_.find(creation_time) == cookies_.end()); 134 EXPECT_TRUE(cookies_.find(creation_time) == cookies_.end());
123 cookies_[creation_time] = cookie; 135 cookies_[creation_time] = cookie;
124 } 136 }
125 137
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 GURL(), "a", "1", base::StringPrintf("h%05d.izzle", i), "/path", 183 GURL(), "a", "1", base::StringPrintf("h%05d.izzle", i), "/path",
172 mac_key, mac_algorithm, creation_time, expiration_time, 184 mac_key, mac_algorithm, creation_time, expiration_time,
173 last_access_time, false, false, true); 185 last_access_time, false, false, true);
174 store->AddCookie(cc); 186 store->AddCookie(cc);
175 } 187 }
176 188
177 return new CookieMonster(store, NULL); 189 return new CookieMonster(store, NULL);
178 } 190 }
179 191
180 } // namespace net 192 } // namespace net
OLDNEW
« no previous file with comments | « net/base/cookie_monster_store_test.h ('k') | net/base/cookie_monster_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698