| 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" |
| 11 #include "base/run_loop.h" |
| 11 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 12 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
| 13 #include "base/test/perf_time_logger.h" | 14 #include "base/test/perf_time_logger.h" |
| 14 #include "net/cookies/canonical_cookie.h" | 15 #include "net/cookies/canonical_cookie.h" |
| 15 #include "net/cookies/cookie_monster.h" | 16 #include "net/cookies/cookie_monster.h" |
| 16 #include "net/cookies/cookie_monster_store_test.h" | 17 #include "net/cookies/cookie_monster_store_test.h" |
| 17 #include "net/cookies/parsed_cookie.h" | 18 #include "net/cookies/parsed_cookie.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 19 #include "url/gurl.h" | 20 #include "url/gurl.h" |
| 20 | 21 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 42 public: | 43 public: |
| 43 BaseCallback() : has_run_(false) {} | 44 BaseCallback() : has_run_(false) {} |
| 44 | 45 |
| 45 protected: | 46 protected: |
| 46 void WaitForCallback() { | 47 void WaitForCallback() { |
| 47 // Note that the performance tests currently all operate on a loaded cookie | 48 // Note that the performance tests currently all operate on a loaded cookie |
| 48 // store (or, more precisely, one that has no backing persistent store). | 49 // store (or, more precisely, one that has no backing persistent store). |
| 49 // Therefore, callbacks will actually always complete synchronously. If the | 50 // Therefore, callbacks will actually always complete synchronously. If the |
| 50 // tests get more advanced we need to add other means of signaling | 51 // tests get more advanced we need to add other means of signaling |
| 51 // completion. | 52 // completion. |
| 52 base::MessageLoop::current()->RunUntilIdle(); | 53 base::RunLoop().RunUntilIdle(); |
| 53 EXPECT_TRUE(has_run_); | 54 EXPECT_TRUE(has_run_); |
| 54 has_run_ = false; | 55 has_run_ = false; |
| 55 } | 56 } |
| 56 | 57 |
| 57 void Run() { has_run_ = true; } | 58 void Run() { has_run_ = true; } |
| 58 | 59 |
| 59 bool has_run_; | 60 bool has_run_; |
| 60 }; | 61 }; |
| 61 | 62 |
| 62 class SetCookieCallback : public BaseCallback { | 63 class SetCookieCallback : public BaseCallback { |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 | 143 |
| 143 base::PerfTimeLogger timer2("Cookie_monster_query_single_host"); | 144 base::PerfTimeLogger timer2("Cookie_monster_query_single_host"); |
| 144 for (std::vector<std::string>::const_iterator it = cookies.begin(); | 145 for (std::vector<std::string>::const_iterator it = cookies.begin(); |
| 145 it != cookies.end(); ++it) { | 146 it != cookies.end(); ++it) { |
| 146 getCookiesCallback.GetCookies(cm.get(), GURL(kGoogleURL)); | 147 getCookiesCallback.GetCookies(cm.get(), GURL(kGoogleURL)); |
| 147 } | 148 } |
| 148 timer2.Done(); | 149 timer2.Done(); |
| 149 | 150 |
| 150 base::PerfTimeLogger timer3("Cookie_monster_deleteall_single_host"); | 151 base::PerfTimeLogger timer3("Cookie_monster_deleteall_single_host"); |
| 151 cm->DeleteAllAsync(CookieMonster::DeleteCallback()); | 152 cm->DeleteAllAsync(CookieMonster::DeleteCallback()); |
| 152 base::MessageLoop::current()->RunUntilIdle(); | 153 base::RunLoop().RunUntilIdle(); |
| 153 timer3.Done(); | 154 timer3.Done(); |
| 154 } | 155 } |
| 155 | 156 |
| 156 TEST_F(CookieMonsterTest, TestAddCookieOnManyHosts) { | 157 TEST_F(CookieMonsterTest, TestAddCookieOnManyHosts) { |
| 157 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); | 158 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
| 158 std::string cookie(kCookieLine); | 159 std::string cookie(kCookieLine); |
| 159 std::vector<GURL> gurls; // just wanna have ffffuunnn | 160 std::vector<GURL> gurls; // just wanna have ffffuunnn |
| 160 for (int i = 0; i < kNumCookies; ++i) { | 161 for (int i = 0; i < kNumCookies; ++i) { |
| 161 gurls.push_back(GURL(base::StringPrintf("https://a%04d.izzle", i))); | 162 gurls.push_back(GURL(base::StringPrintf("https://a%04d.izzle", i))); |
| 162 } | 163 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 175 | 176 |
| 176 base::PerfTimeLogger timer2("Cookie_monster_query_many_hosts"); | 177 base::PerfTimeLogger timer2("Cookie_monster_query_many_hosts"); |
| 177 for (std::vector<GURL>::const_iterator it = gurls.begin(); it != gurls.end(); | 178 for (std::vector<GURL>::const_iterator it = gurls.begin(); it != gurls.end(); |
| 178 ++it) { | 179 ++it) { |
| 179 getCookiesCallback.GetCookies(cm.get(), *it); | 180 getCookiesCallback.GetCookies(cm.get(), *it); |
| 180 } | 181 } |
| 181 timer2.Done(); | 182 timer2.Done(); |
| 182 | 183 |
| 183 base::PerfTimeLogger timer3("Cookie_monster_deleteall_many_hosts"); | 184 base::PerfTimeLogger timer3("Cookie_monster_deleteall_many_hosts"); |
| 184 cm->DeleteAllAsync(CookieMonster::DeleteCallback()); | 185 cm->DeleteAllAsync(CookieMonster::DeleteCallback()); |
| 185 base::MessageLoop::current()->RunUntilIdle(); | 186 base::RunLoop().RunUntilIdle(); |
| 186 timer3.Done(); | 187 timer3.Done(); |
| 187 } | 188 } |
| 188 | 189 |
| 189 TEST_F(CookieMonsterTest, TestDomainTree) { | 190 TEST_F(CookieMonsterTest, TestDomainTree) { |
| 190 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); | 191 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
| 191 GetCookiesCallback getCookiesCallback; | 192 GetCookiesCallback getCookiesCallback; |
| 192 SetCookieCallback setCookieCallback; | 193 SetCookieCallback setCookieCallback; |
| 193 const char domain_cookie_format_tree[] = "a=b; domain=%s"; | 194 const char domain_cookie_format_tree[] = "a=b; domain=%s"; |
| 194 const std::string domain_base("top.com"); | 195 const std::string domain_base("top.com"); |
| 195 | 196 |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 setCookieCallback.SetCookie(cm.get(), gurl, cookie_line); | 382 setCookieCallback.SetCookie(cm.get(), gurl, cookie_line); |
| 382 | 383 |
| 383 base::PerfTimeLogger timer((std::string("GC_") + test_case.name).c_str()); | 384 base::PerfTimeLogger timer((std::string("GC_") + test_case.name).c_str()); |
| 384 for (int i = 0; i < kNumCookies; i++) | 385 for (int i = 0; i < kNumCookies; i++) |
| 385 setCookieCallback.SetCookie(cm.get(), gurl, cookie_line); | 386 setCookieCallback.SetCookie(cm.get(), gurl, cookie_line); |
| 386 timer.Done(); | 387 timer.Done(); |
| 387 } | 388 } |
| 388 } | 389 } |
| 389 | 390 |
| 390 } // namespace net | 391 } // namespace net |
| OLD | NEW |