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 "net/base/net_errors.h" | 7 #include "net/base/net_errors.h" |
8 #include "chrome_frame/custom_sync_call_context.h" | 8 #include "chrome_frame/custom_sync_call_context.h" |
9 #include "chrome_frame/test/chrome_frame_test_utils.h" | 9 #include "chrome_frame/test/chrome_frame_test_utils.h" |
10 | 10 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 scoped_refptr<ChromeFrameAutomationClient> client; | 98 scoped_refptr<ChromeFrameAutomationClient> client; |
99 client = new ChromeFrameAutomationClient(); | 99 client = new ChromeFrameAutomationClient(); |
100 | 100 |
101 EXPECT_CALL(cfd, OnAutomationServerLaunchFailed(AUTOMATION_TIMEOUT, _)) | 101 EXPECT_CALL(cfd, OnAutomationServerLaunchFailed(AUTOMATION_TIMEOUT, _)) |
102 .Times(1) | 102 .Times(1) |
103 .WillOnce(QUIT_LOOP(loop)); | 103 .WillOnce(QUIT_LOOP(loop)); |
104 | 104 |
105 GURL empty; | 105 GURL empty; |
106 scoped_refptr<ChromeFrameLaunchParams> clp(new ChromeFrameLaunchParams( | 106 scoped_refptr<ChromeFrameLaunchParams> clp(new ChromeFrameLaunchParams( |
107 empty, empty, profile_path, profile_path.BaseName().value(), L"", | 107 empty, empty, profile_path, profile_path.BaseName().value(), L"", |
108 false, false)); | 108 false, false, false)); |
109 clp->set_launch_timeout(timeout); | 109 clp->set_launch_timeout(timeout); |
110 clp->set_version_check(false); | 110 clp->set_version_check(false); |
111 EXPECT_TRUE(client->Initialize(&cfd, clp)); | 111 EXPECT_TRUE(client->Initialize(&cfd, clp)); |
112 loop.RunFor(10); | 112 loop.RunFor(10); |
113 client->Uninitialize(); | 113 client->Uninitialize(); |
114 } | 114 } |
115 | 115 |
116 // This test may fail if Chrome take more that 10 seconds (timeout var) to | 116 // This test may fail if Chrome take more that 10 seconds (timeout var) to |
117 // launch. In this case GMock shall print something like "unexpected call to | 117 // launch. In this case GMock shall print something like "unexpected call to |
118 // OnAutomationServerLaunchFailed". I'm yet to find out how to specify | 118 // OnAutomationServerLaunchFailed". I'm yet to find out how to specify |
(...skipping 11 matching lines...) Expand all Loading... |
130 EXPECT_CALL(cfd, OnAutomationServerReady()) | 130 EXPECT_CALL(cfd, OnAutomationServerReady()) |
131 .Times(1) | 131 .Times(1) |
132 .WillOnce(QUIT_LOOP(loop)); | 132 .WillOnce(QUIT_LOOP(loop)); |
133 | 133 |
134 EXPECT_CALL(cfd, OnAutomationServerLaunchFailed(_, _)) | 134 EXPECT_CALL(cfd, OnAutomationServerLaunchFailed(_, _)) |
135 .Times(0); | 135 .Times(0); |
136 | 136 |
137 GURL empty; | 137 GURL empty; |
138 scoped_refptr<ChromeFrameLaunchParams> clp(new ChromeFrameLaunchParams( | 138 scoped_refptr<ChromeFrameLaunchParams> clp(new ChromeFrameLaunchParams( |
139 empty, empty, profile_path, profile_path.BaseName().value(), L"", | 139 empty, empty, profile_path, profile_path.BaseName().value(), L"", |
140 false, false)); | 140 false, false, false)); |
141 clp->set_launch_timeout(timeout); | 141 clp->set_launch_timeout(timeout); |
142 clp->set_version_check(false); | 142 clp->set_version_check(false); |
143 EXPECT_TRUE(client->Initialize(&cfd, clp)); | 143 EXPECT_TRUE(client->Initialize(&cfd, clp)); |
144 | 144 |
145 loop.RunFor(11); | 145 loop.RunFor(11); |
146 client->Uninitialize(); | 146 client->Uninitialize(); |
147 client = NULL; | 147 client = NULL; |
148 } | 148 } |
149 | 149 |
150 TEST(CFACWithChrome, NavigateOk) { | 150 TEST(CFACWithChrome, NavigateOk) { |
(...skipping 25 matching lines...) Expand all Loading... |
176 EXPECT_CALL(cfd, OnUpdateTargetUrl(_, _)).Times(testing::AtMost(1)); | 176 EXPECT_CALL(cfd, OnUpdateTargetUrl(_, _)).Times(testing::AtMost(1)); |
177 | 177 |
178 EXPECT_CALL(cfd, OnLoad(_, _)) | 178 EXPECT_CALL(cfd, OnLoad(_, _)) |
179 .Times(1) | 179 .Times(1) |
180 .WillOnce(QUIT_LOOP(loop)); | 180 .WillOnce(QUIT_LOOP(loop)); |
181 } | 181 } |
182 | 182 |
183 GURL empty; | 183 GURL empty; |
184 scoped_refptr<ChromeFrameLaunchParams> clp(new ChromeFrameLaunchParams( | 184 scoped_refptr<ChromeFrameLaunchParams> clp(new ChromeFrameLaunchParams( |
185 empty, empty, profile_path, profile_path.BaseName().value(), L"", | 185 empty, empty, profile_path, profile_path.BaseName().value(), L"", |
186 false, false)); | 186 false, false, false)); |
187 clp->set_launch_timeout(timeout); | 187 clp->set_launch_timeout(timeout); |
188 clp->set_version_check(false); | 188 clp->set_version_check(false); |
189 EXPECT_TRUE(client->Initialize(&cfd, clp)); | 189 EXPECT_TRUE(client->Initialize(&cfd, clp)); |
190 loop.RunFor(10); | 190 loop.RunFor(10); |
191 client->Uninitialize(); | 191 client->Uninitialize(); |
192 client = NULL; | 192 client = NULL; |
193 } | 193 } |
194 | 194 |
195 TEST(CFACWithChrome, NavigateFailed) { | 195 TEST(CFACWithChrome, NavigateFailed) { |
196 MockCFDelegate cfd; | 196 MockCFDelegate cfd; |
(...skipping 25 matching lines...) Expand all Loading... |
222 EXPECT_CALL(cfd, OnUpdateTargetUrl(_, _)).Times(testing::AnyNumber()); | 222 EXPECT_CALL(cfd, OnUpdateTargetUrl(_, _)).Times(testing::AnyNumber()); |
223 EXPECT_CALL(cfd, OnLoad(_, _)).Times(testing::AtMost(1)); | 223 EXPECT_CALL(cfd, OnLoad(_, _)).Times(testing::AtMost(1)); |
224 | 224 |
225 EXPECT_CALL(cfd, OnNavigationFailed(_, _, GURL(url))) | 225 EXPECT_CALL(cfd, OnNavigationFailed(_, _, GURL(url))) |
226 .Times(1) | 226 .Times(1) |
227 .WillOnce(QUIT_LOOP_SOON(loop, 2)); | 227 .WillOnce(QUIT_LOOP_SOON(loop, 2)); |
228 | 228 |
229 GURL empty; | 229 GURL empty; |
230 scoped_refptr<ChromeFrameLaunchParams> clp(new ChromeFrameLaunchParams( | 230 scoped_refptr<ChromeFrameLaunchParams> clp(new ChromeFrameLaunchParams( |
231 empty, empty, profile_path, profile_path.BaseName().value(), L"", | 231 empty, empty, profile_path, profile_path.BaseName().value(), L"", |
232 false, false)); | 232 false, false, false)); |
233 clp->set_launch_timeout(10000); | 233 clp->set_launch_timeout(10000); |
234 clp->set_version_check(false); | 234 clp->set_version_check(false); |
235 EXPECT_TRUE(client->Initialize(&cfd, clp)); | 235 EXPECT_TRUE(client->Initialize(&cfd, clp)); |
236 | 236 |
237 loop.RunFor(10); | 237 loop.RunFor(10); |
238 client->Uninitialize(); | 238 client->Uninitialize(); |
239 client = NULL; | 239 client = NULL; |
240 } | 240 } |
241 | 241 |
242 TEST_F(CFACMockTest, MockedCreateTabOk) { | 242 TEST_F(CFACMockTest, MockedCreateTabOk) { |
(...skipping 17 matching lines...) Expand all Loading... |
260 | 260 |
261 EXPECT_CALL(cfd_, OnAutomationServerReady()) | 261 EXPECT_CALL(cfd_, OnAutomationServerReady()) |
262 .WillOnce(QUIT_LOOP(loop_)); | 262 .WillOnce(QUIT_LOOP(loop_)); |
263 | 263 |
264 EXPECT_CALL(mock_proxy_, CancelAsync(_)).Times(testing::AnyNumber()); | 264 EXPECT_CALL(mock_proxy_, CancelAsync(_)).Times(testing::AnyNumber()); |
265 | 265 |
266 // Here we go! | 266 // Here we go! |
267 GURL empty; | 267 GURL empty; |
268 scoped_refptr<ChromeFrameLaunchParams> clp(new ChromeFrameLaunchParams( | 268 scoped_refptr<ChromeFrameLaunchParams> clp(new ChromeFrameLaunchParams( |
269 empty, empty, profile_path_, profile_path_.BaseName().value(), L"", | 269 empty, empty, profile_path_, profile_path_.BaseName().value(), L"", |
270 false, false)); | 270 false, false, false)); |
271 clp->set_launch_timeout(timeout); | 271 clp->set_launch_timeout(timeout); |
272 clp->set_version_check(false); | 272 clp->set_version_check(false); |
273 EXPECT_TRUE(client_->Initialize(&cfd_, clp)); | 273 EXPECT_TRUE(client_->Initialize(&cfd_, clp)); |
274 loop_.RunFor(10); | 274 loop_.RunFor(10); |
275 | 275 |
276 EXPECT_CALL(mock_proxy_, ReleaseTabProxy(testing::Eq(tab_handle_))).Times(1); | 276 EXPECT_CALL(mock_proxy_, ReleaseTabProxy(testing::Eq(tab_handle_))).Times(1); |
277 client_->Uninitialize(); | 277 client_->Uninitialize(); |
278 } | 278 } |
279 | 279 |
280 TEST_F(CFACMockTest, MockedCreateTabFailed) { | 280 TEST_F(CFACMockTest, MockedCreateTabFailed) { |
(...skipping 11 matching lines...) Expand all Loading... |
292 EXPECT_CALL(mock_proxy_, CreateTabProxy(_)).Times(0); | 292 EXPECT_CALL(mock_proxy_, CreateTabProxy(_)).Times(0); |
293 | 293 |
294 EXPECT_CALL(mock_proxy_, CancelAsync(_)).Times(testing::AnyNumber()); | 294 EXPECT_CALL(mock_proxy_, CancelAsync(_)).Times(testing::AnyNumber()); |
295 | 295 |
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)); | 302 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(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: |
(...skipping 19 matching lines...) Expand all Loading... |
332 proxy.FakeChannelError(); | 332 proxy.FakeChannelError(); |
333 } | 333 } |
334 | 334 |
335 TEST_F(CFACMockTest, OnChannelError) { | 335 TEST_F(CFACMockTest, OnChannelError) { |
336 TestChromeFrameAutomationProxyImpl proxy; | 336 TestChromeFrameAutomationProxyImpl proxy; |
337 returned_proxy_ = &proxy; | 337 returned_proxy_ = &proxy; |
338 | 338 |
339 GURL empty; | 339 GURL empty; |
340 scoped_refptr<ChromeFrameLaunchParams> clp(new ChromeFrameLaunchParams( | 340 scoped_refptr<ChromeFrameLaunchParams> clp(new ChromeFrameLaunchParams( |
341 empty, empty, profile_path_, profile_path_.BaseName().value(), L"", | 341 empty, empty, profile_path_, profile_path_.BaseName().value(), L"", |
342 false, false)); | 342 false, false, false)); |
343 clp->set_launch_timeout(1); // Unneeded timeout, but can't be 0. | 343 clp->set_launch_timeout(1); // Unneeded timeout, but can't be 0. |
344 clp->set_version_check(false); | 344 clp->set_version_check(false); |
345 | 345 |
346 HWND h1 = ::GetDesktopWindow(); | 346 HWND h1 = ::GetDesktopWindow(); |
347 HWND h2 = ::GetDesktopWindow(); | 347 HWND h2 = ::GetDesktopWindow(); |
348 EXPECT_CALL(proxy, SendAsAsync(testing::Property( | 348 EXPECT_CALL(proxy, SendAsAsync(testing::Property( |
349 &IPC::SyncMessage::type, AutomationMsg_CreateExternalTab__ID), | 349 &IPC::SyncMessage::type, AutomationMsg_CreateExternalTab__ID), |
350 testing::NotNull(), _)).Times(3) | 350 testing::NotNull(), _)).Times(3) |
351 .WillOnce(HandleCreateTab(tab_handle_, h1, h2)) | 351 .WillOnce(HandleCreateTab(tab_handle_, h1, h2)) |
352 .WillOnce(HandleCreateTab(tab_handle_ * 2, h1, h2)) | 352 .WillOnce(HandleCreateTab(tab_handle_ * 2, h1, h2)) |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
450 .Times(1) | 450 .Times(1) |
451 .WillOnce(Return(true)); | 451 .WillOnce(Return(true)); |
452 | 452 |
453 EXPECT_CALL(cfd_, GetBounds(_)).Times(1); | 453 EXPECT_CALL(cfd_, GetBounds(_)).Times(1); |
454 | 454 |
455 // Here we go! | 455 // Here we go! |
456 GURL empty; | 456 GURL empty; |
457 scoped_refptr<ChromeFrameLaunchParams> launch_params( | 457 scoped_refptr<ChromeFrameLaunchParams> launch_params( |
458 new ChromeFrameLaunchParams( | 458 new ChromeFrameLaunchParams( |
459 GURL("http://www.nonexistent.com"), empty, profile_path_, | 459 GURL("http://www.nonexistent.com"), empty, profile_path_, |
460 profile_path_.BaseName().value(), L"", false, false)); | 460 profile_path_.BaseName().value(), L"", false, false, false)); |
461 launch_params->set_launch_timeout(timeout); | 461 launch_params->set_launch_timeout(timeout); |
462 launch_params->set_version_check(false); | 462 launch_params->set_version_check(false); |
463 EXPECT_TRUE(client_->Initialize(&cfd_, launch_params)); | 463 EXPECT_TRUE(client_->Initialize(&cfd_, launch_params)); |
464 loop_.RunFor(10); | 464 loop_.RunFor(10); |
465 | 465 |
466 EXPECT_CALL(mock_proxy_, ReleaseTabProxy(testing::Eq(tab_handle_))).Times(1); | 466 EXPECT_CALL(mock_proxy_, ReleaseTabProxy(testing::Eq(tab_handle_))).Times(1); |
467 client_->Uninitialize(); | 467 client_->Uninitialize(); |
468 } | 468 } |
469 | 469 |
OLD | NEW |