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

Side by Side Diff: telemetry/telemetry/page/__init__.py

Issue 2346093002: [Telemetry] Add API for updating ts_proxy_server's traffic settings (Closed)
Patch Set: Rebase Created 4 years, 2 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 unified diff | Download patch
OLDNEW
1 # Copyright 2012 The Chromium Authors. All rights reserved. 1 # Copyright 2012 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 import inspect 4 import inspect
5 import logging 5 import logging
6 import os 6 import os
7 import urlparse 7 import urlparse
8 8
9 from py_utils import cloud_storage # pylint: disable=import-error 9 from py_utils import cloud_storage # pylint: disable=import-error
10 10
11 from telemetry import story 11 from telemetry import story
12 from telemetry.page import cache_temperature as cache_temperature_module
12 from telemetry.page import shared_page_state 13 from telemetry.page import shared_page_state
13 from telemetry.page import cache_temperature as cache_temperature_module 14 from telemetry.page import traffic_setting as traffic_setting_module
14 from telemetry.internal.actions import action_runner as action_runner_module 15 from telemetry.internal.actions import action_runner as action_runner_module
15 16
16 17
17 class Page(story.Story): 18 class Page(story.Story):
18 19
19 def __init__(self, url, page_set=None, base_dir=None, name='', 20 def __init__(self, url, page_set=None, base_dir=None, name='',
20 credentials_path=None, 21 credentials_path=None,
21 credentials_bucket=cloud_storage.PUBLIC_BUCKET, labels=None, 22 credentials_bucket=cloud_storage.PUBLIC_BUCKET, labels=None,
22 startup_url='', make_javascript_deterministic=True, 23 startup_url='', make_javascript_deterministic=True,
23 shared_page_state_class=shared_page_state.SharedPageState, 24 shared_page_state_class=shared_page_state.SharedPageState,
24 grouping_keys=None, 25 grouping_keys=None,
25 cache_temperature=cache_temperature_module.ANY): 26 cache_temperature=cache_temperature_module.ANY,
27 traffic_setting=traffic_setting_module.NONE):
26 self._url = url 28 self._url = url
27 29
28 super(Page, self).__init__( 30 super(Page, self).__init__(
29 shared_page_state_class, name=name, labels=labels, 31 shared_page_state_class, name=name, labels=labels,
30 is_local=self._scheme in ['file', 'chrome', 'about'], 32 is_local=self._scheme in ['file', 'chrome', 'about'],
31 make_javascript_deterministic=make_javascript_deterministic, 33 make_javascript_deterministic=make_javascript_deterministic,
32 grouping_keys=grouping_keys) 34 grouping_keys=grouping_keys)
33 35
34 self._page_set = page_set 36 self._page_set = page_set
35 # Default value of base_dir is the directory of the file that defines the 37 # Default value of base_dir is the directory of the file that defines the
36 # class of this page instance. 38 # class of this page instance.
37 if base_dir is None: 39 if base_dir is None:
38 base_dir = os.path.dirname(inspect.getfile(self.__class__)) 40 base_dir = os.path.dirname(inspect.getfile(self.__class__))
39 self._base_dir = base_dir 41 self._base_dir = base_dir
40 self._name = name 42 self._name = name
41 if credentials_path: 43 if credentials_path:
42 credentials_path = os.path.join(self._base_dir, credentials_path) 44 credentials_path = os.path.join(self._base_dir, credentials_path)
43 cloud_storage.GetIfChanged(credentials_path, credentials_bucket) 45 cloud_storage.GetIfChanged(credentials_path, credentials_bucket)
44 if not os.path.exists(credentials_path): 46 if not os.path.exists(credentials_path):
45 logging.error('Invalid credentials path: %s' % credentials_path) 47 logging.error('Invalid credentials path: %s' % credentials_path)
46 credentials_path = None 48 credentials_path = None
47 self._credentials_path = credentials_path 49 self._credentials_path = credentials_path
48 self._cache_temperature = cache_temperature 50 self._cache_temperature = cache_temperature
49 if cache_temperature != cache_temperature_module.ANY: 51 if cache_temperature != cache_temperature_module.ANY:
50 self.grouping_keys['cache_temperature'] = cache_temperature 52 self.grouping_keys['cache_temperature'] = cache_temperature
51 53
54 self._traffic_setting = traffic_setting
55
52 # Whether to collect garbage on the page before navigating & performing 56 # Whether to collect garbage on the page before navigating & performing
53 # page actions. 57 # page actions.
54 self._collect_garbage_before_run = True 58 self._collect_garbage_before_run = True
55 59
56 # These attributes can be set dynamically by the page. 60 # These attributes can be set dynamically by the page.
57 self.synthetic_delays = dict() 61 self.synthetic_delays = dict()
58 self._startup_url = startup_url 62 self._startup_url = startup_url
59 self.credentials = None 63 self.credentials = None
60 self.skip_waits = False 64 self.skip_waits = False
61 self.script_to_evaluate_on_commit = None 65 self.script_to_evaluate_on_commit = None
62 self._SchemeErrorCheck() 66 self._SchemeErrorCheck()
63 67
64 @property 68 @property
65 def credentials_path(self): 69 def credentials_path(self):
66 return self._credentials_path 70 return self._credentials_path
67 71
68 @property 72 @property
69 def cache_temperature(self): 73 def cache_temperature(self):
70 return self._cache_temperature 74 return self._cache_temperature
71 75
72 @property 76 @property
77 def traffic_setting(self):
78 return self._traffic_setting
79
80 @property
73 def startup_url(self): 81 def startup_url(self):
74 return self._startup_url 82 return self._startup_url
75 83
76 def _SchemeErrorCheck(self): 84 def _SchemeErrorCheck(self):
77 if not self._scheme: 85 if not self._scheme:
78 raise ValueError('Must prepend the URL with scheme (e.g. file://)') 86 raise ValueError('Must prepend the URL with scheme (e.g. file://)')
79 87
80 if self.startup_url: 88 if self.startup_url:
81 startup_url_scheme = urlparse.urlparse(self.startup_url).scheme 89 startup_url_scheme = urlparse.urlparse(self.startup_url).scheme
82 if not startup_url_scheme: 90 if not startup_url_scheme:
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 218
211 @property 219 @property
212 def display_name(self): 220 def display_name(self):
213 if self.name: 221 if self.name:
214 return self.name 222 return self.name
215 if self.page_set is None or not self.is_file: 223 if self.page_set is None or not self.is_file:
216 return self.url 224 return self.url
217 all_urls = [p.url.rstrip('/') for p in self.page_set if p.is_file] 225 all_urls = [p.url.rstrip('/') for p in self.page_set if p.is_file]
218 common_prefix = os.path.dirname(os.path.commonprefix(all_urls)) 226 common_prefix = os.path.dirname(os.path.commonprefix(all_urls))
219 return self.url[len(common_prefix):].strip('/') 227 return self.url[len(common_prefix):].strip('/')
OLDNEW
« no previous file with comments | « telemetry/telemetry/internal/util/ts_proxy_server_unittest.py ('k') | telemetry/telemetry/page/shared_page_state.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698