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 <atlbase.h> | 5 #include <atlbase.h> |
6 #include <atlcom.h> | 6 #include <atlcom.h> |
7 | 7 |
8 #include "app/win/scoped_com_initializer.h" | 8 #include "app/win/scoped_com_initializer.h" |
9 #include "chrome_frame/test/chrome_frame_test_utils.h" | 9 #include "chrome_frame/test/chrome_frame_test_utils.h" |
10 #include "chrome_frame/test/test_server.h" | 10 #include "chrome_frame/test/test_server.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 ASSERT_HRESULT_SUCCEEDED(s->Seek(current_pos, STREAM_SEEK_SET, NULL)); | 34 ASSERT_HRESULT_SUCCEEDED(s->Seek(current_pos, STREAM_SEEK_SET, NULL)); |
35 } | 35 } |
36 | 36 |
37 class MockUrlDelegate : public PluginUrlRequestDelegate { | 37 class MockUrlDelegate : public PluginUrlRequestDelegate { |
38 public: | 38 public: |
39 MOCK_METHOD7(OnResponseStarted, void(int request_id, const char* mime_type, | 39 MOCK_METHOD7(OnResponseStarted, void(int request_id, const char* mime_type, |
40 const char* headers, int size, base::Time last_modified, | 40 const char* headers, int size, base::Time last_modified, |
41 const std::string& redirect_url, int redirect_status)); | 41 const std::string& redirect_url, int redirect_status)); |
42 MOCK_METHOD2(OnReadComplete, void(int request_id, const std::string& data)); | 42 MOCK_METHOD2(OnReadComplete, void(int request_id, const std::string& data)); |
43 MOCK_METHOD2(OnResponseEnd, void(int request_id, | 43 MOCK_METHOD2(OnResponseEnd, void(int request_id, |
44 const URLRequestStatus& status)); | 44 const net::URLRequestStatus& status)); |
45 MOCK_METHOD4(OnCookiesRetrieved, void(bool success, const GURL& url, | 45 MOCK_METHOD4(OnCookiesRetrieved, void(bool success, const GURL& url, |
46 const std::string& cookie, int cookie_id)); | 46 const std::string& cookie, int cookie_id)); |
47 | 47 |
48 static bool ImplementsThreadSafeReferenceCounting() { | 48 static bool ImplementsThreadSafeReferenceCounting() { |
49 return false; | 49 return false; |
50 } | 50 } |
51 void AddRef() {} | 51 void AddRef() {} |
52 void Release() {} | 52 void Release() {} |
53 | 53 |
54 void PostponeReadRequest(chrome_frame_test::TimedMsgLoop* loop, | 54 void PostponeReadRequest(chrome_frame_test::TimedMsgLoop* loop, |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 | 178 |
179 // Expect headers | 179 // Expect headers |
180 EXPECT_CALL(mock, OnResponseStarted(1, testing::_, | 180 EXPECT_CALL(mock, OnResponseStarted(1, testing::_, |
181 testing::StartsWith("HTTP/1.1 404"), | 181 testing::StartsWith("HTTP/1.1 404"), |
182 testing::_, testing::_, testing::_, | 182 testing::_, testing::_, testing::_, |
183 testing::_)) | 183 testing::_)) |
184 .Times(1) | 184 .Times(1) |
185 .WillOnce(QUIT_LOOP_SOON(loop, 2)); | 185 .WillOnce(QUIT_LOOP_SOON(loop, 2)); |
186 | 186 |
187 EXPECT_CALL(mock, OnResponseEnd(1, testing::Property( | 187 EXPECT_CALL(mock, OnResponseEnd(1, testing::Property( |
188 &URLRequestStatus::os_error, net::ERR_TUNNEL_CONNECTION_FAILED))) | 188 &net::URLRequestStatus::os_error, |
| 189 net::ERR_TUNNEL_CONNECTION_FAILED))) |
189 .Times(testing::AtMost(1)); | 190 .Times(testing::AtMost(1)); |
190 | 191 |
191 request.Start(); | 192 request.Start(); |
192 loop.RunFor(kChromeFrameLongNavigationTimeoutInSeconds); | 193 loop.RunFor(kChromeFrameLongNavigationTimeoutInSeconds); |
193 request.Release(); | 194 request.Release(); |
194 } | 195 } |
195 | 196 |
196 TEST(UrlmonUrlRequestTest, ZeroLengthResponse) { | 197 TEST(UrlmonUrlRequestTest, ZeroLengthResponse) { |
197 MockUrlDelegate mock; | 198 MockUrlDelegate mock; |
198 chrome_frame_test::TimedMsgLoop loop; | 199 chrome_frame_test::TimedMsgLoop loop; |
(...skipping 25 matching lines...) Expand all Loading... |
224 loop.RunFor(kChromeFrameLongNavigationTimeoutInSeconds); | 225 loop.RunFor(kChromeFrameLongNavigationTimeoutInSeconds); |
225 EXPECT_FALSE(loop.WasTimedOut()); | 226 EXPECT_FALSE(loop.WasTimedOut()); |
226 | 227 |
227 // Should stay quiet, since we do not ask for anything for awhile. | 228 // Should stay quiet, since we do not ask for anything for awhile. |
228 EXPECT_CALL(mock, OnResponseEnd(1, testing::_)).Times(0); | 229 EXPECT_CALL(mock, OnResponseEnd(1, testing::_)).Times(0); |
229 loop.RunFor(3); | 230 loop.RunFor(3); |
230 | 231 |
231 // Invoke read. Only now the response end ("server closed the connection") | 232 // Invoke read. Only now the response end ("server closed the connection") |
232 // is supposed to be delivered. | 233 // is supposed to be delivered. |
233 EXPECT_CALL(mock, OnResponseEnd(1, testing::Property( | 234 EXPECT_CALL(mock, OnResponseEnd(1, testing::Property( |
234 &URLRequestStatus::is_success, true))) | 235 &net::URLRequestStatus::is_success, true))).Times(1); |
235 .Times(1); | |
236 request.Read(512); | 236 request.Read(512); |
237 request.Release(); | 237 request.Release(); |
238 } | 238 } |
239 | 239 |
240 ACTION_P4(ManagerRead, loop, mgr, request_id, bytes_to_read) { | 240 ACTION_P4(ManagerRead, loop, mgr, request_id, bytes_to_read) { |
241 loop->PostDelayedTask(FROM_HERE, NewRunnableMethod(mgr, | 241 loop->PostDelayedTask(FROM_HERE, NewRunnableMethod(mgr, |
242 &UrlmonUrlRequestManager::ReadUrlRequest, request_id, | 242 &UrlmonUrlRequestManager::ReadUrlRequest, request_id, |
243 bytes_to_read), 0); | 243 bytes_to_read), 0); |
244 } | 244 } |
245 ACTION_P3(ManagerEndRequest, loop, mgr, request_id) { | 245 ACTION_P3(ManagerEndRequest, loop, mgr, request_id) { |
246 loop->PostDelayedTask(FROM_HERE, NewRunnableMethod(mgr, | 246 loop->PostDelayedTask(FROM_HERE, NewRunnableMethod(mgr, |
247 &UrlmonUrlRequestManager::EndUrlRequest, request_id, | 247 &UrlmonUrlRequestManager::EndUrlRequest, request_id, |
248 URLRequestStatus()), 0); | 248 net::URLRequestStatus()), 0); |
249 } | 249 } |
250 | 250 |
251 // Simplest test - retrieve file from local web server. | 251 // Simplest test - retrieve file from local web server. |
252 TEST(UrlmonUrlRequestManagerTest, Simple1) { | 252 TEST(UrlmonUrlRequestManagerTest, Simple1) { |
253 MockUrlDelegate mock; | 253 MockUrlDelegate mock; |
254 chrome_frame_test::TimedMsgLoop loop; | 254 chrome_frame_test::TimedMsgLoop loop; |
255 | 255 |
256 testing::StrictMock<MockWebServer> mock_server(1337, L"127.0.0.1", | 256 testing::StrictMock<MockWebServer> mock_server(1337, L"127.0.0.1", |
257 chrome_frame_test::GetTestDataFolder()); | 257 chrome_frame_test::GetTestDataFolder()); |
258 mock_server.ExpectAndServeAnyRequests(CFInvocation(CFInvocation::NONE)); | 258 mock_server.ExpectAndServeAnyRequests(CFInvocation(CFInvocation::NONE)); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 EXPECT_CALL(mock, OnReadComplete(1, testing::_)) | 306 EXPECT_CALL(mock, OnReadComplete(1, testing::_)) |
307 .Times(0); | 307 .Times(0); |
308 | 308 |
309 EXPECT_CALL(mock, OnResponseEnd(1, testing::_)) | 309 EXPECT_CALL(mock, OnResponseEnd(1, testing::_)) |
310 .Times(0); | 310 .Times(0); |
311 | 311 |
312 mgr->StartUrlRequest(1, r1); | 312 mgr->StartUrlRequest(1, r1); |
313 loop.RunFor(kChromeFrameLongNavigationTimeoutInSeconds); | 313 loop.RunFor(kChromeFrameLongNavigationTimeoutInSeconds); |
314 mgr.reset(); | 314 mgr.reset(); |
315 } | 315 } |
OLD | NEW |