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

Side by Side Diff: chrome/test/functional/tracing/timeline_model.py

Issue 10736055: Smoke test for tracing infrastructure in PyAuto (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Clean up js TimelineModel when the python TimelineModelProxy is deleted. Created 8 years, 4 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 # Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 import json
6 import os
7
8 def escape_for_quoted_javascript_execution(js):
9 # Poor man's string escape.
10 return js.replace("'", "\\'");
11
12 class TimelineModelProxy:
13 def __init__(self, js_executor, shim_id):
14 self._js_executor = js_executor
15 self._shim_id = shim_id
16
17 # Warning: The JSON serialization process removes cyclic references.
18 # TODO(eatnumber) regenerate these cyclic references on deserialization.
19 def _callModelMethod(self, method_name, *args):
20 result = self._js_executor(
21 """
22 window.timelineModelShims['%s'].invokeMethod('%s', '%s')
23 """ % (
24 self._shim_id,
25 escape_for_quoted_javascript_execution(method_name),
26 escape_for_quoted_javascript_execution(json.dumps(args))
27 )
28 )
29 if result["success"]:
30 return result["data"]
31 # TODO(eatnumber) Make these exceptions more reader friendly.
32 raise Exception(result)
33
34 def __del__(self):
35 self._js_executor(
36 """
37 window.timelineModelShims['%s'] = undefined;
38 window.domAutomationController.send('');
39 """ % self._shim_id
40 )
41
42 def getAllThreads(self):
43 return self._callModelMethod("getAllThreads")
44
45 def getAllCpus(self):
46 return self._callModelMethod("getAllCpus")
47
48 def getAllProcesses(self):
49 return self._callModelMethod("getAllProcesses")
50
51 def getAllCounters(self):
52 return self._callModelMethod("getAllCounters")
53
54 def findAllThreadsNamed(self, name):
55 return self._callModelMethod("findAllThreadsNamed", name);
56
57 # Alias TimelineModel to TimelineModelProxy for convenience.
58 TimelineModel = TimelineModelProxy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698