| OLD | NEW |
| 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 "chrome/browser/browsing_data_cookie_helper.h" | 5 #include "chrome/browser/browsing_data_cookie_helper.h" |
| 6 | 6 |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/synchronization/waitable_event.h" | 10 #include "base/synchronization/waitable_event.h" |
| 11 #include "chrome/test/base/testing_profile.h" | 11 #include "chrome/test/base/testing_profile.h" |
| 12 #include "content/public/test/test_browser_thread.h" | 12 #include "content/public/test/test_browser_thread.h" |
| 13 #include "net/cookies/canonical_cookie.h" |
| 13 #include "net/cookies/parsed_cookie.h" | 14 #include "net/cookies/parsed_cookie.h" |
| 14 #include "net/url_request/url_request_context_getter.h" | 15 #include "net/url_request/url_request_context_getter.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 17 |
| 17 using content::BrowserThread; | 18 using content::BrowserThread; |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| 21 class BrowsingDataCookieHelperTest : public testing::Test { | 22 class BrowsingDataCookieHelperTest : public testing::Test { |
| 22 public: | 23 public: |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 scoped_refptr<BrowsingDataCookieHelper> cookie_helper( | 141 scoped_refptr<BrowsingDataCookieHelper> cookie_helper( |
| 141 new BrowsingDataCookieHelper(testing_profile_->GetRequestContext())); | 142 new BrowsingDataCookieHelper(testing_profile_->GetRequestContext())); |
| 142 | 143 |
| 143 cookie_helper->StartFetching( | 144 cookie_helper->StartFetching( |
| 144 base::Bind(&BrowsingDataCookieHelperTest::FetchCallback, | 145 base::Bind(&BrowsingDataCookieHelperTest::FetchCallback, |
| 145 base::Unretained(this))); | 146 base::Unretained(this))); |
| 146 | 147 |
| 147 // Blocks until BrowsingDataCookieHelperTest::FetchCallback is notified. | 148 // Blocks until BrowsingDataCookieHelperTest::FetchCallback is notified. |
| 148 MessageLoop::current()->Run(); | 149 MessageLoop::current()->Run(); |
| 149 | 150 |
| 150 net::CookieMonster::CanonicalCookie cookie = cookie_list_[0]; | 151 net::CanonicalCookie cookie = cookie_list_[0]; |
| 151 cookie_helper->DeleteCookie(cookie); | 152 cookie_helper->DeleteCookie(cookie); |
| 152 | 153 |
| 153 cookie_helper->StartFetching( | 154 cookie_helper->StartFetching( |
| 154 base::Bind(&BrowsingDataCookieHelperTest::DeleteCallback, | 155 base::Bind(&BrowsingDataCookieHelperTest::DeleteCallback, |
| 155 base::Unretained(this))); | 156 base::Unretained(this))); |
| 156 MessageLoop::current()->Run(); | 157 MessageLoop::current()->Run(); |
| 157 } | 158 } |
| 158 | 159 |
| 159 TEST_F(BrowsingDataCookieHelperTest, CannedUnique) { | 160 TEST_F(BrowsingDataCookieHelperTest, CannedUnique) { |
| 160 const GURL origin("http://www.google.com"); | 161 const GURL origin("http://www.google.com"); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 190 | 191 |
| 191 ASSERT_TRUE(helper->empty()); | 192 ASSERT_TRUE(helper->empty()); |
| 192 helper->AddChangedCookie(url_google, url_google, "a=1", | 193 helper->AddChangedCookie(url_google, url_google, "a=1", |
| 193 net::CookieOptions()); | 194 net::CookieOptions()); |
| 194 ASSERT_FALSE(helper->empty()); | 195 ASSERT_FALSE(helper->empty()); |
| 195 helper->Reset(); | 196 helper->Reset(); |
| 196 ASSERT_TRUE(helper->empty()); | 197 ASSERT_TRUE(helper->empty()); |
| 197 | 198 |
| 198 net::CookieList cookies; | 199 net::CookieList cookies; |
| 199 net::ParsedCookie pc("a=1"); | 200 net::ParsedCookie pc("a=1"); |
| 200 scoped_ptr<net::CookieMonster::CanonicalCookie> cookie( | 201 scoped_ptr<net::CanonicalCookie> cookie( |
| 201 new net::CookieMonster::CanonicalCookie(url_google, pc)); | 202 new net::CanonicalCookie(url_google, pc)); |
| 202 cookies.push_back(*cookie); | 203 cookies.push_back(*cookie); |
| 203 | 204 |
| 204 helper->AddReadCookies(url_google, url_google, cookies); | 205 helper->AddReadCookies(url_google, url_google, cookies); |
| 205 ASSERT_FALSE(helper->empty()); | 206 ASSERT_FALSE(helper->empty()); |
| 206 helper->Reset(); | 207 helper->Reset(); |
| 207 ASSERT_TRUE(helper->empty()); | 208 ASSERT_TRUE(helper->empty()); |
| 208 } | 209 } |
| 209 | 210 |
| 210 TEST_F(BrowsingDataCookieHelperTest, CannedDifferentFrames) { | 211 TEST_F(BrowsingDataCookieHelperTest, CannedDifferentFrames) { |
| 211 GURL frame1_url("http://www.google.com"); | 212 GURL frame1_url("http://www.google.com"); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 223 net::CookieOptions()); | 224 net::CookieOptions()); |
| 224 helper->AddChangedCookie(frame2_url, request_url, "c=1", | 225 helper->AddChangedCookie(frame2_url, request_url, "c=1", |
| 225 net::CookieOptions()); | 226 net::CookieOptions()); |
| 226 | 227 |
| 227 helper->StartFetching( | 228 helper->StartFetching( |
| 228 base::Bind(&BrowsingDataCookieHelperTest::CannedDifferentFramesCallback, | 229 base::Bind(&BrowsingDataCookieHelperTest::CannedDifferentFramesCallback, |
| 229 base::Unretained(this))); | 230 base::Unretained(this))); |
| 230 } | 231 } |
| 231 | 232 |
| 232 } // namespace | 233 } // namespace |
| OLD | NEW |