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

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

Issue 2295443003: [chromedriver] Added option to make element references W3C compliant. (Closed)
Patch Set: fix errors introduced during previous rebase Created 4 years 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 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 // |session| will own the |CommandListener|s. 208 // |session| will own the |CommandListener|s.
209 session->command_listeners.swap(command_listeners); 209 session->command_listeners.swap(command_listeners);
210 210
211 status = LaunchChrome(bound_params.context_getter.get(), 211 status = LaunchChrome(bound_params.context_getter.get(),
212 bound_params.socket_factory, 212 bound_params.socket_factory,
213 bound_params.device_manager, 213 bound_params.device_manager,
214 bound_params.port_server, 214 bound_params.port_server,
215 bound_params.port_manager, 215 bound_params.port_manager,
216 capabilities, 216 capabilities,
217 &devtools_event_listeners, 217 &devtools_event_listeners,
218 &session->chrome); 218 &session->chrome,
219 session->w3c_compliant);
219 if (status.IsError()) 220 if (status.IsError())
220 return status; 221 return status;
221 222
222 status = session->chrome->GetWebViewIdForFirstTab(&session->window); 223 status = session->chrome->GetWebViewIdForFirstTab(&session->window,
224 session->w3c_compliant);
223 if (status.IsError()) 225 if (status.IsError())
224 return status; 226 return status;
225 227
226 session->detach = capabilities.detach; 228 session->detach = capabilities.detach;
227 session->force_devtools_screenshot = capabilities.force_devtools_screenshot; 229 session->force_devtools_screenshot = capabilities.force_devtools_screenshot;
228 session->capabilities = CreateCapabilities(session->chrome.get()); 230 session->capabilities = CreateCapabilities(session->chrome.get());
229 value->reset(session->capabilities->DeepCopy()); 231 value->reset(session->capabilities->DeepCopy());
230 return CheckSessionCreated(session); 232 return CheckSessionCreated(session);
231 } 233 }
232 234
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 std::string id; 284 std::string id;
283 if (!params.GetString("id", &id)) 285 if (!params.GetString("id", &id))
284 return Status(kUnknownError, "'id' must be a string"); 286 return Status(kUnknownError, "'id' must be a string");
285 287
286 ChromeDesktopImpl* desktop = NULL; 288 ChromeDesktopImpl* desktop = NULL;
287 Status status = session->chrome->GetAsDesktop(&desktop); 289 Status status = session->chrome->GetAsDesktop(&desktop);
288 if (status.IsError()) 290 if (status.IsError())
289 return status; 291 return status;
290 292
291 AutomationExtension* extension = NULL; 293 AutomationExtension* extension = NULL;
292 status = desktop->GetAutomationExtension(&extension); 294 status = desktop->GetAutomationExtension(&extension, session->w3c_compliant);
293 if (status.IsError()) 295 if (status.IsError())
294 return status; 296 return status;
295 297
296 return extension->LaunchApp(id); 298 return extension->LaunchApp(id);
297 } 299 }
298 300
299 Status ExecuteClose(Session* session, 301 Status ExecuteClose(Session* session,
300 const base::DictionaryValue& params, 302 const base::DictionaryValue& params,
301 std::unique_ptr<base::Value>* value) { 303 std::unique_ptr<base::Value>* value) {
302 std::list<std::string> web_view_ids; 304 std::list<std::string> web_view_ids;
303 Status status = session->chrome->GetWebViewIds(&web_view_ids); 305 Status status = session->chrome->GetWebViewIds(&web_view_ids,
306 session->w3c_compliant);
304 if (status.IsError()) 307 if (status.IsError())
305 return status; 308 return status;
306 bool is_last_web_view = web_view_ids.size() == 1u; 309 bool is_last_web_view = web_view_ids.size() == 1u;
307 web_view_ids.clear(); 310 web_view_ids.clear();
308 311
309 WebView* web_view = NULL; 312 WebView* web_view = NULL;
310 status = session->GetTargetWindow(&web_view); 313 status = session->GetTargetWindow(&web_view);
311 if (status.IsError()) 314 if (status.IsError())
312 return status; 315 return status;
313 316
314 status = session->chrome->CloseWebView(web_view->GetId()); 317 status = session->chrome->CloseWebView(web_view->GetId());
315 if (status.IsError()) 318 if (status.IsError())
316 return status; 319 return status;
317 320
318 status = session->chrome->GetWebViewIds(&web_view_ids); 321 status = session->chrome->GetWebViewIds(&web_view_ids,
322 session->w3c_compliant);
319 if ((status.code() == kChromeNotReachable && is_last_web_view) || 323 if ((status.code() == kChromeNotReachable && is_last_web_view) ||
320 (status.IsOk() && web_view_ids.empty())) { 324 (status.IsOk() && web_view_ids.empty())) {
321 // If no window is open, close is the equivalent of calling "quit". 325 // If no window is open, close is the equivalent of calling "quit".
322 session->quit = true; 326 session->quit = true;
323 return session->chrome->Quit(); 327 return session->chrome->Quit();
324 } 328 }
325 329
326 return status; 330 return status;
327 } 331 }
328 332
329 Status ExecuteGetWindowHandles(Session* session, 333 Status ExecuteGetWindowHandles(Session* session,
330 const base::DictionaryValue& params, 334 const base::DictionaryValue& params,
331 std::unique_ptr<base::Value>* value) { 335 std::unique_ptr<base::Value>* value) {
332 std::list<std::string> web_view_ids; 336 std::list<std::string> web_view_ids;
333 Status status = session->chrome->GetWebViewIds(&web_view_ids); 337 Status status = session->chrome->GetWebViewIds(&web_view_ids,
338 session->w3c_compliant);
334 if (status.IsError()) 339 if (status.IsError())
335 return status; 340 return status;
336 std::unique_ptr<base::ListValue> window_ids(new base::ListValue()); 341 std::unique_ptr<base::ListValue> window_ids(new base::ListValue());
337 for (std::list<std::string>::const_iterator it = web_view_ids.begin(); 342 for (std::list<std::string>::const_iterator it = web_view_ids.begin();
338 it != web_view_ids.end(); ++it) { 343 it != web_view_ids.end(); ++it) {
339 window_ids->AppendString(WebViewIdToWindowHandle(*it)); 344 window_ids->AppendString(WebViewIdToWindowHandle(*it));
340 } 345 }
341 value->reset(window_ids.release()); 346 value->reset(window_ids.release());
342 return Status(kOk); 347 return Status(kOk);
343 } 348 }
344 349
345 Status ExecuteSwitchToWindow(Session* session, 350 Status ExecuteSwitchToWindow(Session* session,
346 const base::DictionaryValue& params, 351 const base::DictionaryValue& params,
347 std::unique_ptr<base::Value>* value) { 352 std::unique_ptr<base::Value>* value) {
348 std::string name; 353 std::string name;
349 if (!params.GetString("name", &name)) 354 if (!params.GetString("name", &name))
350 return Status(kUnknownError, "'name' must be a string"); 355 return Status(kUnknownError, "'name' must be a string");
351 356
352 std::list<std::string> web_view_ids; 357 std::list<std::string> web_view_ids;
353 Status status = session->chrome->GetWebViewIds(&web_view_ids); 358 Status status = session->chrome->GetWebViewIds(&web_view_ids,
359 session->w3c_compliant);
354 if (status.IsError()) 360 if (status.IsError())
355 return status; 361 return status;
356 362
357 std::string web_view_id; 363 std::string web_view_id;
358 bool found = false; 364 bool found = false;
359 if (WindowHandleToWebViewId(name, &web_view_id)) { 365 if (WindowHandleToWebViewId(name, &web_view_id)) {
360 // Check if any web_view matches |web_view_id|. 366 // Check if any web_view matches |web_view_id|.
361 for (std::list<std::string>::const_iterator it = web_view_ids.begin(); 367 for (std::list<std::string>::const_iterator it = web_view_ids.begin();
362 it != web_view_ids.end(); ++it) { 368 it != web_view_ids.end(); ++it) {
363 if (*it == web_view_id) { 369 if (*it == web_view_id) {
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 network_conditions->offline = true; 610 network_conditions->offline = true;
605 } 611 }
606 612
607 session->overridden_network_conditions.reset( 613 session->overridden_network_conditions.reset(
608 network_conditions.release()); 614 network_conditions.release());
609 615
610 // Applies overridden network connection to all WebViews of the session 616 // Applies overridden network connection to all WebViews of the session
611 // to ensure that network emulation is applied on a per-session basis 617 // to ensure that network emulation is applied on a per-session basis
612 // rather than the just to the current WebView. 618 // rather than the just to the current WebView.
613 std::list<std::string> web_view_ids; 619 std::list<std::string> web_view_ids;
614 status = session->chrome->GetWebViewIds(&web_view_ids); 620 status = session->chrome->GetWebViewIds(&web_view_ids,
621 session->w3c_compliant);
615 if (status.IsError()) 622 if (status.IsError())
616 return status; 623 return status;
617 624
618 for (std::string web_view_id : web_view_ids) { 625 for (std::string web_view_id : web_view_ids) {
619 WebView* web_view; 626 WebView* web_view;
620 status = session->chrome->GetWebViewById(web_view_id, &web_view); 627 status = session->chrome->GetWebViewById(web_view_id, &web_view);
621 if (status.IsError()) 628 if (status.IsError())
622 return status; 629 return status;
623 web_view->OverrideNetworkConditions( 630 web_view->OverrideNetworkConditions(
624 *session->overridden_network_conditions); 631 *session->overridden_network_conditions);
625 } 632 }
626 return Status(kOk); 633 return Status(kOk);
627 } 634 }
628 635
629 Status ExecuteGetWindowPosition(Session* session, 636 Status ExecuteGetWindowPosition(Session* session,
630 const base::DictionaryValue& params, 637 const base::DictionaryValue& params,
631 std::unique_ptr<base::Value>* value) { 638 std::unique_ptr<base::Value>* value) {
632 ChromeDesktopImpl* desktop = NULL; 639 ChromeDesktopImpl* desktop = NULL;
633 Status status = session->chrome->GetAsDesktop(&desktop); 640 Status status = session->chrome->GetAsDesktop(&desktop);
634 if (status.IsError()) 641 if (status.IsError())
635 return status; 642 return status;
636 643
637 AutomationExtension* extension = NULL; 644 AutomationExtension* extension = NULL;
638 status = desktop->GetAutomationExtension(&extension); 645 status = desktop->GetAutomationExtension(&extension, session->w3c_compliant);
639 if (status.IsError()) 646 if (status.IsError())
640 return status; 647 return status;
641 648
642 int x, y; 649 int x, y;
643 status = extension->GetWindowPosition(&x, &y); 650 status = extension->GetWindowPosition(&x, &y);
644 if (status.IsError()) 651 if (status.IsError())
645 return status; 652 return status;
646 653
647 base::DictionaryValue position; 654 base::DictionaryValue position;
648 position.SetInteger("x", x); 655 position.SetInteger("x", x);
649 position.SetInteger("y", y); 656 position.SetInteger("y", y);
650 value->reset(position.DeepCopy()); 657 value->reset(position.DeepCopy());
651 return Status(kOk); 658 return Status(kOk);
652 } 659 }
653 660
654 Status ExecuteSetWindowPosition(Session* session, 661 Status ExecuteSetWindowPosition(Session* session,
655 const base::DictionaryValue& params, 662 const base::DictionaryValue& params,
656 std::unique_ptr<base::Value>* value) { 663 std::unique_ptr<base::Value>* value) {
657 double x = 0; 664 double x = 0;
658 double y = 0; 665 double y = 0;
659 if (!params.GetDouble("x", &x) || !params.GetDouble("y", &y)) 666 if (!params.GetDouble("x", &x) || !params.GetDouble("y", &y))
660 return Status(kUnknownError, "missing or invalid 'x' or 'y'"); 667 return Status(kUnknownError, "missing or invalid 'x' or 'y'");
661 668
662 ChromeDesktopImpl* desktop = NULL; 669 ChromeDesktopImpl* desktop = NULL;
663 Status status = session->chrome->GetAsDesktop(&desktop); 670 Status status = session->chrome->GetAsDesktop(&desktop);
664 if (status.IsError()) 671 if (status.IsError())
665 return status; 672 return status;
666 673
667 AutomationExtension* extension = NULL; 674 AutomationExtension* extension = NULL;
668 status = desktop->GetAutomationExtension(&extension); 675 status = desktop->GetAutomationExtension(&extension, session->w3c_compliant);
669 if (status.IsError()) 676 if (status.IsError())
670 return status; 677 return status;
671 678
672 return extension->SetWindowPosition(static_cast<int>(x), static_cast<int>(y)); 679 return extension->SetWindowPosition(static_cast<int>(x), static_cast<int>(y));
673 } 680 }
674 681
675 Status ExecuteGetWindowSize(Session* session, 682 Status ExecuteGetWindowSize(Session* session,
676 const base::DictionaryValue& params, 683 const base::DictionaryValue& params,
677 std::unique_ptr<base::Value>* value) { 684 std::unique_ptr<base::Value>* value) {
678 ChromeDesktopImpl* desktop = NULL; 685 ChromeDesktopImpl* desktop = NULL;
679 Status status = session->chrome->GetAsDesktop(&desktop); 686 Status status = session->chrome->GetAsDesktop(&desktop);
680 if (status.IsError()) 687 if (status.IsError())
681 return status; 688 return status;
682 689
683 AutomationExtension* extension = NULL; 690 AutomationExtension* extension = NULL;
684 status = desktop->GetAutomationExtension(&extension); 691 status = desktop->GetAutomationExtension(&extension, session->w3c_compliant);
685 if (status.IsError()) 692 if (status.IsError())
686 return status; 693 return status;
687 694
688 int width, height; 695 int width, height;
689 status = extension->GetWindowSize(&width, &height); 696 status = extension->GetWindowSize(&width, &height);
690 if (status.IsError()) 697 if (status.IsError())
691 return status; 698 return status;
692 699
693 base::DictionaryValue size; 700 base::DictionaryValue size;
694 size.SetInteger("width", width); 701 size.SetInteger("width", width);
(...skipping 10 matching lines...) Expand all
705 if (!params.GetDouble("width", &width) || 712 if (!params.GetDouble("width", &width) ||
706 !params.GetDouble("height", &height)) 713 !params.GetDouble("height", &height))
707 return Status(kUnknownError, "missing or invalid 'width' or 'height'"); 714 return Status(kUnknownError, "missing or invalid 'width' or 'height'");
708 715
709 ChromeDesktopImpl* desktop = NULL; 716 ChromeDesktopImpl* desktop = NULL;
710 Status status = session->chrome->GetAsDesktop(&desktop); 717 Status status = session->chrome->GetAsDesktop(&desktop);
711 if (status.IsError()) 718 if (status.IsError())
712 return status; 719 return status;
713 720
714 AutomationExtension* extension = NULL; 721 AutomationExtension* extension = NULL;
715 status = desktop->GetAutomationExtension(&extension); 722 status = desktop->GetAutomationExtension(&extension, session->w3c_compliant);
716 if (status.IsError()) 723 if (status.IsError())
717 return status; 724 return status;
718 725
719 return extension->SetWindowSize( 726 return extension->SetWindowSize(
720 static_cast<int>(width), static_cast<int>(height)); 727 static_cast<int>(width), static_cast<int>(height));
721 } 728 }
722 729
723 Status ExecuteMaximizeWindow(Session* session, 730 Status ExecuteMaximizeWindow(Session* session,
724 const base::DictionaryValue& params, 731 const base::DictionaryValue& params,
725 std::unique_ptr<base::Value>* value) { 732 std::unique_ptr<base::Value>* value) {
726 ChromeDesktopImpl* desktop = NULL; 733 ChromeDesktopImpl* desktop = NULL;
727 Status status = session->chrome->GetAsDesktop(&desktop); 734 Status status = session->chrome->GetAsDesktop(&desktop);
728 if (status.IsError()) 735 if (status.IsError())
729 return status; 736 return status;
730 737
731 AutomationExtension* extension = NULL; 738 AutomationExtension* extension = NULL;
732 status = desktop->GetAutomationExtension(&extension); 739 status = desktop->GetAutomationExtension(&extension, session->w3c_compliant);
733 if (status.IsError()) 740 if (status.IsError())
734 return status; 741 return status;
735 742
736 return extension->MaximizeWindow(); 743 return extension->MaximizeWindow();
737 } 744 }
738 745
739 Status ExecuteGetAvailableLogTypes(Session* session, 746 Status ExecuteGetAvailableLogTypes(Session* session,
740 const base::DictionaryValue& params, 747 const base::DictionaryValue& params,
741 std::unique_ptr<base::Value>* value) { 748 std::unique_ptr<base::Value>* value) {
742 std::unique_ptr<base::ListValue> types(new base::ListValue()); 749 std::unique_ptr<base::ListValue> types(new base::ListValue());
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
874 std::unique_ptr<base::Value>* value) { 881 std::unique_ptr<base::Value>* value) {
875 WebView* web_view = nullptr; 882 WebView* web_view = nullptr;
876 Status status = session->GetTargetWindow(&web_view); 883 Status status = session->GetTargetWindow(&web_view);
877 if (status.IsError()) 884 if (status.IsError())
878 return status; 885 return status;
879 status = web_view->DeleteScreenOrientation(); 886 status = web_view->DeleteScreenOrientation();
880 if (status.IsError()) 887 if (status.IsError())
881 return status; 888 return status;
882 return Status(kOk); 889 return Status(kOk);
883 } 890 }
OLDNEW
« no previous file with comments | « chrome/test/chromedriver/js/call_function_test.html ('k') | chrome/test/chromedriver/test/run_py_tests.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698