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

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: Fix up style issues. Add suite to PYAUTO_TESTS 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.
Nirnimesh 2012/07/30 21:03:51 Need : after TODO(eatnumber)
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
Nirnimesh 2012/07/30 21:03:51 Why not change line 12 instead?
Russ Harmon 2012/07/31 01:11:16 Because while I don't want authors of tests to kno
Nirnimesh 2012/07/31 20:05:57 That seems like a good note to put in the docstrin
Russ Harmon 2012/07/31 20:54:18 How can it be avoided while both keeping a name fo
Nirnimesh 2012/07/31 21:15:05 I don't understand your motivation. You want test
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698