| 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 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 base::PerfTimeLogger timer3("Cookie_monster_deleteall_many_hosts"); | 179 base::PerfTimeLogger timer3("Cookie_monster_deleteall_many_hosts"); |
| 180 cm->DeleteAllAsync(CookieMonster::DeleteCallback()); | 180 cm->DeleteAllAsync(CookieMonster::DeleteCallback()); |
| 181 base::MessageLoop::current()->RunUntilIdle(); | 181 base::MessageLoop::current()->RunUntilIdle(); |
| 182 timer3.Done(); | 182 timer3.Done(); |
| 183 } | 183 } |
| 184 | 184 |
| 185 TEST_F(CookieMonsterTest, TestDomainTree) { | 185 TEST_F(CookieMonsterTest, TestDomainTree) { |
| 186 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 186 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 187 GetCookiesCallback getCookiesCallback; | 187 GetCookiesCallback getCookiesCallback; |
| 188 SetCookieCallback setCookieCallback; | 188 SetCookieCallback setCookieCallback; |
| 189 const char* domain_cookie_format_tree = "a=b; domain=%s"; | 189 const char domain_cookie_format_tree[] = "a=b; domain=%s"; |
| 190 const std::string domain_base("top.com"); | 190 const std::string domain_base("top.com"); |
| 191 | 191 |
| 192 std::vector<std::string> domain_list; | 192 std::vector<std::string> domain_list; |
| 193 | 193 |
| 194 // Create a balanced binary tree of domains on which the cookie is set. | 194 // Create a balanced binary tree of domains on which the cookie is set. |
| 195 domain_list.push_back(domain_base); | 195 domain_list.push_back(domain_base); |
| 196 for (int i1 = 0; i1 < 2; i1++) { | 196 for (int i1 = 0; i1 < 2; i1++) { |
| 197 std::string domain_base_1((i1 ? "a." : "b.") + domain_base); | 197 std::string domain_base_1((i1 ? "a." : "b.") + domain_base); |
| 198 EXPECT_EQ("top.com", cm->GetKey(domain_base_1)); | 198 EXPECT_EQ("top.com", cm->GetKey(domain_base_1)); |
| 199 domain_list.push_back(domain_base_1); | 199 domain_list.push_back(domain_base_1); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 // (TLD + 1 is the level above .com/org/net/etc, e.g. "top.com" | 249 // (TLD + 1 is the level above .com/org/net/etc, e.g. "top.com" |
| 250 // or "google.com". "Effective" is added to include sites like | 250 // or "google.com". "Effective" is added to include sites like |
| 251 // bbc.co.uk, where the effetive TLD+1 is more than one level | 251 // bbc.co.uk, where the effetive TLD+1 is more than one level |
| 252 // below the top level.) | 252 // below the top level.) |
| 253 domain_list.push_back("a.top.com"); | 253 domain_list.push_back("a.top.com"); |
| 254 domain_list.push_back("b.a.top.com"); | 254 domain_list.push_back("b.a.top.com"); |
| 255 domain_list.push_back("a.b.a.top.com"); | 255 domain_list.push_back("a.b.a.top.com"); |
| 256 domain_list.push_back("b.a.b.a.top.com"); | 256 domain_list.push_back("b.a.b.a.top.com"); |
| 257 EXPECT_EQ(4u, domain_list.size()); | 257 EXPECT_EQ(4u, domain_list.size()); |
| 258 | 258 |
| 259 const char* domain_cookie_format_line = "a%03d=b; domain=%s"; | 259 const char domain_cookie_format_line[] = "a%03d=b; domain=%s"; |
| 260 for (int i = 0; i < 8; i++) { | 260 for (int i = 0; i < 8; i++) { |
| 261 for (std::vector<std::string>::const_iterator it = domain_list.begin(); | 261 for (std::vector<std::string>::const_iterator it = domain_list.begin(); |
| 262 it != domain_list.end(); it++) { | 262 it != domain_list.end(); it++) { |
| 263 GURL gurl("https://" + *it + "/"); | 263 GURL gurl("https://" + *it + "/"); |
| 264 const std::string cookie = base::StringPrintf(domain_cookie_format_line, | 264 const std::string cookie = base::StringPrintf(domain_cookie_format_line, |
| 265 i, it->c_str()); | 265 i, it->c_str()); |
| 266 setCookieCallback.SetCookie(cm.get(), gurl, cookie); | 266 setCookieCallback.SetCookie(cm.get(), gurl, cookie); |
| 267 } | 267 } |
| 268 } | 268 } |
| 269 | 269 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 // shouldn't. This will not in general be visible functionally, since | 324 // shouldn't. This will not in general be visible functionally, since |
| 325 // if GC runs twice in a row without any change to the store, the second | 325 // if GC runs twice in a row without any change to the store, the second |
| 326 // GC run will not do anything the first one didn't. That's why this is | 326 // GC run will not do anything the first one didn't. That's why this is |
| 327 // a performance test. The test should be considered to pass if all the | 327 // a performance test. The test should be considered to pass if all the |
| 328 // times reported are approximately the same--this indicates that no GC | 328 // times reported are approximately the same--this indicates that no GC |
| 329 // happened repeatedly for any case. | 329 // happened repeatedly for any case. |
| 330 TEST_F(CookieMonsterTest, TestGCTimes) { | 330 TEST_F(CookieMonsterTest, TestGCTimes) { |
| 331 SetCookieCallback setCookieCallback; | 331 SetCookieCallback setCookieCallback; |
| 332 | 332 |
| 333 const struct TestCase { | 333 const struct TestCase { |
| 334 const char* name; | 334 const char* const name; |
| 335 size_t num_cookies; | 335 size_t num_cookies; |
| 336 size_t num_old_cookies; | 336 size_t num_old_cookies; |
| 337 } test_cases[] = { | 337 } test_cases[] = { |
| 338 { | 338 { |
| 339 // A whole lot of recent cookies; gc shouldn't happen. | 339 // A whole lot of recent cookies; gc shouldn't happen. |
| 340 "all_recent", | 340 "all_recent", |
| 341 CookieMonster::kMaxCookies * 2, | 341 CookieMonster::kMaxCookies * 2, |
| 342 0, | 342 0, |
| 343 }, { | 343 }, { |
| 344 // Some old cookies, but still overflowing max. | 344 // Some old cookies, but still overflowing max. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 setCookieCallback.SetCookie(cm.get(), gurl, cookie_line); | 376 setCookieCallback.SetCookie(cm.get(), gurl, cookie_line); |
| 377 | 377 |
| 378 base::PerfTimeLogger timer((std::string("GC_") + test_case.name).c_str()); | 378 base::PerfTimeLogger timer((std::string("GC_") + test_case.name).c_str()); |
| 379 for (int i = 0; i < kNumCookies; i++) | 379 for (int i = 0; i < kNumCookies; i++) |
| 380 setCookieCallback.SetCookie(cm.get(), gurl, cookie_line); | 380 setCookieCallback.SetCookie(cm.get(), gurl, cookie_line); |
| 381 timer.Done(); | 381 timer.Done(); |
| 382 } | 382 } |
| 383 } | 383 } |
| 384 | 384 |
| 385 } // namespace net | 385 } // namespace net |
| OLD | NEW |