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

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

Issue 858003: First cut of privacy work for GCF. Implements IDeleteBrowsing history and mov... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 9 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) 2006-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/test/chrome_frame_test_utils.h" 8 #include "chrome_frame/test/chrome_frame_test_utils.h"
9 9
10 #define GMOCK_MUTANT_INCLUDE_LATE_OBJECT_BINDING 10 #define GMOCK_MUTANT_INCLUDE_LATE_OBJECT_BINDING
11 #include "testing/gmock_mutant.h" 11 #include "testing/gmock_mutant.h"
(...skipping 25 matching lines...) Expand all
37 *automation_server_id = proxy_id; 37 *automation_server_id = proxy_id;
38 Task* task = NewRunnableMethod(d, 38 Task* task = NewRunnableMethod(d,
39 &ProxyFactory::LaunchDelegate::LaunchComplete, pxy, result); 39 &ProxyFactory::LaunchDelegate::LaunchComplete, pxy, result);
40 loop_->PostDelayedTask(FROM_HERE, task, 40 loop_->PostDelayedTask(FROM_HERE, task,
41 params.automation_server_launch_timeout/2); 41 params.automation_server_launch_timeout/2);
42 } 42 }
43 43
44 void CFACMockTest::SetAutomationServerOk() { 44 void CFACMockTest::SetAutomationServerOk() {
45 EXPECT_CALL(factory_, GetAutomationServer(testing::NotNull(), 45 EXPECT_CALL(factory_, GetAutomationServer(testing::NotNull(),
46 testing::Field(&ChromeFrameLaunchParams::profile_name, 46 testing::Field(&ChromeFrameLaunchParams::profile_name,
47 testing::StrEq(profile_)), 47 testing::StrEq(profile_path_.BaseName().ToWStringHack())),
48 testing::NotNull())) 48 testing::NotNull()))
49 .Times(1) 49 .Times(1)
50 .WillOnce(testing::Invoke(CreateFunctor(&factory_, 50 .WillOnce(testing::Invoke(CreateFunctor(&factory_,
51 &MockProxyFactory::GetServerImpl, 51 &MockProxyFactory::GetServerImpl,
52 get_proxy(), id_, 52 get_proxy(), id_,
53 AUTOMATION_SUCCESS))); 53 AUTOMATION_SUCCESS)));
54 54
55 EXPECT_CALL(factory_, ReleaseAutomationServer(testing::Eq(id_))).Times(1); 55 EXPECT_CALL(factory_, ReleaseAutomationServer(testing::Eq(id_))).Times(1);
56 } 56 }
57 57
(...skipping 26 matching lines...) Expand all
84 c->Run(external_tab_container, tab_wnd, tab_handle); 84 c->Run(external_tab_container, tab_wnd, tab_handle);
85 delete c; 85 delete c;
86 delete arg0; 86 delete arg0;
87 } 87 }
88 88
89 // We mock ChromeFrameDelegate only. The rest is with real AutomationProxy 89 // We mock ChromeFrameDelegate only. The rest is with real AutomationProxy
90 TEST(CFACWithChrome, CreateTooFast) { 90 TEST(CFACWithChrome, CreateTooFast) {
91 MockCFDelegate cfd; 91 MockCFDelegate cfd;
92 chrome_frame_test::TimedMsgLoop loop; 92 chrome_frame_test::TimedMsgLoop loop;
93 int timeout = 0; // Chrome cannot send Hello message so fast. 93 int timeout = 0; // Chrome cannot send Hello message so fast.
94 const std::wstring profile = L"Adam.N.Epilinter"; 94 const FilePath profile_path(
95 chrome_frame_test::GetProfilePath(L"Adam.N.Epilinter"));
95 96
96 scoped_refptr<ChromeFrameAutomationClient> client; 97 scoped_refptr<ChromeFrameAutomationClient> client;
97 client = new ChromeFrameAutomationClient(); 98 client = new ChromeFrameAutomationClient();
98 99
99 EXPECT_CALL(cfd, OnAutomationServerLaunchFailed(AUTOMATION_TIMEOUT, _)) 100 EXPECT_CALL(cfd, OnAutomationServerLaunchFailed(AUTOMATION_TIMEOUT, _))
100 .Times(1) 101 .Times(1)
101 .WillOnce(QUIT_LOOP(loop)); 102 .WillOnce(QUIT_LOOP(loop));
102 103
103 EXPECT_TRUE(client->Initialize(&cfd, timeout, false, profile, L"", false)); 104 EXPECT_TRUE(client->Initialize(&cfd, timeout, false, profile_path, L"",
105 false));
104 loop.RunFor(10); 106 loop.RunFor(10);
105 client->Uninitialize(); 107 client->Uninitialize();
106 } 108 }
107 109
108 // This test may fail if Chrome take more that 10 seconds (timeout var) to 110 // This test may fail if Chrome take more that 10 seconds (timeout var) to
109 // launch. In this case GMock shall print something like "unexpected call to 111 // launch. In this case GMock shall print something like "unexpected call to
110 // OnAutomationServerLaunchFailed". I'm yet to find out how to specify 112 // OnAutomationServerLaunchFailed". I'm yet to find out how to specify
111 // that this is an unexpected call, and still to execute and action. 113 // that this is an unexpected call, and still to execute and action.
112 TEST(CFACWithChrome, CreateNotSoFast) { 114 TEST(CFACWithChrome, CreateNotSoFast) {
113 MockCFDelegate cfd; 115 MockCFDelegate cfd;
114 chrome_frame_test::TimedMsgLoop loop; 116 chrome_frame_test::TimedMsgLoop loop;
115 const std::wstring profile = L"Adam.N.Epilinter"; 117 const FilePath profile_path(
118 chrome_frame_test::GetProfilePath(L"Adam.N.Epilinter"));
116 int timeout = 10000; 119 int timeout = 10000;
117 120
118 scoped_refptr<ChromeFrameAutomationClient> client; 121 scoped_refptr<ChromeFrameAutomationClient> client;
119 client = new ChromeFrameAutomationClient; 122 client = new ChromeFrameAutomationClient;
120 123
121 EXPECT_CALL(cfd, OnAutomationServerReady()) 124 EXPECT_CALL(cfd, OnAutomationServerReady())
122 .Times(1) 125 .Times(1)
123 .WillOnce(QUIT_LOOP(loop)); 126 .WillOnce(QUIT_LOOP(loop));
124 127
125 EXPECT_CALL(cfd, OnAutomationServerLaunchFailed(_, _)) 128 EXPECT_CALL(cfd, OnAutomationServerLaunchFailed(_, _))
126 .Times(0); 129 .Times(0);
127 130
128 EXPECT_TRUE(client->Initialize(&cfd, timeout, false, profile, L"", false)); 131 EXPECT_TRUE(client->Initialize(&cfd, timeout, false, profile_path, L"",
132 false));
129 133
130 loop.RunFor(11); 134 loop.RunFor(11);
131 client->Uninitialize(); 135 client->Uninitialize();
132 client = NULL; 136 client = NULL;
133 } 137 }
134 138
135 TEST(CFACWithChrome, NavigateOk) { 139 TEST(CFACWithChrome, NavigateOk) {
136 MockCFDelegate cfd; 140 MockCFDelegate cfd;
137 chrome_frame_test::TimedMsgLoop loop; 141 chrome_frame_test::TimedMsgLoop loop;
138 const std::wstring profile = L"Adam.N.Epilinter";
139 const std::string url = "about:version"; 142 const std::string url = "about:version";
143 const FilePath profile_path(
144 chrome_frame_test::GetProfilePath(L"Adam.N.Epilinter"));
140 int timeout = 10000; 145 int timeout = 10000;
141 146
142 scoped_refptr<ChromeFrameAutomationClient> client; 147 scoped_refptr<ChromeFrameAutomationClient> client;
143 client = new ChromeFrameAutomationClient; 148 client = new ChromeFrameAutomationClient;
144 149
145 EXPECT_CALL(cfd, OnAutomationServerReady()) 150 EXPECT_CALL(cfd, OnAutomationServerReady())
146 .WillOnce(testing::IgnoreResult(testing::InvokeWithoutArgs(CreateFunctor( 151 .WillOnce(testing::IgnoreResult(testing::InvokeWithoutArgs(CreateFunctor(
147 client.get(), &ChromeFrameAutomationClient::InitiateNavigation, 152 client.get(), &ChromeFrameAutomationClient::InitiateNavigation,
148 url, std::string(), false)))); 153 url, std::string(), false))));
149 154
150 EXPECT_CALL(cfd, GetBounds(_)).Times(testing::AnyNumber()); 155 EXPECT_CALL(cfd, GetBounds(_)).Times(testing::AnyNumber());
151 156
152 EXPECT_CALL(cfd, OnNavigationStateChanged(_, _)) 157 EXPECT_CALL(cfd, OnNavigationStateChanged(_, _))
153 .Times(testing::AnyNumber()); 158 .Times(testing::AnyNumber());
154 159
155 { 160 {
156 testing::InSequence s; 161 testing::InSequence s;
157 162
158 EXPECT_CALL(cfd, OnDidNavigate(_, EqNavigationInfoUrl(GURL()))) 163 EXPECT_CALL(cfd, OnDidNavigate(_, EqNavigationInfoUrl(GURL())))
159 .Times(1); 164 .Times(1);
160 165
161 EXPECT_CALL(cfd, OnUpdateTargetUrl(_, _)).Times(1); 166 EXPECT_CALL(cfd, OnUpdateTargetUrl(_, _)).Times(1);
162 167
163 EXPECT_CALL(cfd, OnLoad(_, _)) 168 EXPECT_CALL(cfd, OnLoad(_, _))
164 .Times(1) 169 .Times(1)
165 .WillOnce(QUIT_LOOP(loop)); 170 .WillOnce(QUIT_LOOP(loop));
166 } 171 }
167 172
168 EXPECT_TRUE(client->Initialize(&cfd, timeout, false, profile, L"", false)); 173 EXPECT_TRUE(client->Initialize(&cfd, timeout, false, profile_path, L"",
174 false));
169 loop.RunFor(10); 175 loop.RunFor(10);
170 client->Uninitialize(); 176 client->Uninitialize();
171 client = NULL; 177 client = NULL;
172 } 178 }
173 179
174 TEST(CFACWithChrome, NavigateFailed) { 180 TEST(CFACWithChrome, NavigateFailed) {
175 MockCFDelegate cfd; 181 MockCFDelegate cfd;
176 chrome_frame_test::TimedMsgLoop loop; 182 chrome_frame_test::TimedMsgLoop loop;
177 const std::wstring profile = L"Adam.N.Epilinter"; 183 const FilePath profile_path(
184 chrome_frame_test::GetProfilePath(L"Adam.N.Epilinter"));
178 const std::string url = "http://127.0.0.3:65412/"; 185 const std::string url = "http://127.0.0.3:65412/";
179 const URLRequestStatus connection_failed(URLRequestStatus::FAILED, 186 const URLRequestStatus connection_failed(URLRequestStatus::FAILED,
180 net::ERR_INVALID_URL); 187 net::ERR_INVALID_URL);
181 188
182 scoped_refptr<ChromeFrameAutomationClient> client; 189 scoped_refptr<ChromeFrameAutomationClient> client;
183 client = new ChromeFrameAutomationClient; 190 client = new ChromeFrameAutomationClient;
184 cfd.SetRequestDelegate(client); 191 cfd.SetRequestDelegate(client);
185 192
186 EXPECT_CALL(cfd, OnAutomationServerReady()) 193 EXPECT_CALL(cfd, OnAutomationServerReady())
187 .WillOnce(testing::IgnoreResult(testing::InvokeWithoutArgs(CreateFunctor( 194 .WillOnce(testing::IgnoreResult(testing::InvokeWithoutArgs(CreateFunctor(
188 client.get(), &ChromeFrameAutomationClient::InitiateNavigation, 195 client.get(), &ChromeFrameAutomationClient::InitiateNavigation,
189 url, std::string(), false)))); 196 url, std::string(), false))));
190 197
191 EXPECT_CALL(cfd, GetBounds(_)).Times(testing::AnyNumber()); 198 EXPECT_CALL(cfd, GetBounds(_)).Times(testing::AnyNumber());
192 EXPECT_CALL(cfd, OnNavigationStateChanged(_, _)).Times(testing::AnyNumber()); 199 EXPECT_CALL(cfd, OnNavigationStateChanged(_, _)).Times(testing::AnyNumber());
193 200
194 EXPECT_CALL(cfd, OnRequestStart(_, _, _)) 201 EXPECT_CALL(cfd, OnRequestStart(_, _, _))
195 // Often there's another request for the error page 202 // Often there's another request for the error page
196 .Times(testing::Between(1, 2)) 203 .Times(testing::Between(1, 2))
197 .WillRepeatedly(testing::WithArgs<1>(testing::Invoke(CreateFunctor(&cfd, 204 .WillRepeatedly(testing::WithArgs<1>(testing::Invoke(CreateFunctor(&cfd,
198 &MockCFDelegate::Reply, connection_failed)))); 205 &MockCFDelegate::Reply, connection_failed))));
199 206
200 EXPECT_CALL(cfd, OnUpdateTargetUrl(_, _)).Times(testing::AnyNumber()); 207 EXPECT_CALL(cfd, OnUpdateTargetUrl(_, _)).Times(testing::AnyNumber());
201 EXPECT_CALL(cfd, OnLoad(_, _)).Times(testing::AtMost(1)); 208 EXPECT_CALL(cfd, OnLoad(_, _)).Times(testing::AtMost(1));
202 209
203 EXPECT_CALL(cfd, OnNavigationFailed(_, _, GURL(url))) 210 EXPECT_CALL(cfd, OnNavigationFailed(_, _, GURL(url)))
204 .Times(1) 211 .Times(1)
205 .WillOnce(QUIT_LOOP_SOON(loop, 2)); 212 .WillOnce(QUIT_LOOP_SOON(loop, 2));
206 213
207 EXPECT_TRUE(client->Initialize(&cfd, 10000, false, profile, L"", false)); 214 EXPECT_TRUE(client->Initialize(&cfd, 10000, false, profile_path, L"",
215 false));
208 216
209 loop.RunFor(10); 217 loop.RunFor(10);
210 client->Uninitialize(); 218 client->Uninitialize();
211 client = NULL; 219 client = NULL;
212 } 220 }
213 221
214 TEST_F(CFACMockTest, MockedCreateTabOk) { 222 TEST_F(CFACMockTest, MockedCreateTabOk) {
215 int timeout = 500; 223 int timeout = 500;
216 CreateTab(); 224 CreateTab();
217 SetAutomationServerOk(); 225 SetAutomationServerOk();
(...skipping 12 matching lines...) Expand all
230 238
231 EXPECT_CALL(proxy_, CreateTabProxy(testing::Eq(tab_handle_))) 239 EXPECT_CALL(proxy_, CreateTabProxy(testing::Eq(tab_handle_)))
232 .WillOnce(testing::Return(tab_)); 240 .WillOnce(testing::Return(tab_));
233 241
234 EXPECT_CALL(cfd_, OnAutomationServerReady()) 242 EXPECT_CALL(cfd_, OnAutomationServerReady())
235 .WillOnce(QUIT_LOOP(loop_)); 243 .WillOnce(QUIT_LOOP(loop_));
236 244
237 EXPECT_CALL(proxy_, CancelAsync(_)).Times(testing::AnyNumber()); 245 EXPECT_CALL(proxy_, CancelAsync(_)).Times(testing::AnyNumber());
238 246
239 // Here we go! 247 // Here we go!
240 EXPECT_TRUE(client_->Initialize(&cfd_, timeout, false, profile_, L"", false)); 248 EXPECT_TRUE(client_->Initialize(&cfd_, timeout, false, profile_path_, L"",
249 false));
241 loop_.RunFor(10); 250 loop_.RunFor(10);
242 client_->Uninitialize(); 251 client_->Uninitialize();
243 } 252 }
244 253
245 TEST_F(CFACMockTest, MockedCreateTabFailed) { 254 TEST_F(CFACMockTest, MockedCreateTabFailed) {
246 HWND null_wnd = NULL; 255 HWND null_wnd = NULL;
247 SetAutomationServerOk(); 256 SetAutomationServerOk();
248 257
249 EXPECT_CALL(proxy_, server_version()).Times(testing::AnyNumber()) 258 EXPECT_CALL(proxy_, server_version()).Times(testing::AnyNumber())
250 .WillRepeatedly(testing::Return("")); 259 .WillRepeatedly(testing::Return(""));
251 260
252 EXPECT_CALL(proxy_, SendAsAsync(testing::Property(&IPC::SyncMessage::type, 261 EXPECT_CALL(proxy_, SendAsAsync(testing::Property(&IPC::SyncMessage::type,
253 AutomationMsg_CreateExternalTab__ID), 262 AutomationMsg_CreateExternalTab__ID),
254 testing::NotNull(), _)) 263 testing::NotNull(), _))
255 .Times(1) 264 .Times(1)
256 .WillOnce(HandleCreateTab(tab_handle_, null_wnd, null_wnd)); 265 .WillOnce(HandleCreateTab(tab_handle_, null_wnd, null_wnd));
257 266
258 EXPECT_CALL(proxy_, CreateTabProxy(_)).Times(0); 267 EXPECT_CALL(proxy_, CreateTabProxy(_)).Times(0);
259 268
260 EXPECT_CALL(proxy_, CancelAsync(_)).Times(testing::AnyNumber()); 269 EXPECT_CALL(proxy_, CancelAsync(_)).Times(testing::AnyNumber());
261 270
262 Set_CFD_LaunchFailed(AUTOMATION_CREATE_TAB_FAILED); 271 Set_CFD_LaunchFailed(AUTOMATION_CREATE_TAB_FAILED);
263 272
264 // Here we go! 273 // Here we go!
265 EXPECT_TRUE(client_->Initialize(&cfd_, timeout_, false, profile_, L"", 274 EXPECT_TRUE(client_->Initialize(&cfd_, timeout_, false, profile_path_, L"",
266 false)); 275 false));
267 loop_.RunFor(4); 276 loop_.RunFor(4);
268 client_->Uninitialize(); 277 client_->Uninitialize();
269 } 278 }
270 279
OLDNEW
« no previous file with comments | « chrome_frame/test/automation_client_mock.h ('k') | chrome_frame/test/chrome_frame_automation_mock.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698