Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(172)

Side by Side Diff: net/cookies/cookie_util_unittest.cc

Issue 1092923006: Use of base::StringPairs appropriately in cookies (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: updated for try bot error Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698