Chromium Code Reviews| 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <memory> | 6 #include <memory> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 91 | 91 |
| 92 private: | 92 private: |
| 93 void Run(const std::string& cookies) { | 93 void Run(const std::string& cookies) { |
| 94 cookies_ = cookies; | 94 cookies_ = cookies; |
| 95 BaseCallback::Run(); | 95 BaseCallback::Run(); |
| 96 } | 96 } |
| 97 std::string cookies_; | 97 std::string cookies_; |
| 98 CookieOptions options_; | 98 CookieOptions options_; |
| 99 }; | 99 }; |
| 100 | 100 |
| 101 class GetAllCookiesCallback : public BaseCallback { | |
|
mmenke
2017/07/12 18:29:04
While you're here...would you mind renaming BaseCa
Randy Smith (Not in Mondays)
2017/07/12 19:47:35
Done.
| |
| 102 public: | |
| 103 CookieList GetAllCookies(CookieMonster* cm) { | |
| 104 cm->GetAllCookiesAsync( | |
| 105 base::Bind(&GetAllCookiesCallback::Run, base::Unretained(this))); | |
| 106 WaitForCallback(); | |
| 107 return cookies_; | |
| 108 } | |
| 109 | |
| 110 private: | |
| 111 void Run(const CookieList& cookies) { | |
| 112 cookies_ = cookies; | |
| 113 BaseCallback::Run(); | |
| 114 } | |
| 115 CookieList cookies_; | |
| 116 }; | |
| 117 | |
| 101 } // namespace | 118 } // namespace |
| 102 | 119 |
| 103 TEST(ParsedCookieTest, TestParseCookies) { | 120 TEST(ParsedCookieTest, TestParseCookies) { |
| 104 std::string cookie(kCookieLine); | 121 std::string cookie(kCookieLine); |
| 105 base::PerfTimeLogger timer("Parsed_cookie_parse_cookies"); | 122 base::PerfTimeLogger timer("Parsed_cookie_parse_cookies"); |
| 106 for (int i = 0; i < kNumCookies; ++i) { | 123 for (int i = 0; i < kNumCookies; ++i) { |
| 107 ParsedCookie pc(cookie); | 124 ParsedCookie pc(cookie); |
| 108 EXPECT_TRUE(pc.IsValid()); | 125 EXPECT_TRUE(pc.IsValid()); |
| 109 } | 126 } |
| 110 timer.Done(); | 127 timer.Done(); |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 220 } | 237 } |
| 221 | 238 |
| 222 EXPECT_EQ(31u, domain_list.size()); | 239 EXPECT_EQ(31u, domain_list.size()); |
| 223 for (std::vector<std::string>::const_iterator it = domain_list.begin(); | 240 for (std::vector<std::string>::const_iterator it = domain_list.begin(); |
| 224 it != domain_list.end(); it++) { | 241 it != domain_list.end(); it++) { |
| 225 GURL gurl("https://" + *it + "/"); | 242 GURL gurl("https://" + *it + "/"); |
| 226 const std::string cookie = | 243 const std::string cookie = |
| 227 base::StringPrintf(domain_cookie_format_tree, it->c_str()); | 244 base::StringPrintf(domain_cookie_format_tree, it->c_str()); |
| 228 setCookieCallback.SetCookie(cm.get(), gurl, cookie); | 245 setCookieCallback.SetCookie(cm.get(), gurl, cookie); |
| 229 } | 246 } |
| 230 EXPECT_EQ(31u, cm->GetAllCookies().size()); | 247 |
| 248 GetAllCookiesCallback getAllCookiesCallback; | |
| 249 EXPECT_EQ(31u, getAllCookiesCallback.GetAllCookies(cm.get()).size()); | |
| 231 | 250 |
| 232 GURL probe_gurl("https://b.a.b.a.top.com/"); | 251 GURL probe_gurl("https://b.a.b.a.top.com/"); |
| 233 std::string cookie_line = getCookiesCallback.GetCookies(cm.get(), probe_gurl); | 252 std::string cookie_line = getCookiesCallback.GetCookies(cm.get(), probe_gurl); |
| 234 EXPECT_EQ(5, CountInString(cookie_line, '=')) | 253 EXPECT_EQ(5, CountInString(cookie_line, '=')) |
| 235 << "Cookie line: " << cookie_line; | 254 << "Cookie line: " << cookie_line; |
| 236 base::PerfTimeLogger timer("Cookie_monster_query_domain_tree"); | 255 base::PerfTimeLogger timer("Cookie_monster_query_domain_tree"); |
| 237 for (int i = 0; i < kNumCookies; i++) { | 256 for (int i = 0; i < kNumCookies; i++) { |
| 238 getCookiesCallback.GetCookies(cm.get(), probe_gurl); | 257 getCookiesCallback.GetCookies(cm.get(), probe_gurl); |
| 239 } | 258 } |
| 240 timer.Done(); | 259 timer.Done(); |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 382 setCookieCallback.SetCookie(cm.get(), gurl, cookie_line); | 401 setCookieCallback.SetCookie(cm.get(), gurl, cookie_line); |
| 383 | 402 |
| 384 base::PerfTimeLogger timer((std::string("GC_") + test_case.name).c_str()); | 403 base::PerfTimeLogger timer((std::string("GC_") + test_case.name).c_str()); |
| 385 for (int i = 0; i < kNumCookies; i++) | 404 for (int i = 0; i < kNumCookies; i++) |
| 386 setCookieCallback.SetCookie(cm.get(), gurl, cookie_line); | 405 setCookieCallback.SetCookie(cm.get(), gurl, cookie_line); |
| 387 timer.Done(); | 406 timer.Done(); |
| 388 } | 407 } |
| 389 } | 408 } |
| 390 | 409 |
| 391 } // namespace net | 410 } // namespace net |
| OLD | NEW |