Chromium Code Reviews| Index: tools/telemetry/telemetry/page/actions/synthetic_delay.py |
| diff --git a/tools/telemetry/telemetry/page/actions/synthetic_delay.py b/tools/telemetry/telemetry/page/actions/synthetic_delay.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..83c0a35b3ce7ce4d235a27ce913b2fd118c2278e |
| --- /dev/null |
| +++ b/tools/telemetry/telemetry/page/actions/synthetic_delay.py |
| @@ -0,0 +1,30 @@ |
| +# Copyright (c) 2012 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. |
| +from telemetry.page.actions import page_action |
|
nduca
2013/11/24 19:22:46
lets put a docstring on this class that explains w
Sami
2013/11/29 19:29:17
Done.
|
| + |
| +class SyntheticDelayAction(page_action.PageAction): |
| + def __init__(self, attributes=None): |
| + super(SyntheticDelayAction, self).__init__(attributes) |
| + |
| + def WillRunAction(self, page, tab): |
| + # Fail if browser doesn't support synthetic delays. |
| + if not tab.EvaluateJavaScript(""" |
| + !!(window.chrome && |
| + chrome.gpuBenchmarking && |
| + chrome.gpuBenchmarking.configureSyntheticDelay);"""): |
| + raise page_action.PageActionNotSupported( |
| + 'Synthetic delays not supported for this browser') |
| + |
| + def RunAction(self, page, tab, previous_action): |
| + done_callback = 'function() { window.__syntheticDelayActionDone = true; }' |
| + target_duration = float(getattr(self, 'target_duration', '0')) |
| + mode = getattr(self, 'mode', 'static') |
| + tab.ExecuteJavaScript(""" |
| + window.__syntheticDelayActionDone = false; |
| + chrome.gpuBenchmarking.configureSyntheticDelay("%s", %f, "%s", %s);""" |
| + % (self.name, target_duration, mode, done_callback)) |
| + tab.WaitForJavaScriptExpression('window.__syntheticDelayActionDone ', 10) |
| + |
| + def CustomizeBrowserOptions(self, options): |
| + options.AppendExtraBrowserArgs('--enable-gpu-benchmarking') |