| 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 // Tests common functionality used by the Chrome Extensions Cookies API | 5 // Tests common functionality used by the Chrome Extensions Cookies API |
| 6 // implementation. | 6 // implementation. |
| 7 | 7 |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 | 9 |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| 11 #include "chrome/browser/extensions/api/cookies/cookies_api_constants.h" | 11 #include "chrome/browser/extensions/api/cookies/cookies_api_constants.h" |
| 12 #include "chrome/browser/extensions/api/cookies/cookies_helpers.h" | 12 #include "chrome/browser/extensions/api/cookies/cookies_helpers.h" |
| 13 #include "chrome/common/extensions/api/cookies.h" | 13 #include "chrome/common/extensions/api/cookies.h" |
| 14 #include "chrome/test/base/testing_profile.h" | 14 #include "chrome/test/base/testing_profile.h" |
| 15 #include "content/public/test/test_browser_thread_bundle.h" | |
| 16 #include "net/cookies/canonical_cookie.h" | 15 #include "net/cookies/canonical_cookie.h" |
| 17 #include "net/cookies/cookie_constants.h" | 16 #include "net/cookies/cookie_constants.h" |
| 18 #include "url/gurl.h" | 17 #include "url/gurl.h" |
| 19 | 18 |
| 20 using extensions::api::cookies::Cookie; | 19 using extensions::api::cookies::Cookie; |
| 21 using extensions::api::cookies::CookieStore; | 20 using extensions::api::cookies::CookieStore; |
| 22 | 21 |
| 23 namespace GetAll = extensions::api::cookies::GetAll; | 22 namespace GetAll = extensions::api::cookies::GetAll; |
| 24 | 23 |
| 25 namespace extensions { | 24 namespace extensions { |
| 26 | 25 |
| 27 namespace keys = cookies_api_constants; | 26 namespace keys = cookies_api_constants; |
| 28 | 27 |
| 29 namespace { | 28 namespace { |
| 30 | 29 |
| 31 struct DomainMatchCase { | 30 struct DomainMatchCase { |
| 32 const char* filter; | 31 const char* filter; |
| 33 const char* domain; | 32 const char* domain; |
| 34 const bool matches; | 33 const bool matches; |
| 35 }; | 34 }; |
| 36 | 35 |
| 37 } // namespace | 36 } // namespace |
| 38 | 37 |
| 39 class ExtensionCookiesTest : public testing::Test { | 38 class ExtensionCookiesTest : public testing::Test { |
| 40 }; | 39 }; |
| 41 | 40 |
| 42 TEST_F(ExtensionCookiesTest, StoreIdProfileConversion) { | 41 TEST_F(ExtensionCookiesTest, StoreIdProfileConversion) { |
| 43 content::TestBrowserThreadBundle thread_bundle; | |
| 44 TestingProfile::Builder profile_builder; | 42 TestingProfile::Builder profile_builder; |
| 45 TestingProfile::Builder otr_profile_builder; | 43 TestingProfile::Builder otr_profile_builder; |
| 46 otr_profile_builder.SetIncognito(); | 44 otr_profile_builder.SetIncognito(); |
| 47 scoped_ptr<TestingProfile> profile = profile_builder.Build(); | 45 scoped_ptr<TestingProfile> profile = profile_builder.Build(); |
| 48 scoped_ptr<TestingProfile> otr_profile = otr_profile_builder.Build(); | 46 scoped_ptr<TestingProfile> otr_profile = otr_profile_builder.Build(); |
| 49 otr_profile->SetOriginalProfile(profile.get()); | 47 otr_profile->SetOriginalProfile(profile.get()); |
| 50 profile->SetOffTheRecordProfile(otr_profile.PassAs<Profile>()); | 48 profile->SetOffTheRecordProfile(otr_profile.PassAs<Profile>()); |
| 51 | 49 |
| 52 EXPECT_EQ(std::string("0"), | 50 EXPECT_EQ(std::string("0"), |
| 53 cookies_helpers::GetStoreIdFromProfile(profile.get())); | 51 cookies_helpers::GetStoreIdFromProfile(profile.get())); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 base::Time(), base::Time::FromDoubleT(10000), base::Time(), | 103 base::Time(), base::Time::FromDoubleT(10000), base::Time(), |
| 106 false, false, net::COOKIE_PRIORITY_DEFAULT); | 104 false, false, net::COOKIE_PRIORITY_DEFAULT); |
| 107 scoped_ptr<Cookie> cookie2( | 105 scoped_ptr<Cookie> cookie2( |
| 108 cookies_helpers::CreateCookie( | 106 cookies_helpers::CreateCookie( |
| 109 canonical_cookie2, "some cookie store")); | 107 canonical_cookie2, "some cookie store")); |
| 110 EXPECT_FALSE(cookie2->host_only); | 108 EXPECT_FALSE(cookie2->host_only); |
| 111 EXPECT_FALSE(cookie2->session); | 109 EXPECT_FALSE(cookie2->session); |
| 112 ASSERT_TRUE(cookie2->expiration_date.get()); | 110 ASSERT_TRUE(cookie2->expiration_date.get()); |
| 113 EXPECT_EQ(10000, *cookie2->expiration_date); | 111 EXPECT_EQ(10000, *cookie2->expiration_date); |
| 114 | 112 |
| 115 content::TestBrowserThreadBundle thread_bundle; | |
| 116 TestingProfile profile; | 113 TestingProfile profile; |
| 117 base::ListValue* tab_ids_list = new base::ListValue(); | 114 base::ListValue* tab_ids_list = new base::ListValue(); |
| 118 std::vector<int> tab_ids; | 115 std::vector<int> tab_ids; |
| 119 scoped_ptr<CookieStore> cookie_store( | 116 scoped_ptr<CookieStore> cookie_store( |
| 120 cookies_helpers::CreateCookieStore(&profile, tab_ids_list)); | 117 cookies_helpers::CreateCookieStore(&profile, tab_ids_list)); |
| 121 EXPECT_EQ("0", cookie_store->id); | 118 EXPECT_EQ("0", cookie_store->id); |
| 122 EXPECT_EQ(tab_ids, cookie_store->tab_ids); | 119 EXPECT_EQ(tab_ids, cookie_store->tab_ids); |
| 123 } | 120 } |
| 124 | 121 |
| 125 TEST_F(ExtensionCookiesTest, GetURLFromCanonicalCookie) { | 122 TEST_F(ExtensionCookiesTest, GetURLFromCanonicalCookie) { |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 false, | 193 false, |
| 197 net::COOKIE_PRIORITY_DEFAULT); | 194 net::COOKIE_PRIORITY_DEFAULT); |
| 198 scoped_ptr<Cookie> cookie( | 195 scoped_ptr<Cookie> cookie( |
| 199 cookies_helpers::CreateCookie( | 196 cookies_helpers::CreateCookie( |
| 200 canonical_cookie, "some cookie store")); | 197 canonical_cookie, "some cookie store")); |
| 201 EXPECT_EQ(std::string("011Q255bNX_1!yd\xEF\xBF\xBD" "e+"), cookie->value); | 198 EXPECT_EQ(std::string("011Q255bNX_1!yd\xEF\xBF\xBD" "e+"), cookie->value); |
| 202 EXPECT_EQ(std::string(), cookie->path); | 199 EXPECT_EQ(std::string(), cookie->path); |
| 203 } | 200 } |
| 204 | 201 |
| 205 } // namespace extensions | 202 } // namespace extensions |
| OLD | NEW |