OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "net/url_request/url_request_unittest.h" | 5 #include "net/url_request/url_request_unittest.h" |
6 | 6 |
| 7 #include "build/build_config.h" |
| 8 |
7 #if defined(OS_WIN) | 9 #if defined(OS_WIN) |
8 #include <windows.h> | 10 #include <windows.h> |
9 #include <shlobj.h> | 11 #include <shlobj.h> |
| 12 #elif defined(OS_LINUX) |
| 13 #include "base/nss_init.h" |
10 #endif | 14 #endif |
11 | 15 |
12 #include <algorithm> | 16 #include <algorithm> |
13 #include <string> | 17 #include <string> |
14 | 18 |
15 #include "base/message_loop.h" | 19 #include "base/message_loop.h" |
16 #include "base/path_service.h" | 20 #include "base/path_service.h" |
17 #include "base/platform_test.h" | 21 #include "base/platform_test.h" |
18 #include "base/process_util.h" | 22 #include "base/process_util.h" |
19 #include "base/string_piece.h" | 23 #include "base/string_piece.h" |
20 #include "base/string_util.h" | 24 #include "base/string_util.h" |
| 25 #include "base/trace_event.h" |
21 #include "net/base/load_flags.h" | 26 #include "net/base/load_flags.h" |
22 #include "net/base/net_errors.h" | 27 #include "net/base/net_errors.h" |
23 #include "net/base/net_module.h" | 28 #include "net/base/net_module.h" |
24 #include "net/base/net_util.h" | 29 #include "net/base/net_util.h" |
| 30 #include "net/base/ssl_test_util.h" |
25 #include "net/disk_cache/disk_cache.h" | 31 #include "net/disk_cache/disk_cache.h" |
26 #include "net/http/http_cache.h" | 32 #include "net/http/http_cache.h" |
27 #include "net/http/http_network_layer.h" | 33 #include "net/http/http_network_layer.h" |
28 #include "net/url_request/url_request.h" | 34 #include "net/url_request/url_request.h" |
29 #include "testing/gtest/include/gtest/gtest.h" | 35 #include "testing/gtest/include/gtest/gtest.h" |
30 | 36 |
31 using base::Time; | 37 using base::Time; |
32 | 38 |
33 namespace { | 39 namespace { |
34 | 40 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 | 115 |
110 EXPECT_EQ(1, d.response_started_count()); | 116 EXPECT_EQ(1, d.response_started_count()); |
111 EXPECT_FALSE(d.received_data_before_response()); | 117 EXPECT_FALSE(d.received_data_before_response()); |
112 EXPECT_NE(0, d.bytes_received()); | 118 EXPECT_NE(0, d.bytes_received()); |
113 } | 119 } |
114 #ifndef NDEBUG | 120 #ifndef NDEBUG |
115 DCHECK_EQ(url_request_metrics.object_count,0); | 121 DCHECK_EQ(url_request_metrics.object_count,0); |
116 #endif | 122 #endif |
117 } | 123 } |
118 | 124 |
| 125 class HTTPSRequestTest : public testing::Test { |
| 126 protected: |
| 127 SSLTestUtil util_; |
| 128 }; |
| 129 |
| 130 #if defined(OS_MACOSX) |
| 131 // TODO(port): support temporary root cert on mac |
| 132 #define MAYBE_HTTPSGetTest DISABLED_HTTPSGetTest |
| 133 #else |
| 134 #define MAYBE_HTTPSGetTest HTTPSGetTest |
| 135 #endif |
| 136 |
| 137 TEST_F(HTTPSRequestTest, MAYBE_HTTPSGetTest) { |
| 138 base::TraceLog::StartTracing(); |
| 139 HTTPSTestServer https_server(util_.kHostName, util_.kOKHTTPSPort, |
| 140 util_.kDocRoot, util_.GetOKCertPath().ToWStringHa
ck()); |
| 141 |
| 142 EXPECT_TRUE(util_.CheckCATrusted()); |
| 143 TestDelegate d; |
| 144 { |
| 145 TestURLRequest r(https_server.TestServerPage(""), &d); |
| 146 |
| 147 r.Start(); |
| 148 EXPECT_TRUE(r.is_pending()); |
| 149 |
| 150 MessageLoop::current()->Run(); |
| 151 |
| 152 EXPECT_EQ(1, d.response_started_count()); |
| 153 EXPECT_FALSE(d.received_data_before_response()); |
| 154 EXPECT_NE(0, d.bytes_received()); |
| 155 } |
| 156 #ifndef NDEBUG |
| 157 DCHECK_EQ(url_request_metrics.object_count,0); |
| 158 #endif |
| 159 } |
| 160 |
119 TEST_F(URLRequestTest, CancelTest) { | 161 TEST_F(URLRequestTest, CancelTest) { |
120 TestDelegate d; | 162 TestDelegate d; |
121 { | 163 { |
122 TestURLRequest r(GURL("http://www.google.com/"), &d); | 164 TestURLRequest r(GURL("http://www.google.com/"), &d); |
123 | 165 |
124 r.Start(); | 166 r.Start(); |
125 EXPECT_TRUE(r.is_pending()); | 167 EXPECT_TRUE(r.is_pending()); |
126 | 168 |
127 r.Cancel(); | 169 r.Cancel(); |
128 | 170 |
(...skipping 698 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
827 EXPECT_FALSE(ContainsString(data, "Content-Length:")); | 869 EXPECT_FALSE(ContainsString(data, "Content-Length:")); |
828 EXPECT_FALSE(ContainsString(data, "Content-Type:")); | 870 EXPECT_FALSE(ContainsString(data, "Content-Type:")); |
829 EXPECT_FALSE(ContainsString(data, "Origin:")); | 871 EXPECT_FALSE(ContainsString(data, "Origin:")); |
830 | 872 |
831 // These extra request headers should not have been stripped. | 873 // These extra request headers should not have been stripped. |
832 EXPECT_TRUE(ContainsString(data, "Accept:")); | 874 EXPECT_TRUE(ContainsString(data, "Accept:")); |
833 EXPECT_TRUE(ContainsString(data, "Accept-Language:")); | 875 EXPECT_TRUE(ContainsString(data, "Accept-Language:")); |
834 EXPECT_TRUE(ContainsString(data, "Accept-Charset:")); | 876 EXPECT_TRUE(ContainsString(data, "Accept-Charset:")); |
835 } | 877 } |
836 | 878 |
OLD | NEW |