| 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 21 matching lines...) Expand all Loading... |
| 32 // Seek to the end. | 32 // Seek to the end. |
| 33 ASSERT_HRESULT_SUCCEEDED(s->Seek(zero, STREAM_SEEK_END, NULL)); | 33 ASSERT_HRESULT_SUCCEEDED(s->Seek(zero, STREAM_SEEK_END, NULL)); |
| 34 ASSERT_HRESULT_SUCCEEDED(s->Write(buffer, cb, &bytes_written)); | 34 ASSERT_HRESULT_SUCCEEDED(s->Write(buffer, cb, &bytes_written)); |
| 35 ASSERT_EQ(cb, bytes_written); | 35 ASSERT_EQ(cb, bytes_written); |
| 36 // Seek to original position. | 36 // Seek to original position. |
| 37 ASSERT_HRESULT_SUCCEEDED(s->Seek(current_pos, STREAM_SEEK_SET, NULL)); | 37 ASSERT_HRESULT_SUCCEEDED(s->Seek(current_pos, STREAM_SEEK_SET, NULL)); |
| 38 } | 38 } |
| 39 | 39 |
| 40 class MockUrlDelegate : public PluginUrlRequestDelegate { | 40 class MockUrlDelegate : public PluginUrlRequestDelegate { |
| 41 public: | 41 public: |
| 42 MOCK_METHOD8(OnResponseStarted, void(int request_id, const char* mime_type, | 42 MOCK_METHOD9(OnResponseStarted, void(int request_id, const char* mime_type, |
| 43 const char* headers, int size, base::Time last_modified, | 43 const char* headers, int size, base::Time last_modified, |
| 44 const std::string& redirect_url, int redirect_status, | 44 const std::string& redirect_url, int redirect_status, |
| 45 const net::HostPortPair& socket_address)); | 45 const net::HostPortPair& socket_address, uint64 upload_size)); |
| 46 MOCK_METHOD2(OnReadComplete, void(int request_id, const std::string& data)); | 46 MOCK_METHOD2(OnReadComplete, void(int request_id, const std::string& data)); |
| 47 MOCK_METHOD2(OnResponseEnd, void(int request_id, | 47 MOCK_METHOD2(OnResponseEnd, void(int request_id, |
| 48 const net::URLRequestStatus& status)); | 48 const net::URLRequestStatus& status)); |
| 49 MOCK_METHOD4(OnCookiesRetrieved, void(bool success, const GURL& url, | 49 MOCK_METHOD4(OnCookiesRetrieved, void(bool success, const GURL& url, |
| 50 const std::string& cookie, int cookie_id)); | 50 const std::string& cookie, int cookie_id)); |
| 51 | 51 |
| 52 void PostponeReadRequest(chrome_frame_test::TimedMsgLoop* loop, | 52 void PostponeReadRequest(chrome_frame_test::TimedMsgLoop* loop, |
| 53 UrlmonUrlRequest* request, int bytes_to_read) { | 53 UrlmonUrlRequest* request, int bytes_to_read) { |
| 54 loop->PostTask(FROM_HERE, | 54 loop->PostTask(FROM_HERE, |
| 55 base::Bind(&MockUrlDelegate::RequestRead, | 55 base::Bind(&MockUrlDelegate::RequestRead, |
| (...skipping 26 matching lines...) Expand all Loading... |
| 82 "", // referrer | 82 "", // referrer |
| 83 "", // extra request | 83 "", // extra request |
| 84 NULL, // upload data | 84 NULL, // upload data |
| 85 ResourceType::MAIN_FRAME, // resource type | 85 ResourceType::MAIN_FRAME, // resource type |
| 86 true, | 86 true, |
| 87 0); // frame busting | 87 0); // frame busting |
| 88 | 88 |
| 89 testing::InSequence s; | 89 testing::InSequence s; |
| 90 EXPECT_CALL(mock, OnResponseStarted(1, testing::_, testing::_, testing::_, | 90 EXPECT_CALL(mock, OnResponseStarted(1, testing::_, testing::_, testing::_, |
| 91 testing::_, testing::_, testing::_, | 91 testing::_, testing::_, testing::_, |
| 92 testing::_)) | 92 testing::_, testing::_)) |
| 93 .Times(1) | 93 .Times(1) |
| 94 .WillOnce(testing::IgnoreResult(testing::InvokeWithoutArgs(CreateFunctor( | 94 .WillOnce(testing::IgnoreResult(testing::InvokeWithoutArgs(CreateFunctor( |
| 95 &request, &UrlmonUrlRequest::Read, 512)))); | 95 &request, &UrlmonUrlRequest::Read, 512)))); |
| 96 | 96 |
| 97 | 97 |
| 98 EXPECT_CALL(mock, OnReadComplete(1, testing::Property(&std::string::size, | 98 EXPECT_CALL(mock, OnReadComplete(1, testing::Property(&std::string::size, |
| 99 testing::Gt(0u)))) | 99 testing::Gt(0u)))) |
| 100 .Times(testing::AtLeast(1)) | 100 .Times(testing::AtLeast(1)) |
| 101 .WillRepeatedly(testing::InvokeWithoutArgs(CreateFunctor(&mock, | 101 .WillRepeatedly(testing::InvokeWithoutArgs(CreateFunctor(&mock, |
| 102 &MockUrlDelegate::PostponeReadRequest, &loop, &request, 64))); | 102 &MockUrlDelegate::PostponeReadRequest, &loop, &request, 64))); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 131 "", // referrer | 131 "", // referrer |
| 132 "", // extra request | 132 "", // extra request |
| 133 NULL, // upload data | 133 NULL, // upload data |
| 134 ResourceType::MAIN_FRAME, // resource type | 134 ResourceType::MAIN_FRAME, // resource type |
| 135 true, | 135 true, |
| 136 0); // frame busting | 136 0); // frame busting |
| 137 | 137 |
| 138 testing::InSequence s; | 138 testing::InSequence s; |
| 139 EXPECT_CALL(mock, OnResponseStarted(1, testing::_, testing::_, testing::_, | 139 EXPECT_CALL(mock, OnResponseStarted(1, testing::_, testing::_, testing::_, |
| 140 testing::_, testing::_, testing::_, | 140 testing::_, testing::_, testing::_, |
| 141 testing::_)) | 141 testing::_, testing::_)) |
| 142 .Times(1) | 142 .Times(1) |
| 143 .WillOnce(testing::IgnoreResult(testing::InvokeWithoutArgs(CreateFunctor( | 143 .WillOnce(testing::IgnoreResult(testing::InvokeWithoutArgs(CreateFunctor( |
| 144 &request, &UrlmonUrlRequest::Read, 512)))); | 144 &request, &UrlmonUrlRequest::Read, 512)))); |
| 145 | 145 |
| 146 // For HEAD requests we don't expect content reads. | 146 // For HEAD requests we don't expect content reads. |
| 147 EXPECT_CALL(mock, OnReadComplete(1, testing::_)).Times(0); | 147 EXPECT_CALL(mock, OnReadComplete(1, testing::_)).Times(0); |
| 148 | 148 |
| 149 EXPECT_CALL(mock, OnResponseEnd(1, testing::_)) | 149 EXPECT_CALL(mock, OnResponseEnd(1, testing::_)) |
| 150 .Times(1) | 150 .Times(1) |
| 151 .WillOnce(QUIT_LOOP_SOON(loop, base::TimeDelta::FromSeconds(2))); | 151 .WillOnce(QUIT_LOOP_SOON(loop, base::TimeDelta::FromSeconds(2))); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 176 "", // extra request | 176 "", // extra request |
| 177 NULL, // upload data | 177 NULL, // upload data |
| 178 ResourceType::MAIN_FRAME, // resource type | 178 ResourceType::MAIN_FRAME, // resource type |
| 179 true, | 179 true, |
| 180 0); // frame busting | 180 0); // frame busting |
| 181 | 181 |
| 182 // Expect headers | 182 // Expect headers |
| 183 EXPECT_CALL(mock, OnResponseStarted(1, testing::_, | 183 EXPECT_CALL(mock, OnResponseStarted(1, testing::_, |
| 184 testing::StartsWith("HTTP/1.1 404"), | 184 testing::StartsWith("HTTP/1.1 404"), |
| 185 testing::_, testing::_, testing::_, | 185 testing::_, testing::_, testing::_, |
| 186 testing::_, testing::_)) | 186 testing::_, testing::_, testing::_)) |
| 187 .Times(1) | 187 .Times(1) |
| 188 .WillOnce(QUIT_LOOP_SOON(loop, base::TimeDelta::FromSeconds(2))); | 188 .WillOnce(QUIT_LOOP_SOON(loop, base::TimeDelta::FromSeconds(2))); |
| 189 | 189 |
| 190 EXPECT_CALL(mock, OnResponseEnd(1, testing::Property( | 190 EXPECT_CALL(mock, OnResponseEnd(1, testing::Property( |
| 191 &net::URLRequestStatus::error, | 191 &net::URLRequestStatus::error, |
| 192 net::ERR_TUNNEL_CONNECTION_FAILED))) | 192 net::ERR_TUNNEL_CONNECTION_FAILED))) |
| 193 .Times(testing::AtMost(1)); | 193 .Times(testing::AtMost(1)); |
| 194 | 194 |
| 195 request.Start(); | 195 request.Start(); |
| 196 loop.RunFor(kChromeFrameLongNavigationTimeout); | 196 loop.RunFor(kChromeFrameLongNavigationTimeout); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 215 "", // referrer | 215 "", // referrer |
| 216 "", // extra request | 216 "", // extra request |
| 217 NULL, // upload data | 217 NULL, // upload data |
| 218 ResourceType::MAIN_FRAME, // resource type | 218 ResourceType::MAIN_FRAME, // resource type |
| 219 true, | 219 true, |
| 220 0); // frame busting | 220 0); // frame busting |
| 221 | 221 |
| 222 // Expect headers | 222 // Expect headers |
| 223 EXPECT_CALL(mock, OnResponseStarted(1, testing::_, testing::_, testing::_, | 223 EXPECT_CALL(mock, OnResponseStarted(1, testing::_, testing::_, testing::_, |
| 224 testing::_, testing::_, testing::_, | 224 testing::_, testing::_, testing::_, |
| 225 testing::_)) | 225 testing::_, testing::_)) |
| 226 .Times(1) | 226 .Times(1) |
| 227 .WillOnce(QUIT_LOOP(loop)); | 227 .WillOnce(QUIT_LOOP(loop)); |
| 228 | 228 |
| 229 request.Start(); | 229 request.Start(); |
| 230 loop.RunFor(kChromeFrameLongNavigationTimeout); | 230 loop.RunFor(kChromeFrameLongNavigationTimeout); |
| 231 EXPECT_FALSE(loop.WasTimedOut()); | 231 EXPECT_FALSE(loop.WasTimedOut()); |
| 232 | 232 |
| 233 // Should stay quiet, since we do not ask for anything for awhile. | 233 // Should stay quiet, since we do not ask for anything for awhile. |
| 234 EXPECT_CALL(mock, OnResponseEnd(1, testing::_)).Times(0); | 234 EXPECT_CALL(mock, OnResponseEnd(1, testing::_)).Times(0); |
| 235 loop.RunFor(base::TimeDelta::FromSeconds(3)); | 235 loop.RunFor(base::TimeDelta::FromSeconds(3)); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 265 | 265 |
| 266 scoped_ptr<UrlmonUrlRequestManager> mgr(new UrlmonUrlRequestManager()); | 266 scoped_ptr<UrlmonUrlRequestManager> mgr(new UrlmonUrlRequestManager()); |
| 267 mgr->set_delegate(&mock); | 267 mgr->set_delegate(&mock); |
| 268 AutomationURLRequest r1; | 268 AutomationURLRequest r1; |
| 269 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")); |
| 270 r1.method = "get"; | 270 r1.method = "get"; |
| 271 r1.resource_type = 0; | 271 r1.resource_type = 0; |
| 272 r1.load_flags = 0; | 272 r1.load_flags = 0; |
| 273 | 273 |
| 274 EXPECT_CALL(mock, OnResponseStarted(1, testing::_, testing::_, testing::_, | 274 EXPECT_CALL(mock, OnResponseStarted(1, testing::_, testing::_, testing::_, |
| 275 testing::_, testing::_, testing::_, testing::_)) | 275 testing::_, testing::_, testing::_, testing::_, |
| 276 testing::_)) |
| 276 .Times(1) | 277 .Times(1) |
| 277 .WillOnce(ManagerRead(&loop, mgr.get(), 1, 512)); | 278 .WillOnce(ManagerRead(&loop, mgr.get(), 1, 512)); |
| 278 | 279 |
| 279 EXPECT_CALL(mock, OnReadComplete(1, testing::Property(&std::string::size, | 280 EXPECT_CALL(mock, OnReadComplete(1, testing::Property(&std::string::size, |
| 280 testing::Gt(0u)))) | 281 testing::Gt(0u)))) |
| 281 .Times(testing::AtLeast(1)) | 282 .Times(testing::AtLeast(1)) |
| 282 .WillRepeatedly(ManagerRead(&loop, mgr.get(), 1, 2)); | 283 .WillRepeatedly(ManagerRead(&loop, mgr.get(), 1, 2)); |
| 283 | 284 |
| 284 EXPECT_CALL(mock, OnResponseEnd(1, testing::_)) | 285 EXPECT_CALL(mock, OnResponseEnd(1, testing::_)) |
| 285 .Times(1) | 286 .Times(1) |
| (...skipping 15 matching lines...) Expand all Loading... |
| 301 | 302 |
| 302 scoped_ptr<UrlmonUrlRequestManager> mgr(new UrlmonUrlRequestManager()); | 303 scoped_ptr<UrlmonUrlRequestManager> mgr(new UrlmonUrlRequestManager()); |
| 303 mgr->set_delegate(&mock); | 304 mgr->set_delegate(&mock); |
| 304 AutomationURLRequest r1; | 305 AutomationURLRequest r1; |
| 305 r1.url = WideToUTF8(mock_server.Resolve(L"chrome_frame_window_open.html")); | 306 r1.url = WideToUTF8(mock_server.Resolve(L"chrome_frame_window_open.html")); |
| 306 r1.method = "get"; | 307 r1.method = "get"; |
| 307 r1.resource_type = 0; | 308 r1.resource_type = 0; |
| 308 r1.load_flags = 0; | 309 r1.load_flags = 0; |
| 309 | 310 |
| 310 EXPECT_CALL(mock, OnResponseStarted(1, testing::_, testing::_, testing::_, | 311 EXPECT_CALL(mock, OnResponseStarted(1, testing::_, testing::_, testing::_, |
| 311 testing::_, testing::_, testing::_, testing::_)) | 312 testing::_, testing::_, testing::_, testing::_, |
| 313 testing::_)) |
| 312 .Times(1) | 314 .Times(1) |
| 313 .WillOnce(testing::DoAll( | 315 .WillOnce(testing::DoAll( |
| 314 ManagerEndRequest(&loop, mgr.get(), 1), | 316 ManagerEndRequest(&loop, mgr.get(), 1), |
| 315 QUIT_LOOP_SOON(loop, base::TimeDelta::FromSeconds(3)))); | 317 QUIT_LOOP_SOON(loop, base::TimeDelta::FromSeconds(3)))); |
| 316 | 318 |
| 317 EXPECT_CALL(mock, OnReadComplete(1, testing::_)) | 319 EXPECT_CALL(mock, OnReadComplete(1, testing::_)) |
| 318 .Times(0); | 320 .Times(0); |
| 319 | 321 |
| 320 EXPECT_CALL(mock, OnResponseEnd(1, testing::_)) | 322 EXPECT_CALL(mock, OnResponseEnd(1, testing::_)) |
| 321 .Times(0); | 323 .Times(0); |
| 322 | 324 |
| 323 mgr->StartUrlRequest(1, r1); | 325 mgr->StartUrlRequest(1, r1); |
| 324 loop.RunFor(kChromeFrameLongNavigationTimeout); | 326 loop.RunFor(kChromeFrameLongNavigationTimeout); |
| 325 mgr.reset(); | 327 mgr.reset(); |
| 326 } | 328 } |
| OLD | NEW |