Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / tools / perf / measurements / smoothness_unittest.py
blob40a66e6f7ed06e6c7f0d97b326e4982403059a74
1 # Copyright 2013 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 import sys
6 from telemetry.core import wpr_modes
7 from telemetry import decorators
8 from telemetry.page import page
9 from telemetry.unittest_util import options_for_unittests
10 from telemetry.unittest_util import page_test_test_case
12 from measurements import smoothness
15 class FakeTracingController(object):
16 def __init__(self):
17 self.category_filter = None
18 def Start(self, options, category_filter):
19 del options # unused
20 self.category_filter = category_filter
22 def IsChromeTracingSupported(self):
23 return True
26 class FakePlatform(object):
27 def __init__(self):
28 self.tracing_controller = FakeTracingController()
31 class FakeBrowser(object):
32 def __init__(self):
33 self.platform = FakePlatform()
36 class FakeTab(object):
37 def __init__(self):
38 self.browser = FakeBrowser()
40 def ExecuteJavaScript(self, js):
41 pass
43 class SmoothnessUnitTest(page_test_test_case.PageTestTestCase):
44 """Smoke test for smoothness measurement
46 Runs smoothness measurement on a simple page and verifies
47 that all metrics were added to the results. The test is purely functional,
48 i.e. it only checks if the metrics are present and non-zero.
49 """
50 def testSyntheticDelayConfiguration(self):
51 test_page = page.Page('http://dummy', None)
52 test_page.synthetic_delays = {
53 'cc.BeginMainFrame': { 'target_duration': 0.012 },
54 'cc.DrawAndSwap': { 'target_duration': 0.012, 'mode': 'alternating' },
55 'gpu.PresentingFrame': { 'target_duration': 0.012 }
58 tab = FakeTab()
59 measurement = smoothness.Smoothness()
60 measurement.WillStartBrowser(tab.browser.platform)
61 measurement.WillNavigateToPage(test_page, tab)
63 expected_synthetic_delay = set([
64 'DELAY(cc.BeginMainFrame;0.012000;static)',
65 'DELAY(cc.DrawAndSwap;0.012000;alternating)',
66 'DELAY(gpu.PresentingFrame;0.012000;static)',
68 tracing_controller = tab.browser.platform.tracing_controller
69 actual_synthetic_delay = (
70 tracing_controller.category_filter.synthetic_delays)
72 if expected_synthetic_delay != actual_synthetic_delay:
73 sys.stderr.write("Expected category filter: %s\n" %
74 repr(expected_synthetic_delay))
75 sys.stderr.write("Actual category filter filter: %s\n" %
76 repr(actual_synthetic_delay))
77 self.assertEquals(expected_synthetic_delay, actual_synthetic_delay)
79 def setUp(self):
80 self._options = options_for_unittests.GetCopy()
81 self._options.browser_options.wpr_mode = wpr_modes.WPR_OFF
83 @decorators.Disabled('chromeos') # crbug.com/483212
84 def testSmoothness(self):
85 ps = self.CreatePageSetFromFileInUnittestDataDir('scrollable_page.html')
86 measurement = smoothness.Smoothness()
87 results = self.RunMeasurement(measurement, ps, options=self._options)
88 self.assertEquals(0, len(results.failures))
90 frame_times = results.FindAllPageSpecificValuesNamed('frame_times')
91 self.assertEquals(len(frame_times), 1)
92 self.assertGreater(frame_times[0].GetRepresentativeNumber(), 0)
94 mean_frame_time = results.FindAllPageSpecificValuesNamed('mean_frame_time')
95 self.assertEquals(len(mean_frame_time), 1)
96 self.assertGreater(mean_frame_time[0].GetRepresentativeNumber(), 0)
98 frame_time_discrepancy = results.FindAllPageSpecificValuesNamed(
99 'frame_time_discrepancy')
100 self.assertEquals(len(frame_time_discrepancy), 1)
101 self.assertGreater(frame_time_discrepancy[0].GetRepresentativeNumber(), 0)
103 percentage_smooth = results.FindAllPageSpecificValuesNamed(
104 'percentage_smooth')
105 self.assertEquals(len(percentage_smooth), 1)
106 self.assertGreaterEqual(percentage_smooth[0].GetRepresentativeNumber(), 0)
108 mean_input_event_latency = results.FindAllPageSpecificValuesNamed(
109 'mean_input_event_latency')
110 if mean_input_event_latency:
111 self.assertEquals(len(mean_input_event_latency), 1)
112 self.assertGreater(
113 mean_input_event_latency[0].GetRepresentativeNumber(), 0)
115 @decorators.Enabled('android') # SurfaceFlinger is android-only
116 def testSmoothnessSurfaceFlingerMetricsCalculated(self):
117 ps = self.CreatePageSetFromFileInUnittestDataDir('scrollable_page.html')
118 measurement = smoothness.Smoothness()
119 results = self.RunMeasurement(measurement, ps, options=self._options)
120 self.assertEquals(0, len(results.failures))
122 avg_surface_fps = results.FindAllPageSpecificValuesNamed('avg_surface_fps')
123 self.assertEquals(1, len(avg_surface_fps))
124 self.assertGreater(avg_surface_fps[0].GetRepresentativeNumber, 0)
126 jank_count = results.FindAllPageSpecificValuesNamed('jank_count')
127 self.assertEquals(1, len(jank_count))
128 self.assertGreater(jank_count[0].GetRepresentativeNumber(), -1)
130 max_frame_delay = results.FindAllPageSpecificValuesNamed('max_frame_delay')
131 self.assertEquals(1, len(max_frame_delay))
132 self.assertGreater(max_frame_delay[0].GetRepresentativeNumber, 0)
134 frame_lengths = results.FindAllPageSpecificValuesNamed('frame_lengths')
135 self.assertEquals(1, len(frame_lengths))
136 self.assertGreater(frame_lengths[0].GetRepresentativeNumber, 0)
138 def testCleanUpTrace(self):
139 self.TestTracingCleanedUp(smoothness.Smoothness, self._options)