OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/bind.h" | 5 #include "base/bind.h" |
6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/scoped_temp_dir.h" | 9 #include "base/scoped_temp_dir.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 void WaitOnDBEvent() { | 54 void WaitOnDBEvent() { |
55 db_thread_event_.Wait(); | 55 db_thread_event_.Wait(); |
56 } | 56 } |
57 | 57 |
58 virtual void SetUp() { | 58 virtual void SetUp() { |
59 ui_thread_.Start(); | 59 ui_thread_.Start(); |
60 db_thread_.Start(); | 60 db_thread_.Start(); |
61 io_thread_.Start(); | 61 io_thread_.Start(); |
62 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 62 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
63 store_ = new SQLitePersistentCookieStore( | 63 store_ = new SQLitePersistentCookieStore( |
64 temp_dir_.path().Append(chrome::kCookieFilename)); | 64 temp_dir_.path().Append(chrome::kCookieFilename), false); |
65 std::vector<net::CookieMonster::CanonicalCookie*> cookies; | 65 std::vector<net::CookieMonster::CanonicalCookie*> cookies; |
66 Load(&cookies); | 66 Load(&cookies); |
67 ASSERT_EQ(0u, cookies.size()); | 67 ASSERT_EQ(0u, cookies.size()); |
68 // Make sure the store gets written at least once. | 68 // Make sure the store gets written at least once. |
69 store_->AddCookie( | 69 store_->AddCookie( |
70 net::CookieMonster::CanonicalCookie(GURL(), "A", "B", "http://foo.bar", | 70 net::CookieMonster::CanonicalCookie(GURL(), "A", "B", "http://foo.bar", |
71 "/", std::string(), std::string(), | 71 "/", std::string(), std::string(), |
72 base::Time::Now(), | 72 base::Time::Now(), |
73 base::Time::Now(), | 73 base::Time::Now(), |
74 base::Time::Now(), | 74 base::Time::Now(), |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 // Replace the store effectively destroying the current one and forcing it | 124 // Replace the store effectively destroying the current one and forcing it |
125 // to write it's data to disk. Then we can see if after loading it again it | 125 // to write it's data to disk. Then we can see if after loading it again it |
126 // is still there. | 126 // is still there. |
127 store_ = NULL; | 127 store_ = NULL; |
128 scoped_refptr<base::ThreadTestHelper> helper( | 128 scoped_refptr<base::ThreadTestHelper> helper( |
129 new base::ThreadTestHelper( | 129 new base::ThreadTestHelper( |
130 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB))); | 130 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB))); |
131 // Make sure we wait until the destructor has run. | 131 // Make sure we wait until the destructor has run. |
132 ASSERT_TRUE(helper->Run()); | 132 ASSERT_TRUE(helper->Run()); |
133 store_ = new SQLitePersistentCookieStore( | 133 store_ = new SQLitePersistentCookieStore( |
134 temp_dir_.path().Append(chrome::kCookieFilename)); | 134 temp_dir_.path().Append(chrome::kCookieFilename), false); |
135 | 135 |
136 // Reload and test for persistence | 136 // Reload and test for persistence |
137 Load(&cookies); | 137 Load(&cookies); |
138 ASSERT_EQ(1U, cookies.size()); | 138 ASSERT_EQ(1U, cookies.size()); |
139 ASSERT_STREQ("http://foo.bar", cookies[0]->Domain().c_str()); | 139 ASSERT_STREQ("http://foo.bar", cookies[0]->Domain().c_str()); |
140 ASSERT_STREQ("A", cookies[0]->Name().c_str()); | 140 ASSERT_STREQ("A", cookies[0]->Name().c_str()); |
141 ASSERT_STREQ("B", cookies[0]->Value().c_str()); | 141 ASSERT_STREQ("B", cookies[0]->Value().c_str()); |
142 | 142 |
143 // Now delete the cookie and check persistence again. | 143 // Now delete the cookie and check persistence again. |
144 store_->DeleteCookie(*cookies[0]); | 144 store_->DeleteCookie(*cookies[0]); |
145 store_ = NULL; | 145 store_ = NULL; |
146 // Make sure we wait until the destructor has run. | 146 // Make sure we wait until the destructor has run. |
147 ASSERT_TRUE(helper->Run()); | 147 ASSERT_TRUE(helper->Run()); |
148 STLDeleteContainerPointers(cookies.begin(), cookies.end()); | 148 STLDeleteContainerPointers(cookies.begin(), cookies.end()); |
149 cookies.clear(); | 149 cookies.clear(); |
150 store_ = new SQLitePersistentCookieStore( | 150 store_ = new SQLitePersistentCookieStore( |
151 temp_dir_.path().Append(chrome::kCookieFilename)); | 151 temp_dir_.path().Append(chrome::kCookieFilename), false); |
152 | 152 |
153 // Reload and check if the cookie has been removed. | 153 // Reload and check if the cookie has been removed. |
154 Load(&cookies); | 154 Load(&cookies); |
155 ASSERT_EQ(0U, cookies.size()); | 155 ASSERT_EQ(0U, cookies.size()); |
156 } | 156 } |
157 | 157 |
158 // Test that priority load of cookies for a specfic domain key could be | 158 // Test that priority load of cookies for a specfic domain key could be |
159 // completed before the entire store is loaded | 159 // completed before the entire store is loaded |
160 TEST_F(SQLitePersistentCookieStoreTest, TestLoadCookiesForKey) { | 160 TEST_F(SQLitePersistentCookieStoreTest, TestLoadCookiesForKey) { |
161 base::Time t = base::Time::Now() + base::TimeDelta::FromInternalValue(10); | 161 base::Time t = base::Time::Now() + base::TimeDelta::FromInternalValue(10); |
(...skipping 17 matching lines...) Expand all Loading... |
179 t, t, t, false, false, true, true)); | 179 t, t, t, false, false, true, true)); |
180 store_ = NULL; | 180 store_ = NULL; |
181 | 181 |
182 scoped_refptr<base::ThreadTestHelper> helper( | 182 scoped_refptr<base::ThreadTestHelper> helper( |
183 new base::ThreadTestHelper( | 183 new base::ThreadTestHelper( |
184 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB))); | 184 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB))); |
185 // Make sure we wait until the destructor has run. | 185 // Make sure we wait until the destructor has run. |
186 ASSERT_TRUE(helper->Run()); | 186 ASSERT_TRUE(helper->Run()); |
187 | 187 |
188 store_ = new SQLitePersistentCookieStore( | 188 store_ = new SQLitePersistentCookieStore( |
189 temp_dir_.path().Append(chrome::kCookieFilename)); | 189 temp_dir_.path().Append(chrome::kCookieFilename), false); |
190 // Posting a blocking task to db_thread_ makes sure that the DB thread waits | 190 // Posting a blocking task to db_thread_ makes sure that the DB thread waits |
191 // until both Load and LoadCookiesForKey have been posted to its task queue. | 191 // until both Load and LoadCookiesForKey have been posted to its task queue. |
192 BrowserThread::PostTask( | 192 BrowserThread::PostTask( |
193 BrowserThread::DB, FROM_HERE, | 193 BrowserThread::DB, FROM_HERE, |
194 base::Bind(&SQLitePersistentCookieStoreTest::WaitOnDBEvent, | 194 base::Bind(&SQLitePersistentCookieStoreTest::WaitOnDBEvent, |
195 base::Unretained(this))); | 195 base::Unretained(this))); |
196 store_->Load(base::Bind(&SQLitePersistentCookieStoreTest::OnLoaded, | 196 store_->Load(base::Bind(&SQLitePersistentCookieStoreTest::OnLoaded, |
197 base::Unretained(this))); | 197 base::Unretained(this))); |
198 store_->LoadCookiesForKey("aaa.com", | 198 store_->LoadCookiesForKey("aaa.com", |
199 base::Bind(&SQLitePersistentCookieStoreTest::OnKeyLoaded, | 199 base::Bind(&SQLitePersistentCookieStoreTest::OnKeyLoaded, |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 | 295 |
296 store_->Flush(NewRunnableMethod(counter.get(), &CallbackCounter::Callback)); | 296 store_->Flush(NewRunnableMethod(counter.get(), &CallbackCounter::Callback)); |
297 | 297 |
298 scoped_refptr<base::ThreadTestHelper> helper( | 298 scoped_refptr<base::ThreadTestHelper> helper( |
299 new base::ThreadTestHelper( | 299 new base::ThreadTestHelper( |
300 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB))); | 300 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB))); |
301 ASSERT_TRUE(helper->Run()); | 301 ASSERT_TRUE(helper->Run()); |
302 | 302 |
303 ASSERT_EQ(1, counter->callback_count()); | 303 ASSERT_EQ(1, counter->callback_count()); |
304 } | 304 } |
OLD | NEW |