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

Side by Side Diff: net/extras/sqlite/sqlite_persistent_cookie_store_unittest.cc

Issue 2030663002: Migrate WaitableEvent to enum-based constructor in net/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@WEvent_enums
Patch Set: Created 4 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
OLDNEW
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 "net/extras/sqlite/sqlite_persistent_cookie_store.h" 5 #include "net/extras/sqlite/sqlite_persistent_cookie_store.h"
6 6
7 #include <map> 7 #include <map>
8 #include <set> 8 #include <set>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 } 79 }
80 80
81 } // namespace 81 } // namespace
82 82
83 typedef std::vector<CanonicalCookie*> CanonicalCookieVector; 83 typedef std::vector<CanonicalCookie*> CanonicalCookieVector;
84 84
85 class SQLitePersistentCookieStoreTest : public testing::Test { 85 class SQLitePersistentCookieStoreTest : public testing::Test {
86 public: 86 public:
87 SQLitePersistentCookieStoreTest() 87 SQLitePersistentCookieStoreTest()
88 : pool_owner_(new base::SequencedWorkerPoolOwner(3, "Background Pool")), 88 : pool_owner_(new base::SequencedWorkerPoolOwner(3, "Background Pool")),
89 loaded_event_(false, false), 89 loaded_event_(base::WaitableEvent::ResetPolicy::AUTOMATIC,
90 key_loaded_event_(false, false), 90 base::WaitableEvent::InitialState::NOT_SIGNALED),
91 db_thread_event_(false, false) {} 91 key_loaded_event_(base::WaitableEvent::ResetPolicy::AUTOMATIC,
92 base::WaitableEvent::InitialState::NOT_SIGNALED),
93 db_thread_event_(base::WaitableEvent::ResetPolicy::AUTOMATIC,
94 base::WaitableEvent::InitialState::NOT_SIGNALED) {}
92 95
93 void OnLoaded(const CanonicalCookieVector& cookies) { 96 void OnLoaded(const CanonicalCookieVector& cookies) {
94 cookies_ = cookies; 97 cookies_ = cookies;
95 loaded_event_.Signal(); 98 loaded_event_.Signal();
96 } 99 }
97 100
98 void OnKeyLoaded(const CanonicalCookieVector& cookies) { 101 void OnKeyLoaded(const CanonicalCookieVector& cookies) {
99 cookies_ = cookies; 102 cookies_ = cookies;
100 key_loaded_event_.Signal(); 103 key_loaded_event_.Signal();
101 } 104 }
102 105
103 void Load(CanonicalCookieVector* cookies) { 106 void Load(CanonicalCookieVector* cookies) {
104 EXPECT_FALSE(loaded_event_.IsSignaled()); 107 EXPECT_FALSE(loaded_event_.IsSignaled());
105 store_->Load(base::Bind(&SQLitePersistentCookieStoreTest::OnLoaded, 108 store_->Load(base::Bind(&SQLitePersistentCookieStoreTest::OnLoaded,
106 base::Unretained(this))); 109 base::Unretained(this)));
107 loaded_event_.Wait(); 110 loaded_event_.Wait();
108 *cookies = cookies_; 111 *cookies = cookies_;
109 } 112 }
110 113
111 void Flush() { 114 void Flush() {
112 base::WaitableEvent event(false, false); 115 base::WaitableEvent event(base::WaitableEvent::ResetPolicy::AUTOMATIC,
116 base::WaitableEvent::InitialState::NOT_SIGNALED);
113 store_->Flush( 117 store_->Flush(
114 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&event))); 118 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&event)));
115 event.Wait(); 119 event.Wait();
116 } 120 }
117 121
118 scoped_refptr<base::SequencedTaskRunner> background_task_runner() { 122 scoped_refptr<base::SequencedTaskRunner> background_task_runner() {
119 return pool_owner_->pool()->GetSequencedTaskRunner( 123 return pool_owner_->pool()->GetSequencedTaskRunner(
120 pool_owner_->pool()->GetNamedSequenceToken("background")); 124 pool_owner_->pool()->GetNamedSequenceToken("background"));
121 } 125 }
122 126
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 313
310 // Posting a blocking task to db_thread_ makes sure that the DB thread waits 314 // Posting a blocking task to db_thread_ makes sure that the DB thread waits
311 // until both Load and Flush have been posted to its task queue. 315 // until both Load and Flush have been posted to its task queue.
312 background_task_runner()->PostTask( 316 background_task_runner()->PostTask(
313 FROM_HERE, base::Bind(&SQLitePersistentCookieStoreTest::WaitOnDBEvent, 317 FROM_HERE, base::Bind(&SQLitePersistentCookieStoreTest::WaitOnDBEvent,
314 base::Unretained(this))); 318 base::Unretained(this)));
315 store_->Load(base::Bind(&SQLitePersistentCookieStoreTest::OnLoaded, 319 store_->Load(base::Bind(&SQLitePersistentCookieStoreTest::OnLoaded,
316 base::Unretained(this))); 320 base::Unretained(this)));
317 t += base::TimeDelta::FromInternalValue(10); 321 t += base::TimeDelta::FromInternalValue(10);
318 AddCookieWithExpiration("A", "B", "c.com", "/", t, base::Time()); 322 AddCookieWithExpiration("A", "B", "c.com", "/", t, base::Time());
319 base::WaitableEvent event(false, false); 323 base::WaitableEvent event(base::WaitableEvent::ResetPolicy::AUTOMATIC,
324 base::WaitableEvent::InitialState::NOT_SIGNALED);
320 store_->Flush( 325 store_->Flush(
321 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&event))); 326 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&event)));
322 327
323 // Now the DB-thread queue contains: 328 // Now the DB-thread queue contains:
324 // (active:) 329 // (active:)
325 // 1. Wait (on db_event) 330 // 1. Wait (on db_event)
326 // (pending:) 331 // (pending:)
327 // 2. "Init And Chain-Load First Domain" 332 // 2. "Init And Chain-Load First Domain"
328 // 3. Add Cookie (c.com) 333 // 3. Add Cookie (c.com)
329 // 4. Flush Cookie (c.com) 334 // 4. Flush Cookie (c.com)
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after
804 EXPECT_TRUE(was_called_with_no_cookies); 809 EXPECT_TRUE(was_called_with_no_cookies);
805 810
806 // Same with trying to load a specific cookie. 811 // Same with trying to load a specific cookie.
807 was_called_with_no_cookies = false; 812 was_called_with_no_cookies = false;
808 store_->LoadCookiesForKey("foo.bar", base::Bind(WasCalledWithNoCookies, 813 store_->LoadCookiesForKey("foo.bar", base::Bind(WasCalledWithNoCookies,
809 &was_called_with_no_cookies)); 814 &was_called_with_no_cookies));
810 EXPECT_TRUE(was_called_with_no_cookies); 815 EXPECT_TRUE(was_called_with_no_cookies);
811 } 816 }
812 817
813 } // namespace net 818 } // namespace net
OLDNEW
« no previous file with comments | « net/extras/sqlite/sqlite_persistent_cookie_store_perftest.cc ('k') | net/log/net_log_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698