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 "content/browser/net/sqlite_persistent_cookie_store.h" | 5 #include "content/browser/net/sqlite_persistent_cookie_store.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
10 #include "base/sequenced_task_runner.h" | 10 #include "base/sequenced_task_runner.h" |
11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
12 #include "base/synchronization/waitable_event.h" | 12 #include "base/synchronization/waitable_event.h" |
13 #include "base/test/perf_time_logger.h" | 13 #include "base/test/perf_time_logger.h" |
14 #include "base/test/sequenced_worker_pool_owner.h" | 14 #include "base/test/sequenced_worker_pool_owner.h" |
15 #include "base/threading/sequenced_worker_pool.h" | 15 #include "base/threading/sequenced_worker_pool.h" |
16 #include "content/public/browser/cookie_crypto_delegate.h" | |
17 #include "net/cookies/canonical_cookie.h" | 16 #include "net/cookies/canonical_cookie.h" |
18 #include "net/cookies/cookie_constants.h" | 17 #include "net/cookies/cookie_constants.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
20 #include "url/gurl.h" | 19 #include "url/gurl.h" |
21 | 20 |
22 namespace content { | 21 namespace content { |
23 | 22 |
24 namespace { | 23 namespace { |
25 | 24 |
26 const base::FilePath::CharType cookie_filename[] = FILE_PATH_LITERAL("Cookies"); | 25 const base::FilePath::CharType cookie_filename[] = FILE_PATH_LITERAL("Cookies"); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 return pool_owner_->pool()->GetSequencedTaskRunner( | 59 return pool_owner_->pool()->GetSequencedTaskRunner( |
61 pool_owner_->pool()->GetNamedSequenceToken("client")); | 60 pool_owner_->pool()->GetNamedSequenceToken("client")); |
62 } | 61 } |
63 | 62 |
64 virtual void SetUp() OVERRIDE { | 63 virtual void SetUp() OVERRIDE { |
65 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 64 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
66 store_ = new SQLitePersistentCookieStore( | 65 store_ = new SQLitePersistentCookieStore( |
67 temp_dir_.path().Append(cookie_filename), | 66 temp_dir_.path().Append(cookie_filename), |
68 client_task_runner(), | 67 client_task_runner(), |
69 background_task_runner(), | 68 background_task_runner(), |
70 false, NULL, | 69 false, NULL); |
71 scoped_ptr<content::CookieCryptoDelegate>()); | |
72 std::vector<net::CanonicalCookie*> cookies; | 70 std::vector<net::CanonicalCookie*> cookies; |
73 Load(); | 71 Load(); |
74 ASSERT_EQ(0u, cookies_.size()); | 72 ASSERT_EQ(0u, cookies_.size()); |
75 // Creates 15000 cookies from 300 eTLD+1s. | 73 // Creates 15000 cookies from 300 eTLD+1s. |
76 base::Time t = base::Time::Now(); | 74 base::Time t = base::Time::Now(); |
77 for (int domain_num = 0; domain_num < 300; domain_num++) { | 75 for (int domain_num = 0; domain_num < 300; domain_num++) { |
78 std::string domain_name(base::StringPrintf(".domain_%d.com", domain_num)); | 76 std::string domain_name(base::StringPrintf(".domain_%d.com", domain_num)); |
79 GURL gurl("www" + domain_name); | 77 GURL gurl("www" + domain_name); |
80 for (int cookie_num = 0; cookie_num < 50; ++cookie_num) { | 78 for (int cookie_num = 0; cookie_num < 50; ++cookie_num) { |
81 t += base::TimeDelta::FromInternalValue(10); | 79 t += base::TimeDelta::FromInternalValue(10); |
(...skipping 10 matching lines...) Expand all Loading... |
92 | 90 |
93 // Shut down the pool, causing deferred (no-op) commits to be discarded. | 91 // Shut down the pool, causing deferred (no-op) commits to be discarded. |
94 pool_owner_->pool()->Shutdown(); | 92 pool_owner_->pool()->Shutdown(); |
95 // ~SequencedWorkerPoolOwner blocks on pool shutdown. | 93 // ~SequencedWorkerPoolOwner blocks on pool shutdown. |
96 pool_owner_.reset(new base::SequencedWorkerPoolOwner(1, "pool")); | 94 pool_owner_.reset(new base::SequencedWorkerPoolOwner(1, "pool")); |
97 | 95 |
98 store_ = new SQLitePersistentCookieStore( | 96 store_ = new SQLitePersistentCookieStore( |
99 temp_dir_.path().Append(cookie_filename), | 97 temp_dir_.path().Append(cookie_filename), |
100 client_task_runner(), | 98 client_task_runner(), |
101 background_task_runner(), | 99 background_task_runner(), |
102 false, NULL, | 100 false, NULL); |
103 scoped_ptr<content::CookieCryptoDelegate>()); | |
104 } | 101 } |
105 | 102 |
106 virtual void TearDown() OVERRIDE { | 103 virtual void TearDown() OVERRIDE { |
107 store_ = NULL; | 104 store_ = NULL; |
108 pool_owner_->pool()->Shutdown(); | 105 pool_owner_->pool()->Shutdown(); |
109 } | 106 } |
110 | 107 |
111 protected: | 108 protected: |
112 scoped_ptr<base::SequencedWorkerPoolOwner> pool_owner_; | 109 scoped_ptr<base::SequencedWorkerPoolOwner> pool_owner_; |
113 base::WaitableEvent loaded_event_; | 110 base::WaitableEvent loaded_event_; |
(...skipping 22 matching lines...) Expand all Loading... |
136 // Test the performance of load | 133 // Test the performance of load |
137 TEST_F(SQLitePersistentCookieStorePerfTest, TestLoadPerformance) { | 134 TEST_F(SQLitePersistentCookieStorePerfTest, TestLoadPerformance) { |
138 base::PerfTimeLogger timer("Load all cookies"); | 135 base::PerfTimeLogger timer("Load all cookies"); |
139 Load(); | 136 Load(); |
140 timer.Done(); | 137 timer.Done(); |
141 | 138 |
142 ASSERT_EQ(15000U, cookies_.size()); | 139 ASSERT_EQ(15000U, cookies_.size()); |
143 } | 140 } |
144 | 141 |
145 } // namespace content | 142 } // namespace content |
OLD | NEW |