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/compiler_specific.h" |
15 #include "base/file_util.h" | 16 #include "base/file_util.h" |
16 #include "base/format_macros.h" | 17 #include "base/format_macros.h" |
17 #include "base/message_loop.h" | 18 #include "base/message_loop.h" |
18 #include "base/path_service.h" | 19 #include "base/path_service.h" |
19 #include "base/process_util.h" | 20 #include "base/process_util.h" |
20 #include "base/string_number_conversions.h" | 21 #include "base/string_number_conversions.h" |
21 #include "base/string_piece.h" | 22 #include "base/string_piece.h" |
22 #include "base/string_util.h" | 23 #include "base/string_util.h" |
23 #include "base/stringprintf.h" | 24 #include "base/stringprintf.h" |
24 #include "base/utf_string_conversions.h" | 25 #include "base/utf_string_conversions.h" |
(...skipping 18 matching lines...) Expand all Loading... |
43 #include "net/url_request/url_request.h" | 44 #include "net/url_request/url_request.h" |
44 #include "net/url_request/url_request_file_dir_job.h" | 45 #include "net/url_request/url_request_file_dir_job.h" |
45 #include "net/url_request/url_request_http_job.h" | 46 #include "net/url_request/url_request_http_job.h" |
46 #include "net/url_request/url_request_test_job.h" | 47 #include "net/url_request/url_request_test_job.h" |
47 #include "net/url_request/url_request_test_util.h" | 48 #include "net/url_request/url_request_test_util.h" |
48 #include "testing/gtest/include/gtest/gtest.h" | 49 #include "testing/gtest/include/gtest/gtest.h" |
49 #include "testing/platform_test.h" | 50 #include "testing/platform_test.h" |
50 | 51 |
51 using base::Time; | 52 using base::Time; |
52 | 53 |
53 // We don't need a refcount because we are guaranteed the test will not proceed | |
54 // until its task is run. | |
55 namespace net { | |
56 class BlockingNetworkDelegate; | |
57 } // namespace net | |
58 DISABLE_RUNNABLE_METHOD_REFCOUNT(net::BlockingNetworkDelegate); | |
59 | |
60 namespace net { | 54 namespace net { |
61 | 55 |
62 namespace { | 56 namespace { |
63 | 57 |
64 const string16 kChrome(ASCIIToUTF16("chrome")); | 58 const string16 kChrome(ASCIIToUTF16("chrome")); |
65 const string16 kSecret(ASCIIToUTF16("secret")); | 59 const string16 kSecret(ASCIIToUTF16("secret")); |
66 const string16 kUser(ASCIIToUTF16("user")); | 60 const string16 kUser(ASCIIToUTF16("user")); |
67 | 61 |
68 base::StringPiece TestNetResourceProvider(int key) { | 62 base::StringPiece TestNetResourceProvider(int key) { |
69 return "header"; | 63 return "header"; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 ssl_info.connection_status); | 113 ssl_info.connection_status); |
120 EXPECT_NE(0, cipher_suite); | 114 EXPECT_NE(0, cipher_suite); |
121 } | 115 } |
122 | 116 |
123 } // namespace | 117 } // namespace |
124 | 118 |
125 // A network delegate that blocks requests, optionally cancelling or redirecting | 119 // A network delegate that blocks requests, optionally cancelling or redirecting |
126 // them. | 120 // them. |
127 class BlockingNetworkDelegate : public TestNetworkDelegate { | 121 class BlockingNetworkDelegate : public TestNetworkDelegate { |
128 public: | 122 public: |
129 BlockingNetworkDelegate() : callback_retval_(net::OK) {} | 123 BlockingNetworkDelegate() |
| 124 : callback_retval_(net::OK), |
| 125 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {} |
130 | 126 |
131 void set_callback_retval(int retval) { callback_retval_ = retval; } | 127 void set_callback_retval(int retval) { callback_retval_ = retval; } |
132 void set_redirect_url(const GURL& url) { redirect_url_ = url; } | 128 void set_redirect_url(const GURL& url) { redirect_url_ = url; } |
133 | 129 |
134 private: | 130 private: |
135 // TestNetworkDelegate: | 131 // TestNetworkDelegate: |
136 virtual int OnBeforeURLRequest(net::URLRequest* request, | 132 virtual int OnBeforeURLRequest(net::URLRequest* request, |
137 net::CompletionCallback* callback, | 133 net::CompletionCallback* callback, |
138 GURL* new_url) { | 134 GURL* new_url) { |
139 if (redirect_url_ == request->url()) { | 135 if (redirect_url_ == request->url()) { |
140 // We've already seen this request and redirected elsewhere. | 136 // We've already seen this request and redirected elsewhere. |
141 return net::OK; | 137 return net::OK; |
142 } | 138 } |
143 | 139 |
144 TestNetworkDelegate::OnBeforeURLRequest(request, callback, new_url); | 140 TestNetworkDelegate::OnBeforeURLRequest(request, callback, new_url); |
145 | 141 |
146 if (!redirect_url_.is_empty()) | 142 if (!redirect_url_.is_empty()) |
147 *new_url = redirect_url_; | 143 *new_url = redirect_url_; |
148 MessageLoop::current()->PostTask(FROM_HERE, | 144 MessageLoop::current()->PostTask( |
149 NewRunnableMethod(this, &BlockingNetworkDelegate::DoCallback, | 145 FROM_HERE, |
150 callback)); | 146 method_factory_.NewRunnableMethod(&BlockingNetworkDelegate::DoCallback, |
| 147 callback)); |
151 return net::ERR_IO_PENDING; | 148 return net::ERR_IO_PENDING; |
152 } | 149 } |
153 | 150 |
154 void DoCallback(net::CompletionCallback* callback) { | 151 void DoCallback(net::CompletionCallback* callback) { |
155 callback->Run(callback_retval_); | 152 callback->Run(callback_retval_); |
156 } | 153 } |
157 | 154 |
158 int callback_retval_; | 155 int callback_retval_; |
159 GURL redirect_url_; | 156 GURL redirect_url_; |
| 157 ScopedRunnableMethodFactory<BlockingNetworkDelegate> method_factory_; |
160 }; | 158 }; |
161 | 159 |
162 // Inherit PlatformTest since we require the autorelease pool on Mac OS X.f | 160 // Inherit PlatformTest since we require the autorelease pool on Mac OS X.f |
163 class URLRequestTest : public PlatformTest { | 161 class URLRequestTest : public PlatformTest { |
164 public: | 162 public: |
165 static void SetUpTestCase() { | 163 static void SetUpTestCase() { |
166 URLRequest::AllowFileAccess(); | 164 URLRequest::AllowFileAccess(); |
167 } | 165 } |
168 }; | 166 }; |
169 | 167 |
(...skipping 2701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2871 req.SetExtraRequestHeaders(headers); | 2869 req.SetExtraRequestHeaders(headers); |
2872 req.Start(); | 2870 req.Start(); |
2873 MessageLoop::current()->Run(); | 2871 MessageLoop::current()->Run(); |
2874 // If the net tests are being run with ChromeFrame then we need to allow for | 2872 // If the net tests are being run with ChromeFrame then we need to allow for |
2875 // the 'chromeframe' suffix which is added to the user agent before the | 2873 // the 'chromeframe' suffix which is added to the user agent before the |
2876 // closing parentheses. | 2874 // closing parentheses. |
2877 EXPECT_TRUE(StartsWithASCII(d.data_received(), "Lynx (textmode", true)); | 2875 EXPECT_TRUE(StartsWithASCII(d.data_received(), "Lynx (textmode", true)); |
2878 } | 2876 } |
2879 | 2877 |
2880 } // namespace net | 2878 } // namespace net |
OLD | NEW |