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

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

Issue 9460019: Reduce flakiness in chrome_frame_tests.exe by having each run in a clean environment. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixed compile break Created 8 years, 10 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
OLDNEW
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/automation_client_mock.h" 5 #include "chrome_frame/test/automation_client_mock.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "chrome/common/automation_messages.h" 9 #include "chrome/common/automation_messages.h"
10 #include "chrome_frame/custom_sync_call_context.h" 10 #include "chrome_frame/custom_sync_call_context.h"
11 #include "chrome_frame/navigation_constraints.h" 11 #include "chrome_frame/navigation_constraints.h"
12 #include "chrome_frame/test/chrome_frame_test_utils.h" 12 #include "chrome_frame/test/chrome_frame_test_utils.h"
13 #include "chrome_frame/test/test_scrubber.h"
13 #include "net/base/net_errors.h" 14 #include "net/base/net_errors.h"
14 15
15 #define GMOCK_MUTANT_INCLUDE_LATE_OBJECT_BINDING 16 #define GMOCK_MUTANT_INCLUDE_LATE_OBJECT_BINDING
16 #include "testing/gmock_mutant.h" 17 #include "testing/gmock_mutant.h"
17 18
18 using testing::_; 19 using testing::_;
19 using testing::CreateFunctor; 20 using testing::CreateFunctor;
20 using testing::Return; 21 using testing::Return;
21 22
23 namespace {
24
25 #ifndef NDEBUG
26 const int kChromeLaunchTimeout = 15;
27 #else
28 const int kChromeLaunchTimeout = 10;
29 #endif
30
31 } // namespace
32
22 MATCHER_P(LaunchParamProfileEq, profile_name, "Check for profile name") { 33 MATCHER_P(LaunchParamProfileEq, profile_name, "Check for profile name") {
23 return arg->profile_name().compare(profile_name) == 0; 34 return arg->profile_name().compare(profile_name) == 0;
24 } 35 }
25 36
26 void MockProxyFactory::GetServerImpl(ChromeFrameAutomationProxy* pxy, 37 void MockProxyFactory::GetServerImpl(ChromeFrameAutomationProxy* pxy,
27 void* proxy_id, 38 void* proxy_id,
28 AutomationLaunchResult result, 39 AutomationLaunchResult result,
29 LaunchDelegate* d, 40 LaunchDelegate* d,
30 ChromeFrameLaunchParams* params, 41 ChromeFrameLaunchParams* params,
31 void** automation_server_id) { 42 void** automation_server_id) {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 CreateExternalTabContext* context = 93 CreateExternalTabContext* context =
83 reinterpret_cast<CreateExternalTabContext*>(arg1); 94 reinterpret_cast<CreateExternalTabContext*>(arg1);
84 DispatchToMethod(context, &CreateExternalTabContext::Completed, input_args); 95 DispatchToMethod(context, &CreateExternalTabContext::Completed, input_args);
85 delete context; 96 delete context;
86 } 97 }
87 98
88 ACTION_P4(InitiateNavigation, client, url, referrer, constraints) { 99 ACTION_P4(InitiateNavigation, client, url, referrer, constraints) {
89 client->InitiateNavigation(url, referrer, constraints); 100 client->InitiateNavigation(url, referrer, constraints);
90 } 101 }
91 102
103 class CFACWithChrome : public testing::Test {
robertshield 2012/02/27 21:13:42 What's a CFAC? I can haz comment / better name?
grt (UTC plus 2) 2012/02/28 03:12:04 Done.
104 protected:
105 static void SetUpTestCase();
106 static void TearDownTestCase();
107
108 virtual void SetUp() OVERRIDE;
109 virtual void TearDown() OVERRIDE;
110
111 static FilePath profile_path_;
112 MockCFDelegate cfd_;
113 scoped_refptr<ChromeFrameAutomationClient> client_;
114 scoped_refptr<ChromeFrameLaunchParams> launch_params_;
115 chrome_frame_test::TimedMsgLoop loop_;
116 };
117
118 // static
119 FilePath CFACWithChrome::profile_path_;
120
121 // static
122 void CFACWithChrome::SetUpTestCase() {
123 profile_path_ = chrome_frame_test::GetProfilePath(L"Adam.N.Epilinter");
124 }
125
126 // static
127 void CFACWithChrome::TearDownTestCase() {
128 profile_path_.clear();
129 }
130
131 void CFACWithChrome::SetUp() {
132 chrome_frame_test::OverrideDataDirectoryForThisTest(profile_path_.value());
133 client_ = new ChromeFrameAutomationClient();
134 GURL empty;
135 launch_params_ = new ChromeFrameLaunchParams(
136 empty, empty, profile_path_, profile_path_.BaseName().value(), L"",
137 false, false, false);
138 launch_params_->set_version_check(false);
139 }
140
141 void CFACWithChrome::TearDown() {
142 client_->Uninitialize();
143 }
144
92 // We mock ChromeFrameDelegate only. The rest is with real AutomationProxy 145 // We mock ChromeFrameDelegate only. The rest is with real AutomationProxy
93 TEST(CFACWithChrome, CreateTooFast) { 146 TEST_F(CFACWithChrome, CreateTooFast) {
94 MockCFDelegate cfd;
95 chrome_frame_test::TimedMsgLoop loop;
96 int timeout = 0; // Chrome cannot send Hello message so fast. 147 int timeout = 0; // Chrome cannot send Hello message so fast.
97 const FilePath profile_path(
98 chrome_frame_test::GetProfilePath(L"Adam.N.Epilinter"));
99 148
100 scoped_refptr<ChromeFrameAutomationClient> client; 149 EXPECT_CALL(cfd_, OnAutomationServerLaunchFailed(AUTOMATION_TIMEOUT, _))
101 client = new ChromeFrameAutomationClient(); 150 .WillOnce(QUIT_LOOP(loop_));
102 151
103 EXPECT_CALL(cfd, OnAutomationServerLaunchFailed(AUTOMATION_TIMEOUT, _)) 152 launch_params_->set_launch_timeout(timeout);
104 .Times(1) 153 EXPECT_TRUE(client_->Initialize(&cfd_, launch_params_));
105 .WillOnce(QUIT_LOOP(loop)); 154 loop_.RunFor(kChromeLaunchTimeout);
106
107 GURL empty;
108 scoped_refptr<ChromeFrameLaunchParams> clp(new ChromeFrameLaunchParams(
109 empty, empty, profile_path, profile_path.BaseName().value(), L"",
110 false, false, false));
111 clp->set_launch_timeout(timeout);
112 clp->set_version_check(false);
113 EXPECT_TRUE(client->Initialize(&cfd, clp));
114 loop.RunFor(10);
115 client->Uninitialize();
116 } 155 }
117 156
118 // This test may fail if Chrome take more that 10 seconds (timeout var) to 157 // 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 158 // launch. In this case GMock shall print something like "unexpected call to
120 // OnAutomationServerLaunchFailed". I'm yet to find out how to specify 159 // OnAutomationServerLaunchFailed". I'm yet to find out how to specify
121 // that this is an unexpected call, and still to execute an action. 160 // that this is an unexpected call, and still to execute an action.
122 TEST(CFACWithChrome, CreateNotSoFast) { 161 TEST_F(CFACWithChrome, CreateNotSoFast) {
123 MockCFDelegate cfd;
124 chrome_frame_test::TimedMsgLoop loop;
125 const FilePath profile_path(
126 chrome_frame_test::GetProfilePath(L"Adam.N.Epilinter"));
127 int timeout = 10000; 162 int timeout = 10000;
robertshield 2012/02/27 21:13:42 constant-ize this?
grt (UTC plus 2) 2012/02/28 03:12:04 Done.
128 163
129 scoped_refptr<ChromeFrameAutomationClient> client; 164 EXPECT_CALL(cfd_, OnAutomationServerReady())
130 client = new ChromeFrameAutomationClient; 165 .WillOnce(QUIT_LOOP(loop_));
131 166
132 EXPECT_CALL(cfd, OnAutomationServerReady()) 167 EXPECT_CALL(cfd_, OnAutomationServerLaunchFailed(_, _))
133 .Times(1)
134 .WillOnce(QUIT_LOOP(loop));
135
136 EXPECT_CALL(cfd, OnAutomationServerLaunchFailed(_, _))
137 .Times(0); 168 .Times(0);
138 169
139 GURL empty; 170 launch_params_->set_launch_timeout(timeout);
140 scoped_refptr<ChromeFrameLaunchParams> clp(new ChromeFrameLaunchParams( 171 EXPECT_TRUE(client_->Initialize(&cfd_, launch_params_));
141 empty, empty, profile_path, profile_path.BaseName().value(), L"",
142 false, false, false));
143 clp->set_launch_timeout(timeout);
144 clp->set_version_check(false);
145 EXPECT_TRUE(client->Initialize(&cfd, clp));
146 172
147 loop.RunFor(11); 173 loop_.RunFor(kChromeLaunchTimeout);
148 client->Uninitialize();
149 client = NULL;
150 } 174 }
151 175
152 // FLAKY: 114386. 176 TEST_F(CFACWithChrome, NavigateOk) {
153 TEST(CFACWithChrome, DISABLED_NavigateOk) {
154 MockCFDelegate cfd;
155 NavigationConstraintsImpl navigation_constraints; 177 NavigationConstraintsImpl navigation_constraints;
156 178
157 chrome_frame_test::TimedMsgLoop loop;
158 const std::string url = "about:version"; 179 const std::string url = "about:version";
159 const FilePath profile_path(
160 chrome_frame_test::GetProfilePath(L"Adam.N.Epilinter"));
161 int timeout = 10000; 180 int timeout = 10000;
robertshield 2012/02/27 21:13:42 ditto
grt (UTC plus 2) 2012/02/28 03:12:04 Done.
162 181
163 scoped_refptr<ChromeFrameAutomationClient> client; 182 EXPECT_CALL(cfd_, OnAutomationServerReady())
164 client = new ChromeFrameAutomationClient; 183 .WillOnce(InitiateNavigation(client_.get(), url, std::string(),
165
166 EXPECT_CALL(cfd, OnAutomationServerReady())
167 .WillOnce(InitiateNavigation(client.get(),
168 url, std::string(),
169 &navigation_constraints)); 184 &navigation_constraints));
170 185
171 EXPECT_CALL(cfd, GetBounds(_)).Times(testing::AnyNumber()); 186 EXPECT_CALL(cfd_, GetBounds(_)).Times(testing::AnyNumber());
172 187
173 EXPECT_CALL(cfd, OnNavigationStateChanged(_)) 188 EXPECT_CALL(cfd_, OnNavigationStateChanged(_))
174 .Times(testing::AnyNumber()); 189 .Times(testing::AnyNumber());
175 190
176 { 191 {
177 testing::InSequence s; 192 testing::InSequence s;
178 193
179 EXPECT_CALL(cfd, OnDidNavigate(EqNavigationInfoUrl(GURL()))) 194 EXPECT_CALL(cfd_, OnDidNavigate(EqNavigationInfoUrl(GURL())))
180 .Times(1); 195 .Times(1);
181 196
182 EXPECT_CALL(cfd, OnUpdateTargetUrl(_)).Times(testing::AtMost(1)); 197 EXPECT_CALL(cfd_, OnUpdateTargetUrl(_)).Times(testing::AtMost(1));
183 198
184 EXPECT_CALL(cfd, OnLoad(_)) 199 EXPECT_CALL(cfd_, OnLoad(_))
185 .Times(1) 200 .WillOnce(QUIT_LOOP(loop_));
186 .WillOnce(QUIT_LOOP(loop));
187 } 201 }
188 202
189 GURL empty; 203 launch_params_->set_launch_timeout(timeout);
190 scoped_refptr<ChromeFrameLaunchParams> clp(new ChromeFrameLaunchParams( 204 EXPECT_TRUE(client_->Initialize(&cfd_, launch_params_));
191 empty, empty, profile_path, profile_path.BaseName().value(), L"", 205 loop_.RunFor(kChromeLaunchTimeout);
192 false, false, false));
193 clp->set_launch_timeout(timeout);
194 clp->set_version_check(false);
195 EXPECT_TRUE(client->Initialize(&cfd, clp));
196 loop.RunFor(10);
197 client->Uninitialize();
198 client = NULL;
199 } 206 }
200 207
201 // FLAKY: 114386. 208 TEST_F(CFACWithChrome, NavigateFailed) {
202 TEST(CFACWithChrome, DISABLED_NavigateFailed) {
203 MockCFDelegate cfd;
204 NavigationConstraintsImpl navigation_constraints; 209 NavigationConstraintsImpl navigation_constraints;
205 chrome_frame_test::TimedMsgLoop loop;
206 const FilePath profile_path(
207 chrome_frame_test::GetProfilePath(L"Adam.N.Epilinter"));
208 const std::string url = "http://127.0.0.3:65412/"; 210 const std::string url = "http://127.0.0.3:65412/";
209 const net::URLRequestStatus connection_failed(net::URLRequestStatus::FAILED, 211 const net::URLRequestStatus connection_failed(net::URLRequestStatus::FAILED,
210 net::ERR_INVALID_URL); 212 net::ERR_INVALID_URL);
211 213
212 scoped_refptr<ChromeFrameAutomationClient> client; 214 cfd_.SetRequestDelegate(client_);
213 client = new ChromeFrameAutomationClient;
214 cfd.SetRequestDelegate(client);
215 215
216 EXPECT_CALL(cfd, OnAutomationServerReady()) 216 EXPECT_CALL(cfd_, OnAutomationServerReady())
217 .WillOnce(testing::IgnoreResult(testing::InvokeWithoutArgs(CreateFunctor( 217 .WillOnce(testing::IgnoreResult(testing::InvokeWithoutArgs(CreateFunctor(
218 client.get(), &ChromeFrameAutomationClient::InitiateNavigation, 218 client_.get(), &ChromeFrameAutomationClient::InitiateNavigation,
219 url, std::string(), &navigation_constraints)))); 219 url, std::string(), &navigation_constraints))));
220 220
221 EXPECT_CALL(cfd, GetBounds(_)).Times(testing::AnyNumber()); 221 EXPECT_CALL(cfd_, GetBounds(_)).Times(testing::AnyNumber());
222 EXPECT_CALL(cfd, OnNavigationStateChanged(_)).Times(testing::AnyNumber()); 222 EXPECT_CALL(cfd_, OnNavigationStateChanged(_)).Times(testing::AnyNumber());
223 223
224 EXPECT_CALL(cfd, OnRequestStart(_, _)) 224 EXPECT_CALL(cfd_, OnRequestStart(_, _))
225 // Often there's another request for the error page 225 // Often there's another request for the error page
226 .Times(testing::Between(1, 2)) 226 .Times(testing::Between(1, 2))
227 .WillRepeatedly(testing::WithArgs<0>(testing::Invoke(CreateFunctor(&cfd, 227 .WillRepeatedly(testing::WithArgs<0>(testing::Invoke(CreateFunctor(&cfd_,
228 &MockCFDelegate::Reply, connection_failed)))); 228 &MockCFDelegate::Reply, connection_failed))));
229 229
230 EXPECT_CALL(cfd, OnUpdateTargetUrl(_)).Times(testing::AnyNumber()); 230 EXPECT_CALL(cfd_, OnUpdateTargetUrl(_)).Times(testing::AnyNumber());
231 EXPECT_CALL(cfd, OnLoad(_)).Times(testing::AtMost(1)); 231 EXPECT_CALL(cfd_, OnLoad(_)).Times(testing::AtMost(1));
232 232
233 EXPECT_CALL(cfd, OnNavigationFailed(_, GURL(url))) 233 EXPECT_CALL(cfd_, OnNavigationFailed(_, GURL(url)))
234 .Times(1) 234 .Times(1)
235 .WillOnce(QUIT_LOOP_SOON(loop, 2)); 235 .WillOnce(QUIT_LOOP_SOON(loop_, 2));
236 236
237 GURL empty; 237 launch_params_->set_launch_timeout(10000);
238 scoped_refptr<ChromeFrameLaunchParams> clp(new ChromeFrameLaunchParams( 238 EXPECT_TRUE(client_->Initialize(&cfd_, launch_params_));
239 empty, empty, profile_path, profile_path.BaseName().value(), L"",
240 false, false, false));
241 clp->set_launch_timeout(10000);
242 clp->set_version_check(false);
243 EXPECT_TRUE(client->Initialize(&cfd, clp));
244 239
245 loop.RunFor(10); 240 loop_.RunFor(kChromeLaunchTimeout);
246 client->Uninitialize();
247 client = NULL;
248 } 241 }
249 242
250 TEST_F(CFACMockTest, MockedCreateTabOk) { 243 TEST_F(CFACMockTest, MockedCreateTabOk) {
251 int timeout = 500; 244 int timeout = 500;
252 CreateTab(); 245 CreateTab();
253 SetAutomationServerOk(1); 246 SetAutomationServerOk(1);
254 247
255 EXPECT_CALL(mock_proxy_, server_version()).Times(testing::AnyNumber()) 248 EXPECT_CALL(mock_proxy_, server_version()).Times(testing::AnyNumber())
256 .WillRepeatedly(Return("")); 249 .WillRepeatedly(Return(""));
257 250
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 GURL("http://www.nonexistent.com"), empty, profile_path_, 464 GURL("http://www.nonexistent.com"), empty, profile_path_,
472 profile_path_.BaseName().value(), L"", false, false, false)); 465 profile_path_.BaseName().value(), L"", false, false, false));
473 launch_params->set_launch_timeout(timeout); 466 launch_params->set_launch_timeout(timeout);
474 launch_params->set_version_check(false); 467 launch_params->set_version_check(false);
475 EXPECT_TRUE(client_->Initialize(&cfd_, launch_params)); 468 EXPECT_TRUE(client_->Initialize(&cfd_, launch_params));
476 loop_.RunFor(10); 469 loop_.RunFor(10);
477 470
478 EXPECT_CALL(mock_proxy_, ReleaseTabProxy(testing::Eq(tab_handle_))).Times(1); 471 EXPECT_CALL(mock_proxy_, ReleaseTabProxy(testing::Eq(tab_handle_))).Times(1);
479 client_->Uninitialize(); 472 client_->Uninitialize();
480 } 473 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698