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