Chromium Code Reviews| Index: chrome/test/functional/tracing/timeline_model.py |
| diff --git a/chrome/test/functional/tracing/timeline_model.py b/chrome/test/functional/tracing/timeline_model.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..997f67fae043cc6abc293161a26d9061ea809e8b |
| --- /dev/null |
| +++ b/chrome/test/functional/tracing/timeline_model.py |
| @@ -0,0 +1,50 @@ |
| +# Copyright (c) 2011 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. |
| + |
| +import json |
| +import os |
| + |
| +def escape_for_quoted_javascript_execution(js): |
| + # Poor man's string escape. |
| + return js.replace("'", "\\'"); |
| + |
| +class TimelineModelProxy: |
| + def __init__(self, js_executor, uuid): |
|
nduca
2012/07/20 07:13:13
uuid -> something more obvious. decorator_id, if t
|
| + self._js_executor = js_executor |
| + self._uuid = uuid |
| + |
| + # Do note that the JSON serialization process removes cyclic references. |
|
nduca
2012/07/20 07:13:13
# NB: The json serialization process ..., or
# Wa
|
| + # TODO(eatnumber) regenerate these cyclic references on deserialization. |
| + def _callModelMethod(self, method_name, *args): |
| + result = self._js_executor.ExecuteJavascript( |
| + """ |
| + window.timelineModelDecorators['%s'].invokeOnTimelineModel('%s', '%s') |
| + """ % ( |
| + self._uuid, |
| + escape_for_quoted_javascript_execution(method_name), |
| + escape_for_quoted_javascript_execution(json.dumps(args)) |
| + ) |
| + ) |
| + if( result["success"] ): |
|
nduca
2012/07/20 07:13:13
python style
if x:
never
if (x):
|
| + return result["data"] |
| + # TODO(eatnumber) Make these exceptions more reader friendly |
|
nduca
2012/07/20 07:13:13
Comments end with periods because they are complet
|
| + raise Exception(result) |
| + |
| + def getAllThreads(self): |
| + return self._callModelMethod("getAllThreads") |
| + |
| + def getAllCpus(self): |
| + return self._callModelMethod("getAllCpus") |
| + |
| + def getAllProcesses(self): |
| + return self._callModelMethod("getAllProcesses") |
| + |
| + def getAllCounters(self): |
| + return self._callModelMethod("getAllCounters") |
| + |
| + def findAllThreadsNamed(self, name): |
| + return self._callModelMethod("findAllThreadsNamed", name); |
| + |
| +# Alias TimelineModel to TimelineModelProxy for convenience |
| +TimelineModel = TimelineModelProxy |