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