Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(23)

Side by Side Diff: chrome/browser/net/sqlite_persistent_cookie_store_unittest.cc

Issue 7239023: Move the thread test helper to base/test (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/file_util.h" 5 #include "base/file_util.h"
6 #include "base/memory/ref_counted.h" 6 #include "base/memory/ref_counted.h"
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/scoped_temp_dir.h" 8 #include "base/scoped_temp_dir.h"
9 #include "base/stl_util-inl.h" 9 #include "base/stl_util-inl.h"
10 #include "base/test/thread_test_helper.h"
10 #include "base/time.h" 11 #include "base/time.h"
11 #include "chrome/browser/net/sqlite_persistent_cookie_store.h" 12 #include "chrome/browser/net/sqlite_persistent_cookie_store.h"
12 #include "chrome/common/chrome_constants.h" 13 #include "chrome/common/chrome_constants.h"
13 #include "chrome/test/thread_test_helper.h"
14 #include "content/browser/browser_thread.h" 14 #include "content/browser/browser_thread.h"
15 #include "googleurl/src/gurl.h" 15 #include "googleurl/src/gurl.h"
16 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
17 17
18 class SQLitePersistentCookieStoreTest : public testing::Test { 18 class SQLitePersistentCookieStoreTest : public testing::Test {
19 public: 19 public:
20 SQLitePersistentCookieStoreTest() 20 SQLitePersistentCookieStoreTest()
21 : ui_thread_(BrowserThread::UI), 21 : ui_thread_(BrowserThread::UI),
22 db_thread_(BrowserThread::DB) { 22 db_thread_(BrowserThread::DB) {
23 } 23 }
(...skipping 21 matching lines...) Expand all
45 BrowserThread ui_thread_; 45 BrowserThread ui_thread_;
46 BrowserThread db_thread_; 46 BrowserThread db_thread_;
47 ScopedTempDir temp_dir_; 47 ScopedTempDir temp_dir_;
48 scoped_refptr<SQLitePersistentCookieStore> store_; 48 scoped_refptr<SQLitePersistentCookieStore> store_;
49 }; 49 };
50 50
51 TEST_F(SQLitePersistentCookieStoreTest, KeepOnDestruction) { 51 TEST_F(SQLitePersistentCookieStoreTest, KeepOnDestruction) {
52 store_->SetClearLocalStateOnExit(false); 52 store_->SetClearLocalStateOnExit(false);
53 store_ = NULL; 53 store_ = NULL;
54 // Make sure we wait until the destructor has run. 54 // Make sure we wait until the destructor has run.
55 scoped_refptr<ThreadTestHelper> helper( 55 scoped_refptr<base::ThreadTestHelper> helper(
56 new ThreadTestHelper(BrowserThread::DB)); 56 new base::ThreadTestHelper(
57 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB)));
57 ASSERT_TRUE(helper->Run()); 58 ASSERT_TRUE(helper->Run());
58 59
59 ASSERT_TRUE(file_util::PathExists( 60 ASSERT_TRUE(file_util::PathExists(
60 temp_dir_.path().Append(chrome::kCookieFilename))); 61 temp_dir_.path().Append(chrome::kCookieFilename)));
61 ASSERT_TRUE(file_util::Delete( 62 ASSERT_TRUE(file_util::Delete(
62 temp_dir_.path().Append(chrome::kCookieFilename), false)); 63 temp_dir_.path().Append(chrome::kCookieFilename), false));
63 } 64 }
64 65
65 TEST_F(SQLitePersistentCookieStoreTest, RemoveOnDestruction) { 66 TEST_F(SQLitePersistentCookieStoreTest, RemoveOnDestruction) {
66 store_->SetClearLocalStateOnExit(true); 67 store_->SetClearLocalStateOnExit(true);
67 // Replace the store effectively destroying the current one and forcing it 68 // Replace the store effectively destroying the current one and forcing it
68 // to write it's data to disk. Then we can see if after loading it again it 69 // to write it's data to disk. Then we can see if after loading it again it
69 // is still there. 70 // is still there.
70 store_ = NULL; 71 store_ = NULL;
71 // Make sure we wait until the destructor has run. 72 // Make sure we wait until the destructor has run.
72 scoped_refptr<ThreadTestHelper> helper( 73 scoped_refptr<base::ThreadTestHelper> helper(
73 new ThreadTestHelper(BrowserThread::DB)); 74 new base::ThreadTestHelper(
75 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB)));
74 ASSERT_TRUE(helper->Run()); 76 ASSERT_TRUE(helper->Run());
75 77
76 ASSERT_FALSE(file_util::PathExists( 78 ASSERT_FALSE(file_util::PathExists(
77 temp_dir_.path().Append(chrome::kCookieFilename))); 79 temp_dir_.path().Append(chrome::kCookieFilename)));
78 } 80 }
79 81
80 // Test if data is stored as expected in the SQLite database. 82 // Test if data is stored as expected in the SQLite database.
81 TEST_F(SQLitePersistentCookieStoreTest, TestPersistance) { 83 TEST_F(SQLitePersistentCookieStoreTest, TestPersistance) {
82 std::vector<net::CookieMonster::CanonicalCookie*> cookies; 84 std::vector<net::CookieMonster::CanonicalCookie*> cookies;
83 // Replace the store effectively destroying the current one and forcing it 85 // Replace the store effectively destroying the current one and forcing it
84 // to write it's data to disk. Then we can see if after loading it again it 86 // to write it's data to disk. Then we can see if after loading it again it
85 // is still there. 87 // is still there.
86 store_ = NULL; 88 store_ = NULL;
87 scoped_refptr<ThreadTestHelper> helper( 89 scoped_refptr<base::ThreadTestHelper> helper(
88 new ThreadTestHelper(BrowserThread::DB)); 90 new base::ThreadTestHelper(
91 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB)));
89 // Make sure we wait until the destructor has run. 92 // Make sure we wait until the destructor has run.
90 ASSERT_TRUE(helper->Run()); 93 ASSERT_TRUE(helper->Run());
91 store_ = new SQLitePersistentCookieStore( 94 store_ = new SQLitePersistentCookieStore(
92 temp_dir_.path().Append(chrome::kCookieFilename)); 95 temp_dir_.path().Append(chrome::kCookieFilename));
93 96
94 // Reload and test for persistence 97 // Reload and test for persistence
95 ASSERT_TRUE(store_->Load(&cookies)); 98 ASSERT_TRUE(store_->Load(&cookies));
96 ASSERT_EQ(1U, cookies.size()); 99 ASSERT_EQ(1U, cookies.size());
97 ASSERT_STREQ("http://foo.bar", cookies[0]->Domain().c_str()); 100 ASSERT_STREQ("http://foo.bar", cookies[0]->Domain().c_str());
98 ASSERT_STREQ("A", cookies[0]->Name().c_str()); 101 ASSERT_STREQ("A", cookies[0]->Name().c_str());
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 store_->AddCookie( 134 store_->AddCookie(
132 net::CookieMonster::CanonicalCookie(GURL(), name, value, 135 net::CookieMonster::CanonicalCookie(GURL(), name, value,
133 "http://foo.bar", "/", 136 "http://foo.bar", "/",
134 std::string(), std::string(), 137 std::string(), std::string(),
135 t, t, t, 138 t, t, t,
136 false, false, true)); 139 false, false, true));
137 } 140 }
138 141
139 // Call Flush() and wait until the DB thread is idle. 142 // Call Flush() and wait until the DB thread is idle.
140 store_->Flush(NULL); 143 store_->Flush(NULL);
141 scoped_refptr<ThreadTestHelper> helper( 144 scoped_refptr<base::ThreadTestHelper> helper(
142 new ThreadTestHelper(BrowserThread::DB)); 145 new base::ThreadTestHelper(
146 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB)));
143 ASSERT_TRUE(helper->Run()); 147 ASSERT_TRUE(helper->Run());
144 148
145 // We forced a write, so now the file will be bigger. 149 // We forced a write, so now the file will be bigger.
146 ASSERT_TRUE(file_util::GetFileInfo(path, &info)); 150 ASSERT_TRUE(file_util::GetFileInfo(path, &info));
147 ASSERT_GT(info.size, base_size); 151 ASSERT_GT(info.size, base_size);
148 } 152 }
149 153
150 // Counts the number of times Callback() has been run. 154 // Counts the number of times Callback() has been run.
151 class CallbackCounter : public base::RefCountedThreadSafe<CallbackCounter> { 155 class CallbackCounter : public base::RefCountedThreadSafe<CallbackCounter> {
152 public: 156 public:
(...skipping 14 matching lines...) Expand all
167 171
168 // Test that we can get a completion callback after a Flush(). 172 // Test that we can get a completion callback after a Flush().
169 TEST_F(SQLitePersistentCookieStoreTest, TestFlushCompletionCallback) { 173 TEST_F(SQLitePersistentCookieStoreTest, TestFlushCompletionCallback) {
170 scoped_refptr<CallbackCounter> counter(new CallbackCounter()); 174 scoped_refptr<CallbackCounter> counter(new CallbackCounter());
171 175
172 // Callback shouldn't be invoked until we call Flush(). 176 // Callback shouldn't be invoked until we call Flush().
173 ASSERT_EQ(0, counter->callback_count()); 177 ASSERT_EQ(0, counter->callback_count());
174 178
175 store_->Flush(NewRunnableMethod(counter.get(), &CallbackCounter::Callback)); 179 store_->Flush(NewRunnableMethod(counter.get(), &CallbackCounter::Callback));
176 180
177 scoped_refptr<ThreadTestHelper> helper( 181 scoped_refptr<base::ThreadTestHelper> helper(
178 new ThreadTestHelper(BrowserThread::DB)); 182 new base::ThreadTestHelper(
183 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB)));
179 ASSERT_TRUE(helper->Run()); 184 ASSERT_TRUE(helper->Run());
180 185
181 ASSERT_EQ(1, counter->callback_count()); 186 ASSERT_EQ(1, counter->callback_count());
182 } 187 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_event_router_forwarder_unittest.cc ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698