| OLD | NEW |
| 1 // Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-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 "net/base/net_errors.h" | 7 #include "net/base/net_errors.h" |
| 8 #include "chrome_frame/test/chrome_frame_test_utils.h" | 8 #include "chrome_frame/test/chrome_frame_test_utils.h" |
| 9 | 9 |
| 10 #define GMOCK_MUTANT_INCLUDE_LATE_OBJECT_BINDING | 10 #define GMOCK_MUTANT_INCLUDE_LATE_OBJECT_BINDING |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 int timeout = 0; // Chrome cannot send Hello message so fast. | 93 int timeout = 0; // Chrome cannot send Hello message so fast. |
| 94 const std::wstring profile = L"Adam.N.Epilinter"; | 94 const std::wstring profile = L"Adam.N.Epilinter"; |
| 95 | 95 |
| 96 scoped_refptr<ChromeFrameAutomationClient> client; | 96 scoped_refptr<ChromeFrameAutomationClient> client; |
| 97 client = new ChromeFrameAutomationClient(); | 97 client = new ChromeFrameAutomationClient(); |
| 98 | 98 |
| 99 EXPECT_CALL(cfd, OnAutomationServerLaunchFailed(AUTOMATION_TIMEOUT, _)) | 99 EXPECT_CALL(cfd, OnAutomationServerLaunchFailed(AUTOMATION_TIMEOUT, _)) |
| 100 .Times(1) | 100 .Times(1) |
| 101 .WillOnce(QUIT_LOOP(loop)); | 101 .WillOnce(QUIT_LOOP(loop)); |
| 102 | 102 |
| 103 ChromeFrameLaunchParams cfp = { | 103 EXPECT_TRUE(client->Initialize(&cfd, timeout, false, profile, L"", false)); |
| 104 timeout, | |
| 105 GURL(), | |
| 106 GURL(), | |
| 107 profile, | |
| 108 L"", | |
| 109 false, | |
| 110 false, | |
| 111 false | |
| 112 }; | |
| 113 EXPECT_TRUE(client->Initialize(&cfd, cfp)); | |
| 114 loop.RunFor(10); | 104 loop.RunFor(10); |
| 115 client->Uninitialize(); | 105 client->Uninitialize(); |
| 116 } | 106 } |
| 117 | 107 |
| 118 // This test may fail if Chrome take more that 10 seconds (timeout var) to | 108 // 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 | 109 // launch. In this case GMock shall print something like "unexpected call to |
| 120 // OnAutomationServerLaunchFailed". I'm yet to find out how to specify | 110 // OnAutomationServerLaunchFailed". I'm yet to find out how to specify |
| 121 // that this is an unexpected call, and still to execute and action. | 111 // that this is an unexpected call, and still to execute and action. |
| 122 TEST(CFACWithChrome, CreateNotSoFast) { | 112 TEST(CFACWithChrome, CreateNotSoFast) { |
| 123 MockCFDelegate cfd; | 113 MockCFDelegate cfd; |
| 124 chrome_frame_test::TimedMsgLoop loop; | 114 chrome_frame_test::TimedMsgLoop loop; |
| 125 const std::wstring profile = L"Adam.N.Epilinter"; | 115 const std::wstring profile = L"Adam.N.Epilinter"; |
| 126 int timeout = 10000; | 116 int timeout = 10000; |
| 127 | 117 |
| 128 scoped_refptr<ChromeFrameAutomationClient> client; | 118 scoped_refptr<ChromeFrameAutomationClient> client; |
| 129 client = new ChromeFrameAutomationClient; | 119 client = new ChromeFrameAutomationClient; |
| 130 | 120 |
| 131 EXPECT_CALL(cfd, OnAutomationServerReady()) | 121 EXPECT_CALL(cfd, OnAutomationServerReady()) |
| 132 .Times(1) | 122 .Times(1) |
| 133 .WillOnce(QUIT_LOOP(loop)); | 123 .WillOnce(QUIT_LOOP(loop)); |
| 134 | 124 |
| 135 EXPECT_CALL(cfd, OnAutomationServerLaunchFailed(_, _)) | 125 EXPECT_CALL(cfd, OnAutomationServerLaunchFailed(_, _)) |
| 136 .Times(0); | 126 .Times(0); |
| 137 | 127 |
| 138 ChromeFrameLaunchParams cfp = { | 128 EXPECT_TRUE(client->Initialize(&cfd, timeout, false, profile, L"", false)); |
| 139 timeout, | |
| 140 GURL(), | |
| 141 GURL(), | |
| 142 profile, | |
| 143 L"", | |
| 144 false, | |
| 145 false, | |
| 146 false | |
| 147 }; | |
| 148 EXPECT_TRUE(client->Initialize(&cfd, cfp)); | |
| 149 | 129 |
| 150 loop.RunFor(11); | 130 loop.RunFor(11); |
| 151 client->Uninitialize(); | 131 client->Uninitialize(); |
| 152 client = NULL; | 132 client = NULL; |
| 153 } | 133 } |
| 154 | 134 |
| 155 TEST(CFACWithChrome, NavigateOk) { | 135 TEST(CFACWithChrome, NavigateOk) { |
| 156 MockCFDelegate cfd; | 136 MockCFDelegate cfd; |
| 157 chrome_frame_test::TimedMsgLoop loop; | 137 chrome_frame_test::TimedMsgLoop loop; |
| 158 const std::wstring profile = L"Adam.N.Epilinter"; | 138 const std::wstring profile = L"Adam.N.Epilinter"; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 178 EXPECT_CALL(cfd, OnDidNavigate(_, EqNavigationInfoUrl(GURL()))) | 158 EXPECT_CALL(cfd, OnDidNavigate(_, EqNavigationInfoUrl(GURL()))) |
| 179 .Times(1); | 159 .Times(1); |
| 180 | 160 |
| 181 EXPECT_CALL(cfd, OnUpdateTargetUrl(_, _)).Times(1); | 161 EXPECT_CALL(cfd, OnUpdateTargetUrl(_, _)).Times(1); |
| 182 | 162 |
| 183 EXPECT_CALL(cfd, OnLoad(_, _)) | 163 EXPECT_CALL(cfd, OnLoad(_, _)) |
| 184 .Times(1) | 164 .Times(1) |
| 185 .WillOnce(QUIT_LOOP(loop)); | 165 .WillOnce(QUIT_LOOP(loop)); |
| 186 } | 166 } |
| 187 | 167 |
| 188 ChromeFrameLaunchParams cfp = { | 168 EXPECT_TRUE(client->Initialize(&cfd, timeout, false, profile, L"", false)); |
| 189 timeout, | |
| 190 GURL(), | |
| 191 GURL(), | |
| 192 profile, | |
| 193 L"", | |
| 194 false, | |
| 195 false, | |
| 196 false | |
| 197 }; | |
| 198 EXPECT_TRUE(client->Initialize(&cfd, cfp)); | |
| 199 loop.RunFor(10); | 169 loop.RunFor(10); |
| 200 client->Uninitialize(); | 170 client->Uninitialize(); |
| 201 client = NULL; | 171 client = NULL; |
| 202 } | 172 } |
| 203 | 173 |
| 204 TEST(CFACWithChrome, NavigateFailed) { | 174 TEST(CFACWithChrome, NavigateFailed) { |
| 205 MockCFDelegate cfd; | 175 MockCFDelegate cfd; |
| 206 chrome_frame_test::TimedMsgLoop loop; | 176 chrome_frame_test::TimedMsgLoop loop; |
| 207 const std::wstring profile = L"Adam.N.Epilinter"; | 177 const std::wstring profile = L"Adam.N.Epilinter"; |
| 208 const std::string url = "http://127.0.0.3:65412/"; | 178 const std::string url = "http://127.0.0.3:65412/"; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 227 .WillRepeatedly(testing::WithArgs<1>(testing::Invoke(CreateFunctor(&cfd, | 197 .WillRepeatedly(testing::WithArgs<1>(testing::Invoke(CreateFunctor(&cfd, |
| 228 &MockCFDelegate::Reply, connection_failed)))); | 198 &MockCFDelegate::Reply, connection_failed)))); |
| 229 | 199 |
| 230 EXPECT_CALL(cfd, OnUpdateTargetUrl(_, _)).Times(testing::AnyNumber()); | 200 EXPECT_CALL(cfd, OnUpdateTargetUrl(_, _)).Times(testing::AnyNumber()); |
| 231 EXPECT_CALL(cfd, OnLoad(_, _)).Times(testing::AtMost(1)); | 201 EXPECT_CALL(cfd, OnLoad(_, _)).Times(testing::AtMost(1)); |
| 232 | 202 |
| 233 EXPECT_CALL(cfd, OnNavigationFailed(_, _, GURL(url))) | 203 EXPECT_CALL(cfd, OnNavigationFailed(_, _, GURL(url))) |
| 234 .Times(1) | 204 .Times(1) |
| 235 .WillOnce(QUIT_LOOP_SOON(loop, 2)); | 205 .WillOnce(QUIT_LOOP_SOON(loop, 2)); |
| 236 | 206 |
| 237 ChromeFrameLaunchParams cfp = { | 207 EXPECT_TRUE(client->Initialize(&cfd, 10000, false, profile, L"", false)); |
| 238 10000, | |
| 239 GURL(), | |
| 240 GURL(), | |
| 241 profile, | |
| 242 L"", | |
| 243 false, | |
| 244 false, | |
| 245 false | |
| 246 }; | |
| 247 EXPECT_TRUE(client->Initialize(&cfd, cfp)); | |
| 248 | 208 |
| 249 loop.RunFor(10); | 209 loop.RunFor(10); |
| 250 client->Uninitialize(); | 210 client->Uninitialize(); |
| 251 client = NULL; | 211 client = NULL; |
| 252 } | 212 } |
| 253 | 213 |
| 254 TEST_F(CFACMockTest, MockedCreateTabOk) { | 214 TEST_F(CFACMockTest, MockedCreateTabOk) { |
| 255 int timeout = 500; | 215 int timeout = 500; |
| 256 CreateTab(); | 216 CreateTab(); |
| 257 SetAutomationServerOk(); | 217 SetAutomationServerOk(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 270 | 230 |
| 271 EXPECT_CALL(proxy_, CreateTabProxy(testing::Eq(tab_handle_))) | 231 EXPECT_CALL(proxy_, CreateTabProxy(testing::Eq(tab_handle_))) |
| 272 .WillOnce(testing::Return(tab_)); | 232 .WillOnce(testing::Return(tab_)); |
| 273 | 233 |
| 274 EXPECT_CALL(cfd_, OnAutomationServerReady()) | 234 EXPECT_CALL(cfd_, OnAutomationServerReady()) |
| 275 .WillOnce(QUIT_LOOP(loop_)); | 235 .WillOnce(QUIT_LOOP(loop_)); |
| 276 | 236 |
| 277 EXPECT_CALL(proxy_, CancelAsync(_)).Times(testing::AnyNumber()); | 237 EXPECT_CALL(proxy_, CancelAsync(_)).Times(testing::AnyNumber()); |
| 278 | 238 |
| 279 // Here we go! | 239 // Here we go! |
| 280 ChromeFrameLaunchParams cfp = { | 240 EXPECT_TRUE(client_->Initialize(&cfd_, timeout, false, profile_, L"", false)); |
| 281 timeout, | |
| 282 GURL(), | |
| 283 GURL(), | |
| 284 profile_, | |
| 285 L"", | |
| 286 false, | |
| 287 false, | |
| 288 false | |
| 289 }; | |
| 290 EXPECT_TRUE(client_->Initialize(&cfd_, cfp)); | |
| 291 loop_.RunFor(10); | 241 loop_.RunFor(10); |
| 292 client_->Uninitialize(); | 242 client_->Uninitialize(); |
| 293 } | 243 } |
| 294 | 244 |
| 295 TEST_F(CFACMockTest, MockedCreateTabFailed) { | 245 TEST_F(CFACMockTest, MockedCreateTabFailed) { |
| 296 HWND null_wnd = NULL; | 246 HWND null_wnd = NULL; |
| 297 SetAutomationServerOk(); | 247 SetAutomationServerOk(); |
| 298 | 248 |
| 299 EXPECT_CALL(proxy_, server_version()).Times(testing::AnyNumber()) | 249 EXPECT_CALL(proxy_, server_version()).Times(testing::AnyNumber()) |
| 300 .WillRepeatedly(testing::Return("")); | 250 .WillRepeatedly(testing::Return("")); |
| 301 | 251 |
| 302 EXPECT_CALL(proxy_, SendAsAsync(testing::Property(&IPC::SyncMessage::type, | 252 EXPECT_CALL(proxy_, SendAsAsync(testing::Property(&IPC::SyncMessage::type, |
| 303 AutomationMsg_CreateExternalTab__ID), | 253 AutomationMsg_CreateExternalTab__ID), |
| 304 testing::NotNull(), _)) | 254 testing::NotNull(), _)) |
| 305 .Times(1) | 255 .Times(1) |
| 306 .WillOnce(HandleCreateTab(tab_handle_, null_wnd, null_wnd)); | 256 .WillOnce(HandleCreateTab(tab_handle_, null_wnd, null_wnd)); |
| 307 | 257 |
| 308 EXPECT_CALL(proxy_, CreateTabProxy(_)).Times(0); | 258 EXPECT_CALL(proxy_, CreateTabProxy(_)).Times(0); |
| 309 | 259 |
| 310 EXPECT_CALL(proxy_, CancelAsync(_)).Times(testing::AnyNumber()); | 260 EXPECT_CALL(proxy_, CancelAsync(_)).Times(testing::AnyNumber()); |
| 311 | 261 |
| 312 Set_CFD_LaunchFailed(AUTOMATION_CREATE_TAB_FAILED); | 262 Set_CFD_LaunchFailed(AUTOMATION_CREATE_TAB_FAILED); |
| 313 | 263 |
| 314 // Here we go! | 264 // Here we go! |
| 315 ChromeFrameLaunchParams cfp = { | 265 EXPECT_TRUE(client_->Initialize(&cfd_, timeout_, false, profile_, L"", |
| 316 timeout_, | 266 false)); |
| 317 GURL(), | |
| 318 GURL(), | |
| 319 profile_, | |
| 320 L"", | |
| 321 false, | |
| 322 false, | |
| 323 false | |
| 324 }; | |
| 325 EXPECT_TRUE(client_->Initialize(&cfd_, cfp)); | |
| 326 loop_.RunFor(4); | 267 loop_.RunFor(4); |
| 327 client_->Uninitialize(); | 268 client_->Uninitialize(); |
| 328 } | 269 } |
| 329 | 270 |
| OLD | NEW |