| 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 "net/base/net_errors.h" | 14 #include "net/base/net_errors.h" |
| 14 | 15 |
| 15 #define GMOCK_MUTANT_INCLUDE_LATE_OBJECT_BINDING | 16 #define GMOCK_MUTANT_INCLUDE_LATE_OBJECT_BINDING |
| 16 #include "testing/gmock_mutant.h" | 17 #include "testing/gmock_mutant.h" |
| 17 | 18 |
| 18 using testing::_; | 19 using testing::_; |
| 19 using testing::CreateFunctor; | 20 using testing::CreateFunctor; |
| 20 using testing::Return; | 21 using testing::Return; |
| 21 | 22 |
| 23 namespace { |
| 24 |
| 25 #ifndef NDEBUG |
| 26 const int kChromeLaunchTimeout = 15; |
| 27 #else |
| 28 const int kChromeLaunchTimeout = 10; |
| 29 #endif |
| 30 |
| 31 const int kSaneAutomationTimeoutMs = 10 * 1000; |
| 32 |
| 33 } // namespace |
| 34 |
| 22 MATCHER_P(LaunchParamProfileEq, profile_name, "Check for profile name") { | 35 MATCHER_P(LaunchParamProfileEq, profile_name, "Check for profile name") { |
| 23 return arg->profile_name().compare(profile_name) == 0; | 36 return arg->profile_name().compare(profile_name) == 0; |
| 24 } | 37 } |
| 25 | 38 |
| 26 void MockProxyFactory::GetServerImpl(ChromeFrameAutomationProxy* pxy, | 39 void MockProxyFactory::GetServerImpl(ChromeFrameAutomationProxy* pxy, |
| 27 void* proxy_id, | 40 void* proxy_id, |
| 28 AutomationLaunchResult result, | 41 AutomationLaunchResult result, |
| 29 LaunchDelegate* d, | 42 LaunchDelegate* d, |
| 30 ChromeFrameLaunchParams* params, | 43 ChromeFrameLaunchParams* params, |
| 31 void** automation_server_id) { | 44 void** automation_server_id) { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 CreateExternalTabContext* context = | 95 CreateExternalTabContext* context = |
| 83 reinterpret_cast<CreateExternalTabContext*>(arg1); | 96 reinterpret_cast<CreateExternalTabContext*>(arg1); |
| 84 DispatchToMethod(context, &CreateExternalTabContext::Completed, input_args); | 97 DispatchToMethod(context, &CreateExternalTabContext::Completed, input_args); |
| 85 delete context; | 98 delete context; |
| 86 } | 99 } |
| 87 | 100 |
| 88 ACTION_P4(InitiateNavigation, client, url, referrer, constraints) { | 101 ACTION_P4(InitiateNavigation, client, url, referrer, constraints) { |
| 89 client->InitiateNavigation(url, referrer, constraints); | 102 client->InitiateNavigation(url, referrer, constraints); |
| 90 } | 103 } |
| 91 | 104 |
| 105 // ChromeFrameAutomationClient tests that launch Chrome. |
| 106 class CFACWithChrome : public testing::Test { |
| 107 protected: |
| 108 static void SetUpTestCase(); |
| 109 static void TearDownTestCase(); |
| 110 |
| 111 virtual void SetUp() OVERRIDE; |
| 112 virtual void TearDown() OVERRIDE; |
| 113 |
| 114 static FilePath profile_path_; |
| 115 MockCFDelegate cfd_; |
| 116 scoped_refptr<ChromeFrameAutomationClient> client_; |
| 117 scoped_refptr<ChromeFrameLaunchParams> launch_params_; |
| 118 chrome_frame_test::TimedMsgLoop loop_; |
| 119 }; |
| 120 |
| 121 // static |
| 122 FilePath CFACWithChrome::profile_path_; |
| 123 |
| 124 // static |
| 125 void CFACWithChrome::SetUpTestCase() { |
| 126 profile_path_ = chrome_frame_test::GetProfilePath(L"Adam.N.Epilinter"); |
| 127 } |
| 128 |
| 129 // static |
| 130 void CFACWithChrome::TearDownTestCase() { |
| 131 profile_path_.clear(); |
| 132 } |
| 133 |
| 134 void CFACWithChrome::SetUp() { |
| 135 chrome_frame_test::OverrideDataDirectoryForThisTest(profile_path_.value()); |
| 136 client_ = new ChromeFrameAutomationClient(); |
| 137 GURL empty; |
| 138 launch_params_ = new ChromeFrameLaunchParams( |
| 139 empty, empty, profile_path_, profile_path_.BaseName().value(), L"", |
| 140 false, false, false); |
| 141 launch_params_->set_version_check(false); |
| 142 launch_params_->set_launch_timeout(kSaneAutomationTimeoutMs); |
| 143 } |
| 144 |
| 145 void CFACWithChrome::TearDown() { |
| 146 client_->Uninitialize(); |
| 147 } |
| 148 |
| 92 // We mock ChromeFrameDelegate only. The rest is with real AutomationProxy | 149 // We mock ChromeFrameDelegate only. The rest is with real AutomationProxy |
| 93 TEST(CFACWithChrome, CreateTooFast) { | 150 TEST_F(CFACWithChrome, CreateTooFast) { |
| 94 MockCFDelegate cfd; | |
| 95 chrome_frame_test::TimedMsgLoop loop; | |
| 96 int timeout = 0; // Chrome cannot send Hello message so fast. | 151 int timeout = 0; // Chrome cannot send Hello message so fast. |
| 97 const FilePath profile_path( | |
| 98 chrome_frame_test::GetProfilePath(L"Adam.N.Epilinter")); | |
| 99 | 152 |
| 100 scoped_refptr<ChromeFrameAutomationClient> client; | 153 EXPECT_CALL(cfd_, OnAutomationServerLaunchFailed(AUTOMATION_TIMEOUT, _)) |
| 101 client = new ChromeFrameAutomationClient(); | 154 .WillOnce(QUIT_LOOP(loop_)); |
| 102 | 155 |
| 103 EXPECT_CALL(cfd, OnAutomationServerLaunchFailed(AUTOMATION_TIMEOUT, _)) | 156 launch_params_->set_launch_timeout(timeout); |
| 104 .Times(1) | 157 EXPECT_TRUE(client_->Initialize(&cfd_, launch_params_)); |
| 105 .WillOnce(QUIT_LOOP(loop)); | 158 loop_.RunFor(kChromeLaunchTimeout); |
| 106 | |
| 107 GURL empty; | |
| 108 scoped_refptr<ChromeFrameLaunchParams> clp(new ChromeFrameLaunchParams( | |
| 109 empty, empty, profile_path, profile_path.BaseName().value(), L"", | |
| 110 false, false, false)); | |
| 111 clp->set_launch_timeout(timeout); | |
| 112 clp->set_version_check(false); | |
| 113 EXPECT_TRUE(client->Initialize(&cfd, clp)); | |
| 114 loop.RunFor(10); | |
| 115 client->Uninitialize(); | |
| 116 } | 159 } |
| 117 | 160 |
| 118 // This test may fail if Chrome take more that 10 seconds (timeout var) to | 161 // This test may fail if Chrome take more that 10 seconds (timeout var) to |
| 119 // launch. In this case GMock shall print something like "unexpected call to | 162 // launch. In this case GMock shall print something like "unexpected call to |
| 120 // OnAutomationServerLaunchFailed". I'm yet to find out how to specify | 163 // OnAutomationServerLaunchFailed". I'm yet to find out how to specify |
| 121 // that this is an unexpected call, and still to execute an action. | 164 // that this is an unexpected call, and still to execute an action. |
| 122 TEST(CFACWithChrome, CreateNotSoFast) { | 165 TEST_F(CFACWithChrome, CreateNotSoFast) { |
| 123 MockCFDelegate cfd; | 166 EXPECT_CALL(cfd_, OnAutomationServerReady()) |
| 124 chrome_frame_test::TimedMsgLoop loop; | 167 .WillOnce(QUIT_LOOP(loop_)); |
| 125 const FilePath profile_path( | |
| 126 chrome_frame_test::GetProfilePath(L"Adam.N.Epilinter")); | |
| 127 int timeout = 10000; | |
| 128 | 168 |
| 129 scoped_refptr<ChromeFrameAutomationClient> client; | 169 EXPECT_CALL(cfd_, OnAutomationServerLaunchFailed(_, _)) |
| 130 client = new ChromeFrameAutomationClient; | |
| 131 | |
| 132 EXPECT_CALL(cfd, OnAutomationServerReady()) | |
| 133 .Times(1) | |
| 134 .WillOnce(QUIT_LOOP(loop)); | |
| 135 | |
| 136 EXPECT_CALL(cfd, OnAutomationServerLaunchFailed(_, _)) | |
| 137 .Times(0); | 170 .Times(0); |
| 138 | 171 |
| 139 GURL empty; | 172 EXPECT_TRUE(client_->Initialize(&cfd_, launch_params_)); |
| 140 scoped_refptr<ChromeFrameLaunchParams> clp(new ChromeFrameLaunchParams( | |
| 141 empty, empty, profile_path, profile_path.BaseName().value(), L"", | |
| 142 false, false, false)); | |
| 143 clp->set_launch_timeout(timeout); | |
| 144 clp->set_version_check(false); | |
| 145 EXPECT_TRUE(client->Initialize(&cfd, clp)); | |
| 146 | 173 |
| 147 loop.RunFor(11); | 174 loop_.RunFor(kChromeLaunchTimeout); |
| 148 client->Uninitialize(); | |
| 149 client = NULL; | |
| 150 } | 175 } |
| 151 | 176 |
| 152 // FLAKY: 114386. | 177 TEST_F(CFACWithChrome, NavigateOk) { |
| 153 TEST(CFACWithChrome, DISABLED_NavigateOk) { | |
| 154 MockCFDelegate cfd; | |
| 155 NavigationConstraintsImpl navigation_constraints; | 178 NavigationConstraintsImpl navigation_constraints; |
| 156 | 179 |
| 157 chrome_frame_test::TimedMsgLoop loop; | |
| 158 const std::string url = "about:version"; | 180 const std::string url = "about:version"; |
| 159 const FilePath profile_path( | |
| 160 chrome_frame_test::GetProfilePath(L"Adam.N.Epilinter")); | |
| 161 int timeout = 10000; | |
| 162 | 181 |
| 163 scoped_refptr<ChromeFrameAutomationClient> client; | 182 EXPECT_CALL(cfd_, OnAutomationServerReady()) |
| 164 client = new ChromeFrameAutomationClient; | 183 .WillOnce(InitiateNavigation(client_.get(), url, std::string(), |
| 165 | |
| 166 EXPECT_CALL(cfd, OnAutomationServerReady()) | |
| 167 .WillOnce(InitiateNavigation(client.get(), | |
| 168 url, std::string(), | |
| 169 &navigation_constraints)); | 184 &navigation_constraints)); |
| 170 | 185 |
| 171 EXPECT_CALL(cfd, GetBounds(_)).Times(testing::AnyNumber()); | 186 EXPECT_CALL(cfd_, GetBounds(_)).Times(testing::AnyNumber()); |
| 172 | 187 |
| 173 EXPECT_CALL(cfd, OnNavigationStateChanged(_)) | 188 EXPECT_CALL(cfd_, OnNavigationStateChanged(_)) |
| 174 .Times(testing::AnyNumber()); | 189 .Times(testing::AnyNumber()); |
| 175 | 190 |
| 176 { | 191 { |
| 177 testing::InSequence s; | 192 testing::InSequence s; |
| 178 | 193 |
| 179 EXPECT_CALL(cfd, OnDidNavigate(EqNavigationInfoUrl(GURL()))) | 194 EXPECT_CALL(cfd_, OnDidNavigate(EqNavigationInfoUrl(GURL()))) |
| 180 .Times(1); | 195 .Times(1); |
| 181 | 196 |
| 182 EXPECT_CALL(cfd, OnUpdateTargetUrl(_)).Times(testing::AtMost(1)); | 197 EXPECT_CALL(cfd_, OnUpdateTargetUrl(_)).Times(testing::AtMost(1)); |
| 183 | 198 |
| 184 EXPECT_CALL(cfd, OnLoad(_)) | 199 EXPECT_CALL(cfd_, OnLoad(_)) |
| 185 .Times(1) | 200 .WillOnce(QUIT_LOOP(loop_)); |
| 186 .WillOnce(QUIT_LOOP(loop)); | |
| 187 } | 201 } |
| 188 | 202 |
| 189 GURL empty; | 203 EXPECT_TRUE(client_->Initialize(&cfd_, launch_params_)); |
| 190 scoped_refptr<ChromeFrameLaunchParams> clp(new ChromeFrameLaunchParams( | 204 loop_.RunFor(kChromeLaunchTimeout); |
| 191 empty, empty, profile_path, profile_path.BaseName().value(), L"", | |
| 192 false, false, false)); | |
| 193 clp->set_launch_timeout(timeout); | |
| 194 clp->set_version_check(false); | |
| 195 EXPECT_TRUE(client->Initialize(&cfd, clp)); | |
| 196 loop.RunFor(10); | |
| 197 client->Uninitialize(); | |
| 198 client = NULL; | |
| 199 } | 205 } |
| 200 | 206 |
| 201 // FLAKY: 114386. | 207 TEST_F(CFACWithChrome, NavigateFailed) { |
| 202 TEST(CFACWithChrome, DISABLED_NavigateFailed) { | |
| 203 MockCFDelegate cfd; | |
| 204 NavigationConstraintsImpl navigation_constraints; | 208 NavigationConstraintsImpl navigation_constraints; |
| 205 chrome_frame_test::TimedMsgLoop loop; | |
| 206 const FilePath profile_path( | |
| 207 chrome_frame_test::GetProfilePath(L"Adam.N.Epilinter")); | |
| 208 const std::string url = "http://127.0.0.3:65412/"; | 209 const std::string url = "http://127.0.0.3:65412/"; |
| 209 const net::URLRequestStatus connection_failed(net::URLRequestStatus::FAILED, | 210 const net::URLRequestStatus connection_failed(net::URLRequestStatus::FAILED, |
| 210 net::ERR_INVALID_URL); | 211 net::ERR_INVALID_URL); |
| 211 | 212 |
| 212 scoped_refptr<ChromeFrameAutomationClient> client; | 213 cfd_.SetRequestDelegate(client_); |
| 213 client = new ChromeFrameAutomationClient; | |
| 214 cfd.SetRequestDelegate(client); | |
| 215 | 214 |
| 216 EXPECT_CALL(cfd, OnAutomationServerReady()) | 215 EXPECT_CALL(cfd_, OnAutomationServerReady()) |
| 217 .WillOnce(testing::IgnoreResult(testing::InvokeWithoutArgs(CreateFunctor( | 216 .WillOnce(testing::IgnoreResult(testing::InvokeWithoutArgs(CreateFunctor( |
| 218 client.get(), &ChromeFrameAutomationClient::InitiateNavigation, | 217 client_.get(), &ChromeFrameAutomationClient::InitiateNavigation, |
| 219 url, std::string(), &navigation_constraints)))); | 218 url, std::string(), &navigation_constraints)))); |
| 220 | 219 |
| 221 EXPECT_CALL(cfd, GetBounds(_)).Times(testing::AnyNumber()); | 220 EXPECT_CALL(cfd_, GetBounds(_)).Times(testing::AnyNumber()); |
| 222 EXPECT_CALL(cfd, OnNavigationStateChanged(_)).Times(testing::AnyNumber()); | 221 EXPECT_CALL(cfd_, OnNavigationStateChanged(_)).Times(testing::AnyNumber()); |
| 223 | 222 |
| 224 EXPECT_CALL(cfd, OnRequestStart(_, _)) | 223 EXPECT_CALL(cfd_, OnRequestStart(_, _)) |
| 225 // Often there's another request for the error page | 224 // Often there's another request for the error page |
| 226 .Times(testing::Between(1, 2)) | 225 .Times(testing::Between(1, 2)) |
| 227 .WillRepeatedly(testing::WithArgs<0>(testing::Invoke(CreateFunctor(&cfd, | 226 .WillRepeatedly(testing::WithArgs<0>(testing::Invoke(CreateFunctor(&cfd_, |
| 228 &MockCFDelegate::Reply, connection_failed)))); | 227 &MockCFDelegate::Reply, connection_failed)))); |
| 229 | 228 |
| 230 EXPECT_CALL(cfd, OnUpdateTargetUrl(_)).Times(testing::AnyNumber()); | 229 EXPECT_CALL(cfd_, OnUpdateTargetUrl(_)).Times(testing::AnyNumber()); |
| 231 EXPECT_CALL(cfd, OnLoad(_)).Times(testing::AtMost(1)); | 230 EXPECT_CALL(cfd_, OnLoad(_)).Times(testing::AtMost(1)); |
| 232 | 231 |
| 233 EXPECT_CALL(cfd, OnNavigationFailed(_, GURL(url))) | 232 EXPECT_CALL(cfd_, OnNavigationFailed(_, GURL(url))) |
| 234 .Times(1) | 233 .Times(1) |
| 235 .WillOnce(QUIT_LOOP_SOON(loop, 2)); | 234 .WillOnce(QUIT_LOOP_SOON(loop_, 2)); |
| 236 | 235 |
| 237 GURL empty; | 236 EXPECT_TRUE(client_->Initialize(&cfd_, launch_params_)); |
| 238 scoped_refptr<ChromeFrameLaunchParams> clp(new ChromeFrameLaunchParams( | |
| 239 empty, empty, profile_path, profile_path.BaseName().value(), L"", | |
| 240 false, false, false)); | |
| 241 clp->set_launch_timeout(10000); | |
| 242 clp->set_version_check(false); | |
| 243 EXPECT_TRUE(client->Initialize(&cfd, clp)); | |
| 244 | 237 |
| 245 loop.RunFor(10); | 238 loop_.RunFor(kChromeLaunchTimeout); |
| 246 client->Uninitialize(); | |
| 247 client = NULL; | |
| 248 } | 239 } |
| 249 | 240 |
| 250 TEST_F(CFACMockTest, MockedCreateTabOk) { | 241 TEST_F(CFACMockTest, MockedCreateTabOk) { |
| 251 int timeout = 500; | 242 int timeout = 500; |
| 252 CreateTab(); | 243 CreateTab(); |
| 253 SetAutomationServerOk(1); | 244 SetAutomationServerOk(1); |
| 254 | 245 |
| 255 EXPECT_CALL(mock_proxy_, server_version()).Times(testing::AnyNumber()) | 246 EXPECT_CALL(mock_proxy_, server_version()).Times(testing::AnyNumber()) |
| 256 .WillRepeatedly(Return("")); | 247 .WillRepeatedly(Return("")); |
| 257 | 248 |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 GURL("http://www.nonexistent.com"), empty, profile_path_, | 462 GURL("http://www.nonexistent.com"), empty, profile_path_, |
| 472 profile_path_.BaseName().value(), L"", false, false, false)); | 463 profile_path_.BaseName().value(), L"", false, false, false)); |
| 473 launch_params->set_launch_timeout(timeout); | 464 launch_params->set_launch_timeout(timeout); |
| 474 launch_params->set_version_check(false); | 465 launch_params->set_version_check(false); |
| 475 EXPECT_TRUE(client_->Initialize(&cfd_, launch_params)); | 466 EXPECT_TRUE(client_->Initialize(&cfd_, launch_params)); |
| 476 loop_.RunFor(10); | 467 loop_.RunFor(10); |
| 477 | 468 |
| 478 EXPECT_CALL(mock_proxy_, ReleaseTabProxy(testing::Eq(tab_handle_))).Times(1); | 469 EXPECT_CALL(mock_proxy_, ReleaseTabProxy(testing::Eq(tab_handle_))).Times(1); |
| 479 client_->Uninitialize(); | 470 client_->Uninitialize(); |
| 480 } | 471 } |
| OLD | NEW |