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

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

Issue 2230053002: [chromedriver] Added option to make element references W3C compliant. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased code with w3c flag change. Created 4 years, 4 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/session_commands.h" 5 #include "chrome/test/chromedriver/session_commands.h"
6 6
7 #include <list> 7 #include <list>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 // |session| will own the |CommandListener|s. 195 // |session| will own the |CommandListener|s.
196 session->command_listeners.swap(command_listeners); 196 session->command_listeners.swap(command_listeners);
197 197
198 status = LaunchChrome(bound_params.context_getter.get(), 198 status = LaunchChrome(bound_params.context_getter.get(),
199 bound_params.socket_factory, 199 bound_params.socket_factory,
200 bound_params.device_manager, 200 bound_params.device_manager,
201 bound_params.port_server, 201 bound_params.port_server,
202 bound_params.port_manager, 202 bound_params.port_manager,
203 capabilities, 203 capabilities,
204 &devtools_event_listeners, 204 &devtools_event_listeners,
205 &session->chrome); 205 &session->chrome,
206 session->w3c_compliant);
206 if (status.IsError()) 207 if (status.IsError())
207 return status; 208 return status;
208 209
209 session->chrome->set_page_load_strategy(capabilities.page_load_strategy); 210 session->chrome->set_page_load_strategy(capabilities.page_load_strategy);
210 211
211 std::list<std::string> web_view_ids; 212 std::list<std::string> web_view_ids;
212 status = session->chrome->GetWebViewIds(&web_view_ids); 213 status = session->chrome->GetWebViewIds(&web_view_ids,
214 session->w3c_compliant);
213 if (status.IsError() || web_view_ids.empty()) { 215 if (status.IsError() || web_view_ids.empty()) {
214 return status.IsError() ? status : 216 return status.IsError() ? status :
215 Status(kUnknownError, "unable to discover open window in chrome"); 217 Status(kUnknownError, "unable to discover open window in chrome");
216 } 218 }
217 219
218 session->window = web_view_ids.front(); 220 session->window = web_view_ids.front();
219 session->detach = capabilities.detach; 221 session->detach = capabilities.detach;
220 session->force_devtools_screenshot = capabilities.force_devtools_screenshot; 222 session->force_devtools_screenshot = capabilities.force_devtools_screenshot;
221 session->capabilities = CreateCapabilities(session->chrome.get()); 223 session->capabilities = CreateCapabilities(session->chrome.get());
222 value->reset(session->capabilities->DeepCopy()); 224 value->reset(session->capabilities->DeepCopy());
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 std::string id; 277 std::string id;
276 if (!params.GetString("id", &id)) 278 if (!params.GetString("id", &id))
277 return Status(kUnknownError, "'id' must be a string"); 279 return Status(kUnknownError, "'id' must be a string");
278 280
279 ChromeDesktopImpl* desktop = NULL; 281 ChromeDesktopImpl* desktop = NULL;
280 Status status = session->chrome->GetAsDesktop(&desktop); 282 Status status = session->chrome->GetAsDesktop(&desktop);
281 if (status.IsError()) 283 if (status.IsError())
282 return status; 284 return status;
283 285
284 AutomationExtension* extension = NULL; 286 AutomationExtension* extension = NULL;
285 status = desktop->GetAutomationExtension(&extension); 287 status = desktop->GetAutomationExtension(&extension, session->w3c_compliant);
286 if (status.IsError()) 288 if (status.IsError())
287 return status; 289 return status;
288 290
289 return extension->LaunchApp(id); 291 return extension->LaunchApp(id);
290 } 292 }
291 293
292 Status ExecuteClose(Session* session, 294 Status ExecuteClose(Session* session,
293 const base::DictionaryValue& params, 295 const base::DictionaryValue& params,
294 std::unique_ptr<base::Value>* value) { 296 std::unique_ptr<base::Value>* value) {
295 std::list<std::string> web_view_ids; 297 std::list<std::string> web_view_ids;
296 Status status = session->chrome->GetWebViewIds(&web_view_ids); 298 Status status = session->chrome->GetWebViewIds(&web_view_ids,
299 session->w3c_compliant);
297 if (status.IsError()) 300 if (status.IsError())
298 return status; 301 return status;
299 bool is_last_web_view = web_view_ids.size() == 1u; 302 bool is_last_web_view = web_view_ids.size() == 1u;
300 web_view_ids.clear(); 303 web_view_ids.clear();
301 304
302 WebView* web_view = NULL; 305 WebView* web_view = NULL;
303 status = session->GetTargetWindow(&web_view); 306 status = session->GetTargetWindow(&web_view);
304 if (status.IsError()) 307 if (status.IsError())
305 return status; 308 return status;
306 309
307 status = session->chrome->CloseWebView(web_view->GetId()); 310 status = session->chrome->CloseWebView(web_view->GetId());
308 if (status.IsError()) 311 if (status.IsError())
309 return status; 312 return status;
310 313
311 status = session->chrome->GetWebViewIds(&web_view_ids); 314 status = session->chrome->GetWebViewIds(&web_view_ids,
315 session->w3c_compliant);
312 if ((status.code() == kChromeNotReachable && is_last_web_view) || 316 if ((status.code() == kChromeNotReachable && is_last_web_view) ||
313 (status.IsOk() && web_view_ids.empty())) { 317 (status.IsOk() && web_view_ids.empty())) {
314 // If no window is open, close is the equivalent of calling "quit". 318 // If no window is open, close is the equivalent of calling "quit".
315 session->quit = true; 319 session->quit = true;
316 return session->chrome->Quit(); 320 return session->chrome->Quit();
317 } 321 }
318 322
319 return status; 323 return status;
320 } 324 }
321 325
322 Status ExecuteGetWindowHandles(Session* session, 326 Status ExecuteGetWindowHandles(Session* session,
323 const base::DictionaryValue& params, 327 const base::DictionaryValue& params,
324 std::unique_ptr<base::Value>* value) { 328 std::unique_ptr<base::Value>* value) {
325 std::list<std::string> web_view_ids; 329 std::list<std::string> web_view_ids;
326 Status status = session->chrome->GetWebViewIds(&web_view_ids); 330 Status status = session->chrome->GetWebViewIds(&web_view_ids,
331 session->w3c_compliant);
327 if (status.IsError()) 332 if (status.IsError())
328 return status; 333 return status;
329 std::unique_ptr<base::ListValue> window_ids(new base::ListValue()); 334 std::unique_ptr<base::ListValue> window_ids(new base::ListValue());
330 for (std::list<std::string>::const_iterator it = web_view_ids.begin(); 335 for (std::list<std::string>::const_iterator it = web_view_ids.begin();
331 it != web_view_ids.end(); ++it) { 336 it != web_view_ids.end(); ++it) {
332 window_ids->AppendString(WebViewIdToWindowHandle(*it)); 337 window_ids->AppendString(WebViewIdToWindowHandle(*it));
333 } 338 }
334 value->reset(window_ids.release()); 339 value->reset(window_ids.release());
335 return Status(kOk); 340 return Status(kOk);
336 } 341 }
337 342
338 Status ExecuteSwitchToWindow(Session* session, 343 Status ExecuteSwitchToWindow(Session* session,
339 const base::DictionaryValue& params, 344 const base::DictionaryValue& params,
340 std::unique_ptr<base::Value>* value) { 345 std::unique_ptr<base::Value>* value) {
341 std::string name; 346 std::string name;
342 if (!params.GetString("name", &name)) 347 if (!params.GetString("name", &name))
343 return Status(kUnknownError, "'name' must be a string"); 348 return Status(kUnknownError, "'name' must be a string");
344 349
345 std::list<std::string> web_view_ids; 350 std::list<std::string> web_view_ids;
346 Status status = session->chrome->GetWebViewIds(&web_view_ids); 351 Status status = session->chrome->GetWebViewIds(&web_view_ids,
352 session->w3c_compliant);
347 if (status.IsError()) 353 if (status.IsError())
348 return status; 354 return status;
349 355
350 std::string web_view_id; 356 std::string web_view_id;
351 bool found = false; 357 bool found = false;
352 if (WindowHandleToWebViewId(name, &web_view_id)) { 358 if (WindowHandleToWebViewId(name, &web_view_id)) {
353 // Check if any web_view matches |web_view_id|. 359 // Check if any web_view matches |web_view_id|.
354 for (std::list<std::string>::const_iterator it = web_view_ids.begin(); 360 for (std::list<std::string>::const_iterator it = web_view_ids.begin();
355 it != web_view_ids.end(); ++it) { 361 it != web_view_ids.end(); ++it) {
356 if (*it == web_view_id) { 362 if (*it == web_view_id) {
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 network_conditions->offline = true; 605 network_conditions->offline = true;
600 } 606 }
601 607
602 session->overridden_network_conditions.reset( 608 session->overridden_network_conditions.reset(
603 network_conditions.release()); 609 network_conditions.release());
604 610
605 // Applies overridden network connection to all WebViews of the session 611 // Applies overridden network connection to all WebViews of the session
606 // to ensure that network emulation is applied on a per-session basis 612 // to ensure that network emulation is applied on a per-session basis
607 // rather than the just to the current WebView. 613 // rather than the just to the current WebView.
608 std::list<std::string> web_view_ids; 614 std::list<std::string> web_view_ids;
609 status = session->chrome->GetWebViewIds(&web_view_ids); 615 status = session->chrome->GetWebViewIds(&web_view_ids,
616 session->w3c_compliant);
610 if (status.IsError()) 617 if (status.IsError())
611 return status; 618 return status;
612 619
613 for (std::string web_view_id : web_view_ids) { 620 for (std::string web_view_id : web_view_ids) {
614 WebView* web_view; 621 WebView* web_view;
615 status = session->chrome->GetWebViewById(web_view_id, &web_view); 622 status = session->chrome->GetWebViewById(web_view_id, &web_view);
616 if (status.IsError()) 623 if (status.IsError())
617 return status; 624 return status;
618 web_view->OverrideNetworkConditions( 625 web_view->OverrideNetworkConditions(
619 *session->overridden_network_conditions); 626 *session->overridden_network_conditions);
620 } 627 }
621 return Status(kOk); 628 return Status(kOk);
622 } 629 }
623 630
624 Status ExecuteGetWindowPosition(Session* session, 631 Status ExecuteGetWindowPosition(Session* session,
625 const base::DictionaryValue& params, 632 const base::DictionaryValue& params,
626 std::unique_ptr<base::Value>* value) { 633 std::unique_ptr<base::Value>* value) {
627 ChromeDesktopImpl* desktop = NULL; 634 ChromeDesktopImpl* desktop = NULL;
628 Status status = session->chrome->GetAsDesktop(&desktop); 635 Status status = session->chrome->GetAsDesktop(&desktop);
629 if (status.IsError()) 636 if (status.IsError())
630 return status; 637 return status;
631 638
632 AutomationExtension* extension = NULL; 639 AutomationExtension* extension = NULL;
633 status = desktop->GetAutomationExtension(&extension); 640 status = desktop->GetAutomationExtension(&extension, session->w3c_compliant);
634 if (status.IsError()) 641 if (status.IsError())
635 return status; 642 return status;
636 643
637 int x, y; 644 int x, y;
638 status = extension->GetWindowPosition(&x, &y); 645 status = extension->GetWindowPosition(&x, &y);
639 if (status.IsError()) 646 if (status.IsError())
640 return status; 647 return status;
641 648
642 base::DictionaryValue position; 649 base::DictionaryValue position;
643 position.SetInteger("x", x); 650 position.SetInteger("x", x);
644 position.SetInteger("y", y); 651 position.SetInteger("y", y);
645 value->reset(position.DeepCopy()); 652 value->reset(position.DeepCopy());
646 return Status(kOk); 653 return Status(kOk);
647 } 654 }
648 655
649 Status ExecuteSetWindowPosition(Session* session, 656 Status ExecuteSetWindowPosition(Session* session,
650 const base::DictionaryValue& params, 657 const base::DictionaryValue& params,
651 std::unique_ptr<base::Value>* value) { 658 std::unique_ptr<base::Value>* value) {
652 double x = 0; 659 double x = 0;
653 double y = 0; 660 double y = 0;
654 if (!params.GetDouble("x", &x) || !params.GetDouble("y", &y)) 661 if (!params.GetDouble("x", &x) || !params.GetDouble("y", &y))
655 return Status(kUnknownError, "missing or invalid 'x' or 'y'"); 662 return Status(kUnknownError, "missing or invalid 'x' or 'y'");
656 663
657 ChromeDesktopImpl* desktop = NULL; 664 ChromeDesktopImpl* desktop = NULL;
658 Status status = session->chrome->GetAsDesktop(&desktop); 665 Status status = session->chrome->GetAsDesktop(&desktop);
659 if (status.IsError()) 666 if (status.IsError())
660 return status; 667 return status;
661 668
662 AutomationExtension* extension = NULL; 669 AutomationExtension* extension = NULL;
663 status = desktop->GetAutomationExtension(&extension); 670 status = desktop->GetAutomationExtension(&extension, session->w3c_compliant);
664 if (status.IsError()) 671 if (status.IsError())
665 return status; 672 return status;
666 673
667 return extension->SetWindowPosition(static_cast<int>(x), static_cast<int>(y)); 674 return extension->SetWindowPosition(static_cast<int>(x), static_cast<int>(y));
668 } 675 }
669 676
670 Status ExecuteGetWindowSize(Session* session, 677 Status ExecuteGetWindowSize(Session* session,
671 const base::DictionaryValue& params, 678 const base::DictionaryValue& params,
672 std::unique_ptr<base::Value>* value) { 679 std::unique_ptr<base::Value>* value) {
673 ChromeDesktopImpl* desktop = NULL; 680 ChromeDesktopImpl* desktop = NULL;
674 Status status = session->chrome->GetAsDesktop(&desktop); 681 Status status = session->chrome->GetAsDesktop(&desktop);
675 if (status.IsError()) 682 if (status.IsError())
676 return status; 683 return status;
677 684
678 AutomationExtension* extension = NULL; 685 AutomationExtension* extension = NULL;
679 status = desktop->GetAutomationExtension(&extension); 686 status = desktop->GetAutomationExtension(&extension, session->w3c_compliant);
680 if (status.IsError()) 687 if (status.IsError())
681 return status; 688 return status;
682 689
683 int width, height; 690 int width, height;
684 status = extension->GetWindowSize(&width, &height); 691 status = extension->GetWindowSize(&width, &height);
685 if (status.IsError()) 692 if (status.IsError())
686 return status; 693 return status;
687 694
688 base::DictionaryValue size; 695 base::DictionaryValue size;
689 size.SetInteger("width", width); 696 size.SetInteger("width", width);
(...skipping 10 matching lines...) Expand all
700 if (!params.GetDouble("width", &width) || 707 if (!params.GetDouble("width", &width) ||
701 !params.GetDouble("height", &height)) 708 !params.GetDouble("height", &height))
702 return Status(kUnknownError, "missing or invalid 'width' or 'height'"); 709 return Status(kUnknownError, "missing or invalid 'width' or 'height'");
703 710
704 ChromeDesktopImpl* desktop = NULL; 711 ChromeDesktopImpl* desktop = NULL;
705 Status status = session->chrome->GetAsDesktop(&desktop); 712 Status status = session->chrome->GetAsDesktop(&desktop);
706 if (status.IsError()) 713 if (status.IsError())
707 return status; 714 return status;
708 715
709 AutomationExtension* extension = NULL; 716 AutomationExtension* extension = NULL;
710 status = desktop->GetAutomationExtension(&extension); 717 status = desktop->GetAutomationExtension(&extension, session->w3c_compliant);
711 if (status.IsError()) 718 if (status.IsError())
712 return status; 719 return status;
713 720
714 return extension->SetWindowSize( 721 return extension->SetWindowSize(
715 static_cast<int>(width), static_cast<int>(height)); 722 static_cast<int>(width), static_cast<int>(height));
716 } 723 }
717 724
718 Status ExecuteMaximizeWindow(Session* session, 725 Status ExecuteMaximizeWindow(Session* session,
719 const base::DictionaryValue& params, 726 const base::DictionaryValue& params,
720 std::unique_ptr<base::Value>* value) { 727 std::unique_ptr<base::Value>* value) {
721 ChromeDesktopImpl* desktop = NULL; 728 ChromeDesktopImpl* desktop = NULL;
722 Status status = session->chrome->GetAsDesktop(&desktop); 729 Status status = session->chrome->GetAsDesktop(&desktop);
723 if (status.IsError()) 730 if (status.IsError())
724 return status; 731 return status;
725 732
726 AutomationExtension* extension = NULL; 733 AutomationExtension* extension = NULL;
727 status = desktop->GetAutomationExtension(&extension); 734 status = desktop->GetAutomationExtension(&extension, session->w3c_compliant);
728 if (status.IsError()) 735 if (status.IsError())
729 return status; 736 return status;
730 737
731 return extension->MaximizeWindow(); 738 return extension->MaximizeWindow();
732 } 739 }
733 740
734 Status ExecuteGetAvailableLogTypes(Session* session, 741 Status ExecuteGetAvailableLogTypes(Session* session,
735 const base::DictionaryValue& params, 742 const base::DictionaryValue& params,
736 std::unique_ptr<base::Value>* value) { 743 std::unique_ptr<base::Value>* value) {
737 std::unique_ptr<base::ListValue> types(new base::ListValue()); 744 std::unique_ptr<base::ListValue> types(new base::ListValue());
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
827 session->auto_reporting_enabled = enabled; 834 session->auto_reporting_enabled = enabled;
828 return Status(kOk); 835 return Status(kOk);
829 } 836 }
830 837
831 838
832 Status ExecuteUnimplementedCommand(Session* session, 839 Status ExecuteUnimplementedCommand(Session* session,
833 const base::DictionaryValue& params, 840 const base::DictionaryValue& params,
834 std::unique_ptr<base::Value>* value) { 841 std::unique_ptr<base::Value>* value) {
835 return Status(kUnknownCommand); 842 return Status(kUnknownCommand);
836 } 843 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698