aboutsummaryrefslogtreecommitdiff
path: root/catapult/systrace/profile_chrome/profiler_unittest.py
blob: 9b35753d3a1ab0867e9de071723553278110ba6d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# Copyright 2014 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 os
import unittest
import zipfile

from profile_chrome import profiler
from profile_chrome import ui
from profile_chrome import fake_agent_1
from profile_chrome import fake_agent_2
from systrace import decorators
from systrace import tracing_controller


class ProfilerTest(unittest.TestCase):
  def setUp(self):
    ui.EnableTestMode()
    self._tracing_options = tracing_controller.TracingControllerConfig(None,
        None, None, None, None, None, None, None, None)

  @decorators.ClientOnlyTest
  def testCaptureBasicProfile(self):
    result = profiler.CaptureProfile(self._tracing_options, 1, [fake_agent_1])

    try:
      self.assertTrue(os.path.exists(result))
      self.assertTrue(result.endswith('.html'))
    finally:
      if os.path.exists(result):
        os.remove(result)

  @decorators.ClientOnlyTest
  def testCaptureJsonProfile(self):
    result = profiler.CaptureProfile(self._tracing_options, 1,
                                     [fake_agent_2], write_json=True)

    try:
      self.assertFalse(result.endswith('.html'))
      with open(result) as f:
        self.assertEquals(f.read(), 'fake-contents')
    finally:
      if os.path.exists(result):
        os.remove(result)

  @decorators.ClientOnlyTest
  def testCaptureMultipleProfiles(self):
    result = profiler.CaptureProfile(self._tracing_options, 1,
                                     [fake_agent_1, fake_agent_2],
                                     write_json=True)

    try:
      self.assertTrue(result.endswith('.zip'))
      self.assertTrue(zipfile.is_zipfile(result))
    finally:
      if os.path.exists(result):
        os.remove(result)