1# Copyright 2014 The Chromium Authors. All rights reserved. 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5from py_trace_event import trace_event 6 7 8class NetworkController(object): 9 """Control network settings and servers to simulate the Web. 10 11 Network changes include forwarding device ports to host platform ports. 12 Web Page Replay is used to record and replay HTTP/HTTPS responses. 13 """ 14 15 __metaclass__ = trace_event.TracedMetaClass 16 17 def __init__(self, network_controller_backend): 18 self._network_controller_backend = network_controller_backend 19 20 def InitializeIfNeeded(self, use_live_traffic=False): 21 self._network_controller_backend.InitializeIfNeeded(use_live_traffic) 22 23 def Open(self, wpr_mode, extra_wpr_args): 24 self._network_controller_backend.Open(wpr_mode, extra_wpr_args) 25 26 def UpdateTrafficSettings(self, round_trip_latency_ms=None, 27 download_bandwidth_kbps=None, upload_bandwidth_kbps=None): 28 self._network_controller_backend.ts_proxy_server.UpdateTrafficSettings( 29 round_trip_latency_ms, download_bandwidth_kbps, upload_bandwidth_kbps) 30 31 @property 32 def is_open(self): 33 return self._network_controller_backend.is_open 34 35 def Close(self): 36 self._network_controller_backend.Close() 37 38 def StartReplay(self, archive_path, make_javascript_deterministic=False): 39 self._network_controller_backend.StartReplay( 40 archive_path, make_javascript_deterministic) 41 42 def StopReplay(self): 43 self._network_controller_backend.StopReplay() 44