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

Side by Side Diff: systrace/profile_chrome/profiler_unittest.py

Issue 2295913002: Enable some profile_chrome unit tests on Trybots (Closed) Base URL: https://chromium.googlesource.com/external/github.com/catapult-project/catapult.git@master
Patch Set: Disable DDMS test because it is flaky Created 4 years, 3 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
OLDNEW
1 # Copyright 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import os 5 import os
6 import tempfile 6 import tempfile
7 import unittest 7 import unittest
8 import zipfile 8 import zipfile
9 9
10 from profile_chrome import profiler 10 from profile_chrome import profiler
11 from profile_chrome import ui 11 from profile_chrome import ui
12 from systrace import decorators
12 from systrace import trace_result 13 from systrace import trace_result
13 14
14 15
15 class FakeAgent(object): 16 class FakeAgent(object):
16 def __init__(self, contents='fake-contents'): 17 def __init__(self, contents='fake-contents'):
17 self.contents = contents 18 self.contents = contents
18 self.stopped = False 19 self.stopped = False
19 self.filename = None 20 self.filename = None
20 self.config = None 21 self.config = None
21 self.timeout = None 22 self.timeout = None
(...skipping 27 matching lines...) Expand all
49 'is not supported.') 50 'is not supported.')
50 51
51 def __repr__(self): 52 def __repr__(self):
52 return 'faketrace' 53 return 'faketrace'
53 54
54 55
55 class ProfilerTest(unittest.TestCase): 56 class ProfilerTest(unittest.TestCase):
56 def setUp(self): 57 def setUp(self):
57 ui.EnableTestMode() 58 ui.EnableTestMode()
58 59
60 @decorators.ClientOnlyTest
59 def testCaptureBasicProfile(self): 61 def testCaptureBasicProfile(self):
60 agent = FakeAgent() 62 agent = FakeAgent()
61 result = profiler.CaptureProfile(None, [agent], 1) 63 result = profiler.CaptureProfile(None, [agent], 1)
62 64
63 try: 65 try:
64 self.assertTrue(agent.stopped) 66 self.assertTrue(agent.stopped)
65 self.assertTrue(os.path.exists(result)) 67 self.assertTrue(os.path.exists(result))
66 self.assertTrue(result.endswith('.html')) 68 self.assertTrue(result.endswith('.html'))
67 finally: 69 finally:
68 if os.path.exists(result): 70 if os.path.exists(result):
69 os.remove(result) 71 os.remove(result)
70 72
73 @decorators.ClientOnlyTest
71 def testCaptureJsonProfile(self): 74 def testCaptureJsonProfile(self):
72 agent = FakeAgent() 75 agent = FakeAgent()
73 result = profiler.CaptureProfile(None, [agent], 1, write_json=True) 76 result = profiler.CaptureProfile(None, [agent], 1, write_json=True)
74 77
75 try: 78 try:
76 self.assertFalse(result.endswith('.html')) 79 self.assertFalse(result.endswith('.html'))
77 with open(result) as f: 80 with open(result) as f:
78 self.assertEquals(f.read(), agent.contents) 81 self.assertEquals(f.read(), agent.contents)
79 finally: 82 finally:
80 if os.path.exists(result): 83 if os.path.exists(result):
81 os.remove(result) 84 os.remove(result)
82 85
86 @decorators.ClientOnlyTest
83 def testCaptureMultipleProfiles(self): 87 def testCaptureMultipleProfiles(self):
84 agents = [FakeAgent('c1'), FakeAgent('c2')] 88 agents = [FakeAgent('c1'), FakeAgent('c2')]
85 result = profiler.CaptureProfile(None, agents, 1, write_json=True) 89 result = profiler.CaptureProfile(None, agents, 1, write_json=True)
86 90
87 try: 91 try:
88 self.assertTrue(result.endswith('.zip')) 92 self.assertTrue(result.endswith('.zip'))
89 self.assertTrue(zipfile.is_zipfile(result)) 93 self.assertTrue(zipfile.is_zipfile(result))
90 finally: 94 finally:
91 if os.path.exists(result): 95 if os.path.exists(result):
92 os.remove(result) 96 os.remove(result)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698