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 "base/bind.h" |
| 9 #include "base/bind_helpers.h" |
8 #include "base/win/scoped_com_initializer.h" | 10 #include "base/win/scoped_com_initializer.h" |
9 #include "chrome/common/automation_messages.h" | 11 #include "chrome/common/automation_messages.h" |
10 #include "chrome_frame/test/chrome_frame_test_utils.h" | 12 #include "chrome_frame/test/chrome_frame_test_utils.h" |
11 #include "chrome_frame/test/test_server.h" | 13 #include "chrome_frame/test/test_server.h" |
12 #include "chrome_frame/test/test_with_web_server.h" | 14 #include "chrome_frame/test/test_with_web_server.h" |
13 #include "chrome_frame/urlmon_url_request.h" | 15 #include "chrome_frame/urlmon_url_request.h" |
14 #include "chrome_frame/urlmon_url_request_private.h" | 16 #include "chrome_frame/urlmon_url_request_private.h" |
15 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
16 #include "testing/gmock_mutant.h" | 18 #include "testing/gmock_mutant.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 25 matching lines...) Expand all Loading... |
43 const net::HostPortPair& socket_address)); | 45 const net::HostPortPair& socket_address)); |
44 MOCK_METHOD2(OnReadComplete, void(int request_id, const std::string& data)); | 46 MOCK_METHOD2(OnReadComplete, void(int request_id, const std::string& data)); |
45 MOCK_METHOD2(OnResponseEnd, void(int request_id, | 47 MOCK_METHOD2(OnResponseEnd, void(int request_id, |
46 const net::URLRequestStatus& status)); | 48 const net::URLRequestStatus& status)); |
47 MOCK_METHOD4(OnCookiesRetrieved, void(bool success, const GURL& url, | 49 MOCK_METHOD4(OnCookiesRetrieved, void(bool success, const GURL& url, |
48 const std::string& cookie, int cookie_id)); | 50 const std::string& cookie, int cookie_id)); |
49 | 51 |
50 static bool ImplementsThreadSafeReferenceCounting() { | 52 static bool ImplementsThreadSafeReferenceCounting() { |
51 return false; | 53 return false; |
52 } | 54 } |
53 void AddRef() {} | |
54 void Release() {} | |
55 | 55 |
56 void PostponeReadRequest(chrome_frame_test::TimedMsgLoop* loop, | 56 void PostponeReadRequest(chrome_frame_test::TimedMsgLoop* loop, |
57 UrlmonUrlRequest* request, int bytes_to_read) { | 57 UrlmonUrlRequest* request, int bytes_to_read) { |
58 loop->PostDelayedTask(FROM_HERE, NewRunnableMethod(this, | 58 loop->PostTask(FROM_HERE, |
59 &MockUrlDelegate::RequestRead, request, bytes_to_read), 0); | 59 base::Bind(&MockUrlDelegate::RequestRead, |
| 60 base::Unretained(this), request, bytes_to_read)); |
60 } | 61 } |
61 | 62 |
62 private: | 63 private: |
63 void RequestRead(UrlmonUrlRequest* request, int bytes_to_read) { | 64 void RequestRead(UrlmonUrlRequest* request, int bytes_to_read) { |
64 request->Read(bytes_to_read); | 65 request->Read(bytes_to_read); |
65 } | 66 } |
66 }; | 67 }; |
67 | 68 |
68 // Simplest UrlmonUrlRequest. Retrieve a file from local web server. | 69 // Simplest UrlmonUrlRequest. Retrieve a file from local web server. |
69 TEST(UrlmonUrlRequestTest, Simple1) { | 70 TEST(UrlmonUrlRequestTest, Simple1) { |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 | 237 |
237 // Invoke read. Only now the response end ("server closed the connection") | 238 // Invoke read. Only now the response end ("server closed the connection") |
238 // is supposed to be delivered. | 239 // is supposed to be delivered. |
239 EXPECT_CALL(mock, OnResponseEnd(1, testing::Property( | 240 EXPECT_CALL(mock, OnResponseEnd(1, testing::Property( |
240 &net::URLRequestStatus::is_success, true))).Times(1); | 241 &net::URLRequestStatus::is_success, true))).Times(1); |
241 request.Read(512); | 242 request.Read(512); |
242 request.Release(); | 243 request.Release(); |
243 } | 244 } |
244 | 245 |
245 ACTION_P4(ManagerRead, loop, mgr, request_id, bytes_to_read) { | 246 ACTION_P4(ManagerRead, loop, mgr, request_id, bytes_to_read) { |
246 loop->PostDelayedTask(FROM_HERE, NewRunnableMethod(mgr, | 247 loop->PostTask(FROM_HERE, |
247 &UrlmonUrlRequestManager::ReadUrlRequest, request_id, | 248 base::Bind(&UrlmonUrlRequestManager::ReadUrlRequest, |
248 bytes_to_read), 0); | 249 base::Unretained(mgr), request_id, bytes_to_read)); |
249 } | 250 } |
250 ACTION_P3(ManagerEndRequest, loop, mgr, request_id) { | 251 ACTION_P3(ManagerEndRequest, loop, mgr, request_id) { |
251 loop->PostDelayedTask(FROM_HERE, NewRunnableMethod(mgr, | 252 loop->PostTask(FROM_HERE, base::Bind(&UrlmonUrlRequestManager::EndUrlRequest, |
252 &UrlmonUrlRequestManager::EndUrlRequest, request_id, | 253 base::Unretained(mgr), request_id, |
253 net::URLRequestStatus()), 0); | 254 net::URLRequestStatus())); |
254 } | 255 } |
255 | 256 |
256 // Simplest test - retrieve file from local web server. | 257 // Simplest test - retrieve file from local web server. |
257 TEST(UrlmonUrlRequestManagerTest, Simple1) { | 258 TEST(UrlmonUrlRequestManagerTest, Simple1) { |
258 MockUrlDelegate mock; | 259 MockUrlDelegate mock; |
259 chrome_frame_test::TimedMsgLoop loop; | 260 chrome_frame_test::TimedMsgLoop loop; |
260 | 261 |
261 testing::StrictMock<MockWebServer> mock_server(1337, L"127.0.0.1", | 262 testing::StrictMock<MockWebServer> mock_server(1337, L"127.0.0.1", |
262 chrome_frame_test::GetTestDataFolder()); | 263 chrome_frame_test::GetTestDataFolder()); |
263 mock_server.ExpectAndServeAnyRequests(CFInvocation(CFInvocation::NONE)); | 264 mock_server.ExpectAndServeAnyRequests(CFInvocation(CFInvocation::NONE)); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 EXPECT_CALL(mock, OnReadComplete(1, testing::_)) | 316 EXPECT_CALL(mock, OnReadComplete(1, testing::_)) |
316 .Times(0); | 317 .Times(0); |
317 | 318 |
318 EXPECT_CALL(mock, OnResponseEnd(1, testing::_)) | 319 EXPECT_CALL(mock, OnResponseEnd(1, testing::_)) |
319 .Times(0); | 320 .Times(0); |
320 | 321 |
321 mgr->StartUrlRequest(1, r1); | 322 mgr->StartUrlRequest(1, r1); |
322 loop.RunFor(kChromeFrameLongNavigationTimeoutInSeconds); | 323 loop.RunFor(kChromeFrameLongNavigationTimeoutInSeconds); |
323 mgr.reset(); | 324 mgr.reset(); |
324 } | 325 } |
OLD | NEW |