OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/profile_resetter/profile_resetter.h" | 5 #include "chrome/browser/profile_resetter/profile_resetter.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "chrome/browser/profile_resetter/profile_resetter_test_base.h" | 9 #include "chrome/browser/profile_resetter/profile_resetter_test_base.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 | 59 |
60 RemoveCookieTester::~RemoveCookieTester() {} | 60 RemoveCookieTester::~RemoveCookieTester() {} |
61 | 61 |
62 // Returns true, if the given cookie exists in the cookie store. | 62 // Returns true, if the given cookie exists in the cookie store. |
63 std::string RemoveCookieTester::GetCookie(const std::string& host) { | 63 std::string RemoveCookieTester::GetCookie(const std::string& host) { |
64 last_cookies_.clear(); | 64 last_cookies_.clear(); |
65 DCHECK(!waiting_callback_); | 65 DCHECK(!waiting_callback_); |
66 waiting_callback_ = true; | 66 waiting_callback_ = true; |
67 BrowserThread::PostTask( | 67 BrowserThread::PostTask( |
68 BrowserThread::IO, FROM_HERE, | 68 BrowserThread::IO, FROM_HERE, |
69 base::Bind(&RemoveCookieTester::GetCookieOnIOThread, | 69 base::BindOnce(&RemoveCookieTester::GetCookieOnIOThread, |
70 base::Unretained(this), | 70 base::Unretained(this), |
71 base::Unretained(profile_->GetRequestContext()), | 71 base::Unretained(profile_->GetRequestContext()), host)); |
72 host)); | |
73 BlockUntilNotified(); | 72 BlockUntilNotified(); |
74 return last_cookies_; | 73 return last_cookies_; |
75 } | 74 } |
76 | 75 |
77 void RemoveCookieTester::AddCookie(const std::string& host, | 76 void RemoveCookieTester::AddCookie(const std::string& host, |
78 const std::string& definition) { | 77 const std::string& definition) { |
79 DCHECK(!waiting_callback_); | 78 DCHECK(!waiting_callback_); |
80 waiting_callback_ = true; | 79 waiting_callback_ = true; |
81 BrowserThread::PostTask( | 80 BrowserThread::PostTask( |
82 BrowserThread::IO, FROM_HERE, | 81 BrowserThread::IO, FROM_HERE, |
83 base::Bind(&RemoveCookieTester::SetCookieOnIOThread, | 82 base::BindOnce( |
84 base::Unretained(this), | 83 &RemoveCookieTester::SetCookieOnIOThread, base::Unretained(this), |
85 base::Unretained(profile_->GetRequestContext()), | 84 base::Unretained(profile_->GetRequestContext()), host, definition)); |
86 host, | |
87 definition)); | |
88 BlockUntilNotified(); | 85 BlockUntilNotified(); |
89 } | 86 } |
90 | 87 |
91 void RemoveCookieTester::GetCookieOnIOThread( | 88 void RemoveCookieTester::GetCookieOnIOThread( |
92 net::URLRequestContextGetter* context_getter, | 89 net::URLRequestContextGetter* context_getter, |
93 const std::string& host) { | 90 const std::string& host) { |
94 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 91 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
95 net::CookieStore* cookie_store = context_getter-> | 92 net::CookieStore* cookie_store = context_getter-> |
96 GetURLRequestContext()->cookie_store(); | 93 GetURLRequestContext()->cookie_store(); |
97 cookie_store->GetCookiesWithOptionsAsync( | 94 cookie_store->GetCookiesWithOptionsAsync( |
(...skipping 12 matching lines...) Expand all Loading... |
110 cookie_store->SetCookieWithOptionsAsync( | 107 cookie_store->SetCookieWithOptionsAsync( |
111 GURL(host), definition, net::CookieOptions(), | 108 GURL(host), definition, net::CookieOptions(), |
112 base::Bind(&RemoveCookieTester::SetCookieCallback, | 109 base::Bind(&RemoveCookieTester::SetCookieCallback, |
113 base::Unretained(this))); | 110 base::Unretained(this))); |
114 } | 111 } |
115 | 112 |
116 void RemoveCookieTester::GetCookieCallback(const std::string& cookies) { | 113 void RemoveCookieTester::GetCookieCallback(const std::string& cookies) { |
117 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 114 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
118 BrowserThread::PostTask( | 115 BrowserThread::PostTask( |
119 BrowserThread::UI, FROM_HERE, | 116 BrowserThread::UI, FROM_HERE, |
120 base::Bind(&RemoveCookieTester::GetCookieCallback, | 117 base::BindOnce(&RemoveCookieTester::GetCookieCallback, |
121 base::Unretained(this), cookies)); | 118 base::Unretained(this), cookies)); |
122 return; | 119 return; |
123 } | 120 } |
124 last_cookies_ = cookies; | 121 last_cookies_ = cookies; |
125 Notify(); | 122 Notify(); |
126 } | 123 } |
127 | 124 |
128 void RemoveCookieTester::SetCookieCallback(bool result) { | 125 void RemoveCookieTester::SetCookieCallback(bool result) { |
129 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 126 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
130 BrowserThread::PostTask( | 127 BrowserThread::PostTask( |
131 BrowserThread::UI, FROM_HERE, | 128 BrowserThread::UI, FROM_HERE, |
132 base::Bind(&RemoveCookieTester::SetCookieCallback, | 129 base::BindOnce(&RemoveCookieTester::SetCookieCallback, |
133 base::Unretained(this), result)); | 130 base::Unretained(this), result)); |
134 return; | 131 return; |
135 } | 132 } |
136 ASSERT_TRUE(result); | 133 ASSERT_TRUE(result); |
137 Notify(); | 134 Notify(); |
138 } | 135 } |
139 | 136 |
140 void RemoveCookieTester::BlockUntilNotified() { | 137 void RemoveCookieTester::BlockUntilNotified() { |
141 DCHECK(!runner_.get()); | 138 DCHECK(!runner_.get()); |
142 if (waiting_callback_) { | 139 if (waiting_callback_) { |
143 runner_ = new content::MessageLoopRunner; | 140 runner_ = new content::MessageLoopRunner; |
(...skipping 22 matching lines...) Expand all Loading... |
166 RemoveCookieTester tester(browser()->profile()); | 163 RemoveCookieTester tester(browser()->profile()); |
167 tester.AddCookie(kCookieHostname, kCookieDefinition); | 164 tester.AddCookie(kCookieHostname, kCookieDefinition); |
168 ASSERT_EQ(kCookieDefinition, tester.GetCookie(kCookieHostname)); | 165 ASSERT_EQ(kCookieDefinition, tester.GetCookie(kCookieHostname)); |
169 | 166 |
170 ResetAndWait(ProfileResetter::COOKIES_AND_SITE_DATA); | 167 ResetAndWait(ProfileResetter::COOKIES_AND_SITE_DATA); |
171 | 168 |
172 EXPECT_EQ("", tester.GetCookie(kCookieHostname)); | 169 EXPECT_EQ("", tester.GetCookie(kCookieHostname)); |
173 } | 170 } |
174 | 171 |
175 } // namespace | 172 } // namespace |
OLD | NEW |