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.
5 from measurements
import thread_times
6 from measurements
import smoothness_unittest
7 from metrics
import timeline
8 from telemetry
import decorators
9 from telemetry
.core
import wpr_modes
10 from telemetry
.web_perf
.metrics
.layout
import LayoutMetric
11 from telemetry
.unittest_util
import options_for_unittests
12 from telemetry
.unittest_util
import page_test_test_case
15 class ThreadTimesUnitTest(page_test_test_case
.PageTestTestCase
):
17 self
._options
= options_for_unittests
.GetCopy()
18 self
._options
.browser_options
.wpr_mode
= wpr_modes
.WPR_OFF
20 @decorators.Disabled('android')
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
))
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)
33 for short_name
in LayoutMetric
.EVENTS
.itervalues():
34 self
.assertEquals(len(results
.FindAllPageSpecificValuesNamed(
35 short_name
+ '_avg')), 1)
36 self
.assertEquals(len(results
.FindAllPageSpecificValuesNamed(
37 short_name
+ '_stddev')), 1)
39 def testBasicForPageWithNoGesture(self
):
40 ps
= self
.CreateEmptyPageSet()
41 ps
.AddUserStory(smoothness_unittest
.AnimatedPage(ps
))
43 measurement
= thread_times
.ThreadTimes()
44 timeline_options
= self
._options
45 results
= self
.RunMeasurement(measurement
, ps
, options
= timeline_options
)
46 self
.assertEquals(0, len(results
.failures
))
48 for category
in timeline
.TimelineThreadCategories
.values():
49 cpu_time_name
= timeline
.ThreadCpuTimeResultName(category
)
50 cpu_time
= results
.FindAllPageSpecificValuesNamed(cpu_time_name
)
51 self
.assertEquals(len(cpu_time
), 1)
53 def testWithSilkDetails(self
):
54 ps
= self
.CreatePageSetFromFileInUnittestDataDir('scrollable_page.html')
55 measurement
= thread_times
.ThreadTimes(report_silk_details
=True)
56 results
= self
.RunMeasurement(measurement
, ps
, options
= self
._options
)
57 self
.assertEquals(0, len(results
.failures
))
59 main_thread
= "renderer_main"
60 expected_trace_categories
= ["blink", "cc", "idle"]
61 for trace_category
in expected_trace_categories
:
62 value_name
= timeline
.ThreadDetailResultName(main_thread
, trace_category
)
63 values
= results
.FindAllPageSpecificValuesNamed(value_name
)
64 self
.assertEquals(len(values
), 1)
66 def testCleanUpTrace(self
):
67 self
.TestTracingCleanedUp(thread_times
.ThreadTimes
, self
._options
)