OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "base/perftimer.h" | 5 #include "base/perftimer.h" |
6 #include "base/string_util.h" | 6 #include "base/string_util.h" |
7 #include "net/base/cookie_monster.h" | 7 #include "net/base/cookie_monster.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 #include "googleurl/src/gurl.h" | 9 #include "googleurl/src/gurl.h" |
10 | 10 |
(...skipping 22 matching lines...) Expand all Loading... |
33 for (int i = 0; i < kNumCookies; ++i) { | 33 for (int i = 0; i < kNumCookies; ++i) { |
34 net::CookieMonster::ParsedCookie pc(cookie); | 34 net::CookieMonster::ParsedCookie pc(cookie); |
35 EXPECT_TRUE(pc.IsValid()); | 35 EXPECT_TRUE(pc.IsValid()); |
36 } | 36 } |
37 timer.Done(); | 37 timer.Done(); |
38 } | 38 } |
39 | 39 |
40 static const GURL kUrlGoogle("http://www.google.izzle"); | 40 static const GURL kUrlGoogle("http://www.google.izzle"); |
41 | 41 |
42 TEST(CookieMonsterTest, TestAddCookiesOnSingleHost) { | 42 TEST(CookieMonsterTest, TestAddCookiesOnSingleHost) { |
43 net::CookieMonster cm; | 43 scoped_refptr<net::CookieMonster> cm(new net::CookieMonster); |
44 std::vector<std::string> cookies; | 44 std::vector<std::string> cookies; |
45 for (int i = 0; i < kNumCookies; i++) { | 45 for (int i = 0; i < kNumCookies; i++) { |
46 cookies.push_back(StringPrintf("a%03d=b", i)); | 46 cookies.push_back(StringPrintf("a%03d=b", i)); |
47 } | 47 } |
48 | 48 |
49 // Add a bunch of cookies on a single host | 49 // Add a bunch of cookies on a single host |
50 PerfTimeLogger timer("Cookie_monster_add_single_host"); | 50 PerfTimeLogger timer("Cookie_monster_add_single_host"); |
51 for (std::vector<std::string>::const_iterator it = cookies.begin(); | 51 for (std::vector<std::string>::const_iterator it = cookies.begin(); |
52 it != cookies.end(); ++it) { | 52 it != cookies.end(); ++it) { |
53 EXPECT_TRUE(cm.SetCookie(kUrlGoogle, *it)); | 53 EXPECT_TRUE(cm->SetCookie(kUrlGoogle, *it)); |
54 } | 54 } |
55 timer.Done(); | 55 timer.Done(); |
56 | 56 |
57 PerfTimeLogger timer2("Cookie_monster_query_single_host"); | 57 PerfTimeLogger timer2("Cookie_monster_query_single_host"); |
58 for (std::vector<std::string>::const_iterator it = cookies.begin(); | 58 for (std::vector<std::string>::const_iterator it = cookies.begin(); |
59 it != cookies.end(); ++it) { | 59 it != cookies.end(); ++it) { |
60 cm.GetCookies(kUrlGoogle); | 60 cm->GetCookies(kUrlGoogle); |
61 } | 61 } |
62 timer2.Done(); | 62 timer2.Done(); |
63 | 63 |
64 PerfTimeLogger timer3("Cookie_monster_deleteall_single_host"); | 64 PerfTimeLogger timer3("Cookie_monster_deleteall_single_host"); |
65 cm.DeleteAll(false); | 65 cm->DeleteAll(false); |
66 timer3.Done(); | 66 timer3.Done(); |
67 } | 67 } |
68 | 68 |
69 TEST(CookieMonsterTest, TestAddCookieOnManyHosts) { | 69 TEST(CookieMonsterTest, TestAddCookieOnManyHosts) { |
70 net::CookieMonster cm; | 70 scoped_refptr<net::CookieMonster> cm(new net::CookieMonster); |
71 std::string cookie(kCookieLine); | 71 std::string cookie(kCookieLine); |
72 std::vector<GURL> gurls; // just wanna have ffffuunnn | 72 std::vector<GURL> gurls; // just wanna have ffffuunnn |
73 for (int i = 0; i < kNumCookies; ++i) { | 73 for (int i = 0; i < kNumCookies; ++i) { |
74 gurls.push_back(GURL(StringPrintf("http://a%04d.izzle", i))); | 74 gurls.push_back(GURL(StringPrintf("http://a%04d.izzle", i))); |
75 } | 75 } |
76 | 76 |
77 // Add a cookie on a bunch of host | 77 // Add a cookie on a bunch of host |
78 PerfTimeLogger timer("Cookie_monster_add_many_hosts"); | 78 PerfTimeLogger timer("Cookie_monster_add_many_hosts"); |
79 for (std::vector<GURL>::const_iterator it = gurls.begin(); | 79 for (std::vector<GURL>::const_iterator it = gurls.begin(); |
80 it != gurls.end(); ++it) { | 80 it != gurls.end(); ++it) { |
81 EXPECT_TRUE(cm.SetCookie(*it, cookie)); | 81 EXPECT_TRUE(cm->SetCookie(*it, cookie)); |
82 } | 82 } |
83 timer.Done(); | 83 timer.Done(); |
84 | 84 |
85 PerfTimeLogger timer2("Cookie_monster_query_many_hosts"); | 85 PerfTimeLogger timer2("Cookie_monster_query_many_hosts"); |
86 for (std::vector<GURL>::const_iterator it = gurls.begin(); | 86 for (std::vector<GURL>::const_iterator it = gurls.begin(); |
87 it != gurls.end(); ++it) { | 87 it != gurls.end(); ++it) { |
88 cm.GetCookies(*it); | 88 cm->GetCookies(*it); |
89 } | 89 } |
90 timer2.Done(); | 90 timer2.Done(); |
91 | 91 |
92 PerfTimeLogger timer3("Cookie_monster_deleteall_many_hosts"); | 92 PerfTimeLogger timer3("Cookie_monster_deleteall_many_hosts"); |
93 cm.DeleteAll(false); | 93 cm->DeleteAll(false); |
94 timer3.Done(); | 94 timer3.Done(); |
95 } | 95 } |
OLD | NEW |