| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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" | 8 #include "base/bind.h" |
| 9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
| 10 #include "base/win/scoped_com_initializer.h" | 10 #include "base/win/scoped_com_initializer.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 void RequestRead(UrlmonUrlRequest* request, int bytes_to_read) { | 60 void RequestRead(UrlmonUrlRequest* request, int bytes_to_read) { |
| 61 request->Read(bytes_to_read); | 61 request->Read(bytes_to_read); |
| 62 } | 62 } |
| 63 }; | 63 }; |
| 64 | 64 |
| 65 // Simplest UrlmonUrlRequest. Retrieve a file from local web server. | 65 // Simplest UrlmonUrlRequest. Retrieve a file from local web server. |
| 66 TEST(UrlmonUrlRequestTest, Simple1) { | 66 TEST(UrlmonUrlRequestTest, Simple1) { |
| 67 MockUrlDelegate mock; | 67 MockUrlDelegate mock; |
| 68 chrome_frame_test::TimedMsgLoop loop; | 68 chrome_frame_test::TimedMsgLoop loop; |
| 69 | 69 |
| 70 testing::StrictMock<MockWebServer> mock_server(1337, L"127.0.0.1", | 70 testing::StrictMock<MockWebServer> mock_server(1337, |
| 71 ASCIIToWide(chrome_frame_test::GetLocalIPv4Address()), |
| 71 chrome_frame_test::GetTestDataFolder()); | 72 chrome_frame_test::GetTestDataFolder()); |
| 72 mock_server.ExpectAndServeAnyRequests(CFInvocation(CFInvocation::NONE)); | 73 mock_server.ExpectAndServeAnyRequests(CFInvocation(CFInvocation::NONE)); |
| 73 | 74 |
| 74 base::win::ScopedCOMInitializer init_com; | 75 base::win::ScopedCOMInitializer init_com; |
| 75 CComObjectStackEx<UrlmonUrlRequest> request; | 76 CComObjectStackEx<UrlmonUrlRequest> request; |
| 76 | 77 |
| 77 request.AddRef(); | 78 request.AddRef(); |
| 78 request.Initialize(&mock, 1, // request_id | 79 request.Initialize(&mock, 1, // request_id |
| 79 WideToUTF8(mock_server.Resolve(L"chrome_frame_window_open.html")), | 80 WideToUTF8(mock_server.Resolve(L"chrome_frame_window_open.html")), |
| 80 "get", | 81 "get", |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 // requests. | 119 // requests. |
| 119 test_server::SimpleWebServer server(13337); | 120 test_server::SimpleWebServer server(13337); |
| 120 test_server::SimpleResponse head_response("/head", ""); | 121 test_server::SimpleResponse head_response("/head", ""); |
| 121 server.AddResponse(&head_response); | 122 server.AddResponse(&head_response); |
| 122 | 123 |
| 123 base::win::ScopedCOMInitializer init_com; | 124 base::win::ScopedCOMInitializer init_com; |
| 124 CComObjectStackEx<UrlmonUrlRequest> request; | 125 CComObjectStackEx<UrlmonUrlRequest> request; |
| 125 | 126 |
| 126 request.AddRef(); | 127 request.AddRef(); |
| 127 request.Initialize(&mock, 1, // request_id | 128 request.Initialize(&mock, 1, // request_id |
| 128 "http://localhost:13337/head", | 129 base::StringPrintf("http://%s:13337/head", server.host().c_str()), |
| 129 "head", | 130 "head", |
| 130 "", // referrer | 131 "", // referrer |
| 131 "", // extra request | 132 "", // extra request |
| 132 NULL, // upload data | 133 NULL, // upload data |
| 133 ResourceType::MAIN_FRAME, // resource type | 134 ResourceType::MAIN_FRAME, // resource type |
| 134 true, | 135 true, |
| 135 0); // frame busting | 136 0); // frame busting |
| 136 | 137 |
| 137 testing::InSequence s; | 138 testing::InSequence s; |
| 138 EXPECT_CALL(mock, OnResponseStarted(1, testing::_, testing::_, testing::_, | 139 EXPECT_CALL(mock, OnResponseStarted(1, testing::_, testing::_, testing::_, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 153 loop.RunFor(kChromeFrameLongNavigationTimeout); | 154 loop.RunFor(kChromeFrameLongNavigationTimeout); |
| 154 request.Release(); | 155 request.Release(); |
| 155 } | 156 } |
| 156 | 157 |
| 157 TEST(UrlmonUrlRequestTest, UnreachableUrl) { | 158 TEST(UrlmonUrlRequestTest, UnreachableUrl) { |
| 158 MockUrlDelegate mock; | 159 MockUrlDelegate mock; |
| 159 chrome_frame_test::TimedMsgLoop loop; | 160 chrome_frame_test::TimedMsgLoop loop; |
| 160 base::win::ScopedCOMInitializer init_com; | 161 base::win::ScopedCOMInitializer init_com; |
| 161 CComObjectStackEx<UrlmonUrlRequest> request; | 162 CComObjectStackEx<UrlmonUrlRequest> request; |
| 162 | 163 |
| 163 testing::StrictMock<MockWebServer> mock_server(1337, L"127.0.0.1", | 164 testing::StrictMock<MockWebServer> mock_server(1337, |
| 165 ASCIIToWide(chrome_frame_test::GetLocalIPv4Address()), |
| 164 chrome_frame_test::GetTestDataFolder()); | 166 chrome_frame_test::GetTestDataFolder()); |
| 165 mock_server.ExpectAndServeAnyRequests(CFInvocation(CFInvocation::NONE)); | 167 mock_server.ExpectAndServeAnyRequests(CFInvocation(CFInvocation::NONE)); |
| 166 | 168 |
| 167 GURL unreachable(WideToUTF8(mock_server.Resolve( | 169 GURL unreachable(WideToUTF8(mock_server.Resolve( |
| 168 L"non_existing.html"))); | 170 L"non_existing.html"))); |
| 169 | 171 |
| 170 request.AddRef(); | 172 request.AddRef(); |
| 171 request.Initialize(&mock, 1, // request_id | 173 request.Initialize(&mock, 1, // request_id |
| 172 unreachable.spec(), "get", | 174 unreachable.spec(), "get", |
| 173 "", // referrer | 175 "", // referrer |
| (...skipping 18 matching lines...) Expand all Loading... |
| 192 | 194 |
| 193 request.Start(); | 195 request.Start(); |
| 194 loop.RunFor(kChromeFrameLongNavigationTimeout); | 196 loop.RunFor(kChromeFrameLongNavigationTimeout); |
| 195 request.Release(); | 197 request.Release(); |
| 196 } | 198 } |
| 197 | 199 |
| 198 TEST(UrlmonUrlRequestTest, ZeroLengthResponse) { | 200 TEST(UrlmonUrlRequestTest, ZeroLengthResponse) { |
| 199 MockUrlDelegate mock; | 201 MockUrlDelegate mock; |
| 200 chrome_frame_test::TimedMsgLoop loop; | 202 chrome_frame_test::TimedMsgLoop loop; |
| 201 | 203 |
| 202 testing::StrictMock<MockWebServer> mock_server(1337, L"127.0.0.1", | 204 testing::StrictMock<MockWebServer> mock_server(1337, |
| 205 ASCIIToWide(chrome_frame_test::GetLocalIPv4Address()), |
| 203 chrome_frame_test::GetTestDataFolder()); | 206 chrome_frame_test::GetTestDataFolder()); |
| 204 mock_server.ExpectAndServeAnyRequests(CFInvocation(CFInvocation::NONE)); | 207 mock_server.ExpectAndServeAnyRequests(CFInvocation(CFInvocation::NONE)); |
| 205 | 208 |
| 206 base::win::ScopedCOMInitializer init_com; | 209 base::win::ScopedCOMInitializer init_com; |
| 207 CComObjectStackEx<UrlmonUrlRequest> request; | 210 CComObjectStackEx<UrlmonUrlRequest> request; |
| 208 | 211 |
| 209 request.AddRef(); | 212 request.AddRef(); |
| 210 request.Initialize(&mock, 1, // request_id | 213 request.Initialize(&mock, 1, // request_id |
| 211 WideToUTF8(mock_server.Resolve(L"empty.html")), "get", | 214 WideToUTF8(mock_server.Resolve(L"empty.html")), "get", |
| 212 "", // referrer | 215 "", // referrer |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 loop->PostTask(FROM_HERE, base::Bind(&UrlmonUrlRequestManager::EndUrlRequest, | 251 loop->PostTask(FROM_HERE, base::Bind(&UrlmonUrlRequestManager::EndUrlRequest, |
| 249 base::Unretained(mgr), request_id, | 252 base::Unretained(mgr), request_id, |
| 250 net::URLRequestStatus())); | 253 net::URLRequestStatus())); |
| 251 } | 254 } |
| 252 | 255 |
| 253 // Simplest test - retrieve file from local web server. | 256 // Simplest test - retrieve file from local web server. |
| 254 TEST(UrlmonUrlRequestManagerTest, Simple1) { | 257 TEST(UrlmonUrlRequestManagerTest, Simple1) { |
| 255 MockUrlDelegate mock; | 258 MockUrlDelegate mock; |
| 256 chrome_frame_test::TimedMsgLoop loop; | 259 chrome_frame_test::TimedMsgLoop loop; |
| 257 | 260 |
| 258 testing::StrictMock<MockWebServer> mock_server(1337, L"127.0.0.1", | 261 testing::StrictMock<MockWebServer> mock_server(1337, |
| 262 ASCIIToWide(chrome_frame_test::GetLocalIPv4Address()), |
| 259 chrome_frame_test::GetTestDataFolder()); | 263 chrome_frame_test::GetTestDataFolder()); |
| 260 mock_server.ExpectAndServeAnyRequests(CFInvocation(CFInvocation::NONE)); | 264 mock_server.ExpectAndServeAnyRequests(CFInvocation(CFInvocation::NONE)); |
| 261 | 265 |
| 262 scoped_ptr<UrlmonUrlRequestManager> mgr(new UrlmonUrlRequestManager()); | 266 scoped_ptr<UrlmonUrlRequestManager> mgr(new UrlmonUrlRequestManager()); |
| 263 mgr->set_delegate(&mock); | 267 mgr->set_delegate(&mock); |
| 264 AutomationURLRequest r1; | 268 AutomationURLRequest r1; |
| 265 r1.url = WideToUTF8(mock_server.Resolve(L"chrome_frame_window_open.html")); | 269 r1.url = WideToUTF8(mock_server.Resolve(L"chrome_frame_window_open.html")); |
| 266 r1.method = "get"; | 270 r1.method = "get"; |
| 267 r1.resource_type = 0; | 271 r1.resource_type = 0; |
| 268 r1.load_flags = 0; | 272 r1.load_flags = 0; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 283 | 287 |
| 284 mgr->StartUrlRequest(1, r1); | 288 mgr->StartUrlRequest(1, r1); |
| 285 loop.RunFor(kChromeFrameLongNavigationTimeout); | 289 loop.RunFor(kChromeFrameLongNavigationTimeout); |
| 286 mgr.reset(); | 290 mgr.reset(); |
| 287 } | 291 } |
| 288 | 292 |
| 289 TEST(UrlmonUrlRequestManagerTest, Abort1) { | 293 TEST(UrlmonUrlRequestManagerTest, Abort1) { |
| 290 MockUrlDelegate mock; | 294 MockUrlDelegate mock; |
| 291 chrome_frame_test::TimedMsgLoop loop; | 295 chrome_frame_test::TimedMsgLoop loop; |
| 292 | 296 |
| 293 testing::StrictMock<MockWebServer> mock_server(1337, L"127.0.0.1", | 297 testing::StrictMock<MockWebServer> mock_server(1337, |
| 298 ASCIIToWide(chrome_frame_test::GetLocalIPv4Address()), |
| 294 chrome_frame_test::GetTestDataFolder()); | 299 chrome_frame_test::GetTestDataFolder()); |
| 295 mock_server.ExpectAndServeAnyRequests(CFInvocation(CFInvocation::NONE)); | 300 mock_server.ExpectAndServeAnyRequests(CFInvocation(CFInvocation::NONE)); |
| 296 | 301 |
| 297 scoped_ptr<UrlmonUrlRequestManager> mgr(new UrlmonUrlRequestManager()); | 302 scoped_ptr<UrlmonUrlRequestManager> mgr(new UrlmonUrlRequestManager()); |
| 298 mgr->set_delegate(&mock); | 303 mgr->set_delegate(&mock); |
| 299 AutomationURLRequest r1; | 304 AutomationURLRequest r1; |
| 300 r1.url = WideToUTF8(mock_server.Resolve(L"chrome_frame_window_open.html")); | 305 r1.url = WideToUTF8(mock_server.Resolve(L"chrome_frame_window_open.html")); |
| 301 r1.method = "get"; | 306 r1.method = "get"; |
| 302 r1.resource_type = 0; | 307 r1.resource_type = 0; |
| 303 r1.load_flags = 0; | 308 r1.load_flags = 0; |
| 304 | 309 |
| 305 EXPECT_CALL(mock, OnResponseStarted(1, testing::_, testing::_, testing::_, | 310 EXPECT_CALL(mock, OnResponseStarted(1, testing::_, testing::_, testing::_, |
| 306 testing::_, testing::_, testing::_, testing::_)) | 311 testing::_, testing::_, testing::_, testing::_)) |
| 307 .Times(1) | 312 .Times(1) |
| 308 .WillOnce(testing::DoAll( | 313 .WillOnce(testing::DoAll( |
| 309 ManagerEndRequest(&loop, mgr.get(), 1), | 314 ManagerEndRequest(&loop, mgr.get(), 1), |
| 310 QUIT_LOOP_SOON(loop, base::TimeDelta::FromSeconds(3)))); | 315 QUIT_LOOP_SOON(loop, base::TimeDelta::FromSeconds(3)))); |
| 311 | 316 |
| 312 EXPECT_CALL(mock, OnReadComplete(1, testing::_)) | 317 EXPECT_CALL(mock, OnReadComplete(1, testing::_)) |
| 313 .Times(0); | 318 .Times(0); |
| 314 | 319 |
| 315 EXPECT_CALL(mock, OnResponseEnd(1, testing::_)) | 320 EXPECT_CALL(mock, OnResponseEnd(1, testing::_)) |
| 316 .Times(0); | 321 .Times(0); |
| 317 | 322 |
| 318 mgr->StartUrlRequest(1, r1); | 323 mgr->StartUrlRequest(1, r1); |
| 319 loop.RunFor(kChromeFrameLongNavigationTimeout); | 324 loop.RunFor(kChromeFrameLongNavigationTimeout); |
| 320 mgr.reset(); | 325 mgr.reset(); |
| 321 } | 326 } |
| OLD | NEW |