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

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

Issue 2882063002: Add a SetCanonicalCookie method for CookieMonster. (Closed)
Patch Set: Fix AW cookie store wrapper. Created 3 years, 6 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.cc ('k') | net/cookies/cookie_store.h » ('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) 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/cookie_monster.h" 5 #include "net/cookies/cookie_monster.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 bool SetAllCookies(CookieMonster* cm, const CookieList& list) { 141 bool SetAllCookies(CookieMonster* cm, const CookieList& list) {
142 DCHECK(cm); 142 DCHECK(cm);
143 ResultSavingCookieCallback<bool> callback; 143 ResultSavingCookieCallback<bool> callback;
144 cm->SetAllCookiesAsync(list, 144 cm->SetAllCookiesAsync(list,
145 base::Bind(&ResultSavingCookieCallback<bool>::Run, 145 base::Bind(&ResultSavingCookieCallback<bool>::Run,
146 base::Unretained(&callback))); 146 base::Unretained(&callback)));
147 callback.WaitUntilDone(); 147 callback.WaitUntilDone();
148 return callback.result(); 148 return callback.result();
149 } 149 }
150 150
151 bool SetCanonicalCookie(std::unique_ptr<CookieMonster> cm,
152 std::unique_ptr<CanonicalCookie> cookie,
153 bool secure_source,
154 bool modify_http_only) {
155 DCHECK(cm);
156 ResultSavingCookieCallback<bool> callback;
157 cm->SetCanonicalCookieAsync(
158 std::move(cookie), secure_source, modify_http_only,
159 base::Bind(&ResultSavingCookieCallback<bool>::Run,
160 base::Unretained(&callback)));
161 callback.WaitUntilDone();
162 return callback.result();
163 }
164
151 int DeleteAllCreatedBetween(CookieMonster* cm, 165 int DeleteAllCreatedBetween(CookieMonster* cm,
152 const base::Time& delete_begin, 166 const base::Time& delete_begin,
153 const base::Time& delete_end) { 167 const base::Time& delete_end) {
154 DCHECK(cm); 168 DCHECK(cm);
155 ResultSavingCookieCallback<int> callback; 169 ResultSavingCookieCallback<int> callback;
156 cm->DeleteAllCreatedBetweenAsync( 170 cm->DeleteAllCreatedBetweenAsync(
157 delete_begin, delete_end, 171 delete_begin, delete_end,
158 base::Bind(&ResultSavingCookieCallback<int>::Run, 172 base::Bind(&ResultSavingCookieCallback<int>::Run,
159 base::Unretained(&callback))); 173 base::Unretained(&callback)));
160 callback.WaitUntilDone(); 174 callback.WaitUntilDone();
(...skipping 2135 matching lines...) Expand 10 before | Expand all | Expand 10 after
2296 base::Unretained(&get_cookie_list_callback))); 2310 base::Unretained(&get_cookie_list_callback)));
2297 2311
2298 // Only the main load should have been queued. 2312 // Only the main load should have been queued.
2299 ASSERT_EQ(1u, store->commands().size()); 2313 ASSERT_EQ(1u, store->commands().size());
2300 ASSERT_EQ(CookieStoreCommand::LOAD, store->commands()[0].type); 2314 ASSERT_EQ(CookieStoreCommand::LOAD, store->commands()[0].type);
2301 2315
2302 std::vector<std::unique_ptr<CanonicalCookie>> cookies; 2316 std::vector<std::unique_ptr<CanonicalCookie>> cookies;
2303 // When passed to the CookieMonster, it takes ownership of the pointed to 2317 // When passed to the CookieMonster, it takes ownership of the pointed to
2304 // cookies. 2318 // cookies.
2305 cookies.push_back( 2319 cookies.push_back(
2306 CanonicalCookie::Create(kUrl, "a=b", base::Time(), CookieOptions())); 2320 CanonicalCookie::Create(kUrl, "a=b", base::Time::Now(), CookieOptions()));
2307 ASSERT_TRUE(cookies[0]); 2321 ASSERT_TRUE(cookies[0]);
2308 store->commands()[0].loaded_callback.Run(std::move(cookies)); 2322 store->commands()[0].loaded_callback.Run(std::move(cookies));
2309 2323
2310 delete_callback.WaitUntilDone(); 2324 delete_callback.WaitUntilDone();
2311 EXPECT_EQ(1, delete_callback.result()); 2325 EXPECT_EQ(1, delete_callback.result());
2312 2326
2313 get_cookie_list_callback.WaitUntilDone(); 2327 get_cookie_list_callback.WaitUntilDone();
2314 EXPECT_EQ(0u, get_cookie_list_callback.cookies().size()); 2328 EXPECT_EQ(0u, get_cookie_list_callback.cookies().size());
2315 } 2329 }
2316 2330
(...skipping 1100 matching lines...) Expand 10 before | Expand all | Expand 10 after
3417 monster()->AddCallbackForCookie( 3431 monster()->AddCallbackForCookie(
3418 test_url_, "abc", 3432 test_url_, "abc",
3419 base::Bind(&RecordCookieChanges, &cookies1, nullptr))); 3433 base::Bind(&RecordCookieChanges, &cookies1, nullptr)));
3420 SetCookie(monster(), test_url_, "abc=def"); 3434 SetCookie(monster(), test_url_, "abc=def");
3421 base::RunLoop().RunUntilIdle(); 3435 base::RunLoop().RunUntilIdle();
3422 EXPECT_EQ(1U, cookies0.size()); 3436 EXPECT_EQ(1U, cookies0.size());
3423 EXPECT_EQ(1U, cookies0.size()); 3437 EXPECT_EQ(1U, cookies0.size());
3424 } 3438 }
3425 3439
3426 } // namespace net 3440 } // namespace net
OLDNEW
« no previous file with comments | « net/cookies/cookie_monster.cc ('k') | net/cookies/cookie_store.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698