Chromium Code Reviews| 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/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 Loading... | |
| 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 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 } |
| 197 | |
| 198 class CookieUtilDomainTest : public testing::Test { | |
| 199 protected: | |
| 200 void TearDown() override { | |
| 201 net::registry_controlled_domains::SetFindDomainGraph(); | |
| 202 } | |
| 203 }; | |
| 204 | |
| 205 TEST_F(CookieUtilDomainTest, TestGetEffectiveDomain) { | |
| 206 net::test::registry_controlled_domains::SetFindDomainTestGraph(); | |
|
Adam Rice
2015/01/19 05:18:56
This should go in CookieUtilDomainTest::SetUp() fo
yhirano
2015/01/19 05:56:21
Done.
| |
| 207 // Note: registry_controlled_domains::GetDomainAndRegistry is tested in its | |
| 208 // unittests. | |
| 209 | |
| 210 EXPECT_EQ("", net::cookie_util::GetEffectiveDomain("http", "ac.jp")); | |
| 211 EXPECT_EQ("", net::cookie_util::GetEffectiveDomain("http", "ac.jp")); | |
| 212 EXPECT_EQ("", net::cookie_util::GetEffectiveDomain("https", "ac.jp")); | |
| 213 EXPECT_EQ("", net::cookie_util::GetEffectiveDomain("ws", "ac.jp")); | |
| 214 EXPECT_EQ("", net::cookie_util::GetEffectiveDomain("wss", "ac.jp")); | |
| 215 EXPECT_EQ("ac.jp", net::cookie_util::GetEffectiveDomain("foo", "ac.jp")); | |
|
Adam Rice
2015/01/19 05:18:56
Suggestion: use "ftp" instead of "foo" here. I thi
yhirano
2015/01/19 05:56:21
Done.
| |
| 216 } | |
| 217 | |
| 218 } // namespace | |
| OLD | NEW |