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..5f13bf10f205e3225553d916b31ad4ef95b8b003 |
| --- /dev/null |
| +++ b/chrome/test/functional/tracing/timeline_model.py |
| @@ -0,0 +1,57 @@ |
| +#!/usr/bin/env python |
| +# 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 |
| + |
| +class TimelineModelProxy: |
|
nduca
2012/07/18 05:51:35
Seems to me you can just read the js here one-off,
|
| + def __init__(self, tracing_js_host, remote_object_js): |
| + self._tracing_js_host = tracing_js_host |
| + self._remote_object_js = remote_object_js |
|
nduca
2012/07/18 05:51:35
_remote_shim_name
|
| + |
| + def _escape_for_quoted_javascript_execution(self, js): |
|
nduca
2012/07/18 05:51:35
this should be a global var. It doesn't need anyt
|
| + # Poor man's string escape. |
| + return js.replace("'", "\\'"); |
| + |
| + # Do note that the JSON serialization process removes cyclic references. |
| + # TODO(eatnumber) regenerate these cyclic references on deserialization. |
| + def _js_call(self, method_name, *args): |
|
nduca
2012/07/18 05:51:35
I think this is overcomplex.
I think that you sho
|
| + result = json.loads(self._tracing_js_host.ExecuteJavascriptWithFile( |
| + js = """ |
| + // For simplicity, I'm putting a vulnerability to js injection here (in |
| + // the eval), as this code should never be invoked by untrusted code. |
| + // This injection allows the caller to use remote_object_jss like |
| + // "profilingView.timelineView.model" which is a needed feature. |
| + invokeJsMethodFromPython(eval('%s'), '%s', '%s'); |
| + """ % ( |
| + self._escape_for_quoted_javascript_execution(self._remote_object_js), |
| + self._escape_for_quoted_javascript_execution(method_name), |
| + self._escape_for_quoted_javascript_execution(json.dumps(args)) |
| + ), |
| + fileName = os.path.join(os.path.dirname(__file__), 'timeline_model.js'), |
| + windex = self._tracing_js_host._trace_win) |
|
nduca
2012/07/18 05:51:35
Is accessing _trace_win a normative pracice in pya
|
| + ) |
| + if( result["success"] ): |
| + return result["data"] |
| + # TODO(eatnumber) Make these exceptions more reader friendly |
| + raise Exception(result) |
| + |
| + def getAllThreads(self): |
| + return self._js_call("getAllThreads") |
| + |
| + def getAllCpus(self): |
| + return self._js_call("getAllCpus") |
| + |
| + def getAllProcesses(self): |
| + return self._js_call("getAllProcesses") |
| + |
| + def getAllCounters(self): |
| + return self._js_call("getAllCounters") |
| + |
| + def findAllThreadsNamed(self, name): |
| + return self._js_call("findAllThreadsNamed", name); |
| + |
| +# Alias TimelineModel to TimelineModelProxy for convenience |
| +TimelineModel = TimelineModelProxy |