Chromium Code Reviews| 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 "chrome_frame/test/automation_client_mock.h" | 5 #include "chrome_frame/test/automation_client_mock.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "chrome/common/automation_messages.h" | 9 #include "chrome/common/automation_messages.h" |
| 10 #include "chrome_frame/custom_sync_call_context.h" | 10 #include "chrome_frame/custom_sync_call_context.h" |
| 11 #include "chrome_frame/navigation_constraints.h" | 11 #include "chrome_frame/navigation_constraints.h" |
| 12 #include "chrome_frame/test/chrome_frame_test_utils.h" | 12 #include "chrome_frame/test/chrome_frame_test_utils.h" |
| 13 #include "chrome_frame/test/test_scrubber.h" | 13 #include "chrome_frame/test/test_scrubber.h" |
| 14 #include "net/base/net_errors.h" | 14 #include "net/base/net_errors.h" |
| 15 | 15 |
| 16 #define GMOCK_MUTANT_INCLUDE_LATE_OBJECT_BINDING | 16 #define GMOCK_MUTANT_INCLUDE_LATE_OBJECT_BINDING |
| 17 #include "testing/gmock_mutant.h" | 17 #include "testing/gmock_mutant.h" |
| 18 | 18 |
| 19 using testing::_; | 19 using testing::_; |
| 20 using testing::CreateFunctor; | 20 using testing::CreateFunctor; |
| 21 using testing::Return; | 21 using testing::Return; |
| 22 | 22 |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 #ifndef NDEBUG | 25 #ifndef NDEBUG |
| 26 const int kChromeLaunchTimeout = 15; | 26 const base::TimeDelta kChromeLaunchTimeout = base::TimeDelta::FromSeconds(15); |
| 27 #else | 27 #else |
| 28 const int kChromeLaunchTimeout = 10; | 28 const base::TimeDelta kChromeLaunchTimeout = base::TimeDelta::FromSeconds(10); |
| 29 #endif | 29 #endif |
| 30 | 30 |
| 31 const int kSaneAutomationTimeoutMs = 10 * 1000; | 31 const int kSaneAutomationTimeoutMs = 10 * 1000; |
| 32 | 32 |
| 33 } // namespace | 33 } // namespace |
| 34 | 34 |
| 35 MATCHER_P(LaunchParamProfileEq, profile_name, "Check for profile name") { | 35 MATCHER_P(LaunchParamProfileEq, profile_name, "Check for profile name") { |
| 36 return arg->profile_name().compare(profile_name) == 0; | 36 return arg->profile_name().compare(profile_name) == 0; |
| 37 } | 37 } |
| 38 | 38 |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 224 // Often there's another request for the error page | 224 // Often there's another request for the error page |
| 225 .Times(testing::Between(1, 2)) | 225 .Times(testing::Between(1, 2)) |
| 226 .WillRepeatedly(testing::WithArgs<0>(testing::Invoke(CreateFunctor(&cfd_, | 226 .WillRepeatedly(testing::WithArgs<0>(testing::Invoke(CreateFunctor(&cfd_, |
| 227 &MockCFDelegate::Reply, connection_failed)))); | 227 &MockCFDelegate::Reply, connection_failed)))); |
| 228 | 228 |
| 229 EXPECT_CALL(cfd_, OnUpdateTargetUrl(_)).Times(testing::AnyNumber()); | 229 EXPECT_CALL(cfd_, OnUpdateTargetUrl(_)).Times(testing::AnyNumber()); |
| 230 EXPECT_CALL(cfd_, OnLoad(_)).Times(testing::AtMost(1)); | 230 EXPECT_CALL(cfd_, OnLoad(_)).Times(testing::AtMost(1)); |
| 231 | 231 |
| 232 EXPECT_CALL(cfd_, OnNavigationFailed(_, GURL(url))) | 232 EXPECT_CALL(cfd_, OnNavigationFailed(_, GURL(url))) |
| 233 .Times(1) | 233 .Times(1) |
| 234 .WillOnce(QUIT_LOOP_SOON(loop_, 2)); | 234 .WillOnce(QUIT_LOOP_SOON(loop_, base::TimeDelta::FromSeconds(2))); |
| 235 | 235 |
| 236 EXPECT_TRUE(client_->Initialize(&cfd_, launch_params_)); | 236 EXPECT_TRUE(client_->Initialize(&cfd_, launch_params_)); |
| 237 | 237 |
| 238 loop_.RunFor(kChromeLaunchTimeout); | 238 loop_.RunFor(kChromeLaunchTimeout); |
| 239 } | 239 } |
| 240 | 240 |
| 241 TEST_F(CFACMockTest, MockedCreateTabOk) { | 241 TEST_F(CFACMockTest, MockedCreateTabOk) { |
| 242 int timeout = 500; | 242 int timeout = 500; |
| 243 CreateTab(); | 243 CreateTab(); |
| 244 SetAutomationServerOk(1); | 244 SetAutomationServerOk(1); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 263 EXPECT_CALL(mock_proxy_, CancelAsync(_)).Times(testing::AnyNumber()); | 263 EXPECT_CALL(mock_proxy_, CancelAsync(_)).Times(testing::AnyNumber()); |
| 264 | 264 |
| 265 // Here we go! | 265 // Here we go! |
| 266 GURL empty; | 266 GURL empty; |
| 267 scoped_refptr<ChromeFrameLaunchParams> clp(new ChromeFrameLaunchParams( | 267 scoped_refptr<ChromeFrameLaunchParams> clp(new ChromeFrameLaunchParams( |
| 268 empty, empty, profile_path_, profile_path_.BaseName().value(), L"", | 268 empty, empty, profile_path_, profile_path_.BaseName().value(), L"", |
| 269 false, false, false, false)); | 269 false, false, false, false)); |
| 270 clp->set_launch_timeout(timeout); | 270 clp->set_launch_timeout(timeout); |
| 271 clp->set_version_check(false); | 271 clp->set_version_check(false); |
| 272 EXPECT_TRUE(client_->Initialize(&cfd_, clp)); | 272 EXPECT_TRUE(client_->Initialize(&cfd_, clp)); |
| 273 loop_.RunFor(10); | 273 loop_.RunFor(base::TimeDelta::FromSeconds(10)); |
| 274 | 274 |
| 275 EXPECT_CALL(mock_proxy_, ReleaseTabProxy(testing::Eq(tab_handle_))).Times(1); | 275 EXPECT_CALL(mock_proxy_, ReleaseTabProxy(testing::Eq(tab_handle_))).Times(1); |
| 276 client_->Uninitialize(); | 276 client_->Uninitialize(); |
| 277 } | 277 } |
| 278 | 278 |
| 279 TEST_F(CFACMockTest, MockedCreateTabFailed) { | 279 TEST_F(CFACMockTest, MockedCreateTabFailed) { |
| 280 HWND null_wnd = NULL; | 280 HWND null_wnd = NULL; |
| 281 SetAutomationServerOk(1); | 281 SetAutomationServerOk(1); |
| 282 | 282 |
| 283 EXPECT_CALL(mock_proxy_, server_version()).Times(testing::AnyNumber()) | 283 EXPECT_CALL(mock_proxy_, server_version()).Times(testing::AnyNumber()) |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 296 Set_CFD_LaunchFailed(AUTOMATION_CREATE_TAB_FAILED); | 296 Set_CFD_LaunchFailed(AUTOMATION_CREATE_TAB_FAILED); |
| 297 | 297 |
| 298 // Here we go! | 298 // Here we go! |
| 299 GURL empty; | 299 GURL empty; |
| 300 scoped_refptr<ChromeFrameLaunchParams> clp(new ChromeFrameLaunchParams( | 300 scoped_refptr<ChromeFrameLaunchParams> clp(new ChromeFrameLaunchParams( |
| 301 empty, empty, profile_path_, profile_path_.BaseName().value(), L"", | 301 empty, empty, profile_path_, profile_path_.BaseName().value(), L"", |
| 302 false, false, false, false)); | 302 false, false, false, false)); |
| 303 clp->set_launch_timeout(timeout_); | 303 clp->set_launch_timeout(timeout_); |
| 304 clp->set_version_check(false); | 304 clp->set_version_check(false); |
| 305 EXPECT_TRUE(client_->Initialize(&cfd_, clp)); | 305 EXPECT_TRUE(client_->Initialize(&cfd_, clp)); |
| 306 loop_.RunFor(4); | 306 loop_.RunFor(base::TimeDelta::FromSeconds(4)); |
| 307 client_->Uninitialize(); | 307 client_->Uninitialize(); |
| 308 } | 308 } |
| 309 | 309 |
| 310 class TestChromeFrameAutomationProxyImpl | 310 class TestChromeFrameAutomationProxyImpl |
| 311 : public ChromeFrameAutomationProxyImpl { | 311 : public ChromeFrameAutomationProxyImpl { |
| 312 public: | 312 public: |
| 313 TestChromeFrameAutomationProxyImpl() | 313 TestChromeFrameAutomationProxyImpl() |
| 314 // 1 is an unneeded timeout. | 314 // 1 is an unneeded timeout. |
| 315 : ChromeFrameAutomationProxyImpl( | 315 : ChromeFrameAutomationProxyImpl( |
| 316 NULL, AutomationProxy::GenerateChannelID(), 1) { | 316 NULL, AutomationProxy::GenerateChannelID(), 1) { |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 327 }; | 327 }; |
| 328 | 328 |
| 329 TEST_F(CFACMockTest, OnChannelErrorEmpty) { | 329 TEST_F(CFACMockTest, OnChannelErrorEmpty) { |
| 330 TestChromeFrameAutomationProxyImpl proxy; | 330 TestChromeFrameAutomationProxyImpl proxy; |
| 331 | 331 |
| 332 // No tabs should do nothing yet still not fail either. | 332 // No tabs should do nothing yet still not fail either. |
| 333 proxy.FakeChannelError(); | 333 proxy.FakeChannelError(); |
| 334 } | 334 } |
| 335 | 335 |
| 336 TEST_F(CFACMockTest, OnChannelError) { | 336 TEST_F(CFACMockTest, OnChannelError) { |
| 337 const base::TimeDelta loop_duration = base::TimeDelta::FromSeconds(11); | |
|
robertshield
2012/04/11 17:03:36
loop_duration -> loop_duration_seconds
grt (UTC plus 2)
2012/04/11 17:33:08
I disagree. That implies that |loop_duration|'s u
| |
| 337 TestChromeFrameAutomationProxyImpl proxy; | 338 TestChromeFrameAutomationProxyImpl proxy; |
| 338 returned_proxy_ = &proxy; | 339 returned_proxy_ = &proxy; |
| 339 | 340 |
| 340 GURL empty; | 341 GURL empty; |
| 341 scoped_refptr<ChromeFrameLaunchParams> clp(new ChromeFrameLaunchParams( | 342 scoped_refptr<ChromeFrameLaunchParams> clp(new ChromeFrameLaunchParams( |
| 342 empty, empty, profile_path_, profile_path_.BaseName().value(), L"", | 343 empty, empty, profile_path_, profile_path_.BaseName().value(), L"", |
| 343 false, false, false, false)); | 344 false, false, false, false)); |
| 344 clp->set_launch_timeout(1); // Unneeded timeout, but can't be 0. | 345 clp->set_launch_timeout(1); // Unneeded timeout, but can't be 0. |
| 345 clp->set_version_check(false); | 346 clp->set_version_check(false); |
| 346 | 347 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 358 // First, try a single tab and make sure the notification find its way to the | 359 // First, try a single tab and make sure the notification find its way to the |
| 359 // Chrome Frame Delegate. | 360 // Chrome Frame Delegate. |
| 360 StrictMock<MockCFDelegate> cfd1; | 361 StrictMock<MockCFDelegate> cfd1; |
| 361 scoped_refptr<ChromeFrameAutomationClient> client1; | 362 scoped_refptr<ChromeFrameAutomationClient> client1; |
| 362 client1 = new ChromeFrameAutomationClient; | 363 client1 = new ChromeFrameAutomationClient; |
| 363 client1->set_proxy_factory(&factory_); | 364 client1->set_proxy_factory(&factory_); |
| 364 | 365 |
| 365 EXPECT_CALL(cfd1, OnAutomationServerReady()).WillOnce(QUIT_LOOP(loop_)); | 366 EXPECT_CALL(cfd1, OnAutomationServerReady()).WillOnce(QUIT_LOOP(loop_)); |
| 366 EXPECT_TRUE(client1->Initialize(&cfd1, clp)); | 367 EXPECT_TRUE(client1->Initialize(&cfd1, clp)); |
| 367 // Wait for OnAutomationServerReady to be called in the UI thread. | 368 // Wait for OnAutomationServerReady to be called in the UI thread. |
| 368 loop_.RunFor(11); | 369 loop_.RunFor(loop_duration); |
| 369 | 370 |
| 370 proxy.FakeChannelError(); | 371 proxy.FakeChannelError(); |
| 371 EXPECT_CALL(cfd1, OnChannelError()).WillOnce(QUIT_LOOP(loop_)); | 372 EXPECT_CALL(cfd1, OnChannelError()).WillOnce(QUIT_LOOP(loop_)); |
| 372 // Wait for OnChannelError to be propagated to delegate from the UI thread. | 373 // Wait for OnChannelError to be propagated to delegate from the UI thread. |
| 373 loop_.RunFor(11); | 374 loop_.RunFor(loop_duration); |
| 374 | 375 |
| 375 // Add a second tab using a different delegate. | 376 // Add a second tab using a different delegate. |
| 376 StrictMock<MockCFDelegate> cfd2; | 377 StrictMock<MockCFDelegate> cfd2; |
| 377 scoped_refptr<ChromeFrameAutomationClient> client2; | 378 scoped_refptr<ChromeFrameAutomationClient> client2; |
| 378 client2 = new ChromeFrameAutomationClient; | 379 client2 = new ChromeFrameAutomationClient; |
| 379 client2->set_proxy_factory(&factory_); | 380 client2->set_proxy_factory(&factory_); |
| 380 | 381 |
| 381 EXPECT_CALL(cfd2, OnAutomationServerReady()).WillOnce(QUIT_LOOP(loop_)); | 382 EXPECT_CALL(cfd2, OnAutomationServerReady()).WillOnce(QUIT_LOOP(loop_)); |
| 382 EXPECT_TRUE(client2->Initialize(&cfd2, clp)); | 383 EXPECT_TRUE(client2->Initialize(&cfd2, clp)); |
| 383 // Wait for OnAutomationServerReady to be called in the UI thread. | 384 // Wait for OnAutomationServerReady to be called in the UI thread. |
| 384 loop_.RunFor(11); | 385 loop_.RunFor(loop_duration); |
| 385 | 386 |
| 386 EXPECT_CALL(cfd1, OnChannelError()).Times(1); | 387 EXPECT_CALL(cfd1, OnChannelError()).Times(1); |
| 387 EXPECT_CALL(cfd2, OnChannelError()).WillOnce(QUIT_LOOP(loop_)); | 388 EXPECT_CALL(cfd2, OnChannelError()).WillOnce(QUIT_LOOP(loop_)); |
| 388 proxy.FakeChannelError(); | 389 proxy.FakeChannelError(); |
| 389 // Wait for OnChannelError to be propagated to delegate from the UI thread. | 390 // Wait for OnChannelError to be propagated to delegate from the UI thread. |
| 390 loop_.RunFor(11); | 391 loop_.RunFor(loop_duration); |
| 391 | 392 |
| 392 // And now a 3rd tab using the first delegate. | 393 // And now a 3rd tab using the first delegate. |
| 393 scoped_refptr<ChromeFrameAutomationClient> client3; | 394 scoped_refptr<ChromeFrameAutomationClient> client3; |
| 394 client3 = new ChromeFrameAutomationClient; | 395 client3 = new ChromeFrameAutomationClient; |
| 395 client3->set_proxy_factory(&factory_); | 396 client3->set_proxy_factory(&factory_); |
| 396 | 397 |
| 397 EXPECT_CALL(cfd1, OnAutomationServerReady()).WillOnce(QUIT_LOOP(loop_)); | 398 EXPECT_CALL(cfd1, OnAutomationServerReady()).WillOnce(QUIT_LOOP(loop_)); |
| 398 EXPECT_TRUE(client3->Initialize(&cfd1, clp)); | 399 EXPECT_TRUE(client3->Initialize(&cfd1, clp)); |
| 399 // Wait for OnAutomationServerReady to be called in the UI thread. | 400 // Wait for OnAutomationServerReady to be called in the UI thread. |
| 400 loop_.RunFor(11); | 401 loop_.RunFor(loop_duration); |
| 401 | 402 |
| 402 EXPECT_CALL(cfd2, OnChannelError()).Times(1); | 403 EXPECT_CALL(cfd2, OnChannelError()).Times(1); |
| 403 EXPECT_CALL(cfd1, OnChannelError()).Times(2).WillOnce(Return()) | 404 EXPECT_CALL(cfd1, OnChannelError()).Times(2).WillOnce(Return()) |
| 404 .WillOnce(QUIT_LOOP(loop_)); | 405 .WillOnce(QUIT_LOOP(loop_)); |
| 405 proxy.FakeChannelError(); | 406 proxy.FakeChannelError(); |
| 406 // Wait for OnChannelError to be propagated to delegate from the UI thread. | 407 // Wait for OnChannelError to be propagated to delegate from the UI thread. |
| 407 loop_.RunFor(11); | 408 loop_.RunFor(loop_duration); |
| 408 | 409 |
| 409 // Cleanup. | 410 // Cleanup. |
| 410 client1->Uninitialize(); | 411 client1->Uninitialize(); |
| 411 client2->Uninitialize(); | 412 client2->Uninitialize(); |
| 412 client3->Uninitialize(); | 413 client3->Uninitialize(); |
| 413 client1 = NULL; | 414 client1 = NULL; |
| 414 client2 = NULL; | 415 client2 = NULL; |
| 415 client3 = NULL; | 416 client3 = NULL; |
| 416 } | 417 } |
| 417 | 418 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 457 | 458 |
| 458 // Here we go! | 459 // Here we go! |
| 459 GURL empty; | 460 GURL empty; |
| 460 scoped_refptr<ChromeFrameLaunchParams> launch_params( | 461 scoped_refptr<ChromeFrameLaunchParams> launch_params( |
| 461 new ChromeFrameLaunchParams( | 462 new ChromeFrameLaunchParams( |
| 462 GURL("http://www.nonexistent.com"), empty, profile_path_, | 463 GURL("http://www.nonexistent.com"), empty, profile_path_, |
| 463 profile_path_.BaseName().value(), L"", false, false, false, false)); | 464 profile_path_.BaseName().value(), L"", false, false, false, false)); |
| 464 launch_params->set_launch_timeout(timeout); | 465 launch_params->set_launch_timeout(timeout); |
| 465 launch_params->set_version_check(false); | 466 launch_params->set_version_check(false); |
| 466 EXPECT_TRUE(client_->Initialize(&cfd_, launch_params)); | 467 EXPECT_TRUE(client_->Initialize(&cfd_, launch_params)); |
| 467 loop_.RunFor(10); | 468 loop_.RunFor(base::TimeDelta::FromSeconds(10)); |
| 468 | 469 |
| 469 EXPECT_CALL(mock_proxy_, ReleaseTabProxy(testing::Eq(tab_handle_))).Times(1); | 470 EXPECT_CALL(mock_proxy_, ReleaseTabProxy(testing::Eq(tab_handle_))).Times(1); |
| 470 client_->Uninitialize(); | 471 client_->Uninitialize(); |
| 471 } | 472 } |
| OLD | NEW |