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