Chromium Code Reviews| 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/browsing_data_cookie_helper.h" | 5 #include "chrome/browser/browsing_data/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" |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 103 cookie_list_ = cookies; | 103 cookie_list_ = cookies; |
| 104 net::CookieList::const_iterator it = cookies.begin(); | 104 net::CookieList::const_iterator it = cookies.begin(); |
| 105 | 105 |
| 106 ASSERT_TRUE(it != cookies.end()); | 106 ASSERT_TRUE(it != cookies.end()); |
| 107 EXPECT_EQ("http://www.google.com/", it->Source()); | 107 EXPECT_EQ("http://www.google.com/", it->Source()); |
| 108 EXPECT_EQ("A", it->Name()); | 108 EXPECT_EQ("A", it->Name()); |
| 109 | 109 |
| 110 ASSERT_TRUE(++it == cookies.end()); | 110 ASSERT_TRUE(++it == cookies.end()); |
| 111 } | 111 } |
| 112 | 112 |
| 113 void CannedDomainCallback(const net::CookieList& cookies) { | |
| 114 ASSERT_EQ(1UL, cookies.size()); | |
| 115 cookie_list_ = cookies; | |
| 116 net::CookieList::const_iterator it = cookies.begin(); | |
| 117 | |
| 118 ASSERT_TRUE(it != cookies.end()); | |
| 119 EXPECT_EQ("http://www.google.com/", it->Source()); | |
| 120 EXPECT_EQ("A", it->Name()); | |
| 121 EXPECT_EQ("www.google.com", it->Domain()); | |
| 122 | |
| 123 ASSERT_TRUE(++it == cookies.end()); | |
| 124 } | |
| 125 | |
| 113 void CannedDifferentFramesCallback(const net::CookieList& cookie_list) { | 126 void CannedDifferentFramesCallback(const net::CookieList& cookie_list) { |
| 114 ASSERT_EQ(3U, cookie_list.size()); | 127 ASSERT_EQ(3U, cookie_list.size()); |
| 115 } | 128 } |
| 116 | 129 |
| 117 protected: | 130 protected: |
| 118 MessageLoop message_loop_; | 131 MessageLoop message_loop_; |
| 119 scoped_ptr<content::TestBrowserThread> ui_thread_; | 132 scoped_ptr<content::TestBrowserThread> ui_thread_; |
| 120 scoped_ptr<content::TestBrowserThread> io_thread_; | 133 scoped_ptr<content::TestBrowserThread> io_thread_; |
| 121 scoped_ptr<TestingProfile> testing_profile_; | 134 scoped_ptr<TestingProfile> testing_profile_; |
| 122 | 135 |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 150 | 163 |
| 151 net::CanonicalCookie cookie = cookie_list_[0]; | 164 net::CanonicalCookie cookie = cookie_list_[0]; |
| 152 cookie_helper->DeleteCookie(cookie); | 165 cookie_helper->DeleteCookie(cookie); |
| 153 | 166 |
| 154 cookie_helper->StartFetching( | 167 cookie_helper->StartFetching( |
| 155 base::Bind(&BrowsingDataCookieHelperTest::DeleteCallback, | 168 base::Bind(&BrowsingDataCookieHelperTest::DeleteCallback, |
| 156 base::Unretained(this))); | 169 base::Unretained(this))); |
| 157 MessageLoop::current()->Run(); | 170 MessageLoop::current()->Run(); |
| 158 } | 171 } |
| 159 | 172 |
| 173 TEST_F(BrowsingDataCookieHelperTest, CannedCookieDomain) { | |
|
jochen (gone - plz use gerrit)
2012/10/29 16:29:48
can you add a test where you feed the same cookie
markusheintz_
2012/10/29 18:13:00
Done.
| |
| 174 const GURL origin("http://www.google.com"); | |
| 175 net::CookieList cookie; | |
| 176 | |
| 177 scoped_refptr<CannedBrowsingDataCookieHelper> helper( | |
| 178 new CannedBrowsingDataCookieHelper( | |
| 179 testing_profile_->GetRequestContext())); | |
| 180 | |
| 181 ASSERT_TRUE(helper->empty()); | |
| 182 helper->AddChangedCookie(origin, origin, "A=1", net::CookieOptions()); | |
| 183 helper->StartFetching( | |
| 184 base::Bind(&BrowsingDataCookieHelperTest::CannedDomainCallback, | |
| 185 base::Unretained(this))); | |
| 186 cookie = cookie_list_; | |
| 187 | |
| 188 helper->Reset(); | |
| 189 ASSERT_TRUE(helper->empty()); | |
| 190 | |
| 191 helper->AddReadCookies(origin, origin, cookie); | |
| 192 helper->StartFetching( | |
| 193 base::Bind(&BrowsingDataCookieHelperTest::CannedDomainCallback, | |
| 194 base::Unretained(this))); | |
| 195 } | |
| 196 | |
| 197 | |
| 198 | |
| 160 TEST_F(BrowsingDataCookieHelperTest, CannedUnique) { | 199 TEST_F(BrowsingDataCookieHelperTest, CannedUnique) { |
| 161 const GURL origin("http://www.google.com"); | 200 const GURL origin("http://www.google.com"); |
| 162 net::CookieList cookie; | 201 net::CookieList cookie; |
| 163 | 202 |
| 164 scoped_refptr<CannedBrowsingDataCookieHelper> helper( | 203 scoped_refptr<CannedBrowsingDataCookieHelper> helper( |
| 165 new CannedBrowsingDataCookieHelper( | 204 new CannedBrowsingDataCookieHelper( |
| 166 testing_profile_->GetRequestContext())); | 205 testing_profile_->GetRequestContext())); |
| 167 | 206 |
| 168 ASSERT_TRUE(helper->empty()); | 207 ASSERT_TRUE(helper->empty()); |
| 169 helper->AddChangedCookie(origin, origin, "A=1", net::CookieOptions()); | 208 helper->AddChangedCookie(origin, origin, "A=1", net::CookieOptions()); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 224 net::CookieOptions()); | 263 net::CookieOptions()); |
| 225 helper->AddChangedCookie(frame2_url, request_url, "c=1", | 264 helper->AddChangedCookie(frame2_url, request_url, "c=1", |
| 226 net::CookieOptions()); | 265 net::CookieOptions()); |
| 227 | 266 |
| 228 helper->StartFetching( | 267 helper->StartFetching( |
| 229 base::Bind(&BrowsingDataCookieHelperTest::CannedDifferentFramesCallback, | 268 base::Bind(&BrowsingDataCookieHelperTest::CannedDifferentFramesCallback, |
| 230 base::Unretained(this))); | 269 base::Unretained(this))); |
| 231 } | 270 } |
| 232 | 271 |
| 233 } // namespace | 272 } // namespace |
| OLD | NEW |