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> | |
8 | 7 |
9 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/strings/string_split.h" |
10 #include "net/cookies/cookie_util.h" | 10 #include "net/cookies/cookie_util.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
12 | 12 |
13 namespace net { | 13 namespace net { |
14 | 14 |
15 namespace { | 15 namespace { |
16 | 16 |
17 struct RequestCookieParsingTest { | 17 struct RequestCookieParsingTest { |
18 std::string str; | 18 std::string str; |
19 std::vector<std::pair<std::string, std::string> > parsed; | 19 base::StringPairs parsed; |
20 }; | 20 }; |
21 | 21 |
22 cookie_util::ParsedRequestCookies MakeParsedRequestCookies( | 22 cookie_util::ParsedRequestCookies MakeParsedRequestCookies( |
23 const std::vector<std::pair<std::string, std::string>>& data) { | 23 const base::StringPairs& data) { |
24 cookie_util::ParsedRequestCookies parsed; | 24 cookie_util::ParsedRequestCookies parsed; |
25 for (size_t i = 0; i < data.size(); i++) { | 25 for (size_t i = 0; i < data.size(); i++) { |
26 parsed.push_back(std::make_pair(base::StringPiece(data[i].first), | 26 parsed.push_back(std::make_pair(base::StringPiece(data[i].first), |
27 base::StringPiece(data[i].second))); | 27 base::StringPiece(data[i].second))); |
28 } | 28 } |
29 return parsed; | 29 return parsed; |
30 } | 30 } |
31 | 31 |
32 void CheckParse( | 32 void CheckParse(const std::string& str, |
33 const std::string& str, | 33 const base::StringPairs& parsed_expected) { |
34 const std::vector<std::pair<std::string, std::string> >& parsed_expected) { | |
35 cookie_util::ParsedRequestCookies parsed; | 34 cookie_util::ParsedRequestCookies parsed; |
36 cookie_util::ParseRequestCookieLine(str, &parsed); | 35 cookie_util::ParseRequestCookieLine(str, &parsed); |
37 EXPECT_EQ(MakeParsedRequestCookies(parsed_expected), parsed); | 36 EXPECT_EQ(MakeParsedRequestCookies(parsed_expected), parsed); |
38 } | 37 } |
39 | 38 |
40 void CheckSerialize( | 39 void CheckSerialize(const base::StringPairs& parsed, |
41 const std::vector<std::pair<std::string, std::string> >& parsed, | 40 const std::string& str_expected) { |
42 const std::string& str_expected) { | |
43 cookie_util::ParsedRequestCookies prc = MakeParsedRequestCookies(parsed); | 41 cookie_util::ParsedRequestCookies prc = MakeParsedRequestCookies(parsed); |
44 EXPECT_EQ(str_expected, cookie_util::SerializeRequestCookieLine(prc)); | 42 EXPECT_EQ(str_expected, cookie_util::SerializeRequestCookieLine(prc)); |
45 } | 43 } |
46 | 44 |
47 TEST(CookieUtilTest, TestDomainIsHostOnly) { | 45 TEST(CookieUtilTest, TestDomainIsHostOnly) { |
48 const struct { | 46 const struct { |
49 const char* str; | 47 const char* str; |
50 const bool is_host_only; | 48 const bool is_host_only; |
51 } tests[] = { | 49 } tests[] = { |
52 { "", true }, | 50 { "", true }, |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 cookie_util::GetEffectiveDomain("ws", "www.example.com")); | 203 cookie_util::GetEffectiveDomain("ws", "www.example.com")); |
206 EXPECT_EQ("example.com", | 204 EXPECT_EQ("example.com", |
207 cookie_util::GetEffectiveDomain("wss", "www.example.com")); | 205 cookie_util::GetEffectiveDomain("wss", "www.example.com")); |
208 EXPECT_EQ("www.example.com", | 206 EXPECT_EQ("www.example.com", |
209 cookie_util::GetEffectiveDomain("ftp", "www.example.com")); | 207 cookie_util::GetEffectiveDomain("ftp", "www.example.com")); |
210 } | 208 } |
211 | 209 |
212 } // namespace | 210 } // namespace |
213 | 211 |
214 } // namespace net | 212 } // namespace net |
OLD | NEW |