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

Side by Side Diff: chrome/test/chromedriver/chrome/chrome_impl.cc

Issue 12978003: [chromedriver] Fix 3 bugs about web view, window handle and target window. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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) 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/test/chromedriver/chrome/chrome_impl.h" 5 #include "chrome/test/chromedriver/chrome/chrome_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <list> 8 #include <list>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 build_no_(0) {} 206 build_no_(0) {}
207 207
208 ChromeImpl::~ChromeImpl() { 208 ChromeImpl::~ChromeImpl() {
209 web_view_map_.clear(); 209 web_view_map_.clear();
210 } 210 }
211 211
212 std::string ChromeImpl::GetVersion() { 212 std::string ChromeImpl::GetVersion() {
213 return version_; 213 return version_;
214 } 214 }
215 215
216 Status ChromeImpl::GetWebViews(std::list<WebView*>* web_views) { 216 Status ChromeImpl::GetWebViewIds(std::list<std::string>* web_view_ids) {
217 WebViewInfoList info_list; 217 WebViewInfoList info_list;
218 Status status = FetchWebViewsInfo( 218 Status status = FetchWebViewsInfo(
219 context_getter_, port_, &info_list); 219 context_getter_, port_, &info_list);
220 if (status.IsError()) 220 if (status.IsError())
221 return status; 221 return status;
222 222
223 std::list<WebView*> internal_web_views; 223 // Check if some web views are closed.
224 std::list<std::string>::iterator it = web_view_ids_.begin();
225 while (it != web_view_ids_.end()) {
226 if (!GetWebViewFromList(*it, info_list)) {
227 web_view_map_.erase(*it);
228 it = web_view_ids_.erase(it);
229 } else {
230 ++it;
231 }
232 }
233
234 // Check for newly-opened web views.
224 for (WebViewInfoList::const_iterator it = info_list.begin(); 235 for (WebViewInfoList::const_iterator it = info_list.begin();
225 it != info_list.end(); ++it) { 236 it != info_list.end(); ++it) {
226 WebViewMap::const_iterator found = web_view_map_.find(it->id); 237 if (it->type != internal::WebViewInfo::kPage)
227 if (found != web_view_map_.end()) {
228 internal_web_views.push_back(found->second.get());
229 continue; 238 continue;
239
240 if (std::find(web_view_ids_.begin(), web_view_ids_.end(), it->id) ==
241 web_view_ids_.end()) {
242 web_view_ids_.push_back(it->id);
230 } 243 }
231
232 std::string ws_url = base::StringPrintf(
233 "ws://127.0.0.1:%d/devtools/page/%s", port_, it->id.c_str());
234 DevToolsClientImpl::FrontendCloserFunc frontend_closer_func = base::Bind(
235 &CloseDevToolsFrontend, this, socket_factory_,
236 context_getter_, port_, it->id);
237 web_view_map_[it->id] = make_linked_ptr(new WebViewImpl(
238 it->id,
239 new DevToolsClientImpl(socket_factory_, ws_url, frontend_closer_func),
240 this,
241 base::Bind(&CloseWebView, context_getter_, port_, it->id)));
242 internal_web_views.push_back(web_view_map_[it->id].get());
243 } 244 }
244 245
245 web_views->swap(internal_web_views); 246 *web_view_ids = web_view_ids_;
246 return Status(kOk); 247 return Status(kOk);
247 } 248 }
248 249
250 Status ChromeImpl::GetWebViewById(const std::string& id, WebView** web_view) {
251 WebViewMap::const_iterator found = web_view_map_.find(id);
252 if (found != web_view_map_.end()) {
253 *web_view = found->second.get();
254 return Status(kOk);
255 }
256
257 WebViewInfoList info_list;
258 Status status = FetchWebViewsInfo(context_getter_, port_, &info_list);
259 if (status.IsError())
260 return status;
261 for (WebViewInfoList::const_iterator it = info_list.begin();
262 it != info_list.end(); ++it) {
263 if (it->id == id && it->type == internal::WebViewInfo::kPage) {
264 std::string ws_url = base::StringPrintf(
265 "ws://127.0.0.1:%d/devtools/page/%s", port_, it->id.c_str());
266 DevToolsClientImpl::FrontendCloserFunc frontend_closer_func = base::Bind(
267 &CloseDevToolsFrontend, this, socket_factory_,
268 context_getter_, port_, it->id);
269 web_view_map_[it->id] = make_linked_ptr(new WebViewImpl(
270 it->id,
271 new DevToolsClientImpl(socket_factory_, ws_url, frontend_closer_func),
272 this,
273 base::Bind(&CloseWebView, context_getter_, port_, it->id)));
274 *web_view = web_view_map_[it->id].get();
275 return Status(kOk);
276 }
277 }
278 return Status(kUnknownError, "web view not found");
279 }
280
249 Status ChromeImpl::IsJavaScriptDialogOpen(bool* is_open) { 281 Status ChromeImpl::IsJavaScriptDialogOpen(bool* is_open) {
250 JavaScriptDialogManager* manager; 282 JavaScriptDialogManager* manager;
251 Status status = GetDialogManagerForOpenDialog(&manager); 283 Status status = GetDialogManagerForOpenDialog(&manager);
252 if (status.IsError()) 284 if (status.IsError())
253 return status; 285 return status;
254 *is_open = manager != NULL; 286 *is_open = manager != NULL;
255 return Status(kOk); 287 return Status(kOk);
256 } 288 }
257 289
258 Status ChromeImpl::GetJavaScriptDialogMessage(std::string* message) { 290 Status ChromeImpl::GetJavaScriptDialogMessage(std::string* message) {
(...skipping 13 matching lines...) Expand all
272 Status status = GetDialogManagerForOpenDialog(&manager); 304 Status status = GetDialogManagerForOpenDialog(&manager);
273 if (status.IsError()) 305 if (status.IsError())
274 return status; 306 return status;
275 if (!manager) 307 if (!manager)
276 return Status(kNoAlertOpen); 308 return Status(kNoAlertOpen);
277 309
278 return manager->HandleDialog(accept, prompt_text); 310 return manager->HandleDialog(accept, prompt_text);
279 } 311 }
280 312
281 void ChromeImpl::OnWebViewClose(WebView* web_view) { 313 void ChromeImpl::OnWebViewClose(WebView* web_view) {
314 web_view_ids_.remove(web_view->GetId());
282 web_view_map_.erase(web_view->GetId()); 315 web_view_map_.erase(web_view->GetId());
283 } 316 }
284 317
285 Status ChromeImpl::Init() { 318 Status ChromeImpl::Init() {
286 base::Time deadline = base::Time::Now() + base::TimeDelta::FromSeconds(20); 319 base::Time deadline = base::Time::Now() + base::TimeDelta::FromSeconds(20);
287 std::string version; 320 std::string version;
288 Status status(kOk); 321 Status status(kOk);
289 while (base::Time::Now() < deadline) { 322 while (base::Time::Now() < deadline) {
290 status = FetchVersionInfo(context_getter_, port_, &version); 323 status = FetchVersionInfo(context_getter_, port_, &version);
291 if (status.IsOk()) 324 if (status.IsOk())
(...skipping 18 matching lines...) Expand all
310 } 343 }
311 return Status(kUnknownError, "unable to discover open pages"); 344 return Status(kUnknownError, "unable to discover open pages");
312 } 345 }
313 346
314 int ChromeImpl::GetPort() const { 347 int ChromeImpl::GetPort() const {
315 return port_; 348 return port_;
316 } 349 }
317 350
318 Status ChromeImpl::GetDialogManagerForOpenDialog( 351 Status ChromeImpl::GetDialogManagerForOpenDialog(
319 JavaScriptDialogManager** manager) { 352 JavaScriptDialogManager** manager) {
320 std::list<WebView*> web_views; 353 std::list<std::string> web_view_ids;
321 Status status = GetWebViews(&web_views); 354 Status status = GetWebViewIds(&web_view_ids);
322 if (status.IsError()) 355 if (status.IsError())
323 return status; 356 return status;
324 357
325 for (std::list<WebView*>::const_iterator it = web_views.begin(); 358 for (std::list<std::string>::const_iterator it = web_view_ids.begin();
326 it != web_views.end(); ++it) { 359 it != web_view_ids.end(); ++it) {
327 if ((*it)->GetJavaScriptDialogManager()->IsDialogOpen()) { 360 WebView* web_view;
328 *manager = (*it)->GetJavaScriptDialogManager(); 361 status = GetWebViewById(*it, &web_view);
362 if (status.IsError())
363 return status;
364 if (web_view->GetJavaScriptDialogManager()->IsDialogOpen()) {
365 *manager = web_view->GetJavaScriptDialogManager();
329 return Status(kOk); 366 return Status(kOk);
330 } 367 }
331 } 368 }
332 *manager = NULL; 369 *manager = NULL;
333 return Status(kOk); 370 return Status(kOk);
334 } 371 }
335 372
336 Status ChromeImpl::ParseAndCheckVersion(const std::string& version) { 373 Status ChromeImpl::ParseAndCheckVersion(const std::string& version) {
337 if (version.empty()) { 374 if (version.empty()) {
338 // Content Shell has an empty product version and a fake user agent. 375 // Content Shell has an empty product version and a fake user agent.
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 return Status(kUnknownError, "version info not a dictionary"); 460 return Status(kUnknownError, "version info not a dictionary");
424 if (!dict->GetString("Browser", version)) { 461 if (!dict->GetString("Browser", version)) {
425 return Status( 462 return Status(
426 kUnknownError, "Chrome version must be >= 26", 463 kUnknownError, "Chrome version must be >= 26",
427 Status(kUnknownError, "version info doesn't include string 'Browser'")); 464 Status(kUnknownError, "version info doesn't include string 'Browser'"));
428 } 465 }
429 return Status(kOk); 466 return Status(kOk);
430 } 467 }
431 468
432 } // namespace internal 469 } // namespace internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698