diff options
author | gabadie <gabadie@chromium.org> | 2016-03-23 11:05:47 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-03-23 18:07:28 +0000 |
commit | a9415b6fd69350e6410726008c0843ee690baade (patch) | |
tree | 6bb2d99e2d939e7f07b80326baac384236123df8 | |
parent | 9a7b8ea49fe9b5d8509a9a43275809ab759853a8 (diff) | |
download | chromium_src-a9415b6fd69350e6410726008c0843ee690baade.zip chromium_src-a9415b6fd69350e6410726008c0843ee690baade.tar.gz chromium_src-a9415b6fd69350e6410726008c0843ee690baade.tar.bz2 |
tools/android/loading: Remove old chrome API
Currently, all the code has been migrated to the
ChromeController API. This CL remove the no longer
used legacy API, becoming dead code.
BUG=582080
Review URL: https://codereview.chromium.org/1825403002
Cr-Commit-Position: refs/heads/master@{#382880}
-rw-r--r-- | tools/android/loading/chrome_setup.py | 187 | ||||
-rw-r--r-- | tools/android/loading/device_setup.py | 73 | ||||
-rwxr-xr-x | tools/android/loading/trace_recorder.py | 85 | ||||
-rwxr-xr-x | tools/android/loading/trace_test/webserver_test.py | 2 |
4 files changed, 7 insertions, 340 deletions
diff --git a/tools/android/loading/chrome_setup.py b/tools/android/loading/chrome_setup.py deleted file mode 100644 index 245246d..0000000 --- a/tools/android/loading/chrome_setup.py +++ /dev/null @@ -1,187 +0,0 @@ -# Copyright 2016 The Chromium Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -"""Handles Chrome's configuration. DEPRECATED!""" - -import contextlib -import json -import shutil -import subprocess -import tempfile -import time - -import devtools_monitor -from options import OPTIONS - - -# Copied from -# WebKit/Source/devtools/front_end/network/NetworkConditionsSelector.js -# Units: -# download/upload: byte/s -# latency: ms -NETWORK_CONDITIONS = { - 'GPRS': { - 'download': 50 * 1024 / 8, 'upload': 20 * 1024 / 8, 'latency': 500}, - 'Regular 2G': { - 'download': 250 * 1024 / 8, 'upload': 50 * 1024 / 8, 'latency': 300}, - 'Good 2G': { - 'download': 450 * 1024 / 8, 'upload': 150 * 1024 / 8, 'latency': 150}, - 'Regular 3G': { - 'download': 750 * 1024 / 8, 'upload': 250 * 1024 / 8, 'latency': 100}, - 'Good 3G': { - 'download': 1.5 * 1024 * 1024 / 8, 'upload': 750 * 1024 / 8, - 'latency': 40}, - 'Regular 4G': { - 'download': 4 * 1024 * 1024 / 8, 'upload': 3 * 1024 * 1024 / 8, - 'latency': 20}, - 'DSL': { - 'download': 2 * 1024 * 1024 / 8, 'upload': 1 * 1024 * 1024 / 8, - 'latency': 5}, - 'WiFi': { - 'download': 30 * 1024 * 1024 / 8, 'upload': 15 * 1024 * 1024 / 8, - 'latency': 2} -} - - -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. - - Args: - flags: ([str]) List of flags to pass to the browser. - - Returns: - A DevToolsConnection context manager. - """ - binary_filename = OPTIONS.local_binary - profile_dir = OPTIONS.local_profile_dir - using_temp_profile_dir = profile_dir is None - if using_temp_profile_dir: - profile_dir = tempfile.mkdtemp() - flags.append('--user-data-dir=%s' % profile_dir) - chrome_out = None if OPTIONS.local_noisy else file('/dev/null', 'w') - process = subprocess.Popen( - [binary_filename] + flags, shell=False, stderr=chrome_out) - try: - time.sleep(10) - yield devtools_monitor.DevToolsConnection( - OPTIONS.devtools_hostname, OPTIONS.devtools_port) - finally: - process.kill() - if using_temp_profile_dir: - shutil.rmtree(profile_dir) - - -def SetUpEmulationAndReturnMetadata(connection, emulated_device_name, - emulated_network_name): - """Sets up the device and network emulation and returns the trace metadata. - - Args: - connection: (DevToolsConnection) - emulated_device_name: (str) Key in the dict returned by - _LoadEmulatedDevices(). - emulated_network_name: (str) Key in NETWORK_CONDITIONS. - - Returns: - A metadata dict {'deviceEmulation': params, 'networkEmulation': params}. - """ - result = {'deviceEmulation': {}, 'networkEmulation': {}} - if emulated_device_name: - devices = _LoadEmulatedDevices(OPTIONS.devices_file) - emulated_device = devices[emulated_device_name] - emulation_params = _SetUpDeviceEmulationAndReturnMetadata( - connection, emulated_device) - result['deviceEmulation'] = emulation_params - if emulated_network_name: - params = NETWORK_CONDITIONS[emulated_network_name] - _SetUpNetworkEmulation( - connection, params['latency'], params['download'], params['upload']) - result['networkEmulation'] = params - return result - - -def _LoadEmulatedDevices(filename): - """Loads a list of emulated devices from the DevTools JSON registry. - - Args: - filename: (str) Path to the JSON file. - - Returns: - {'device_name': device} - """ - json_dict = json.load(open(filename, 'r')) - devices = {} - for device in json_dict['extensions']: - device = device['device'] - devices[device['title']] = device - return devices - - -def _GetDeviceEmulationMetadata(device): - """Returns the metadata associated with a given device.""" - return {'width': device['screen']['vertical']['width'], - 'height': device['screen']['vertical']['height'], - 'deviceScaleFactor': device['screen']['device-pixel-ratio'], - 'mobile': 'mobile' in device['capabilities'], - 'userAgent': device['user-agent']} - - -def _SetUpDeviceEmulationAndReturnMetadata(connection, device): - """Configures an instance of Chrome for device emulation. - - Args: - connection: (DevToolsConnection) - device: (dict) As returned by LoadEmulatedDevices(). - - Returns: - A dict containing the device emulation metadata. - """ - print device - res = connection.SyncRequest('Emulation.canEmulate') - assert res['result'], 'Cannot set device emulation.' - data = _GetDeviceEmulationMetadata(device) - connection.SyncRequestNoResponse( - 'Emulation.setDeviceMetricsOverride', - {'width': data['width'], - 'height': data['height'], - 'deviceScaleFactor': data['deviceScaleFactor'], - 'mobile': data['mobile'], - 'fitWindow': True}) - connection.SyncRequestNoResponse('Network.setUserAgentOverride', - {'userAgent': data['userAgent']}) - return data - - -def _SetUpNetworkEmulation(connection, latency, download, upload): - """Configures an instance of Chrome for network emulation. - - Args: - connection: (DevToolsConnection) - latency: (float) Latency in ms. - download: (float) Download speed (Bytes / s). - upload: (float) Upload speed (Bytes / s). - """ - res = connection.SyncRequest('Network.canEmulateNetworkConditions') - assert res['result'], 'Cannot set network emulation.' - connection.SyncRequestNoResponse( - 'Network.emulateNetworkConditions', - {'offline': False, 'latency': latency, 'downloadThroughput': download, - 'uploadThroughput': upload}) diff --git a/tools/android/loading/device_setup.py b/tools/android/loading/device_setup.py index 787cd79..d2c466d 100644 --- a/tools/android/loading/device_setup.py +++ b/tools/android/loading/device_setup.py @@ -35,8 +35,8 @@ sys.path.append(os.path.join(_SRC_DIR, 'third_party', 'webpagereplay')) import adb_install_cert import certutils -import chrome_setup import devtools_monitor +import emulation import options @@ -127,13 +127,6 @@ def ForwardPort(device, local, remote): device.adb.ForwardRemove(local) -# Deprecated -def _SetUpDevice(device, package_info): - """Enables root and closes Chrome on a device.""" - device.EnableRoot() - device.KillAll(package_info.package, quiet=True) - - @contextlib.contextmanager def _WprHost(wpr_archive_path, record=False, network_condition_name=None, @@ -148,13 +141,13 @@ def _WprHost(wpr_archive_path, record=False, else: assert os.path.exists(wpr_archive_path) if network_condition_name: - condition = chrome_setup.NETWORK_CONDITIONS[network_condition_name] + condition = emulation.NETWORK_CONDITIONS[network_condition_name] if record: logging.warning('WPR network condition is ignored when recording.') else: wpr_server_args.extend([ - '--down', chrome_setup.BandwidthToString(condition['download']), - '--up', chrome_setup.BandwidthToString(condition['upload']), + '--down', emulation.BandwidthToString(condition['download']), + '--up', emulation.BandwidthToString(condition['upload']), '--delay_ms', str(condition['latency']), '--shaping_type', 'proxy']) @@ -207,7 +200,7 @@ def LocalWprHost(wpr_archive_path, record=False, wpr_archive_path: host sided WPR archive's path. record: Enables or disables WPR archive recording. network_condition_name: Network condition name available in - chrome_setup.NETWORK_CONDITIONS. + emulation.NETWORK_CONDITIONS. disable_script_injection: Disable JavaScript file injections that is fighting against resources name entropy. @@ -243,7 +236,7 @@ def RemoteWprHost(device, wpr_archive_path, record=False, wpr_archive_path: host sided WPR archive's path. record: Enables or disables WPR archive recording. network_condition_name: Network condition name available in - chrome_setup.NETWORK_CONDITIONS. + emulation.NETWORK_CONDITIONS. disable_script_injection: Disable JavaScript file injections that is fighting against resources name entropy. @@ -374,57 +367,3 @@ def RemoteSpeedIndexRecorder(device, connection, local_output_path): })(); """) yield - - -@contextlib.contextmanager -def _DevToolsConnectionOnDevice(device, flags): - """Returns a DevToolsConnection context manager for a given device. - - Args: - device: Device to connect to. - flags: ([str]) List of flags. - - Returns: - A DevToolsConnection context manager. - """ - package_info = OPTIONS.ChromePackage() - command_line_path = '/data/local/chrome-command-line' - _SetUpDevice(device, package_info) - with FlagReplacer(device, command_line_path, flags): - start_intent = intent.Intent( - package=package_info.package, activity=package_info.activity, - data='about:blank') - device.StartActivity(start_intent, blocking=True) - time.sleep(2) - with ForwardPort(device, 'tcp:%d' % OPTIONS.devtools_port, - 'localabstract:chrome_devtools_remote'): - yield devtools_monitor.DevToolsConnection( - OPTIONS.devtools_hostname, OPTIONS.devtools_port) - - -# Deprecated, use *Controller. -def DeviceConnection(device, additional_flags=None): - """Context for starting recording on a device. - - Sets up and restores any device and tracing appropriately - - Args: - device: Android device, or None for a local run (in which case chrome needs - to have been started with --remote-debugging-port=XXX). - additional_flags: Additional chromium arguments. - - Returns: - A context manager type which evaluates to a DevToolsConnection. - """ - new_flags = ['--disable-fre', - '--enable-test-events', - '--remote-debugging-port=%d' % OPTIONS.devtools_port] - if OPTIONS.no_sandbox: - new_flags.append('--no-sandbox') - if additional_flags != None: - new_flags.extend(additional_flags) - - if device: - return _DevToolsConnectionOnDevice(device, new_flags) - else: - return chrome_setup.DevToolsConnectionForLocalBinary(new_flags) diff --git a/tools/android/loading/trace_recorder.py b/tools/android/loading/trace_recorder.py deleted file mode 100755 index 7c9e822..0000000 --- a/tools/android/loading/trace_recorder.py +++ /dev/null @@ -1,85 +0,0 @@ -#! /usr/bin/python -# Copyright 2016 The Chromium Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -"""Loading trace recorder. DEPRECATED!""" - -import argparse -import datetime -import json -import logging -import os -import sys -import time - -_SRC_DIR = os.path.abspath(os.path.join( - os.path.dirname(__file__), '..', '..', '..')) - -sys.path.append(os.path.join(_SRC_DIR, 'third_party', 'catapult', 'devil')) -from devil.android import device_utils - -sys.path.append(os.path.join(_SRC_DIR, 'build', 'android')) -import devil_chromium - -import device_setup -import devtools_monitor -import loading_trace -import page_track -import request_track -import tracing - - -def MonitorUrl(connection, url, clear_cache=False, - categories=tracing.DEFAULT_CATEGORIES, - timeout=devtools_monitor.DEFAULT_TIMEOUT_SECONDS): - """Monitor a URL via a trace recorder. - - DEPRECATED! Use LoadingTrace.FromUrlAndController instead. - - Args: - connection: A devtools_monitor.DevToolsConnection instance. - url: url to navigate to as string. - clear_cache: boolean indicating if cache should be cleared before loading. - categories: List of tracing event categories to record. - timeout: Websocket timeout. - - Returns: - loading_trace.LoadingTrace. - """ - page = page_track.PageTrack(connection) - request = request_track.RequestTrack(connection) - trace = tracing.TracingTrack(connection, categories=categories) - connection.SetUpMonitoring() - if clear_cache: - connection.ClearCache() - connection.SendAndIgnoreResponse('Page.navigate', {'url': url}) - connection.StartMonitoring(timeout=timeout) - metadata = {'date': datetime.datetime.utcnow().isoformat(), - 'seconds_since_epoch': time.time()} - return loading_trace.LoadingTrace(url, metadata, page, request, trace) - -def RecordAndDumpTrace(device, url, output_filename): - with file(output_filename, 'w') as output,\ - device_setup.DeviceConnection(device) as connection: - trace = MonitorUrl(connection, url) - json.dump(trace.ToJsonDict(), output) - - -def main(): - logging.basicConfig(level=logging.INFO) - devil_chromium.Initialize() - - parser = argparse.ArgumentParser() - parser.add_argument('--url', required=True) - parser.add_argument('--output', required=True) - args = parser.parse_args() - url = args.url - if not url.startswith('http'): - url = 'http://' + url - device = device_utils.DeviceUtils.HealthyDevices()[0] - RecordAndDumpTrace(device, url, args.output) - - -if __name__ == '__main__': - main() diff --git a/tools/android/loading/trace_test/webserver_test.py b/tools/android/loading/trace_test/webserver_test.py index aad36c1..1db5da7 100755 --- a/tools/android/loading/trace_test/webserver_test.py +++ b/tools/android/loading/trace_test/webserver_test.py @@ -44,7 +44,7 @@ sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..')) import controller import loading_trace import options -import trace_recorder + OPTIONS = options.OPTIONS WEBSERVER = os.path.join(os.path.dirname(__file__), 'test_server.py') |