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 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "net/cookies/cookie_util.h" | 10 #include "net/cookies/cookie_util.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 TEST(CookieUtilTest, TestDomainIsHostOnly) { | 48 TEST(CookieUtilTest, TestDomainIsHostOnly) { |
49 const struct { | 49 const struct { |
50 const char* str; | 50 const char* str; |
51 const bool is_host_only; | 51 const bool is_host_only; |
52 } tests[] = { | 52 } tests[] = { |
53 { "", true }, | 53 { "", true }, |
54 { "www.google.com", true }, | 54 { "www.google.com", true }, |
55 { ".google.com", false } | 55 { ".google.com", false } |
56 }; | 56 }; |
57 | 57 |
58 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 58 for (size_t i = 0; i < arraysize(tests); ++i) { |
59 EXPECT_EQ(tests[i].is_host_only, | 59 EXPECT_EQ(tests[i].is_host_only, |
60 net::cookie_util::DomainIsHostOnly(tests[i].str)); | 60 net::cookie_util::DomainIsHostOnly(tests[i].str)); |
61 } | 61 } |
62 } | 62 } |
63 | 63 |
64 TEST(CookieUtilTest, TestCookieDateParsing) { | 64 TEST(CookieUtilTest, TestCookieDateParsing) { |
65 const struct { | 65 const struct { |
66 const char* str; | 66 const char* str; |
67 const bool valid; | 67 const bool valid; |
68 const time_t epoch; | 68 const time_t epoch; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 { "98 April 17 21:01:22", false, 0 }, | 131 { "98 April 17 21:01:22", false, 0 }, |
132 { "Thu, 012-Aug-2008 20:49:07 GMT", false, 0 }, | 132 { "Thu, 012-Aug-2008 20:49:07 GMT", false, 0 }, |
133 { "Thu, 12-Aug-31841 20:49:07 GMT", false, 0 }, | 133 { "Thu, 12-Aug-31841 20:49:07 GMT", false, 0 }, |
134 { "Thu, 12-Aug-9999999999 20:49:07 GMT", false, 0 }, | 134 { "Thu, 12-Aug-9999999999 20:49:07 GMT", false, 0 }, |
135 { "Thu, 999999999999-Aug-2007 20:49:07 GMT", false, 0 }, | 135 { "Thu, 999999999999-Aug-2007 20:49:07 GMT", false, 0 }, |
136 { "Thu, 12-Aug-2007 20:61:99999999999 GMT", false, 0 }, | 136 { "Thu, 12-Aug-2007 20:61:99999999999 GMT", false, 0 }, |
137 { "IAintNoDateFool", false, 0 }, | 137 { "IAintNoDateFool", false, 0 }, |
138 }; | 138 }; |
139 | 139 |
140 base::Time parsed_time; | 140 base::Time parsed_time; |
141 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 141 for (size_t i = 0; i < arraysize(tests); ++i) { |
142 parsed_time = net::cookie_util::ParseCookieTime(tests[i].str); | 142 parsed_time = net::cookie_util::ParseCookieTime(tests[i].str); |
143 if (!tests[i].valid) { | 143 if (!tests[i].valid) { |
144 EXPECT_FALSE(!parsed_time.is_null()) << tests[i].str; | 144 EXPECT_FALSE(!parsed_time.is_null()) << tests[i].str; |
145 continue; | 145 continue; |
146 } | 146 } |
147 EXPECT_TRUE(!parsed_time.is_null()) << tests[i].str; | 147 EXPECT_TRUE(!parsed_time.is_null()) << tests[i].str; |
148 EXPECT_EQ(tests[i].epoch, parsed_time.ToTimeT()) << tests[i].str; | 148 EXPECT_EQ(tests[i].epoch, parsed_time.ToTimeT()) << tests[i].str; |
149 } | 149 } |
150 } | 150 } |
151 | 151 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 std::string("\"abcdef\""))); | 187 std::string("\"abcdef\""))); |
188 tests.back().parsed.push_back(std::make_pair(std::string("otherkey"), | 188 tests.back().parsed.push_back(std::make_pair(std::string("otherkey"), |
189 std::string("1234"))); | 189 std::string("1234"))); |
190 | 190 |
191 for (size_t i = 0; i < tests.size(); i++) { | 191 for (size_t i = 0; i < tests.size(); i++) { |
192 SCOPED_TRACE(testing::Message() << "Test " << i); | 192 SCOPED_TRACE(testing::Message() << "Test " << i); |
193 CheckParse(tests[i].str, tests[i].parsed); | 193 CheckParse(tests[i].str, tests[i].parsed); |
194 CheckSerialize(tests[i].parsed, tests[i].str); | 194 CheckSerialize(tests[i].parsed, tests[i].str); |
195 } | 195 } |
196 } | 196 } |
OLD | NEW |