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 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "chrome/test/base/testing_profile.h" | 9 #include "chrome/test/base/testing_profile.h" |
| 10 #include "content/public/browser/storage_partition.h" | |
| 11 #include "content/public/common/url_constants.h" | |
| 10 #include "content/public/test/test_browser_thread_bundle.h" | 12 #include "content/public/test/test_browser_thread_bundle.h" |
| 13 #include "content/public/test/test_utils.h" | |
| 11 #include "net/cookies/canonical_cookie.h" | 14 #include "net/cookies/canonical_cookie.h" |
| 12 #include "net/cookies/parsed_cookie.h" | 15 #include "net/cookies/parsed_cookie.h" |
| 13 #include "net/url_request/url_request_context_getter.h" | 16 #include "net/url_request/url_request_context_getter.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 18 |
| 16 namespace { | 19 namespace { |
| 17 | 20 |
| 18 class BrowsingDataCookieHelperTest : public testing::Test { | 21 class BrowsingDataCookieHelperTest : public testing::Test { |
| 19 public: | 22 public: |
| 20 BrowsingDataCookieHelperTest() | 23 BrowsingDataCookieHelperTest() |
| 21 : testing_profile_(new TestingProfile()) { | 24 : testing_profile_(new TestingProfile()) { |
| 22 } | 25 } |
| 23 | 26 |
| 27 net::CookieMonster* GetCookieMonster(const GURL& origin) { | |
| 28 using content::BrowserContext; | |
|
Bernhard Bauer
2013/08/16 06:46:44
This isn't very... commonly seen in Chrome code. A
awong
2013/08/17 00:32:52
Since no one else was using it, didn't see a reaso
| |
| 29 // Since it's a unittest, assume default StoragePartition. | |
| 30 return content::GetCookieStoreForScheme( | |
| 31 BrowserContext::GetDefaultStoragePartition(testing_profile_.get()), | |
| 32 origin.scheme())->GetCookieMonster(); | |
| 33 } | |
| 34 | |
| 24 void CreateCookiesForTest() { | 35 void CreateCookiesForTest() { |
| 25 scoped_refptr<net::CookieMonster> cookie_monster = | 36 GURL origin1("http://www.google.com"); |
| 26 testing_profile_->GetCookieMonster(); | 37 GURL origin2("http://www.gmail.google.com"); |
| 27 cookie_monster->SetCookieWithOptionsAsync( | 38 GetCookieMonster(origin1)->SetCookieWithOptionsAsync( |
| 28 GURL("http://www.google.com"), "A=1", net::CookieOptions(), | 39 origin1, "A=1", net::CookieOptions(), |
| 29 net::CookieMonster::SetCookiesCallback()); | 40 net::CookieMonster::SetCookiesCallback()); |
| 30 cookie_monster->SetCookieWithOptionsAsync( | 41 GetCookieMonster(origin2)->SetCookieWithOptionsAsync( |
| 31 GURL("http://www.gmail.google.com"), "B=1", net::CookieOptions(), | 42 origin2, "B=1", net::CookieOptions(), |
| 32 net::CookieMonster::SetCookiesCallback()); | 43 net::CookieMonster::SetCookiesCallback()); |
| 33 } | 44 } |
| 34 | 45 |
| 35 void CreateCookiesForDomainCookieTest() { | 46 void CreateCookiesForDomainCookieTest() { |
| 36 scoped_refptr<net::CookieMonster> cookie_monster = | 47 GURL origin("http://www.google.com"); |
| 37 testing_profile_->GetCookieMonster(); | 48 scoped_refptr<net::CookieMonster> cookie_monster = GetCookieMonster(origin); |
| 38 cookie_monster->SetCookieWithOptionsAsync( | 49 cookie_monster->SetCookieWithOptionsAsync( |
| 39 GURL("http://www.google.com"), "A=1", net::CookieOptions(), | 50 origin, "A=1", net::CookieOptions(), |
| 40 net::CookieMonster::SetCookiesCallback()); | 51 net::CookieMonster::SetCookiesCallback()); |
| 41 cookie_monster->SetCookieWithOptionsAsync( | 52 cookie_monster->SetCookieWithOptionsAsync( |
| 42 GURL("http://www.google.com"), "A=2; Domain=.www.google.com ", | 53 origin, "A=2; Domain=.www.google.com ", |
| 43 net::CookieOptions(), net::CookieMonster::SetCookiesCallback()); | 54 net::CookieOptions(), net::CookieMonster::SetCookiesCallback()); |
| 44 } | 55 } |
| 45 | 56 |
| 46 void FetchCallback(const net::CookieList& cookies) { | 57 void FetchCallback(const net::CookieList& cookies) { |
| 47 ASSERT_EQ(2UL, cookies.size()); | 58 ASSERT_EQ(2UL, cookies.size()); |
| 48 cookie_list_ = cookies; | 59 cookie_list_ = cookies; |
| 49 net::CookieList::const_iterator it = cookies.begin(); | 60 net::CookieList::const_iterator it = cookies.begin(); |
| 50 | 61 |
| 51 // Correct because fetching cookies will get a sorted cookie list. | 62 // Correct because fetching cookies will get a sorted cookie list. |
| 52 ASSERT_TRUE(it != cookies.end()); | 63 ASSERT_TRUE(it != cookies.end()); |
| (...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 434 // "A=1; | 445 // "A=1; |
| 435 // "A=3; Domain=www.google.com" | 446 // "A=3; Domain=www.google.com" |
| 436 // Add a domain cookie and check if it increases the cookie count. | 447 // Add a domain cookie and check if it increases the cookie count. |
| 437 helper->AddChangedCookie(frame2_url, frame1_url, | 448 helper->AddChangedCookie(frame2_url, frame1_url, |
| 438 cookie_pair4 + "; Domain=" + cookie_domain, | 449 cookie_pair4 + "; Domain=" + cookie_domain, |
| 439 net::CookieOptions()); | 450 net::CookieOptions()); |
| 440 EXPECT_EQ(5U, helper->GetCookieCount()); | 451 EXPECT_EQ(5U, helper->GetCookieCount()); |
| 441 } | 452 } |
| 442 | 453 |
| 443 } // namespace | 454 } // namespace |
| OLD | NEW |