| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #include "chrome_frame/test/automation_client_mock.h" | 4 #include "chrome_frame/test/automation_client_mock.h" |
| 5 | 5 |
| 6 #include "base/callback.h" | 6 #include "base/callback.h" |
| 7 #include "chrome_frame/custom_sync_call_context.h" |
| 8 #include "chrome_frame/navigation_constraints.h" |
| 9 #include "chrome_frame/test/chrome_frame_test_utils.h" |
| 7 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
| 8 #include "chrome_frame/custom_sync_call_context.h" | |
| 9 #include "chrome_frame/test/chrome_frame_test_utils.h" | |
| 10 | 11 |
| 11 #define GMOCK_MUTANT_INCLUDE_LATE_OBJECT_BINDING | 12 #define GMOCK_MUTANT_INCLUDE_LATE_OBJECT_BINDING |
| 12 #include "testing/gmock_mutant.h" | 13 #include "testing/gmock_mutant.h" |
| 13 | 14 |
| 14 using testing::_; | 15 using testing::_; |
| 15 using testing::CreateFunctor; | 16 using testing::CreateFunctor; |
| 16 using testing::Return; | 17 using testing::Return; |
| 17 | 18 |
| 18 DISABLE_RUNNABLE_METHOD_REFCOUNT(LaunchDelegate); | 19 DISABLE_RUNNABLE_METHOD_REFCOUNT(LaunchDelegate); |
| 19 DISABLE_RUNNABLE_METHOD_REFCOUNT(ChromeFrameAutomationClient); | 20 DISABLE_RUNNABLE_METHOD_REFCOUNT(ChromeFrameAutomationClient); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 CreateExternalTabContext::output_type input_args(tab_wnd, | 79 CreateExternalTabContext::output_type input_args(tab_wnd, |
| 79 external_tab_container, | 80 external_tab_container, |
| 80 tab_handle, | 81 tab_handle, |
| 81 session_id); | 82 session_id); |
| 82 CreateExternalTabContext* context = | 83 CreateExternalTabContext* context = |
| 83 reinterpret_cast<CreateExternalTabContext*>(arg1); | 84 reinterpret_cast<CreateExternalTabContext*>(arg1); |
| 84 DispatchToMethod(context, &CreateExternalTabContext::Completed, input_args); | 85 DispatchToMethod(context, &CreateExternalTabContext::Completed, input_args); |
| 85 delete context; | 86 delete context; |
| 86 } | 87 } |
| 87 | 88 |
| 88 ACTION_P4(InitiateNavigation, client, url, referrer, privileged) { | 89 ACTION_P4(InitiateNavigation, client, url, referrer, constraints) { |
| 89 client->InitiateNavigation(url, referrer, privileged); | 90 client->InitiateNavigation(url, referrer, constraints); |
| 90 } | 91 } |
| 91 | 92 |
| 92 // We mock ChromeFrameDelegate only. The rest is with real AutomationProxy | 93 // We mock ChromeFrameDelegate only. The rest is with real AutomationProxy |
| 93 TEST(CFACWithChrome, CreateTooFast) { | 94 TEST(CFACWithChrome, CreateTooFast) { |
| 94 MockCFDelegate cfd; | 95 MockCFDelegate cfd; |
| 95 chrome_frame_test::TimedMsgLoop loop; | 96 chrome_frame_test::TimedMsgLoop loop; |
| 96 int timeout = 0; // Chrome cannot send Hello message so fast. | 97 int timeout = 0; // Chrome cannot send Hello message so fast. |
| 97 const FilePath profile_path( | 98 const FilePath profile_path( |
| 98 chrome_frame_test::GetProfilePath(L"Adam.N.Epilinter")); | 99 chrome_frame_test::GetProfilePath(L"Adam.N.Epilinter")); |
| 99 | 100 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 clp->set_version_check(false); | 145 clp->set_version_check(false); |
| 145 EXPECT_TRUE(client->Initialize(&cfd, clp)); | 146 EXPECT_TRUE(client->Initialize(&cfd, clp)); |
| 146 | 147 |
| 147 loop.RunFor(11); | 148 loop.RunFor(11); |
| 148 client->Uninitialize(); | 149 client->Uninitialize(); |
| 149 client = NULL; | 150 client = NULL; |
| 150 } | 151 } |
| 151 | 152 |
| 152 TEST(CFACWithChrome, NavigateOk) { | 153 TEST(CFACWithChrome, NavigateOk) { |
| 153 MockCFDelegate cfd; | 154 MockCFDelegate cfd; |
| 155 NavigationConstraintsImpl navigation_constraints; |
| 156 |
| 154 chrome_frame_test::TimedMsgLoop loop; | 157 chrome_frame_test::TimedMsgLoop loop; |
| 155 const std::string url = "about:version"; | 158 const std::string url = "about:version"; |
| 156 const FilePath profile_path( | 159 const FilePath profile_path( |
| 157 chrome_frame_test::GetProfilePath(L"Adam.N.Epilinter")); | 160 chrome_frame_test::GetProfilePath(L"Adam.N.Epilinter")); |
| 158 int timeout = 10000; | 161 int timeout = 10000; |
| 159 | 162 |
| 160 scoped_refptr<ChromeFrameAutomationClient> client; | 163 scoped_refptr<ChromeFrameAutomationClient> client; |
| 161 client = new ChromeFrameAutomationClient; | 164 client = new ChromeFrameAutomationClient; |
| 162 | 165 |
| 163 EXPECT_CALL(cfd, OnAutomationServerReady()) | 166 EXPECT_CALL(cfd, OnAutomationServerReady()) |
| 164 .WillOnce(InitiateNavigation(client.get(), | 167 .WillOnce(InitiateNavigation(client.get(), |
| 165 url, std::string(), false)); | 168 url, std::string(), |
| 169 &navigation_constraints)); |
| 166 | 170 |
| 167 EXPECT_CALL(cfd, GetBounds(_)).Times(testing::AnyNumber()); | 171 EXPECT_CALL(cfd, GetBounds(_)).Times(testing::AnyNumber()); |
| 168 | 172 |
| 169 EXPECT_CALL(cfd, OnNavigationStateChanged(_, _)) | 173 EXPECT_CALL(cfd, OnNavigationStateChanged(_, _)) |
| 170 .Times(testing::AnyNumber()); | 174 .Times(testing::AnyNumber()); |
| 171 | 175 |
| 172 { | 176 { |
| 173 testing::InSequence s; | 177 testing::InSequence s; |
| 174 | 178 |
| 175 EXPECT_CALL(cfd, OnDidNavigate(_, EqNavigationInfoUrl(GURL()))) | 179 EXPECT_CALL(cfd, OnDidNavigate(_, EqNavigationInfoUrl(GURL()))) |
| (...skipping 13 matching lines...) Expand all Loading... |
| 189 clp->set_launch_timeout(timeout); | 193 clp->set_launch_timeout(timeout); |
| 190 clp->set_version_check(false); | 194 clp->set_version_check(false); |
| 191 EXPECT_TRUE(client->Initialize(&cfd, clp)); | 195 EXPECT_TRUE(client->Initialize(&cfd, clp)); |
| 192 loop.RunFor(10); | 196 loop.RunFor(10); |
| 193 client->Uninitialize(); | 197 client->Uninitialize(); |
| 194 client = NULL; | 198 client = NULL; |
| 195 } | 199 } |
| 196 | 200 |
| 197 TEST(CFACWithChrome, NavigateFailed) { | 201 TEST(CFACWithChrome, NavigateFailed) { |
| 198 MockCFDelegate cfd; | 202 MockCFDelegate cfd; |
| 203 NavigationConstraintsImpl navigation_constraints; |
| 199 chrome_frame_test::TimedMsgLoop loop; | 204 chrome_frame_test::TimedMsgLoop loop; |
| 200 const FilePath profile_path( | 205 const FilePath profile_path( |
| 201 chrome_frame_test::GetProfilePath(L"Adam.N.Epilinter")); | 206 chrome_frame_test::GetProfilePath(L"Adam.N.Epilinter")); |
| 202 const std::string url = "http://127.0.0.3:65412/"; | 207 const std::string url = "http://127.0.0.3:65412/"; |
| 203 const URLRequestStatus connection_failed(URLRequestStatus::FAILED, | 208 const URLRequestStatus connection_failed(URLRequestStatus::FAILED, |
| 204 net::ERR_INVALID_URL); | 209 net::ERR_INVALID_URL); |
| 205 | 210 |
| 206 scoped_refptr<ChromeFrameAutomationClient> client; | 211 scoped_refptr<ChromeFrameAutomationClient> client; |
| 207 client = new ChromeFrameAutomationClient; | 212 client = new ChromeFrameAutomationClient; |
| 208 cfd.SetRequestDelegate(client); | 213 cfd.SetRequestDelegate(client); |
| 209 | 214 |
| 210 EXPECT_CALL(cfd, OnAutomationServerReady()) | 215 EXPECT_CALL(cfd, OnAutomationServerReady()) |
| 211 .WillOnce(testing::IgnoreResult(testing::InvokeWithoutArgs(CreateFunctor( | 216 .WillOnce(testing::IgnoreResult(testing::InvokeWithoutArgs(CreateFunctor( |
| 212 client.get(), &ChromeFrameAutomationClient::InitiateNavigation, | 217 client.get(), &ChromeFrameAutomationClient::InitiateNavigation, |
| 213 url, std::string(), false)))); | 218 url, std::string(), &navigation_constraints)))); |
| 214 | 219 |
| 215 EXPECT_CALL(cfd, GetBounds(_)).Times(testing::AnyNumber()); | 220 EXPECT_CALL(cfd, GetBounds(_)).Times(testing::AnyNumber()); |
| 216 EXPECT_CALL(cfd, OnNavigationStateChanged(_, _)).Times(testing::AnyNumber()); | 221 EXPECT_CALL(cfd, OnNavigationStateChanged(_, _)).Times(testing::AnyNumber()); |
| 217 | 222 |
| 218 EXPECT_CALL(cfd, OnRequestStart(_, _, _)) | 223 EXPECT_CALL(cfd, OnRequestStart(_, _, _)) |
| 219 // Often there's another request for the error page | 224 // Often there's another request for the error page |
| 220 .Times(testing::Between(1, 2)) | 225 .Times(testing::Between(1, 2)) |
| 221 .WillRepeatedly(testing::WithArgs<1>(testing::Invoke(CreateFunctor(&cfd, | 226 .WillRepeatedly(testing::WithArgs<1>(testing::Invoke(CreateFunctor(&cfd, |
| 222 &MockCFDelegate::Reply, connection_failed)))); | 227 &MockCFDelegate::Reply, connection_failed)))); |
| 223 | 228 |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 client1->Uninitialize(); | 418 client1->Uninitialize(); |
| 414 client2->Uninitialize(); | 419 client2->Uninitialize(); |
| 415 client3->Uninitialize(); | 420 client3->Uninitialize(); |
| 416 client1 = NULL; | 421 client1 = NULL; |
| 417 client2 = NULL; | 422 client2 = NULL; |
| 418 client3 = NULL; | 423 client3 = NULL; |
| 419 } | 424 } |
| 420 | 425 |
| 421 TEST_F(CFACMockTest, NavigateTwiceAfterInitToSameUrl) { | 426 TEST_F(CFACMockTest, NavigateTwiceAfterInitToSameUrl) { |
| 422 int timeout = 500; | 427 int timeout = 500; |
| 428 NavigationConstraintsImpl navigation_constraints; |
| 429 |
| 423 CreateTab(); | 430 CreateTab(); |
| 424 SetAutomationServerOk(1); | 431 SetAutomationServerOk(1); |
| 425 | 432 |
| 426 EXPECT_CALL(mock_proxy_, server_version()).Times(testing::AnyNumber()) | 433 EXPECT_CALL(mock_proxy_, server_version()).Times(testing::AnyNumber()) |
| 427 .WillRepeatedly(Return("")); | 434 .WillRepeatedly(Return("")); |
| 428 | 435 |
| 429 // We need some valid HWNDs, when responding to CreateExternalTab | 436 // We need some valid HWNDs, when responding to CreateExternalTab |
| 430 HWND h1 = ::GetDesktopWindow(); | 437 HWND h1 = ::GetDesktopWindow(); |
| 431 HWND h2 = ::GetDesktopWindow(); | 438 HWND h2 = ::GetDesktopWindow(); |
| 432 EXPECT_CALL(mock_proxy_, SendAsAsync(testing::Property( | 439 EXPECT_CALL(mock_proxy_, SendAsAsync(testing::Property( |
| 433 &IPC::SyncMessage::type, AutomationMsg_CreateExternalTab::ID), | 440 &IPC::SyncMessage::type, AutomationMsg_CreateExternalTab::ID), |
| 434 testing::NotNull(), _)) | 441 testing::NotNull(), _)) |
| 435 .Times(1).WillOnce(HandleCreateTab(tab_handle_, h1, h2, 99)); | 442 .Times(1).WillOnce(HandleCreateTab(tab_handle_, h1, h2, 99)); |
| 436 | 443 |
| 437 EXPECT_CALL(mock_proxy_, CreateTabProxy(testing::Eq(tab_handle_))) | 444 EXPECT_CALL(mock_proxy_, CreateTabProxy(testing::Eq(tab_handle_))) |
| 438 .WillOnce(Return(tab_)); | 445 .WillOnce(Return(tab_)); |
| 439 | 446 |
| 440 EXPECT_CALL(cfd_, OnAutomationServerReady()) | 447 EXPECT_CALL(cfd_, OnAutomationServerReady()) |
| 441 .WillOnce(InitiateNavigation(client_.get(), | 448 .WillOnce(InitiateNavigation(client_.get(), |
| 442 std::string("http://www.nonexistent.com"), | 449 std::string("http://www.nonexistent.com"), |
| 443 std::string(), false)); | 450 std::string(), &navigation_constraints)); |
| 444 | 451 |
| 445 EXPECT_CALL(mock_proxy_, SendAsAsync(testing::Property( | 452 EXPECT_CALL(mock_proxy_, SendAsAsync(testing::Property( |
| 446 &IPC::SyncMessage::type, AutomationMsg_NavigateInExternalTab::ID), | 453 &IPC::SyncMessage::type, AutomationMsg_NavigateInExternalTab::ID), |
| 447 testing::NotNull(), _)) | 454 testing::NotNull(), _)) |
| 448 .Times(1).WillOnce(QUIT_LOOP(loop_)); | 455 .Times(1).WillOnce(QUIT_LOOP(loop_)); |
| 449 | 456 |
| 450 EXPECT_CALL(mock_proxy_, CancelAsync(_)).Times(testing::AnyNumber()); | 457 EXPECT_CALL(mock_proxy_, CancelAsync(_)).Times(testing::AnyNumber()); |
| 451 | 458 |
| 452 EXPECT_CALL(mock_proxy_, Send( | 459 EXPECT_CALL(mock_proxy_, Send( |
| 453 testing::Property(&IPC::Message::type, AutomationMsg_TabReposition::ID))) | 460 testing::Property(&IPC::Message::type, AutomationMsg_TabReposition::ID))) |
| 454 .Times(1) | 461 .Times(1) |
| 455 .WillOnce(Return(true)); | 462 .WillOnce(Return(true)); |
| 456 | 463 |
| 457 EXPECT_CALL(cfd_, GetBounds(_)).Times(1); | 464 EXPECT_CALL(cfd_, GetBounds(_)).Times(1); |
| 458 | 465 |
| 459 // Here we go! | 466 // Here we go! |
| 460 GURL empty; | 467 GURL empty; |
| 461 scoped_refptr<ChromeFrameLaunchParams> launch_params( | 468 scoped_refptr<ChromeFrameLaunchParams> launch_params( |
| 462 new ChromeFrameLaunchParams( | 469 new ChromeFrameLaunchParams( |
| 463 GURL("http://www.nonexistent.com"), empty, profile_path_, | 470 GURL("http://www.nonexistent.com"), empty, profile_path_, |
| 464 profile_path_.BaseName().value(), L"", L"", false, false, false)); | 471 profile_path_.BaseName().value(), L"", L"", false, false, false)); |
| 465 launch_params->set_launch_timeout(timeout); | 472 launch_params->set_launch_timeout(timeout); |
| 466 launch_params->set_version_check(false); | 473 launch_params->set_version_check(false); |
| 467 EXPECT_TRUE(client_->Initialize(&cfd_, launch_params)); | 474 EXPECT_TRUE(client_->Initialize(&cfd_, launch_params)); |
| 468 loop_.RunFor(10); | 475 loop_.RunFor(10); |
| 469 | 476 |
| 470 EXPECT_CALL(mock_proxy_, ReleaseTabProxy(testing::Eq(tab_handle_))).Times(1); | 477 EXPECT_CALL(mock_proxy_, ReleaseTabProxy(testing::Eq(tab_handle_))).Times(1); |
| 471 client_->Uninitialize(); | 478 client_->Uninitialize(); |
| 472 } | 479 } |
| OLD | NEW |