| 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/mock_ie_event_sink_test.h" | 5 #include "chrome_frame/test/mock_ie_event_sink_test.h" |
| 6 | 6 |
| 7 #include <sstream> | 7 #include <sstream> |
| 8 | 8 |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "base/win/scoped_variant.h" | 10 #include "base/win/scoped_variant.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 | 25 |
| 26 // MockIEEventSink methods | 26 // MockIEEventSink methods |
| 27 void MockIEEventSink::OnDocumentComplete(IDispatch* dispatch, VARIANT* url) { | 27 void MockIEEventSink::OnDocumentComplete(IDispatch* dispatch, VARIANT* url) { |
| 28 if (!event_sink_->IsCFRendering()) { | 28 if (!event_sink_->IsCFRendering()) { |
| 29 HWND renderer_window = event_sink_->GetRendererWindowSafe(); | 29 HWND renderer_window = event_sink_->GetRendererWindowSafe(); |
| 30 if (renderer_window) { | 30 if (renderer_window) { |
| 31 ::NotifyWinEvent(IA2_EVENT_DOCUMENT_LOAD_COMPLETE, | 31 ::NotifyWinEvent(IA2_EVENT_DOCUMENT_LOAD_COMPLETE, |
| 32 renderer_window, | 32 renderer_window, |
| 33 OBJID_CLIENT, 0L); | 33 OBJID_CLIENT, 0L); |
| 34 } else { | 34 } else { |
| 35 DVLOG(1) << "Browser does not have renderer window"; | 35 VLOG(1) << "Browser does not have renderer window"; |
| 36 } | 36 } |
| 37 OnLoad(IN_IE, V_BSTR(url)); | 37 OnLoad(IN_IE, V_BSTR(url)); |
| 38 } | 38 } |
| 39 } | 39 } |
| 40 | 40 |
| 41 ExpectationSet MockIEEventSink::ExpectNavigationCardinality( | 41 ExpectationSet MockIEEventSink::ExpectNavigationCardinality( |
| 42 const std::wstring& url, Cardinality before_cardinality, | 42 const std::wstring& url, Cardinality before_cardinality, |
| 43 Cardinality complete_cardinality) { | 43 Cardinality complete_cardinality) { |
| 44 ExpectationSet navigation; | 44 ExpectationSet navigation; |
| 45 if (url.empty()) { | 45 if (url.empty()) { |
| 46 navigation += EXPECT_CALL(*this, OnBeforeNavigate2(_, _, _, _, _, _, _)) | 46 navigation += EXPECT_CALL(*this, OnBeforeNavigate2(_, _, _, _, _, _, _)) |
| 47 .Times(before_cardinality).RetiresOnSaturation(); | 47 .Times(before_cardinality).RetiresOnSaturation(); |
| 48 } else { | 48 } else { |
| 49 navigation += EXPECT_CALL(*this, OnBeforeNavigate2(_, | 49 navigation += EXPECT_CALL(*this, OnBeforeNavigate2(_, |
| 50 testing::Field(&VARIANT::bstrVal, | 50 testing::Field(&VARIANT::bstrVal, |
| 51 StrCaseEq(url)), _, _, _, _, _)) | 51 StrCaseEq(url)), _, _, _, _, _)) |
| 52 .Times(before_cardinality).RetiresOnSaturation(); | 52 .Times(before_cardinality).RetiresOnSaturation(); |
| 53 } | 53 } |
| 54 | 54 |
| 55 // Hack: OnFileDownload may occur zero or once (for reasons not understood) | 55 // Hack: OnFileDownload may occur zero or once (for reasons not understood) |
| 56 // before each OnNavigateComplete2 which causes problems for tests expecting | 56 // before each OnNavigateComplete2 which causes problems for tests expecting |
| 57 // things in sequence. To redress this, expectations which allow multiple | 57 // things in sequence. To redress this, expectations which allow multiple |
| 58 // calls are split into expect statements expecting exactly one call or at | 58 // calls are split into expect statements expecting exactly one call or at |
| 59 // most one call. | 59 // most one call. |
| 60 // TODO(kkania): Consider avoiding this problem by creating a mock without | 60 // TODO(kkania): Consider avoiding this problem by creating a mock without |
| 61 // the OnFileDownload call or by removing the dependency of some tests on | 61 // the OnFileDownload call or by removing the dependency of some tests on |
| 62 // InSequence. | 62 // InSequence. |
| 63 DLOG_IF(WARNING, complete_cardinality.ConservativeUpperBound() > 1000) | 63 LOG_IF(WARNING, complete_cardinality.ConservativeUpperBound() > 1000) |
| 64 << "Cardinality upper bound may be too great to be split up into single " | 64 << "Cardinality upper bound may be too great to be split up into single " |
| 65 "expect statements. If you do not require this navigation to be in " | 65 "expect statements. If you do not require this navigation to be in " |
| 66 "sequence, do not call this method."; | 66 "sequence, do not call this method."; |
| 67 int call_count = 0; | 67 int call_count = 0; |
| 68 InSequence expect_in_sequence_for_scope; | 68 InSequence expect_in_sequence_for_scope; |
| 69 while (!complete_cardinality.IsSaturatedByCallCount(call_count)) { | 69 while (!complete_cardinality.IsSaturatedByCallCount(call_count)) { |
| 70 navigation += EXPECT_CALL(*this, OnFileDownload(_, _)) | 70 navigation += EXPECT_CALL(*this, OnFileDownload(_, _)) |
| 71 .Times(testing::AtMost(1)) | 71 .Times(testing::AtMost(1)) |
| 72 .WillOnce(testing::SetArgumentPointee<1>(VARIANT_TRUE)) | 72 .WillOnce(testing::SetArgumentPointee<1>(VARIANT_TRUE)) |
| 73 .RetiresOnSaturation(); | 73 .RetiresOnSaturation(); |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 const std::wstring& relative_path) { | 225 const std::wstring& relative_path) { |
| 226 return server_mock_.root_dir().Append(relative_path); | 226 return server_mock_.root_dir().Append(relative_path); |
| 227 } | 227 } |
| 228 | 228 |
| 229 std::wstring MockIEEventSinkTest::GetTestUrl( | 229 std::wstring MockIEEventSinkTest::GetTestUrl( |
| 230 const std::wstring& relative_path) { | 230 const std::wstring& relative_path) { |
| 231 return server_mock_.Resolve(relative_path.c_str()); | 231 return server_mock_.Resolve(relative_path.c_str()); |
| 232 } | 232 } |
| 233 | 233 |
| 234 } // namespace chrome_frame_test | 234 } // namespace chrome_frame_test |
| OLD | NEW |