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

Unified Diff: tools/android/loading/chrome_setup.py

Issue 1707363002: sandwich: Implements network condition on WPR server and browser. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@i00
Patch Set: Created 4 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tools/android/loading/device_setup.py » ('j') | tools/android/loading/devtools_monitor.py » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/android/loading/chrome_setup.py
diff --git a/tools/android/loading/chrome_setup.py b/tools/android/loading/chrome_setup.py
index 8d7948c60bdf94c40b327bf8b4a640ca7fb08439..1b0f124917f7aef4bf2723e85c8fa9c649c9b1de 100644
--- a/tools/android/loading/chrome_setup.py
+++ b/tools/android/loading/chrome_setup.py
@@ -17,9 +17,10 @@ from options import OPTIONS
# Copied from
# WebKit/Source/devtools/front_end/network/NetworkConditionsSelector.js
-_NETWORK_CONDITIONS = {
- 'Offline': {
- 'download': 0 * 1024 / 8, 'upload': 0 * 1024 / 8, 'latency': 0},
+# Units:
+# download/upload: byte/s
+# latency: ms
+NETWORK_CONDITIONS = {
'GPRS': {
'download': 50 * 1024 / 8, 'upload': 20 * 1024 / 8, 'latency': 500},
'Regular 2G': {
@@ -43,6 +44,23 @@ _NETWORK_CONDITIONS = {
}
+def BandwidthToString(bandwidth):
+ """Converts a bandwidth to string.
+
+ Args:
+ bandwidth: The bandwidth to convert in byte/s. Must be a multiple of 1024/8.
+
+ Returns:
+ A string compatible with wpr --{up,down} command line flags.
+ """
+ assert type(bandwidth) == int
+ assert bandwidth % (1024/8) == 0
+ bandwidth_kbps = (bandwidth * 8) / 1024
+ if bandwidth_kbps % 1024:
+ return '{}Kbit/s'.format(bandwidth_kbps)
+ return '{}Mbit/s'.format(bandwidth_kbps / 1024)
+
+
@contextlib.contextmanager
def DevToolsConnectionForLocalBinary(flags):
"""Returns a DevToolsConnection context manager for a local binary.
@@ -80,7 +98,7 @@ def SetUpEmulationAndReturnMetadata(connection, emulated_device_name,
connection: (DevToolsConnection)
emulated_device_name: (str) Key in the dict returned by
_LoadEmulatedDevices().
- emulated_network_name: (str) Key in _NETWORK_CONDITIONS.
+ emulated_network_name: (str) Key in NETWORK_CONDITIONS.
Returns:
A metadata dict {'deviceEmulation': params, 'networkEmulation': params}.
@@ -93,7 +111,7 @@ def SetUpEmulationAndReturnMetadata(connection, emulated_device_name,
connection, emulated_device)
result['deviceEmulation'] = emulation_params
if emulated_network_name:
- params = _NETWORK_CONDITIONS[emulated_network_name]
+ params = NETWORK_CONDITIONS[emulated_network_name]
_SetUpNetworkEmulation(
connection, params['latency'], params['download'], params['upload'])
result['networkEmulation'] = params
« no previous file with comments | « no previous file | tools/android/loading/device_setup.py » ('j') | tools/android/loading/devtools_monitor.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698