| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "build/build_config.h" | 5 #include "build/build_config.h" |
| 6 | 6 |
| 7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
| 8 #include <shlobj.h> | 8 #include <shlobj.h> |
| 9 #include <windows.h> | 9 #include <windows.h> |
| 10 #endif | 10 #endif |
| 11 | 11 |
| 12 #include <algorithm> | 12 #include <algorithm> |
| 13 #include <string> | 13 #include <string> |
| 14 | 14 |
| 15 #include "base/basictypes.h" | 15 #include "base/basictypes.h" |
| 16 #include "base/bind.h" |
| 16 #include "base/compiler_specific.h" | 17 #include "base/compiler_specific.h" |
| 17 #include "base/file_util.h" | 18 #include "base/file_util.h" |
| 18 #include "base/format_macros.h" | 19 #include "base/format_macros.h" |
| 19 #include "base/message_loop.h" | 20 #include "base/message_loop.h" |
| 20 #include "base/path_service.h" | 21 #include "base/path_service.h" |
| 21 #include "base/process_util.h" | 22 #include "base/process_util.h" |
| 22 #include "base/string_number_conversions.h" | 23 #include "base/string_number_conversions.h" |
| 23 #include "base/string_piece.h" | 24 #include "base/string_piece.h" |
| 24 #include "base/string_util.h" | 25 #include "base/string_util.h" |
| 25 #include "base/stringprintf.h" | 26 #include "base/stringprintf.h" |
| (...skipping 1949 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1975 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") | 1976 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") |
| 1976 == std::string::npos); | 1977 == std::string::npos); |
| 1977 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") | 1978 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") |
| 1978 != std::string::npos); | 1979 != std::string::npos); |
| 1979 | 1980 |
| 1980 EXPECT_EQ(0, d.blocked_get_cookies_count()); | 1981 EXPECT_EQ(0, d.blocked_get_cookies_count()); |
| 1981 EXPECT_EQ(0, d.blocked_set_cookie_count()); | 1982 EXPECT_EQ(0, d.blocked_set_cookie_count()); |
| 1982 } | 1983 } |
| 1983 } | 1984 } |
| 1984 | 1985 |
| 1986 void CheckCookiePolicyCallback(bool* was_run, const CookieList& cookies) { |
| 1987 EXPECT_EQ(1U, cookies.size()); |
| 1988 EXPECT_FALSE(cookies[0].IsPersistent()); |
| 1989 *was_run = true; |
| 1990 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask()); |
| 1991 } |
| 1992 |
| 1985 TEST_F(URLRequestTest, CookiePolicy_ForceSession) { | 1993 TEST_F(URLRequestTest, CookiePolicy_ForceSession) { |
| 1986 TestServer test_server(TestServer::TYPE_HTTP, FilePath()); | 1994 TestServer test_server(TestServer::TYPE_HTTP, FilePath()); |
| 1987 ASSERT_TRUE(test_server.Start()); | 1995 ASSERT_TRUE(test_server.Start()); |
| 1988 | 1996 |
| 1989 // Set up a cookie. | 1997 // Set up a cookie. |
| 1990 { | 1998 { |
| 1991 TestDelegate d; | 1999 TestDelegate d; |
| 1992 d.set_cookie_options(TestDelegate::FORCE_SESSION); | 2000 d.set_cookie_options(TestDelegate::FORCE_SESSION); |
| 1993 URLRequest req(test_server.GetURL( | 2001 URLRequest req(test_server.GetURL( |
| 1994 "set-cookie?A=1;expires=\"Fri, 05 Feb 2010 23:42:01 GMT\""), &d); | 2002 "set-cookie?A=1;expires=\"Fri, 05 Feb 2010 23:42:01 GMT\""), &d); |
| 1995 req.set_context(default_context_); | 2003 req.set_context(default_context_); |
| 1996 req.Start(); // Triggers an asynchronous cookie policy check. | 2004 req.Start(); // Triggers an asynchronous cookie policy check. |
| 1997 | 2005 |
| 1998 MessageLoop::current()->Run(); | 2006 MessageLoop::current()->Run(); |
| 1999 | 2007 |
| 2000 EXPECT_EQ(0, d.blocked_get_cookies_count()); | 2008 EXPECT_EQ(0, d.blocked_get_cookies_count()); |
| 2001 EXPECT_EQ(0, d.blocked_set_cookie_count()); | 2009 EXPECT_EQ(0, d.blocked_set_cookie_count()); |
| 2002 } | 2010 } |
| 2003 | 2011 |
| 2004 // Now, check the cookie store. | 2012 // Now, check the cookie store. |
| 2005 CookieList cookies = | 2013 bool was_run = false; |
| 2006 default_context_->cookie_store()->GetCookieMonster()->GetAllCookies(); | 2014 default_context_->cookie_store()->GetCookieMonster()->GetAllCookiesAsync( |
| 2007 EXPECT_EQ(1U, cookies.size()); | 2015 base::Bind(&CheckCookiePolicyCallback, &was_run)); |
| 2008 EXPECT_FALSE(cookies[0].IsPersistent()); | 2016 MessageLoop::current()->RunAllPending(); |
| 2017 DCHECK(was_run); |
| 2009 } | 2018 } |
| 2010 | 2019 |
| 2011 // In this test, we do a POST which the server will 302 redirect. | 2020 // In this test, we do a POST which the server will 302 redirect. |
| 2012 // The subsequent transaction should use GET, and should not send the | 2021 // The subsequent transaction should use GET, and should not send the |
| 2013 // Content-Type header. | 2022 // Content-Type header. |
| 2014 // http://code.google.com/p/chromium/issues/detail?id=843 | 2023 // http://code.google.com/p/chromium/issues/detail?id=843 |
| 2015 TEST_F(URLRequestTestHTTP, Post302RedirectGet) { | 2024 TEST_F(URLRequestTestHTTP, Post302RedirectGet) { |
| 2016 ASSERT_TRUE(test_server_.Start()); | 2025 ASSERT_TRUE(test_server_.Start()); |
| 2017 | 2026 |
| 2018 const char kData[] = "hello world"; | 2027 const char kData[] = "hello world"; |
| (...skipping 1114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3133 req.SetExtraRequestHeaders(headers); | 3142 req.SetExtraRequestHeaders(headers); |
| 3134 req.Start(); | 3143 req.Start(); |
| 3135 MessageLoop::current()->Run(); | 3144 MessageLoop::current()->Run(); |
| 3136 // If the net tests are being run with ChromeFrame then we need to allow for | 3145 // If the net tests are being run with ChromeFrame then we need to allow for |
| 3137 // the 'chromeframe' suffix which is added to the user agent before the | 3146 // the 'chromeframe' suffix which is added to the user agent before the |
| 3138 // closing parentheses. | 3147 // closing parentheses. |
| 3139 EXPECT_TRUE(StartsWithASCII(d.data_received(), "Lynx (textmode", true)); | 3148 EXPECT_TRUE(StartsWithASCII(d.data_received(), "Lynx (textmode", true)); |
| 3140 } | 3149 } |
| 3141 | 3150 |
| 3142 } // namespace net | 3151 } // namespace net |
| OLD | NEW |