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 <string> | 5 #include <string> |
6 #include <utility> | 6 #include <utility> |
7 | 7 |
8 #include "base/strings/string_split.h" | 8 #include "base/strings/string_split.h" |
9 #include "net/cookies/cookie_util.h" | 9 #include "net/cookies/cookie_util.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 // incapable of doing this, however the expectation is for cookie parsing to | 151 // incapable of doing this, however the expectation is for cookie parsing to |
152 // succeed anyway (and return the minimum value Time::FromUTCExploded() can | 152 // succeed anyway (and return the minimum value Time::FromUTCExploded() can |
153 // parse on the current platform). Also checks a date outside the limit on | 153 // parse on the current platform). Also checks a date outside the limit on |
154 // Windows, which is year 30827. | 154 // Windows, which is year 30827. |
155 TEST(CookieUtilTest, ParseCookieExpirationTimeBeyond2038) { | 155 TEST(CookieUtilTest, ParseCookieExpirationTimeBeyond2038) { |
156 const char* kTests[] = { | 156 const char* kTests[] = { |
157 "Thu, 12-Aug-31841 20:49:07 GMT", "2039 April 15 21:01:22", | 157 "Thu, 12-Aug-31841 20:49:07 GMT", "2039 April 15 21:01:22", |
158 "2039 April 15 21:01:22", "2038 April 15 21:01:22", | 158 "2039 April 15 21:01:22", "2038 April 15 21:01:22", |
159 }; | 159 }; |
160 | 160 |
161 for (const auto& test : kTests) { | 161 for (auto* test : kTests) { |
162 base::Time parsed_time = cookie_util::ParseCookieExpirationTime(test); | 162 base::Time parsed_time = cookie_util::ParseCookieExpirationTime(test); |
163 EXPECT_FALSE(parsed_time.is_null()); | 163 EXPECT_FALSE(parsed_time.is_null()); |
164 | 164 |
165 // It should either have an exact value, or be base::Time::Max(). For | 165 // It should either have an exact value, or be base::Time::Max(). For |
166 // simplicity just check that it is greater than an arbitray date. | 166 // simplicity just check that it is greater than an arbitray date. |
167 base::Time almost_jan_2038 = | 167 base::Time almost_jan_2038 = |
168 base::Time::UnixEpoch() + base::TimeDelta::FromDays(365 * 68); | 168 base::Time::UnixEpoch() + base::TimeDelta::FromDays(365 * 68); |
169 EXPECT_LT(almost_jan_2038, parsed_time); | 169 EXPECT_LT(almost_jan_2038, parsed_time); |
170 } | 170 } |
171 } | 171 } |
172 | 172 |
173 // Tests parsing dates that are prior to (or around) 1970. Non-Mac POSIX systems | 173 // Tests parsing dates that are prior to (or around) 1970. Non-Mac POSIX systems |
174 // are incapable of doing this, however the expectation is for cookie parsing to | 174 // are incapable of doing this, however the expectation is for cookie parsing to |
175 // succeed anyway (and return a minimal base::Time). | 175 // succeed anyway (and return a minimal base::Time). |
176 TEST(CookieUtilTest, ParseCookieExpirationTimeBefore1970) { | 176 TEST(CookieUtilTest, ParseCookieExpirationTimeBefore1970) { |
177 const char* kTests[] = { | 177 const char* kTests[] = { |
178 // The unix epoch. | 178 // The unix epoch. |
179 "1970 Jan 1 00:00:00", | 179 "1970 Jan 1 00:00:00", |
180 // The windows epoch. | 180 // The windows epoch. |
181 "1601 Jan 1 00:00:00", | 181 "1601 Jan 1 00:00:00", |
182 // Other dates. | 182 // Other dates. |
183 "1969 March 3 21:01:22", "1600 April 15 21:01:22", | 183 "1969 March 3 21:01:22", "1600 April 15 21:01:22", |
184 }; | 184 }; |
185 | 185 |
186 for (const auto& test : kTests) { | 186 for (auto* test : kTests) { |
187 base::Time parsed_time = cookie_util::ParseCookieExpirationTime(test); | 187 base::Time parsed_time = cookie_util::ParseCookieExpirationTime(test); |
188 EXPECT_FALSE(parsed_time.is_null()); | 188 EXPECT_FALSE(parsed_time.is_null()); |
189 | 189 |
190 // It should either have an exact value, or should be base::Time(1) | 190 // It should either have an exact value, or should be base::Time(1) |
191 // For simplicity just check that it is less than the unix epoch. | 191 // For simplicity just check that it is less than the unix epoch. |
192 EXPECT_LE(parsed_time, base::Time::UnixEpoch()); | 192 EXPECT_LE(parsed_time, base::Time::UnixEpoch()); |
193 } | 193 } |
194 } | 194 } |
195 | 195 |
196 TEST(CookieUtilTest, TestRequestCookieParsing) { | 196 TEST(CookieUtilTest, TestRequestCookieParsing) { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 cookie_util::GetEffectiveDomain("ws", "www.example.com")); | 250 cookie_util::GetEffectiveDomain("ws", "www.example.com")); |
251 EXPECT_EQ("example.com", | 251 EXPECT_EQ("example.com", |
252 cookie_util::GetEffectiveDomain("wss", "www.example.com")); | 252 cookie_util::GetEffectiveDomain("wss", "www.example.com")); |
253 EXPECT_EQ("www.example.com", | 253 EXPECT_EQ("www.example.com", |
254 cookie_util::GetEffectiveDomain("ftp", "www.example.com")); | 254 cookie_util::GetEffectiveDomain("ftp", "www.example.com")); |
255 } | 255 } |
256 | 256 |
257 } // namespace | 257 } // namespace |
258 | 258 |
259 } // namespace net | 259 } // namespace net |
OLD | NEW |