| OLD | NEW |
| 1 // Copyright (c) 2011 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/threading/thread.h" | 9 #include "base/threading/thread.h" |
| 10 #include "base/win/scoped_comptr.h" | 10 #include "base/win/scoped_comptr.h" |
| 11 #include "base/win/scoped_handle.h" | 11 #include "base/win/scoped_handle.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 24 using testing::CreateFunctor; | 24 using testing::CreateFunctor; |
| 25 using testing::Eq; | 25 using testing::Eq; |
| 26 using testing::Invoke; | 26 using testing::Invoke; |
| 27 using testing::SetArgumentPointee; | 27 using testing::SetArgumentPointee; |
| 28 using testing::StrEq; | 28 using testing::StrEq; |
| 29 using testing::Return; | 29 using testing::Return; |
| 30 using testing::DoAll; | 30 using testing::DoAll; |
| 31 using testing::WithArgs; | 31 using testing::WithArgs; |
| 32 | 32 |
| 33 | 33 |
| 34 static int kUrlmonMonikerTimeoutSec = 5; | 34 static const base::TimeDelta kUrlmonMonikerTimeout = |
| 35 base::TimeDelta::FromSeconds(5); |
| 35 | 36 |
| 36 namespace { | 37 namespace { |
| 37 const char kTestContent[] = "<html><head>" | 38 const char kTestContent[] = "<html><head>" |
| 38 "<meta http-equiv=\"X-UA-Compatible\" content=\"chrome=1\" />" | 39 "<meta http-equiv=\"X-UA-Compatible\" content=\"chrome=1\" />" |
| 39 "</head><body>Test HTML content</body></html>"; | 40 "</head><body>Test HTML content</body></html>"; |
| 40 } // end namespace | 41 } // end namespace |
| 41 | 42 |
| 42 class UrlmonMonikerTest : public testing::Test { | 43 class UrlmonMonikerTest : public testing::Test { |
| 43 protected: | 44 protected: |
| 44 UrlmonMonikerTest() { | 45 UrlmonMonikerTest() { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 74 return ret; | 75 return ret; |
| 75 } | 76 } |
| 76 | 77 |
| 77 static void StartServer(RunTestServer* me) { | 78 static void StartServer(RunTestServer* me) { |
| 78 me->server_.reset(new test_server::SimpleWebServer(43210)); | 79 me->server_.reset(new test_server::SimpleWebServer(43210)); |
| 79 me->server_->AddResponse(&me->default_response_); | 80 me->server_->AddResponse(&me->default_response_); |
| 80 ::SetEvent(me->ready_); | 81 ::SetEvent(me->ready_); |
| 81 } | 82 } |
| 82 | 83 |
| 83 bool wait_until_ready() { | 84 bool wait_until_ready() { |
| 84 return ::WaitForSingleObject(ready_, kUrlmonMonikerTimeoutSec * 1000) | 85 return ::WaitForSingleObject(ready_, kUrlmonMonikerTimeout.InMilliseconds()) |
| 85 == WAIT_OBJECT_0; | 86 == WAIT_OBJECT_0; |
| 86 } | 87 } |
| 87 | 88 |
| 88 protected: | 89 protected: |
| 89 scoped_ptr<test_server::SimpleWebServer> server_; | 90 scoped_ptr<test_server::SimpleWebServer> server_; |
| 90 test_server::SimpleResponse default_response_; | 91 test_server::SimpleResponse default_response_; |
| 91 base::win::ScopedHandle ready_; | 92 base::win::ScopedHandle ready_; |
| 92 }; | 93 }; |
| 93 | 94 |
| 94 // Helper class for running tests that rely on the NavigationManager. | 95 // Helper class for running tests that rely on the NavigationManager. |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 test_server::SimpleResponse default_response("/", kTestContent); | 244 test_server::SimpleResponse default_response("/", kTestContent); |
| 244 server.AddResponse(&default_response); | 245 server.AddResponse(&default_response); |
| 245 | 246 |
| 246 callback.SetCallbackExpectations( | 247 callback.SetCallbackExpectations( |
| 247 UrlmonMonikerTestCallback::REQUEST_ASYNCHRONOUS, S_OK, true); | 248 UrlmonMonikerTestCallback::REQUEST_ASYNCHRONOUS, S_OK, true); |
| 248 | 249 |
| 249 base::win::ScopedComPtr<IBindCtx> bind_ctx; | 250 base::win::ScopedComPtr<IBindCtx> bind_ctx; |
| 250 HRESULT hr = callback.CreateUrlMonikerAndBindToStorage(test_url, | 251 HRESULT hr = callback.CreateUrlMonikerAndBindToStorage(test_url, |
| 251 bind_ctx.Receive()); | 252 bind_ctx.Receive()); |
| 252 EXPECT_EQ(MK_S_ASYNCHRONOUS, hr); | 253 EXPECT_EQ(MK_S_ASYNCHRONOUS, hr); |
| 253 test.loop().RunFor(kUrlmonMonikerTimeoutSec); | 254 test.loop().RunFor(kUrlmonMonikerTimeout); |
| 254 | 255 |
| 255 IBindCtx* release = bind_ctx.Detach(); | 256 IBindCtx* release = bind_ctx.Detach(); |
| 256 EXPECT_EQ(0, release->Release()); | 257 EXPECT_EQ(0, release->Release()); |
| 257 } | 258 } |
| 258 | 259 |
| 259 // Responds with the Chrome mime type. | 260 // Responds with the Chrome mime type. |
| 260 class ResponseWithContentType : public test_server::SimpleResponse { | 261 class ResponseWithContentType : public test_server::SimpleResponse { |
| 261 public: | 262 public: |
| 262 ResponseWithContentType(const char* request_path, | 263 ResponseWithContentType(const char* request_path, |
| 263 const std::string& contents) | 264 const std::string& contents) |
| (...skipping 17 matching lines...) Expand all Loading... |
| 281 test_server::SimpleWebServer server(43210); | 282 test_server::SimpleWebServer server(43210); |
| 282 ResponseWithContentType default_response("/", kTestContent); | 283 ResponseWithContentType default_response("/", kTestContent); |
| 283 server.AddResponse(&default_response); | 284 server.AddResponse(&default_response); |
| 284 | 285 |
| 285 callback.SetCallbackExpectations( | 286 callback.SetCallbackExpectations( |
| 286 UrlmonMonikerTestCallback::REQUEST_ASYNCHRONOUS, INET_E_TERMINATED_BIND, | 287 UrlmonMonikerTestCallback::REQUEST_ASYNCHRONOUS, INET_E_TERMINATED_BIND, |
| 287 true); | 288 true); |
| 288 | 289 |
| 289 HRESULT hr = callback.CreateUrlMonikerAndBindToStorage(test_url, NULL); | 290 HRESULT hr = callback.CreateUrlMonikerAndBindToStorage(test_url, NULL); |
| 290 EXPECT_EQ(MK_S_ASYNCHRONOUS, hr); | 291 EXPECT_EQ(MK_S_ASYNCHRONOUS, hr); |
| 291 test.loop().RunFor(kUrlmonMonikerTimeoutSec); | 292 test.loop().RunFor(kUrlmonMonikerTimeout); |
| 292 | 293 |
| 293 scoped_refptr<RequestData> request_data( | 294 scoped_refptr<RequestData> request_data( |
| 294 test.nav_manager().GetActiveRequestData(test_url)); | 295 test.nav_manager().GetActiveRequestData(test_url)); |
| 295 EXPECT_TRUE(request_data != NULL); | 296 EXPECT_TRUE(request_data != NULL); |
| 296 | 297 |
| 297 if (request_data) { | 298 if (request_data) { |
| 298 EXPECT_EQ(request_data->GetCachedContentSize(), | 299 EXPECT_EQ(request_data->GetCachedContentSize(), |
| 299 arraysize(kTestContent) - 1); | 300 arraysize(kTestContent) - 1); |
| 300 base::win::ScopedComPtr<IStream> stream; | 301 base::win::ScopedComPtr<IStream> stream; |
| 301 request_data->GetResetCachedContentStream(stream.Receive()); | 302 request_data->GetResetCachedContentStream(stream.Receive()); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 325 // First set of expectations. Download the contents | 326 // First set of expectations. Download the contents |
| 326 // asynchronously. This should populate the cache so that | 327 // asynchronously. This should populate the cache so that |
| 327 // the second request should be served synchronously without | 328 // the second request should be served synchronously without |
| 328 // going to the server. | 329 // going to the server. |
| 329 callback.SetCallbackExpectations( | 330 callback.SetCallbackExpectations( |
| 330 UrlmonMonikerTestCallback::REQUEST_ASYNCHRONOUS, INET_E_TERMINATED_BIND, | 331 UrlmonMonikerTestCallback::REQUEST_ASYNCHRONOUS, INET_E_TERMINATED_BIND, |
| 331 true); | 332 true); |
| 332 | 333 |
| 333 HRESULT hr = callback.CreateUrlMonikerAndBindToStorage(test_url, NULL); | 334 HRESULT hr = callback.CreateUrlMonikerAndBindToStorage(test_url, NULL); |
| 334 EXPECT_EQ(MK_S_ASYNCHRONOUS, hr); | 335 EXPECT_EQ(MK_S_ASYNCHRONOUS, hr); |
| 335 test.loop().RunFor(kUrlmonMonikerTimeoutSec); | 336 test.loop().RunFor(kUrlmonMonikerTimeout); |
| 336 | 337 |
| 337 scoped_refptr<RequestData> request_data( | 338 scoped_refptr<RequestData> request_data( |
| 338 test.nav_manager().GetActiveRequestData(test_url)); | 339 test.nav_manager().GetActiveRequestData(test_url)); |
| 339 EXPECT_TRUE(request_data != NULL); | 340 EXPECT_TRUE(request_data != NULL); |
| 340 | 341 |
| 341 if (request_data) { | 342 if (request_data) { |
| 342 // This time, just accept the content as normal. | 343 // This time, just accept the content as normal. |
| 343 UrlmonMonikerTestCallback callback2(&test); | 344 UrlmonMonikerTestCallback callback2(&test); |
| 344 callback2.SetCallbackExpectations( | 345 callback2.SetCallbackExpectations( |
| 345 UrlmonMonikerTestCallback::EXPECT_NO_CALL, S_OK, false); | 346 UrlmonMonikerTestCallback::EXPECT_NO_CALL, S_OK, false); |
| 346 hr = callback2.CreateUrlMonikerAndBindToStorage(test_url, NULL); | 347 hr = callback2.CreateUrlMonikerAndBindToStorage(test_url, NULL); |
| 347 // S_OK means that the operation completed synchronously. | 348 // S_OK means that the operation completed synchronously. |
| 348 // Otherwise we'd get MK_S_ASYNCHRONOUS. | 349 // Otherwise we'd get MK_S_ASYNCHRONOUS. |
| 349 EXPECT_EQ(S_OK, hr); | 350 EXPECT_EQ(S_OK, hr); |
| 350 } | 351 } |
| 351 } | 352 } |
| 352 | 353 |
| 353 */ | 354 */ |
| OLD | NEW |