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

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

Issue 859663003: GetEffectiveDomain should handle ws scheme as same as http scheme. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 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
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> 7 #include <vector>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
11 #include "net/base/registry_controlled_domains/test_util.h"
10 #include "net/cookies/cookie_util.h" 12 #include "net/cookies/cookie_util.h"
11 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
12 14
13 namespace { 15 namespace {
14 16
15 struct RequestCookieParsingTest { 17 struct RequestCookieParsingTest {
16 std::string str; 18 std::string str;
17 std::vector<std::pair<std::string, std::string> > parsed; 19 std::vector<std::pair<std::string, std::string> > parsed;
18 }; 20 };
19 21
(...skipping 16 matching lines...) Expand all
36 } 38 }
37 39
38 void CheckSerialize( 40 void CheckSerialize(
39 const std::vector<std::pair<std::string, std::string> >& parsed, 41 const std::vector<std::pair<std::string, std::string> >& parsed,
40 const std::string& str_expected) { 42 const std::string& str_expected) {
41 net::cookie_util::ParsedRequestCookies prc = 43 net::cookie_util::ParsedRequestCookies prc =
42 MakeParsedRequestCookies(parsed); 44 MakeParsedRequestCookies(parsed);
43 EXPECT_EQ(str_expected, net::cookie_util::SerializeRequestCookieLine(prc)); 45 EXPECT_EQ(str_expected, net::cookie_util::SerializeRequestCookieLine(prc));
44 } 46 }
45 47
46 } // namespace
47
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
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 }
197
198 class CookieUtilDomainTest : public testing::Test {
199 protected:
200 void SetUp() override {
201 net::test::registry_controlled_domains::SetFindDomainTestGraph();
202 }
203
204 void TearDown() override {
205 net::registry_controlled_domains::SetFindDomainGraph();
206 }
207 };
208
209 TEST_F(CookieUtilDomainTest, TestGetEffectiveDomain) {
210 // Note: registry_controlled_domains::GetDomainAndRegistry is tested in its
211 // unittests.
Adam Rice 2015/01/19 06:05:57 Nit: It would be clearer to add the word "own", ie
yhirano 2015/01/19 06:11:53 Done.
212 EXPECT_EQ("", net::cookie_util::GetEffectiveDomain("http", "ac.jp"));
213 EXPECT_EQ("", net::cookie_util::GetEffectiveDomain("http", "ac.jp"));
214 EXPECT_EQ("", net::cookie_util::GetEffectiveDomain("https", "ac.jp"));
215 EXPECT_EQ("", net::cookie_util::GetEffectiveDomain("ws", "ac.jp"));
216 EXPECT_EQ("", net::cookie_util::GetEffectiveDomain("wss", "ac.jp"));
217 EXPECT_EQ("ac.jp", net::cookie_util::GetEffectiveDomain("ftp", "ac.jp"));
218 }
219
220 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698