Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(99)

Side by Side Diff: chrome_frame/test/mock_ie_event_sink_test.cc

Issue 2822016: [chrome_frame] Refactor/merge IE no interference tests with other mock event ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome_frame/test/mock_ie_event_sink_test.h ('k') | chrome_frame/test/navigation_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome_frame/test/mock_ie_event_sink_test.h"
6
7 #include <sstream>
8
9 #include "base/utf_string_conversions.h"
10 #include "chrome_frame/test/mock_ie_event_sink_actions.h"
11
12 // Needed for CreateFunctor.
13 #define GMOCK_MUTANT_INCLUDE_LATE_OBJECT_BINDING
14 #include "testing/gmock_mutant.h"
15
16 using testing::_;
17 using testing::Cardinality;
18 using testing::Exactly;
19 using testing::ExpectationSet;
20 using testing::InSequence;
21 using testing::StrCaseEq;
22
23 namespace chrome_frame_test {
24
25 // MockIEEventSink methods
26 ExpectationSet MockIEEventSink::ExpectNavigationCardinality(
27 const std::wstring& url, Cardinality before_cardinality,
28 Cardinality complete_cardinality) {
29 ExpectationSet navigation;
30 if (url.empty()) {
31 navigation += EXPECT_CALL(*this, OnBeforeNavigate2(_, _, _, _, _, _, _))
32 .Times(before_cardinality).RetiresOnSaturation();
33 } else {
34 navigation += EXPECT_CALL(*this, OnBeforeNavigate2(_,
35 testing::Field(&VARIANT::bstrVal,
36 StrCaseEq(url)), _, _, _, _, _))
37 .Times(before_cardinality).RetiresOnSaturation();
38 }
39
40 // Hack: OnFileDownload may occur zero or once (for reasons not understood)
41 // before each OnNavigateComplete2 which causes problems for tests expecting
42 // things in sequence. To redress this, expectations which allow multiple
43 // calls are split into expect statements expecting exactly one call or at
44 // most one call.
45 // TODO(kkania): Consider avoiding this problem by creating a mock without
46 // the OnFileDownload call or by removing the dependency of some tests on
47 // InSequence.
48 DLOG_IF(WARNING, complete_cardinality.ConservativeUpperBound() > 1000)
49 << "Cardinality upper bound may be too great to be split up into single "
50 << "expect statements. If you do not require this navigation to be in "
51 << "sequence, do not call this method.";
52 int call_count = 0;
53 InSequence expect_in_sequence_for_scope;
54 while (!complete_cardinality.IsSaturatedByCallCount(call_count)) {
55 navigation += EXPECT_CALL(*this, OnFileDownload(_, _))
56 .Times(testing::AtMost(1))
57 .RetiresOnSaturation();
58
59 Cardinality split_complete_cardinality = testing::Exactly(1);
60 if (complete_cardinality.IsSatisfiedByCallCount(call_count))
61 split_complete_cardinality = testing::AtMost(1);
62
63 if (url.empty()) {
64 navigation += EXPECT_CALL(*this, OnNavigateComplete2(_, _))
65 .Times(split_complete_cardinality)
66 .RetiresOnSaturation();
67 } else {
68 navigation += EXPECT_CALL(*this, OnNavigateComplete2(_,
69 testing::Field(&VARIANT::bstrVal,
70 StrCaseEq(url))))
71 .Times(split_complete_cardinality)
72 .RetiresOnSaturation();
73 }
74 call_count++;
75 }
76 return navigation;
77 }
78
79 void MockIEEventSink::ExpectNavigation(bool is_cf, const std::wstring& url) {
80 InSequence expect_in_sequence_for_scope;
81 if (is_cf) {
82 ExpectNavigationCardinality(url, Exactly(1), testing::Between(1, 2));
83 } else {
84 ExpectNavigationCardinality(url, Exactly(1), Exactly(1));
85 }
86 }
87
88 void MockIEEventSink::ExpectInPageNavigation(bool is_cf,
89 const std::wstring& url) {
90 InSequence expect_in_sequence_for_scope;
91 if (is_cf && GetInstalledIEVersion() == IE_6) {
92 // OnBeforeNavigation events are not sent for navigation between different
93 // anchors in a CF page in IE6.
94 ExpectNavigationCardinality(url, testing::AtMost(1),
95 testing::Between(1, 2));
96 } else {
97 ExpectNavigation(is_cf, url);
98 }
99 }
100
101 void MockIEEventSink::ExpectJavascriptWindowOpenNavigation(
102 bool parent_cf, bool new_window_cf, const std::wstring& url) {
103 DCHECK(!(parent_cf && !new_window_cf)) << "Cannot expect popup to be loaded"
104 " in Internet Explorer if parent window is loaded in Chrome Frame.";
105
106 if (parent_cf) {
107 InSequence expect_in_sequence_for_scope;
108 ExpectNavigation(IN_CF, L"");
109 ExpectNavigationCardinality(L"", testing::AtMost(1),
110 testing::Between(1, 2));
111 } else {
112 if (new_window_cf) {
113 ExpectNavigationCardinality(url, testing::AtMost(1), testing::AtMost(1));
114 // Sometimes an extra load occurs here for some reason.
115 EXPECT_CALL(*this, OnLoad(IN_IE, StrCaseEq(url)))
116 .Times(testing::AtMost(1));
117 ExpectNavigationCardinality(url, testing::AtMost(1),
118 testing::Between(1, 2));
119 } else {
120 ExpectNavigation(IN_IE, url);
121 }
122 }
123 }
124
125 void MockIEEventSink::ExpectNewWindow(MockIEEventSink* new_window_mock) {
126 DCHECK(new_window_mock);
127
128 EXPECT_CALL(*this, OnNewWindow3(_, _, _, _, _));
129 EXPECT_CALL(*this, OnNewBrowserWindow(_, _))
130 .WillOnce(testing::WithArgs<0>(testing::Invoke(testing::CreateFunctor(
131 new_window_mock, &MockIEEventSink::Attach))));
132 }
133
134 void MockIEEventSink::ExpectAnyNavigations() {
135 EXPECT_CALL(*this, OnBeforeNavigate2(_, _, _, _, _, _, _))
136 .Times(testing::AnyNumber());
137 EXPECT_CALL(*this, OnFileDownload(VARIANT_TRUE, _))
138 .Times(testing::AnyNumber());
139 EXPECT_CALL(*this, OnNavigateComplete2(_, _))
140 .Times(testing::AnyNumber());
141 }
142
143 // MockIEEventSinkTest methods
144 MockIEEventSinkTest::MockIEEventSinkTest() : server_mock_(1337, L"127.0.0.1",
145 GetTestDataFolder()) {
146 EXPECT_CALL(server_mock_, Get(_, StrCaseEq(L"/favicon.ico"), _))
147 .WillRepeatedly(SendFast("HTTP/1.1 404 Not Found", ""));
148 }
149
150 void MockIEEventSinkTest::LaunchIEAndNavigate(const std::wstring& url) {
151 LaunchIENavigateAndLoop(url, kChromeFrameLongNavigationTimeoutInSeconds);
152 }
153
154 void MockIEEventSinkTest::LaunchIENavigateAndLoop(const std::wstring& url,
155 int timeout) {
156 EXPECT_CALL(ie_mock_, OnQuit())
157 .WillOnce(QUIT_LOOP(loop_));
158 HRESULT hr = ie_mock_.event_sink()->LaunchIEAndNavigate(url, &ie_mock_);
159 ASSERT_HRESULT_SUCCEEDED(hr);
160 if (hr == S_FALSE)
161 return;
162
163 ASSERT_TRUE(ie_mock_.event_sink()->web_browser2() != NULL);
164 loop_.RunFor(timeout);
165 }
166
167 std::wstring MockIEEventSinkTest::GetTestUrl(
168 const std::wstring& relative_path) {
169 return server_mock_.Resolve(relative_path.c_str());
170 }
171
172 } // namespace chrome_frame_test
OLDNEW
« no previous file with comments | « chrome_frame/test/mock_ie_event_sink_test.h ('k') | chrome_frame/test/navigation_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698