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

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: Fixed presubmit errors. 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
« no previous file with comments | « chrome/test/chromedriver/session.cc ('k') | chrome/test/chromedriver/test/run_py_tests.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
597 network_conditions->offline = true; 603 network_conditions->offline = true;
598 } 604 }
599 605
600 session->overridden_network_conditions.reset( 606 session->overridden_network_conditions.reset(
601 network_conditions.release()); 607 network_conditions.release());
602 608
603 // Applies overridden network connection to all WebViews of the session 609 // Applies overridden network connection to all WebViews of the session
604 // to ensure that network emulation is applied on a per-session basis 610 // to ensure that network emulation is applied on a per-session basis
605 // rather than the just to the current WebView. 611 // rather than the just to the current WebView.
606 std::list<std::string> web_view_ids; 612 std::list<std::string> web_view_ids;
607 status = session->chrome->GetWebViewIds(&web_view_ids); 613 status = session->chrome->GetWebViewIds(&web_view_ids,
614 session->w3c_compliant);
608 if (status.IsError()) 615 if (status.IsError())
609 return status; 616 return status;
610 617
611 for (std::string web_view_id : web_view_ids) { 618 for (std::string web_view_id : web_view_ids) {
612 WebView* web_view; 619 WebView* web_view;
613 status = session->chrome->GetWebViewById(web_view_id, &web_view); 620 status = session->chrome->GetWebViewById(web_view_id, &web_view);
614 if (status.IsError()) 621 if (status.IsError())
615 return status; 622 return status;
616 web_view->OverrideNetworkConditions( 623 web_view->OverrideNetworkConditions(
617 *session->overridden_network_conditions); 624 *session->overridden_network_conditions);
618 } 625 }
619 return Status(kOk); 626 return Status(kOk);
620 } 627 }
621 628
622 Status ExecuteGetWindowPosition(Session* session, 629 Status ExecuteGetWindowPosition(Session* session,
623 const base::DictionaryValue& params, 630 const base::DictionaryValue& params,
624 std::unique_ptr<base::Value>* value) { 631 std::unique_ptr<base::Value>* value) {
625 ChromeDesktopImpl* desktop = NULL; 632 ChromeDesktopImpl* desktop = NULL;
626 Status status = session->chrome->GetAsDesktop(&desktop); 633 Status status = session->chrome->GetAsDesktop(&desktop);
627 if (status.IsError()) 634 if (status.IsError())
628 return status; 635 return status;
629 636
630 AutomationExtension* extension = NULL; 637 AutomationExtension* extension = NULL;
631 status = desktop->GetAutomationExtension(&extension); 638 status = desktop->GetAutomationExtension(&extension, session->w3c_compliant);
632 if (status.IsError()) 639 if (status.IsError())
633 return status; 640 return status;
634 641
635 int x, y; 642 int x, y;
636 status = extension->GetWindowPosition(&x, &y); 643 status = extension->GetWindowPosition(&x, &y);
637 if (status.IsError()) 644 if (status.IsError())
638 return status; 645 return status;
639 646
640 base::DictionaryValue position; 647 base::DictionaryValue position;
641 position.SetInteger("x", x); 648 position.SetInteger("x", x);
642 position.SetInteger("y", y); 649 position.SetInteger("y", y);
643 value->reset(position.DeepCopy()); 650 value->reset(position.DeepCopy());
644 return Status(kOk); 651 return Status(kOk);
645 } 652 }
646 653
647 Status ExecuteSetWindowPosition(Session* session, 654 Status ExecuteSetWindowPosition(Session* session,
648 const base::DictionaryValue& params, 655 const base::DictionaryValue& params,
649 std::unique_ptr<base::Value>* value) { 656 std::unique_ptr<base::Value>* value) {
650 double x = 0; 657 double x = 0;
651 double y = 0; 658 double y = 0;
652 if (!params.GetDouble("x", &x) || !params.GetDouble("y", &y)) 659 if (!params.GetDouble("x", &x) || !params.GetDouble("y", &y))
653 return Status(kUnknownError, "missing or invalid 'x' or 'y'"); 660 return Status(kUnknownError, "missing or invalid 'x' or 'y'");
654 661
655 ChromeDesktopImpl* desktop = NULL; 662 ChromeDesktopImpl* desktop = NULL;
656 Status status = session->chrome->GetAsDesktop(&desktop); 663 Status status = session->chrome->GetAsDesktop(&desktop);
657 if (status.IsError()) 664 if (status.IsError())
658 return status; 665 return status;
659 666
660 AutomationExtension* extension = NULL; 667 AutomationExtension* extension = NULL;
661 status = desktop->GetAutomationExtension(&extension); 668 status = desktop->GetAutomationExtension(&extension, session->w3c_compliant);
662 if (status.IsError()) 669 if (status.IsError())
663 return status; 670 return status;
664 671
665 return extension->SetWindowPosition(static_cast<int>(x), static_cast<int>(y)); 672 return extension->SetWindowPosition(static_cast<int>(x), static_cast<int>(y));
666 } 673 }
667 674
668 Status ExecuteGetWindowSize(Session* session, 675 Status ExecuteGetWindowSize(Session* session,
669 const base::DictionaryValue& params, 676 const base::DictionaryValue& params,
670 std::unique_ptr<base::Value>* value) { 677 std::unique_ptr<base::Value>* value) {
671 ChromeDesktopImpl* desktop = NULL; 678 ChromeDesktopImpl* desktop = NULL;
672 Status status = session->chrome->GetAsDesktop(&desktop); 679 Status status = session->chrome->GetAsDesktop(&desktop);
673 if (status.IsError()) 680 if (status.IsError())
674 return status; 681 return status;
675 682
676 AutomationExtension* extension = NULL; 683 AutomationExtension* extension = NULL;
677 status = desktop->GetAutomationExtension(&extension); 684 status = desktop->GetAutomationExtension(&extension, session->w3c_compliant);
678 if (status.IsError()) 685 if (status.IsError())
679 return status; 686 return status;
680 687
681 int width, height; 688 int width, height;
682 status = extension->GetWindowSize(&width, &height); 689 status = extension->GetWindowSize(&width, &height);
683 if (status.IsError()) 690 if (status.IsError())
684 return status; 691 return status;
685 692
686 base::DictionaryValue size; 693 base::DictionaryValue size;
687 size.SetInteger("width", width); 694 size.SetInteger("width", width);
(...skipping 10 matching lines...) Expand all
698 if (!params.GetDouble("width", &width) || 705 if (!params.GetDouble("width", &width) ||
699 !params.GetDouble("height", &height)) 706 !params.GetDouble("height", &height))
700 return Status(kUnknownError, "missing or invalid 'width' or 'height'"); 707 return Status(kUnknownError, "missing or invalid 'width' or 'height'");
701 708
702 ChromeDesktopImpl* desktop = NULL; 709 ChromeDesktopImpl* desktop = NULL;
703 Status status = session->chrome->GetAsDesktop(&desktop); 710 Status status = session->chrome->GetAsDesktop(&desktop);
704 if (status.IsError()) 711 if (status.IsError())
705 return status; 712 return status;
706 713
707 AutomationExtension* extension = NULL; 714 AutomationExtension* extension = NULL;
708 status = desktop->GetAutomationExtension(&extension); 715 status = desktop->GetAutomationExtension(&extension, session->w3c_compliant);
709 if (status.IsError()) 716 if (status.IsError())
710 return status; 717 return status;
711 718
712 return extension->SetWindowSize( 719 return extension->SetWindowSize(
713 static_cast<int>(width), static_cast<int>(height)); 720 static_cast<int>(width), static_cast<int>(height));
714 } 721 }
715 722
716 Status ExecuteMaximizeWindow(Session* session, 723 Status ExecuteMaximizeWindow(Session* session,
717 const base::DictionaryValue& params, 724 const base::DictionaryValue& params,
718 std::unique_ptr<base::Value>* value) { 725 std::unique_ptr<base::Value>* value) {
719 ChromeDesktopImpl* desktop = NULL; 726 ChromeDesktopImpl* desktop = NULL;
720 Status status = session->chrome->GetAsDesktop(&desktop); 727 Status status = session->chrome->GetAsDesktop(&desktop);
721 if (status.IsError()) 728 if (status.IsError())
722 return status; 729 return status;
723 730
724 AutomationExtension* extension = NULL; 731 AutomationExtension* extension = NULL;
725 status = desktop->GetAutomationExtension(&extension); 732 status = desktop->GetAutomationExtension(&extension, session->w3c_compliant);
726 if (status.IsError()) 733 if (status.IsError())
727 return status; 734 return status;
728 735
729 return extension->MaximizeWindow(); 736 return extension->MaximizeWindow();
730 } 737 }
731 738
732 Status ExecuteGetAvailableLogTypes(Session* session, 739 Status ExecuteGetAvailableLogTypes(Session* session,
733 const base::DictionaryValue& params, 740 const base::DictionaryValue& params,
734 std::unique_ptr<base::Value>* value) { 741 std::unique_ptr<base::Value>* value) {
735 std::unique_ptr<base::ListValue> types(new base::ListValue()); 742 std::unique_ptr<base::ListValue> types(new base::ListValue());
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
825 session->auto_reporting_enabled = enabled; 832 session->auto_reporting_enabled = enabled;
826 return Status(kOk); 833 return Status(kOk);
827 } 834 }
828 835
829 836
830 Status ExecuteUnimplementedCommand(Session* session, 837 Status ExecuteUnimplementedCommand(Session* session,
831 const base::DictionaryValue& params, 838 const base::DictionaryValue& params,
832 std::unique_ptr<base::Value>* value) { 839 std::unique_ptr<base::Value>* value) {
833 return Status(kUnknownCommand); 840 return Status(kUnknownCommand);
834 } 841 }
OLDNEW
« no previous file with comments | « chrome/test/chromedriver/session.cc ('k') | chrome/test/chromedriver/test/run_py_tests.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698