OLD | NEW |
---|---|
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 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
498 conditions.SetInteger( | 498 conditions.SetInteger( |
499 "download_throughput", | 499 "download_throughput", |
500 session->overridden_network_conditions->download_throughput); | 500 session->overridden_network_conditions->download_throughput); |
501 conditions.SetInteger( | 501 conditions.SetInteger( |
502 "upload_throughput", | 502 "upload_throughput", |
503 session->overridden_network_conditions->upload_throughput); | 503 session->overridden_network_conditions->upload_throughput); |
504 value->reset(conditions.DeepCopy()); | 504 value->reset(conditions.DeepCopy()); |
505 return Status(kOk); | 505 return Status(kOk); |
506 } | 506 } |
507 | 507 |
508 Status ExecuteSetNetworkConnection(Session* session, | |
509 const base::DictionaryValue& params, | |
510 std::unique_ptr<Value>* value) { | |
511 const int kAirplaneMask = 0x1; | |
512 const int kWifiMask = 0x2; | |
513 const int k4GMask = 0x8; | |
514 const int k3GMask = 0x10; | |
515 const int k2GMask = 0x20; | |
samuong
2016/06/17 22:01:30
You should put these at the top of the file in an
roisinmcl
2016/06/20 18:14:17
Done.
| |
516 | |
517 int connection_type; | |
518 | |
519 const base::DictionaryValue* parameters = NULL; | |
520 | |
521 params.GetDictionary("parameters", ¶meters); | |
522 | |
523 if(!parameters->GetInteger("type", &connection_type)) { | |
524 return Status(kUnknownError, | |
525 "invalid network_connections is missing 'connection_type'"); | |
prasadv
2016/06/17 18:43:35
Error message is confusing.
Do we have anything as
roisinmcl
2016/06/20 18:14:17
I changed this error message to be more clear. I c
| |
526 } | |
527 | |
528 std::unique_ptr<NetworkConditions> network_conditions( | |
529 new NetworkConditions()); | |
530 | |
531 if (connection_type & kAirplaneMask) { | |
532 network_conditions->latency = 0; | |
533 network_conditions->upload_throughput = 0; | |
534 network_conditions->download_throughput = 0; | |
535 network_conditions->offline = true; | |
536 } else if (connection_type & kWifiMask) { | |
537 network_conditions->latency = 2; | |
538 network_conditions->upload_throughput = 30720 * 1024; | |
prasadv
2016/06/17 18:43:35
I prefer using constants instant of using hard cod
samuong
2016/06/17 22:01:30
Agreed. Roisin can you add them and coordinate wit
roisinmcl
2016/06/20 18:14:17
Done.
roisinmcl
2016/06/20 18:14:17
Done.
| |
539 network_conditions->download_throughput = 30720 * 1024; | |
540 network_conditions->offline = false; | |
541 } else if (connection_type & k4GMask) { | |
542 network_conditions->latency = 20; | |
543 network_conditions->upload_throughput = 4096 * 1024; | |
544 network_conditions->download_throughput = 4096 * 1024; | |
545 network_conditions->offline = false; | |
546 } else if (connection_type & k3GMask) { | |
547 network_conditions->latency = 100; | |
548 network_conditions->upload_throughput = 750 * 1024; | |
549 network_conditions->download_throughput = 750 * 1024; | |
550 network_conditions->offline = false; | |
551 } else if (connection_type & k2GMask) { | |
552 network_conditions->latency = 300; | |
553 network_conditions->upload_throughput = 250 * 1024; | |
554 network_conditions->download_throughput = 250 * 1024; | |
555 network_conditions->offline = false; | |
556 } else { | |
557 return Status(kUnknownError, "invalid 'connection_type'"); | |
558 } | |
559 | |
560 session->overridden_network_conditions.reset( | |
561 network_conditions.release()); | |
562 | |
563 // get list of all webview objects | |
564 // iterate through and override each one's network conditions to the new ones | |
565 // if any has an error, return that | |
566 // otherwise return Status(kOk) | |
567 std::list<std::string> web_view_ids; | |
568 chrome->GetWebViewIds(web_view_ids); | |
569 | |
570 std::string web_view_id; | |
571 | |
572 for (int i = 0; i < web_view_ids.size; ++i) { | |
573 WebView current_web_view; | |
574 web_view_id = web_view_ids[i]; | |
575 chrome->GetWebViewById(web_view_id, web_view) | |
576 if (!web_view) { | |
577 return Status(kUnknowError, "invalid web view"); | |
578 } | |
579 web_view->OverrideNetworkConditions( | |
580 *session->overridden_network_conditions); | |
581 } | |
582 | |
583 return Status(kOk); | |
584 | |
585 //return web_view->OverrideNetworkConditions( | |
prasadv
2016/06/17 18:43:35
Remove these lines if not needed.
roisinmcl
2016/06/20 18:14:16
Done.
| |
586 // *session->overridden_network_conditions); | |
587 | |
588 } | |
589 | |
508 Status ExecuteGetWindowPosition(Session* session, | 590 Status ExecuteGetWindowPosition(Session* session, |
509 const base::DictionaryValue& params, | 591 const base::DictionaryValue& params, |
510 std::unique_ptr<base::Value>* value) { | 592 std::unique_ptr<base::Value>* value) { |
511 ChromeDesktopImpl* desktop = NULL; | 593 ChromeDesktopImpl* desktop = NULL; |
512 Status status = session->chrome->GetAsDesktop(&desktop); | 594 Status status = session->chrome->GetAsDesktop(&desktop); |
513 if (status.IsError()) | 595 if (status.IsError()) |
514 return status; | 596 return status; |
515 | 597 |
516 AutomationExtension* extension = NULL; | 598 AutomationExtension* extension = NULL; |
517 status = desktop->GetAutomationExtension(&extension); | 599 status = desktop->GetAutomationExtension(&extension); |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
687 | 769 |
688 Status ExecuteSetAutoReporting(Session* session, | 770 Status ExecuteSetAutoReporting(Session* session, |
689 const base::DictionaryValue& params, | 771 const base::DictionaryValue& params, |
690 std::unique_ptr<base::Value>* value) { | 772 std::unique_ptr<base::Value>* value) { |
691 bool enabled; | 773 bool enabled; |
692 if (!params.GetBoolean("enabled", &enabled)) | 774 if (!params.GetBoolean("enabled", &enabled)) |
693 return Status(kUnknownError, "missing parameter 'enabled'"); | 775 return Status(kUnknownError, "missing parameter 'enabled'"); |
694 session->auto_reporting_enabled = enabled; | 776 session->auto_reporting_enabled = enabled; |
695 return Status(kOk); | 777 return Status(kOk); |
696 } | 778 } |
OLD | NEW |