| 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 1984 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2010 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") | 2011 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") |
| 2011 == std::string::npos); | 2012 == std::string::npos); |
| 2012 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") | 2013 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") |
| 2013 != std::string::npos); | 2014 != std::string::npos); |
| 2014 | 2015 |
| 2015 EXPECT_EQ(0, d.blocked_get_cookies_count()); | 2016 EXPECT_EQ(0, d.blocked_get_cookies_count()); |
| 2016 EXPECT_EQ(0, d.blocked_set_cookie_count()); | 2017 EXPECT_EQ(0, d.blocked_set_cookie_count()); |
| 2017 } | 2018 } |
| 2018 } | 2019 } |
| 2019 | 2020 |
| 2021 void CheckCookiePolicyCallback(bool* was_run, const CookieList& cookies) { |
| 2022 EXPECT_EQ(1U, cookies.size()); |
| 2023 EXPECT_FALSE(cookies[0].IsPersistent()); |
| 2024 *was_run = true; |
| 2025 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask()); |
| 2026 } |
| 2027 |
| 2020 TEST_F(URLRequestTest, CookiePolicy_ForceSession) { | 2028 TEST_F(URLRequestTest, CookiePolicy_ForceSession) { |
| 2021 TestServer test_server(TestServer::TYPE_HTTP, FilePath()); | 2029 TestServer test_server(TestServer::TYPE_HTTP, FilePath()); |
| 2022 ASSERT_TRUE(test_server.Start()); | 2030 ASSERT_TRUE(test_server.Start()); |
| 2023 | 2031 |
| 2024 // Set up a cookie. | 2032 // Set up a cookie. |
| 2025 { | 2033 { |
| 2026 TestDelegate d; | 2034 TestDelegate d; |
| 2027 d.set_cookie_options(TestDelegate::FORCE_SESSION); | 2035 d.set_cookie_options(TestDelegate::FORCE_SESSION); |
| 2028 URLRequest req(test_server.GetURL( | 2036 URLRequest req(test_server.GetURL( |
| 2029 "set-cookie?A=1;expires=\"Fri, 05 Feb 2010 23:42:01 GMT\""), &d); | 2037 "set-cookie?A=1;expires=\"Fri, 05 Feb 2010 23:42:01 GMT\""), &d); |
| 2030 req.set_context(default_context_); | 2038 req.set_context(default_context_); |
| 2031 req.Start(); // Triggers an asynchronous cookie policy check. | 2039 req.Start(); // Triggers an asynchronous cookie policy check. |
| 2032 | 2040 |
| 2033 MessageLoop::current()->Run(); | 2041 MessageLoop::current()->Run(); |
| 2034 | 2042 |
| 2035 EXPECT_EQ(0, d.blocked_get_cookies_count()); | 2043 EXPECT_EQ(0, d.blocked_get_cookies_count()); |
| 2036 EXPECT_EQ(0, d.blocked_set_cookie_count()); | 2044 EXPECT_EQ(0, d.blocked_set_cookie_count()); |
| 2037 } | 2045 } |
| 2038 | 2046 |
| 2039 // Now, check the cookie store. | 2047 // Now, check the cookie store. |
| 2040 CookieList cookies = | 2048 bool was_run = false; |
| 2041 default_context_->cookie_store()->GetCookieMonster()->GetAllCookies(); | 2049 default_context_->cookie_store()->GetCookieMonster()->GetAllCookiesAsync( |
| 2042 EXPECT_EQ(1U, cookies.size()); | 2050 base::Bind(&CheckCookiePolicyCallback, &was_run)); |
| 2043 EXPECT_FALSE(cookies[0].IsPersistent()); | 2051 MessageLoop::current()->RunAllPending(); |
| 2052 DCHECK(was_run); |
| 2044 } | 2053 } |
| 2045 | 2054 |
| 2046 // In this test, we do a POST which the server will 302 redirect. | 2055 // In this test, we do a POST which the server will 302 redirect. |
| 2047 // The subsequent transaction should use GET, and should not send the | 2056 // The subsequent transaction should use GET, and should not send the |
| 2048 // Content-Type header. | 2057 // Content-Type header. |
| 2049 // http://code.google.com/p/chromium/issues/detail?id=843 | 2058 // http://code.google.com/p/chromium/issues/detail?id=843 |
| 2050 TEST_F(URLRequestTestHTTP, Post302RedirectGet) { | 2059 TEST_F(URLRequestTestHTTP, Post302RedirectGet) { |
| 2051 ASSERT_TRUE(test_server_.Start()); | 2060 ASSERT_TRUE(test_server_.Start()); |
| 2052 | 2061 |
| 2053 const char kData[] = "hello world"; | 2062 const char kData[] = "hello world"; |
| (...skipping 1114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3168 req.SetExtraRequestHeaders(headers); | 3177 req.SetExtraRequestHeaders(headers); |
| 3169 req.Start(); | 3178 req.Start(); |
| 3170 MessageLoop::current()->Run(); | 3179 MessageLoop::current()->Run(); |
| 3171 // If the net tests are being run with ChromeFrame then we need to allow for | 3180 // If the net tests are being run with ChromeFrame then we need to allow for |
| 3172 // the 'chromeframe' suffix which is added to the user agent before the | 3181 // the 'chromeframe' suffix which is added to the user agent before the |
| 3173 // closing parentheses. | 3182 // closing parentheses. |
| 3174 EXPECT_TRUE(StartsWithASCII(d.data_received(), "Lynx (textmode", true)); | 3183 EXPECT_TRUE(StartsWithASCII(d.data_received(), "Lynx (textmode", true)); |
| 3175 } | 3184 } |
| 3176 | 3185 |
| 3177 } // namespace net | 3186 } // namespace net |
| OLD | NEW |