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 | 4 |
5 #include "chrome_frame/test/ie_event_sink.h" | 5 #include "chrome_frame/test/ie_event_sink.h" |
6 | 6 |
7 #include "base/scoped_handle.h" | 7 #include "base/scoped_handle.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
11 #include "base/win/scoped_bstr.h" | 11 #include "base/win/scoped_bstr.h" |
12 #include "base/win/scoped_variant.h" | 12 #include "base/win/scoped_variant.h" |
13 #include "chrome_frame/test/chrome_frame_test_utils.h" | 13 #include "chrome_frame/test/chrome_frame_test_utils.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
15 | 15 |
16 using base::win::ScopedBstr; | 16 using base::win::ScopedBstr; |
17 using base::win::ScopedVariant; | |
18 | 17 |
19 namespace chrome_frame_test { | 18 namespace chrome_frame_test { |
20 | 19 |
21 const int kDefaultWaitForIEToTerminateMs = 10 * 1000; | 20 const int kDefaultWaitForIEToTerminateMs = 10 * 1000; |
22 | 21 |
23 _ATL_FUNC_INFO IEEventSink::kNavigateErrorInfo = { | 22 _ATL_FUNC_INFO IEEventSink::kNavigateErrorInfo = { |
24 CC_STDCALL, VT_EMPTY, 5, { | 23 CC_STDCALL, VT_EMPTY, 5, { |
25 VT_DISPATCH, | 24 VT_DISPATCH, |
26 VT_VARIANT | VT_BYREF, | 25 VT_VARIANT | VT_BYREF, |
27 VT_VARIANT | VT_BYREF, | 26 VT_VARIANT | VT_BYREF, |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 chrome_frame.QueryFrom(doc); | 172 chrome_frame.QueryFrom(doc); |
174 return chrome_frame.get(); | 173 return chrome_frame.get(); |
175 } | 174 } |
176 } | 175 } |
177 return false; | 176 return false; |
178 } | 177 } |
179 | 178 |
180 void IEEventSink::PostMessageToCF(const std::wstring& message, | 179 void IEEventSink::PostMessageToCF(const std::wstring& message, |
181 const std::wstring& target) { | 180 const std::wstring& target) { |
182 ScopedBstr message_bstr(message.c_str()); | 181 ScopedBstr message_bstr(message.c_str()); |
183 ScopedVariant target_variant(target.c_str()); | 182 base::win::ScopedVariant target_variant(target.c_str()); |
184 EXPECT_HRESULT_SUCCEEDED( | 183 EXPECT_HRESULT_SUCCEEDED( |
185 chrome_frame_->postMessage(message_bstr, target_variant)); | 184 chrome_frame_->postMessage(message_bstr, target_variant)); |
186 } | 185 } |
187 | 186 |
188 void IEEventSink::SetFocusToRenderer() { | 187 void IEEventSink::SetFocusToRenderer() { |
189 simulate_input::SetKeyboardFocusToWindow(GetRendererWindow()); | 188 simulate_input::SetKeyboardFocusToWindow(GetRendererWindow()); |
190 } | 189 } |
191 | 190 |
192 void IEEventSink::SendKeys(const wchar_t* input_string) { | 191 void IEEventSink::SendKeys(const wchar_t* input_string) { |
193 SetFocusToRenderer(); | 192 SetFocusToRenderer(); |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 HRESULT hr = LaunchIEAsComServer(web_browser2_.Receive()); | 327 HRESULT hr = LaunchIEAsComServer(web_browser2_.Receive()); |
329 if (SUCCEEDED(hr)) { | 328 if (SUCCEEDED(hr)) { |
330 web_browser2_->put_Visible(VARIANT_TRUE); | 329 web_browser2_->put_Visible(VARIANT_TRUE); |
331 Attach(web_browser2_); | 330 Attach(web_browser2_); |
332 hr = Navigate(navigate_url); | 331 hr = Navigate(navigate_url); |
333 } | 332 } |
334 return hr; | 333 return hr; |
335 } | 334 } |
336 | 335 |
337 HRESULT IEEventSink::Navigate(const std::wstring& navigate_url) { | 336 HRESULT IEEventSink::Navigate(const std::wstring& navigate_url) { |
338 VARIANT empty = ScopedVariant::kEmptyVariant; | 337 VARIANT empty = base::win::ScopedVariant::kEmptyVariant; |
339 ScopedVariant url; | 338 base::win::ScopedVariant url; |
340 url.Set(navigate_url.c_str()); | 339 url.Set(navigate_url.c_str()); |
341 | 340 |
342 HRESULT hr = S_OK; | 341 HRESULT hr = S_OK; |
343 hr = web_browser2_->Navigate2(url.AsInput(), &empty, &empty, &empty, &empty); | 342 hr = web_browser2_->Navigate2(url.AsInput(), &empty, &empty, &empty, &empty); |
344 EXPECT_TRUE(hr == S_OK); | 343 EXPECT_TRUE(hr == S_OK); |
345 return hr; | 344 return hr; |
346 } | 345 } |
347 | 346 |
348 HRESULT IEEventSink::CloseWebBrowser() { | 347 HRESULT IEEventSink::CloseWebBrowser() { |
349 if (!web_browser2_) | 348 if (!web_browser2_) |
350 return E_FAIL; | 349 return E_FAIL; |
351 | 350 |
352 DisconnectFromChromeFrame(); | 351 DisconnectFromChromeFrame(); |
353 EXPECT_HRESULT_SUCCEEDED(web_browser2_->Quit()); | 352 EXPECT_HRESULT_SUCCEEDED(web_browser2_->Quit()); |
354 return S_OK; | 353 return S_OK; |
355 } | 354 } |
356 | 355 |
357 void IEEventSink::Refresh() { | 356 void IEEventSink::Refresh() { |
358 ScopedVariant refresh_level(REFRESH_NORMAL); | 357 base::win::ScopedVariant refresh_level(REFRESH_NORMAL); |
359 web_browser2_->Refresh2(refresh_level.AsInput()); | 358 web_browser2_->Refresh2(refresh_level.AsInput()); |
360 } | 359 } |
361 | 360 |
362 // private methods | 361 // private methods |
363 void IEEventSink::ConnectToChromeFrame() { | 362 void IEEventSink::ConnectToChromeFrame() { |
364 DCHECK(web_browser2_); | 363 DCHECK(web_browser2_); |
365 if (chrome_frame_.get()) | 364 if (chrome_frame_.get()) |
366 return; | 365 return; |
367 ScopedComPtr<IShellBrowser> shell_browser; | 366 ScopedComPtr<IShellBrowser> shell_browser; |
368 DoQueryService(SID_STopLevelBrowser, web_browser2_, | 367 DoQueryService(SID_STopLevelBrowser, web_browser2_, |
369 shell_browser.Receive()); | 368 shell_browser.Receive()); |
370 | 369 |
371 if (shell_browser) { | 370 if (shell_browser) { |
372 ScopedComPtr<IShellView> shell_view; | 371 ScopedComPtr<IShellView> shell_view; |
373 shell_browser->QueryActiveShellView(shell_view.Receive()); | 372 shell_browser->QueryActiveShellView(shell_view.Receive()); |
374 if (shell_view) { | 373 if (shell_view) { |
375 shell_view->GetItemObject(SVGIO_BACKGROUND, __uuidof(IChromeFrame), | 374 shell_view->GetItemObject(SVGIO_BACKGROUND, __uuidof(IChromeFrame), |
376 reinterpret_cast<void**>(chrome_frame_.Receive())); | 375 reinterpret_cast<void**>(chrome_frame_.Receive())); |
377 } | 376 } |
378 | 377 |
379 if (chrome_frame_) { | 378 if (chrome_frame_) { |
380 ScopedVariant onmessage(onmessage_.ToDispatch()); | 379 base::win::ScopedVariant onmessage(onmessage_.ToDispatch()); |
381 ScopedVariant onloaderror(onloaderror_.ToDispatch()); | 380 base::win::ScopedVariant onloaderror(onloaderror_.ToDispatch()); |
382 ScopedVariant onload(onload_.ToDispatch()); | 381 base::win::ScopedVariant onload(onload_.ToDispatch()); |
383 EXPECT_HRESULT_SUCCEEDED(chrome_frame_->put_onmessage(onmessage)); | 382 EXPECT_HRESULT_SUCCEEDED(chrome_frame_->put_onmessage(onmessage)); |
384 EXPECT_HRESULT_SUCCEEDED(chrome_frame_->put_onloaderror(onloaderror)); | 383 EXPECT_HRESULT_SUCCEEDED(chrome_frame_->put_onloaderror(onloaderror)); |
385 EXPECT_HRESULT_SUCCEEDED(chrome_frame_->put_onload(onload)); | 384 EXPECT_HRESULT_SUCCEEDED(chrome_frame_->put_onload(onload)); |
386 } | 385 } |
387 } | 386 } |
388 } | 387 } |
389 | 388 |
390 void IEEventSink::DisconnectFromChromeFrame() { | 389 void IEEventSink::DisconnectFromChromeFrame() { |
391 if (chrome_frame_) { | 390 if (chrome_frame_) { |
392 // Use a local ref counted copy of the IChromeFrame interface as the | 391 // Use a local ref counted copy of the IChromeFrame interface as the |
393 // outgoing calls could cause the interface to be deleted due to a message | 392 // outgoing calls could cause the interface to be deleted due to a message |
394 // pump running in the context of the outgoing call. | 393 // pump running in the context of the outgoing call. |
395 ScopedComPtr<IChromeFrame> chrome_frame(chrome_frame_); | 394 ScopedComPtr<IChromeFrame> chrome_frame(chrome_frame_); |
396 chrome_frame_.Release(); | 395 chrome_frame_.Release(); |
397 ScopedVariant dummy(static_cast<IDispatch*>(NULL)); | 396 base::win::ScopedVariant dummy(static_cast<IDispatch*>(NULL)); |
398 chrome_frame->put_onmessage(dummy); | 397 chrome_frame->put_onmessage(dummy); |
399 chrome_frame->put_onload(dummy); | 398 chrome_frame->put_onload(dummy); |
400 chrome_frame->put_onloaderror(dummy); | 399 chrome_frame->put_onloaderror(dummy); |
401 } | 400 } |
402 } | 401 } |
403 | 402 |
404 void IEEventSink::FindIEProcessId() { | 403 void IEEventSink::FindIEProcessId() { |
405 HWND hwnd = NULL; | 404 HWND hwnd = NULL; |
406 web_browser2_->get_HWND(reinterpret_cast<SHANDLE_PTR*>(&hwnd)); | 405 web_browser2_->get_HWND(reinterpret_cast<SHANDLE_PTR*>(&hwnd)); |
407 EXPECT_TRUE(::IsWindow(hwnd)); | 406 EXPECT_TRUE(::IsWindow(hwnd)); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
507 | 506 |
508 DispEventUnadvise(web_browser2_); | 507 DispEventUnadvise(web_browser2_); |
509 CoDisconnectObject(this, 0); | 508 CoDisconnectObject(this, 0); |
510 | 509 |
511 if (listener_) | 510 if (listener_) |
512 listener_->OnQuit(); | 511 listener_->OnQuit(); |
513 } | 512 } |
514 | 513 |
515 HRESULT IEEventSink::OnLoad(const VARIANT* param) { | 514 HRESULT IEEventSink::OnLoad(const VARIANT* param) { |
516 DVLOG(1) << __FUNCTION__ << " " << param->bstrVal; | 515 DVLOG(1) << __FUNCTION__ << " " << param->bstrVal; |
517 ScopedVariant stack_object(*param); | 516 base::win::ScopedVariant stack_object(*param); |
518 if (chrome_frame_) { | 517 if (chrome_frame_) { |
519 if (listener_) | 518 if (listener_) |
520 listener_->OnLoad(param->bstrVal); | 519 listener_->OnLoad(param->bstrVal); |
521 } else { | 520 } else { |
522 DLOG(WARNING) << "Invalid chrome frame pointer"; | 521 DLOG(WARNING) << "Invalid chrome frame pointer"; |
523 } | 522 } |
524 return S_OK; | 523 return S_OK; |
525 } | 524 } |
526 | 525 |
527 HRESULT IEEventSink::OnLoadError(const VARIANT* param) { | 526 HRESULT IEEventSink::OnLoadError(const VARIANT* param) { |
528 DVLOG(1) << __FUNCTION__ << " " << param->bstrVal; | 527 DVLOG(1) << __FUNCTION__ << " " << param->bstrVal; |
529 if (chrome_frame_) { | 528 if (chrome_frame_) { |
530 if (listener_) | 529 if (listener_) |
531 listener_->OnLoadError(param->bstrVal); | 530 listener_->OnLoadError(param->bstrVal); |
532 } else { | 531 } else { |
533 DLOG(WARNING) << "Invalid chrome frame pointer"; | 532 DLOG(WARNING) << "Invalid chrome frame pointer"; |
534 } | 533 } |
535 return S_OK; | 534 return S_OK; |
536 } | 535 } |
537 | 536 |
538 HRESULT IEEventSink::OnMessage(const VARIANT* param) { | 537 HRESULT IEEventSink::OnMessage(const VARIANT* param) { |
539 DVLOG(1) << __FUNCTION__ << " " << param; | 538 DVLOG(1) << __FUNCTION__ << " " << param; |
540 if (!chrome_frame_.get()) { | 539 if (!chrome_frame_.get()) { |
541 DLOG(WARNING) << "Invalid chrome frame pointer"; | 540 DLOG(WARNING) << "Invalid chrome frame pointer"; |
542 return S_OK; | 541 return S_OK; |
543 } | 542 } |
544 | 543 |
545 ScopedVariant data, origin, source; | 544 base::win::ScopedVariant data, origin, source; |
546 if (param && (V_VT(param) == VT_DISPATCH)) { | 545 if (param && (V_VT(param) == VT_DISPATCH)) { |
547 wchar_t* properties[] = { L"data", L"origin", L"source" }; | 546 wchar_t* properties[] = { L"data", L"origin", L"source" }; |
548 const int prop_count = arraysize(properties); | 547 const int prop_count = arraysize(properties); |
549 DISPID ids[prop_count] = {0}; | 548 DISPID ids[prop_count] = {0}; |
550 | 549 |
551 HRESULT hr = param->pdispVal->GetIDsOfNames(IID_NULL, properties, | 550 HRESULT hr = param->pdispVal->GetIDsOfNames(IID_NULL, properties, |
552 prop_count, LOCALE_SYSTEM_DEFAULT, ids); | 551 prop_count, LOCALE_SYSTEM_DEFAULT, ids); |
553 if (SUCCEEDED(hr)) { | 552 if (SUCCEEDED(hr)) { |
554 DISPPARAMS params = { 0 }; | 553 DISPPARAMS params = { 0 }; |
555 EXPECT_HRESULT_SUCCEEDED(param->pdispVal->Invoke(ids[0], IID_NULL, | 554 EXPECT_HRESULT_SUCCEEDED(param->pdispVal->Invoke(ids[0], IID_NULL, |
556 LOCALE_SYSTEM_DEFAULT, DISPATCH_PROPERTYGET, ¶ms, | 555 LOCALE_SYSTEM_DEFAULT, DISPATCH_PROPERTYGET, ¶ms, |
557 data.Receive(), NULL, NULL)); | 556 data.Receive(), NULL, NULL)); |
558 EXPECT_HRESULT_SUCCEEDED(param->pdispVal->Invoke(ids[1], IID_NULL, | 557 EXPECT_HRESULT_SUCCEEDED(param->pdispVal->Invoke(ids[1], IID_NULL, |
559 LOCALE_SYSTEM_DEFAULT, DISPATCH_PROPERTYGET, ¶ms, | 558 LOCALE_SYSTEM_DEFAULT, DISPATCH_PROPERTYGET, ¶ms, |
560 origin.Receive(), NULL, NULL)); | 559 origin.Receive(), NULL, NULL)); |
561 EXPECT_HRESULT_SUCCEEDED(param->pdispVal->Invoke(ids[2], IID_NULL, | 560 EXPECT_HRESULT_SUCCEEDED(param->pdispVal->Invoke(ids[2], IID_NULL, |
562 LOCALE_SYSTEM_DEFAULT, DISPATCH_PROPERTYGET, ¶ms, | 561 LOCALE_SYSTEM_DEFAULT, DISPATCH_PROPERTYGET, ¶ms, |
563 source.Receive(), NULL, NULL)); | 562 source.Receive(), NULL, NULL)); |
564 } | 563 } |
565 } | 564 } |
566 | 565 |
567 if (listener_) | 566 if (listener_) |
568 listener_->OnMessage(V_BSTR(&data), V_BSTR(&origin), V_BSTR(&source)); | 567 listener_->OnMessage(V_BSTR(&data), V_BSTR(&origin), V_BSTR(&source)); |
569 return S_OK; | 568 return S_OK; |
570 } | 569 } |
571 | 570 |
572 } // namespace chrome_frame_test | 571 } // namespace chrome_frame_test |
OLD | NEW |