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/file_util.h" | 6 #include "base/file_util.h" |
6 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
7 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
8 #include "base/scoped_temp_dir.h" | 9 #include "base/scoped_temp_dir.h" |
9 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
10 #include "base/test/thread_test_helper.h" | 11 #include "base/test/thread_test_helper.h" |
11 #include "chrome/browser/net/sqlite_origin_bound_cert_store.h" | 12 #include "chrome/browser/net/sqlite_origin_bound_cert_store.h" |
12 #include "chrome/common/chrome_constants.h" | 13 #include "chrome/common/chrome_constants.h" |
13 #include "content/test/test_browser_thread.h" | 14 #include "content/test/test_browser_thread.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 std::string origin(1, c); | 124 std::string origin(1, c); |
124 std::string private_key(1000, c); | 125 std::string private_key(1000, c); |
125 std::string cert(1000, c); | 126 std::string cert(1000, c); |
126 store_->AddOriginBoundCert( | 127 store_->AddOriginBoundCert( |
127 net::DefaultOriginBoundCertStore::OriginBoundCert(origin, | 128 net::DefaultOriginBoundCertStore::OriginBoundCert(origin, |
128 private_key, | 129 private_key, |
129 cert)); | 130 cert)); |
130 } | 131 } |
131 | 132 |
132 // Call Flush() and wait until the DB thread is idle. | 133 // Call Flush() and wait until the DB thread is idle. |
133 store_->Flush(NULL); | 134 store_->Flush(base::Closure()); |
134 scoped_refptr<base::ThreadTestHelper> helper( | 135 scoped_refptr<base::ThreadTestHelper> helper( |
135 new base::ThreadTestHelper( | 136 new base::ThreadTestHelper( |
136 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB))); | 137 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB))); |
137 ASSERT_TRUE(helper->Run()); | 138 ASSERT_TRUE(helper->Run()); |
138 | 139 |
139 // We forced a write, so now the file will be bigger. | 140 // We forced a write, so now the file will be bigger. |
140 ASSERT_TRUE(file_util::GetFileInfo(path, &info)); | 141 ASSERT_TRUE(file_util::GetFileInfo(path, &info)); |
141 ASSERT_GT(info.size, base_size); | 142 ASSERT_GT(info.size, base_size); |
142 } | 143 } |
143 | 144 |
(...skipping 15 matching lines...) Expand all Loading... |
159 volatile int callback_count_; | 160 volatile int callback_count_; |
160 }; | 161 }; |
161 | 162 |
162 // Test that we can get a completion callback after a Flush(). | 163 // Test that we can get a completion callback after a Flush(). |
163 TEST_F(SQLiteOriginBoundCertStoreTest, TestFlushCompletionCallback) { | 164 TEST_F(SQLiteOriginBoundCertStoreTest, TestFlushCompletionCallback) { |
164 scoped_refptr<CallbackCounter> counter(new CallbackCounter()); | 165 scoped_refptr<CallbackCounter> counter(new CallbackCounter()); |
165 | 166 |
166 // Callback shouldn't be invoked until we call Flush(). | 167 // Callback shouldn't be invoked until we call Flush(). |
167 ASSERT_EQ(0, counter->callback_count()); | 168 ASSERT_EQ(0, counter->callback_count()); |
168 | 169 |
169 store_->Flush(NewRunnableMethod(counter.get(), &CallbackCounter::Callback)); | 170 store_->Flush(base::Bind(&CallbackCounter::Callback, counter.get())); |
170 | 171 |
171 scoped_refptr<base::ThreadTestHelper> helper( | 172 scoped_refptr<base::ThreadTestHelper> helper( |
172 new base::ThreadTestHelper( | 173 new base::ThreadTestHelper( |
173 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB))); | 174 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB))); |
174 ASSERT_TRUE(helper->Run()); | 175 ASSERT_TRUE(helper->Run()); |
175 | 176 |
176 ASSERT_EQ(1, counter->callback_count()); | 177 ASSERT_EQ(1, counter->callback_count()); |
177 } | 178 } |
OLD | NEW |