| 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" |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 EXPECT_EQ(profile->GetOffTheRecordProfile(), | 74 EXPECT_EQ(profile->GetOffTheRecordProfile(), |
| 75 cookies_helpers::ChooseProfileFromStoreId( | 75 cookies_helpers::ChooseProfileFromStoreId( |
| 76 "1", profile->GetOffTheRecordProfile(), true)); | 76 "1", profile->GetOffTheRecordProfile(), true)); |
| 77 EXPECT_EQ(profile->GetOffTheRecordProfile(), | 77 EXPECT_EQ(profile->GetOffTheRecordProfile(), |
| 78 cookies_helpers::ChooseProfileFromStoreId( | 78 cookies_helpers::ChooseProfileFromStoreId( |
| 79 "1", profile->GetOffTheRecordProfile(), false)); | 79 "1", profile->GetOffTheRecordProfile(), false)); |
| 80 } | 80 } |
| 81 | 81 |
| 82 TEST_F(ExtensionCookiesTest, ExtensionTypeCreation) { | 82 TEST_F(ExtensionCookiesTest, ExtensionTypeCreation) { |
| 83 net::CanonicalCookie canonical_cookie1( | 83 net::CanonicalCookie canonical_cookie1( |
| 84 GURL(), "ABC", "DEF", "www.foobar.com", "/", | 84 GURL(), "ABC", "DEF", "www.foobar.com", "/", base::Time(), base::Time(), |
| 85 base::Time(), base::Time(), base::Time(), | 85 base::Time(), false, false, false, net::COOKIE_PRIORITY_DEFAULT); |
| 86 false, false, net::COOKIE_PRIORITY_DEFAULT); | |
| 87 scoped_ptr<Cookie> cookie1( | 86 scoped_ptr<Cookie> cookie1( |
| 88 cookies_helpers::CreateCookie( | 87 cookies_helpers::CreateCookie( |
| 89 canonical_cookie1, "some cookie store")); | 88 canonical_cookie1, "some cookie store")); |
| 90 EXPECT_EQ("ABC", cookie1->name); | 89 EXPECT_EQ("ABC", cookie1->name); |
| 91 EXPECT_EQ("DEF", cookie1->value); | 90 EXPECT_EQ("DEF", cookie1->value); |
| 92 EXPECT_EQ("www.foobar.com", cookie1->domain); | 91 EXPECT_EQ("www.foobar.com", cookie1->domain); |
| 93 EXPECT_TRUE(cookie1->host_only); | 92 EXPECT_TRUE(cookie1->host_only); |
| 94 EXPECT_EQ("/", cookie1->path); | 93 EXPECT_EQ("/", cookie1->path); |
| 95 EXPECT_FALSE(cookie1->secure); | 94 EXPECT_FALSE(cookie1->secure); |
| 96 EXPECT_FALSE(cookie1->http_only); | 95 EXPECT_FALSE(cookie1->http_only); |
| 97 EXPECT_TRUE(cookie1->session); | 96 EXPECT_TRUE(cookie1->session); |
| 98 EXPECT_FALSE(cookie1->expiration_date.get()); | 97 EXPECT_FALSE(cookie1->expiration_date.get()); |
| 99 EXPECT_EQ("some cookie store", cookie1->store_id); | 98 EXPECT_EQ("some cookie store", cookie1->store_id); |
| 100 | 99 |
| 101 net::CanonicalCookie canonical_cookie2( | 100 net::CanonicalCookie canonical_cookie2( |
| 102 GURL(), "ABC", "DEF", ".foobar.com", "/", | 101 GURL(), "ABC", "DEF", ".foobar.com", "/", base::Time(), |
| 103 base::Time(), base::Time::FromDoubleT(10000), base::Time(), | 102 base::Time::FromDoubleT(10000), base::Time(), false, false, false, |
| 104 false, false, net::COOKIE_PRIORITY_DEFAULT); | 103 net::COOKIE_PRIORITY_DEFAULT); |
| 105 scoped_ptr<Cookie> cookie2( | 104 scoped_ptr<Cookie> cookie2( |
| 106 cookies_helpers::CreateCookie( | 105 cookies_helpers::CreateCookie( |
| 107 canonical_cookie2, "some cookie store")); | 106 canonical_cookie2, "some cookie store")); |
| 108 EXPECT_FALSE(cookie2->host_only); | 107 EXPECT_FALSE(cookie2->host_only); |
| 109 EXPECT_FALSE(cookie2->session); | 108 EXPECT_FALSE(cookie2->session); |
| 110 ASSERT_TRUE(cookie2->expiration_date.get()); | 109 ASSERT_TRUE(cookie2->expiration_date.get()); |
| 111 EXPECT_EQ(10000, *cookie2->expiration_date); | 110 EXPECT_EQ(10000, *cookie2->expiration_date); |
| 112 | 111 |
| 113 TestingProfile profile; | 112 TestingProfile profile; |
| 114 base::ListValue* tab_ids_list = new base::ListValue(); | 113 base::ListValue* tab_ids_list = new base::ListValue(); |
| 115 std::vector<int> tab_ids; | 114 std::vector<int> tab_ids; |
| 116 scoped_ptr<CookieStore> cookie_store( | 115 scoped_ptr<CookieStore> cookie_store( |
| 117 cookies_helpers::CreateCookieStore(&profile, tab_ids_list)); | 116 cookies_helpers::CreateCookieStore(&profile, tab_ids_list)); |
| 118 EXPECT_EQ("0", cookie_store->id); | 117 EXPECT_EQ("0", cookie_store->id); |
| 119 EXPECT_EQ(tab_ids, cookie_store->tab_ids); | 118 EXPECT_EQ(tab_ids, cookie_store->tab_ids); |
| 120 } | 119 } |
| 121 | 120 |
| 122 TEST_F(ExtensionCookiesTest, GetURLFromCanonicalCookie) { | 121 TEST_F(ExtensionCookiesTest, GetURLFromCanonicalCookie) { |
| 123 net::CanonicalCookie cookie1( | 122 net::CanonicalCookie cookie1(GURL(), "ABC", "DEF", "www.foobar.com", "/", |
| 124 GURL(), "ABC", "DEF", "www.foobar.com", "/", base::Time(), base::Time(), | 123 base::Time(), base::Time(), base::Time(), false, |
| 125 base::Time(), false, false, net::COOKIE_PRIORITY_DEFAULT); | 124 false, false, net::COOKIE_PRIORITY_DEFAULT); |
| 126 EXPECT_EQ("http://www.foobar.com/", | 125 EXPECT_EQ("http://www.foobar.com/", |
| 127 cookies_helpers::GetURLFromCanonicalCookie( | 126 cookies_helpers::GetURLFromCanonicalCookie( |
| 128 cookie1).spec()); | 127 cookie1).spec()); |
| 129 | 128 |
| 130 net::CanonicalCookie cookie2( | 129 net::CanonicalCookie cookie2(GURL(), "ABC", "DEF", ".helloworld.com", "/", |
| 131 GURL(), "ABC", "DEF", ".helloworld.com", "/", base::Time(), base::Time(), | 130 base::Time(), base::Time(), base::Time(), true, |
| 132 base::Time(), true, false, net::COOKIE_PRIORITY_DEFAULT); | 131 false, false, net::COOKIE_PRIORITY_DEFAULT); |
| 133 EXPECT_EQ("https://helloworld.com/", | 132 EXPECT_EQ("https://helloworld.com/", |
| 134 cookies_helpers::GetURLFromCanonicalCookie( | 133 cookies_helpers::GetURLFromCanonicalCookie( |
| 135 cookie2).spec()); | 134 cookie2).spec()); |
| 136 } | 135 } |
| 137 | 136 |
| 138 TEST_F(ExtensionCookiesTest, EmptyDictionary) { | 137 TEST_F(ExtensionCookiesTest, EmptyDictionary) { |
| 139 base::DictionaryValue dict; | 138 base::DictionaryValue dict; |
| 140 GetAll::Params::Details details; | 139 GetAll::Params::Details details; |
| 141 bool rv = GetAll::Params::Details::Populate(dict, &details); | 140 bool rv = GetAll::Params::Details::Populate(dict, &details); |
| 142 ASSERT_TRUE(rv); | 141 ASSERT_TRUE(rv); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 158 | 157 |
| 159 for (size_t i = 0; i < arraysize(tests); ++i) { | 158 for (size_t i = 0; i < arraysize(tests); ++i) { |
| 160 // Build up the Params struct. | 159 // Build up the Params struct. |
| 161 base::ListValue args; | 160 base::ListValue args; |
| 162 base::DictionaryValue* dict = new base::DictionaryValue(); | 161 base::DictionaryValue* dict = new base::DictionaryValue(); |
| 163 dict->SetString(keys::kDomainKey, std::string(tests[i].filter)); | 162 dict->SetString(keys::kDomainKey, std::string(tests[i].filter)); |
| 164 args.Set(0, dict); | 163 args.Set(0, dict); |
| 165 scoped_ptr<GetAll::Params> params(GetAll::Params::Create(args)); | 164 scoped_ptr<GetAll::Params> params(GetAll::Params::Create(args)); |
| 166 | 165 |
| 167 cookies_helpers::MatchFilter filter(¶ms->details); | 166 cookies_helpers::MatchFilter filter(¶ms->details); |
| 168 net::CanonicalCookie cookie(GURL(), | 167 net::CanonicalCookie cookie(GURL(), std::string(), std::string(), |
| 169 std::string(), | 168 tests[i].domain, std::string(), base::Time(), |
| 170 std::string(), | 169 base::Time(), base::Time(), false, false, false, |
| 171 tests[i].domain, | |
| 172 std::string(), | |
| 173 base::Time(), | |
| 174 base::Time(), | |
| 175 base::Time(), | |
| 176 false, | |
| 177 false, | |
| 178 net::COOKIE_PRIORITY_DEFAULT); | 170 net::COOKIE_PRIORITY_DEFAULT); |
| 179 EXPECT_EQ(tests[i].matches, filter.MatchesCookie(cookie)); | 171 EXPECT_EQ(tests[i].matches, filter.MatchesCookie(cookie)); |
| 180 } | 172 } |
| 181 } | 173 } |
| 182 | 174 |
| 183 TEST_F(ExtensionCookiesTest, DecodeUTF8WithErrorHandling) { | 175 TEST_F(ExtensionCookiesTest, DecodeUTF8WithErrorHandling) { |
| 184 net::CanonicalCookie canonical_cookie(GURL(), | 176 net::CanonicalCookie canonical_cookie( |
| 185 std::string(), | 177 GURL(), std::string(), "011Q255bNX_1!yd\203e+", "test.com", "/path\203", |
| 186 "011Q255bNX_1!yd\203e+", | 178 base::Time(), base::Time(), base::Time(), false, false, false, |
| 187 "test.com", | 179 net::COOKIE_PRIORITY_DEFAULT); |
| 188 "/path\203", | |
| 189 base::Time(), | |
| 190 base::Time(), | |
| 191 base::Time(), | |
| 192 false, | |
| 193 false, | |
| 194 net::COOKIE_PRIORITY_DEFAULT); | |
| 195 scoped_ptr<Cookie> cookie( | 180 scoped_ptr<Cookie> cookie( |
| 196 cookies_helpers::CreateCookie( | 181 cookies_helpers::CreateCookie( |
| 197 canonical_cookie, "some cookie store")); | 182 canonical_cookie, "some cookie store")); |
| 198 EXPECT_EQ(std::string("011Q255bNX_1!yd\xEF\xBF\xBD" "e+"), cookie->value); | 183 EXPECT_EQ(std::string("011Q255bNX_1!yd\xEF\xBF\xBD" "e+"), cookie->value); |
| 199 EXPECT_EQ(std::string(), cookie->path); | 184 EXPECT_EQ(std::string(), cookie->path); |
| 200 } | 185 } |
| 201 | 186 |
| 202 } // namespace extensions | 187 } // namespace extensions |
| OLD | NEW |