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
3# found in the LICENSE file.
4
5from measurements import thread_times
6from measurements import smoothness_unittest
7from metrics import timeline
8from telemetry.core import wpr_modes
9from telemetry.unittest import options_for_unittests
10from telemetry.unittest import page_test_test_case
11from telemetry.unittest import test
12
13
14
15class ThreadTimesUnitTest(page_test_test_case.PageTestTestCase):
16  def setUp(self):
17    self._options = options_for_unittests.GetCopy()
18    self._options.browser_options.wpr_mode = wpr_modes.WPR_OFF
19
20  @test.Disabled('android')
21  def testBasic(self):
22    ps = self.CreatePageSetFromFileInUnittestDataDir('scrollable_page.html')
23    measurement = thread_times.ThreadTimes()
24    timeline_options = self._options
25    results = self.RunMeasurement(measurement, ps, options = timeline_options)
26    self.assertEquals(0, len(results.failures))
27
28    for category in timeline.TimelineThreadCategories.values():
29      cpu_time_name = timeline.ThreadCpuTimeResultName(category)
30      cpu_time = results.FindAllPageSpecificValuesNamed(cpu_time_name)
31      self.assertEquals(len(cpu_time), 1)
32
33  def testBasicForPageWithNoGesture(self):
34    ps = self.CreateEmptyPageSet()
35    ps.AddPage(smoothness_unittest.AnimatedPage(ps))
36
37    measurement = thread_times.ThreadTimes()
38    timeline_options = self._options
39    results = self.RunMeasurement(measurement, ps, options = timeline_options)
40    self.assertEquals(0, len(results.failures))
41
42    for category in timeline.TimelineThreadCategories.values():
43      cpu_time_name = timeline.ThreadCpuTimeResultName(category)
44      cpu_time = results.FindAllPageSpecificValuesNamed(cpu_time_name)
45      self.assertEquals(len(cpu_time), 1)
46
47
48  def testCleanUpTrace(self):
49    self.TestTracingCleanedUp(thread_times.ThreadTimes, self._options)
50