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 { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 private: | 70 private: |
70 OtrTestingProfile* linked_profile_; | 71 OtrTestingProfile* linked_profile_; |
71 }; | 72 }; |
72 | 73 |
73 } // namespace | 74 } // namespace |
74 | 75 |
75 class ExtensionCookiesTest : public testing::Test { | 76 class ExtensionCookiesTest : public testing::Test { |
76 }; | 77 }; |
77 | 78 |
78 TEST_F(ExtensionCookiesTest, StoreIdProfileConversion) { | 79 TEST_F(ExtensionCookiesTest, StoreIdProfileConversion) { |
| 80 content::TestBrowserThreadBundle thread_bundle; |
79 OtrTestingProfile profile, otrProfile; | 81 OtrTestingProfile profile, otrProfile; |
80 otrProfile.set_incognito(true); | 82 otrProfile.set_incognito(true); |
81 OtrTestingProfile::LinkProfiles(&profile, &otrProfile); | 83 OtrTestingProfile::LinkProfiles(&profile, &otrProfile); |
82 | 84 |
83 EXPECT_EQ(std::string("0"), | 85 EXPECT_EQ(std::string("0"), |
84 cookies_helpers::GetStoreIdFromProfile(&profile)); | 86 cookies_helpers::GetStoreIdFromProfile(&profile)); |
85 EXPECT_EQ(&profile, | 87 EXPECT_EQ(&profile, |
86 cookies_helpers::ChooseProfileFromStoreId( | 88 cookies_helpers::ChooseProfileFromStoreId( |
87 "0", &profile, true)); | 89 "0", &profile, true)); |
88 EXPECT_EQ(&profile, | 90 EXPECT_EQ(&profile, |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 base::Time(), base::Time::FromDoubleT(10000), base::Time(), | 137 base::Time(), base::Time::FromDoubleT(10000), base::Time(), |
136 false, false, net::COOKIE_PRIORITY_DEFAULT); | 138 false, false, net::COOKIE_PRIORITY_DEFAULT); |
137 scoped_ptr<Cookie> cookie2( | 139 scoped_ptr<Cookie> cookie2( |
138 cookies_helpers::CreateCookie( | 140 cookies_helpers::CreateCookie( |
139 canonical_cookie2, "some cookie store")); | 141 canonical_cookie2, "some cookie store")); |
140 EXPECT_FALSE(cookie2->host_only); | 142 EXPECT_FALSE(cookie2->host_only); |
141 EXPECT_FALSE(cookie2->session); | 143 EXPECT_FALSE(cookie2->session); |
142 ASSERT_TRUE(cookie2->expiration_date.get()); | 144 ASSERT_TRUE(cookie2->expiration_date.get()); |
143 EXPECT_EQ(10000, *cookie2->expiration_date); | 145 EXPECT_EQ(10000, *cookie2->expiration_date); |
144 | 146 |
| 147 content::TestBrowserThreadBundle thread_bundle; |
145 TestingProfile profile; | 148 TestingProfile profile; |
146 base::ListValue* tab_ids_list = new base::ListValue(); | 149 base::ListValue* tab_ids_list = new base::ListValue(); |
147 std::vector<int> tab_ids; | 150 std::vector<int> tab_ids; |
148 scoped_ptr<CookieStore> cookie_store( | 151 scoped_ptr<CookieStore> cookie_store( |
149 cookies_helpers::CreateCookieStore(&profile, tab_ids_list)); | 152 cookies_helpers::CreateCookieStore(&profile, tab_ids_list)); |
150 EXPECT_EQ("0", cookie_store->id); | 153 EXPECT_EQ("0", cookie_store->id); |
151 EXPECT_EQ(tab_ids, cookie_store->tab_ids); | 154 EXPECT_EQ(tab_ids, cookie_store->tab_ids); |
152 } | 155 } |
153 | 156 |
154 TEST_F(ExtensionCookiesTest, GetURLFromCanonicalCookie) { | 157 TEST_F(ExtensionCookiesTest, GetURLFromCanonicalCookie) { |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 false, | 228 false, |
226 net::COOKIE_PRIORITY_DEFAULT); | 229 net::COOKIE_PRIORITY_DEFAULT); |
227 scoped_ptr<Cookie> cookie( | 230 scoped_ptr<Cookie> cookie( |
228 cookies_helpers::CreateCookie( | 231 cookies_helpers::CreateCookie( |
229 canonical_cookie, "some cookie store")); | 232 canonical_cookie, "some cookie store")); |
230 EXPECT_EQ(std::string("011Q255bNX_1!yd\xEF\xBF\xBD" "e+"), cookie->value); | 233 EXPECT_EQ(std::string("011Q255bNX_1!yd\xEF\xBF\xBD" "e+"), cookie->value); |
231 EXPECT_EQ(std::string(), cookie->path); | 234 EXPECT_EQ(std::string(), cookie->path); |
232 } | 235 } |
233 | 236 |
234 } // namespace extensions | 237 } // namespace extensions |
OLD | NEW |