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 20 matching lines...) Expand all Loading... | |
31 #include "chrome/test/chromedriver/chrome_launcher.h" | 31 #include "chrome/test/chromedriver/chrome_launcher.h" |
32 #include "chrome/test/chromedriver/command_listener.h" | 32 #include "chrome/test/chromedriver/command_listener.h" |
33 #include "chrome/test/chromedriver/logging.h" | 33 #include "chrome/test/chromedriver/logging.h" |
34 #include "chrome/test/chromedriver/net/url_request_context_getter.h" | 34 #include "chrome/test/chromedriver/net/url_request_context_getter.h" |
35 #include "chrome/test/chromedriver/session.h" | 35 #include "chrome/test/chromedriver/session.h" |
36 #include "chrome/test/chromedriver/util.h" | 36 #include "chrome/test/chromedriver/util.h" |
37 #include "chrome/test/chromedriver/version.h" | 37 #include "chrome/test/chromedriver/version.h" |
38 | 38 |
39 namespace { | 39 namespace { |
40 | 40 |
41 const int kAirplaneMask = 0x1; | |
samuong
2016/06/20 21:43:23
nit: lets call it kAirplaneModeMask (same with kAi
roisinmcl
2016/06/21 18:55:11
Done.
| |
42 const int kWifiMask = 0x2; | |
43 const int k4GMask = 0x8; | |
44 const int k3GMask = 0x10; | |
45 const int k2GMask = 0x20; | |
46 | |
47 const int kAirplaneLatency = 0; | |
48 const int kAirplaneThroughput = 0; | |
49 const int kWifiLatency = 2; | |
50 const int kWifiThroughput = 30720 * 1024; | |
51 const int k4GLatency = 20; | |
52 const int k4GThroughput = 4096 * 1024; | |
53 const int k3GLatency = 100; | |
54 const int k3GThroughput = 750 * 1024; | |
55 const int k2GLatency = 300; | |
56 const int k2GThroughput = 250 * 1024; | |
57 | |
58 const bool kOnline = false; | |
59 const bool kOffline = true; | |
60 | |
41 const char kWindowHandlePrefix[] = "CDwindow-"; | 61 const char kWindowHandlePrefix[] = "CDwindow-"; |
42 | 62 |
43 std::string WebViewIdToWindowHandle(const std::string& web_view_id) { | 63 std::string WebViewIdToWindowHandle(const std::string& web_view_id) { |
44 return kWindowHandlePrefix + web_view_id; | 64 return kWindowHandlePrefix + web_view_id; |
45 } | 65 } |
46 | 66 |
47 bool WindowHandleToWebViewId(const std::string& window_handle, | 67 bool WindowHandleToWebViewId(const std::string& window_handle, |
48 std::string* web_view_id) { | 68 std::string* web_view_id) { |
49 if (window_handle.find(kWindowHandlePrefix) != 0u) | 69 if (window_handle.find(kWindowHandlePrefix) != 0u) |
50 return false; | 70 return false; |
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
498 conditions.SetInteger( | 518 conditions.SetInteger( |
499 "download_throughput", | 519 "download_throughput", |
500 session->overridden_network_conditions->download_throughput); | 520 session->overridden_network_conditions->download_throughput); |
501 conditions.SetInteger( | 521 conditions.SetInteger( |
502 "upload_throughput", | 522 "upload_throughput", |
503 session->overridden_network_conditions->upload_throughput); | 523 session->overridden_network_conditions->upload_throughput); |
504 value->reset(conditions.DeepCopy()); | 524 value->reset(conditions.DeepCopy()); |
505 return Status(kOk); | 525 return Status(kOk); |
506 } | 526 } |
507 | 527 |
528 Status ExecuteSetNetworkConnection(Session* session, | |
529 const base::DictionaryValue& params, | |
530 std::unique_ptr<Value>* value) { | |
531 int connection_type; | |
532 | |
samuong
2016/06/20 21:43:23
nit: delete blank line
roisinmcl
2016/06/21 18:55:11
Done.
| |
533 const base::DictionaryValue* parameters = NULL; | |
samuong
2016/06/20 21:43:23
use nullptr instead of NULL
roisinmcl
2016/06/21 18:55:10
Done.
| |
534 | |
535 params.GetDictionary("parameters", ¶meters); | |
536 | |
samuong
2016/06/20 21:43:23
nit: delete blank line
roisinmcl
2016/06/21 18:55:10
Done.
| |
537 if(!parameters->GetInteger("type", &connection_type)) { | |
samuong
2016/06/20 21:43:23
nit: space after 'if'
roisinmcl
2016/06/21 18:55:11
Done.
| |
538 return Status(kUnknownError, | |
539 "invalid 'connection_type'"); | |
samuong
2016/06/20 21:43:23
nit: join these two lines into one, remove braces
roisinmcl
2016/06/21 18:55:10
Done.
| |
540 } | |
541 | |
542 std::unique_ptr<NetworkConditions> network_conditions( | |
543 new NetworkConditions()); | |
544 | |
545 if (connection_type & kAirplaneMask) { | |
546 network_conditions->latency = kAirplaneLatency; | |
547 network_conditions->upload_throughput = kAirplaneThroughput; | |
548 network_conditions->download_throughput = kAirplaneThroughput; | |
549 network_conditions->offline = kOffline; | |
550 } else if (connection_type & kWifiMask) { | |
551 network_conditions->latency = kWifiLatency; | |
552 network_conditions->upload_throughput = kWifiThroughput; | |
553 network_conditions->download_throughput = kWifiThroughput; | |
554 network_conditions->offline = kOnline; | |
555 } else if (connection_type & k4GMask) { | |
556 network_conditions->latency = k4GLatency; | |
557 network_conditions->upload_throughput = k4GThroughput; | |
558 network_conditions->download_throughput = k4GThroughput; | |
559 network_conditions->offline = kOnline; | |
560 } else if (connection_type & k3GMask) { | |
561 network_conditions->latency = k3GLatency; | |
562 network_conditions->upload_throughput = k3GThroughput; | |
563 network_conditions->download_throughput = k3GThroughput; | |
564 network_conditions->offline = kOnline; | |
565 } else if (connection_type & k2GMask) { | |
566 network_conditions->latency = k2GLatency; | |
567 network_conditions->upload_throughput = k2GThroughput; | |
568 network_conditions->download_throughput = k2GThroughput; | |
569 network_conditions->offline = kOnline; | |
570 } else { | |
571 return Status(kUnknownError, "invalid 'connection_type'"); | |
572 } | |
samuong
2016/06/20 21:43:23
if |connection_type| is 011 (airplane mode + wifi)
roisinmcl
2016/06/21 18:55:11
I changed the orders to set the connection to the
| |
573 | |
574 session->overridden_network_conditions.reset( | |
575 network_conditions.release()); | |
576 | |
577 // get list of all webview objects | |
578 // iterate through and override each one's network conditions | |
samuong
2016/06/20 21:43:23
use full sentences for comments, and try to explai
roisinmcl
2016/06/21 18:55:11
Done.
| |
579 std::list<std::string> web_view_ids; | |
580 chrome->GetWebViewIds(web_view_ids); | |
581 | |
582 std::string web_view_id; | |
samuong
2016/06/20 21:43:23
nit: since this is only used within the for loop,
roisinmcl
2016/06/21 18:55:11
Done.
| |
583 | |
584 for (int i = 0; i < web_view_ids.size; ++i) { | |
585 WebView current_web_view; | |
586 web_view_id = web_view_ids[i]; | |
587 chrome->GetWebViewById(web_view_id, web_view) | |
588 if (!web_view) { | |
589 return Status(kUnknowError, "invalid web view"); | |
590 } | |
591 web_view->OverrideNetworkConditions( | |
592 *session->overridden_network_conditions); | |
593 } | |
594 | |
595 return Status(kOk); | |
596 } | |
597 | |
508 Status ExecuteGetWindowPosition(Session* session, | 598 Status ExecuteGetWindowPosition(Session* session, |
509 const base::DictionaryValue& params, | 599 const base::DictionaryValue& params, |
510 std::unique_ptr<base::Value>* value) { | 600 std::unique_ptr<base::Value>* value) { |
511 ChromeDesktopImpl* desktop = NULL; | 601 ChromeDesktopImpl* desktop = NULL; |
512 Status status = session->chrome->GetAsDesktop(&desktop); | 602 Status status = session->chrome->GetAsDesktop(&desktop); |
513 if (status.IsError()) | 603 if (status.IsError()) |
514 return status; | 604 return status; |
515 | 605 |
516 AutomationExtension* extension = NULL; | 606 AutomationExtension* extension = NULL; |
517 status = desktop->GetAutomationExtension(&extension); | 607 status = desktop->GetAutomationExtension(&extension); |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
687 | 777 |
688 Status ExecuteSetAutoReporting(Session* session, | 778 Status ExecuteSetAutoReporting(Session* session, |
689 const base::DictionaryValue& params, | 779 const base::DictionaryValue& params, |
690 std::unique_ptr<base::Value>* value) { | 780 std::unique_ptr<base::Value>* value) { |
691 bool enabled; | 781 bool enabled; |
692 if (!params.GetBoolean("enabled", &enabled)) | 782 if (!params.GetBoolean("enabled", &enabled)) |
693 return Status(kUnknownError, "missing parameter 'enabled'"); | 783 return Status(kUnknownError, "missing parameter 'enabled'"); |
694 session->auto_reporting_enabled = enabled; | 784 session->auto_reporting_enabled = enabled; |
695 return Status(kOk); | 785 return Status(kOk); |
696 } | 786 } |
OLD | NEW |