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