1 # Copyright (c) 2012 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 from perf_tools
import smoothness_benchmark
5 from telemetry
.page
import page_benchmark_unittest_base
6 from telemetry
.page
import page
7 from telemetry
.page
.page_benchmark_results
import PageBenchmarkResults
9 class SmoothnessBenchmarkUnitTest(
10 page_benchmark_unittest_base
.PageBenchmarkUnitTestBase
):
12 def testFirstPaintTimeMeasurement(self
):
13 ps
= self
.CreatePageSetFromFileInUnittestDataDir('scrollable_page.html')
15 benchmark
= smoothness_benchmark
.SmoothnessBenchmark()
16 all_results
= self
.RunBenchmark(benchmark
, ps
)
18 self
.assertEqual(0, len(all_results
.page_failures
))
19 self
.assertEqual(1, len(all_results
.page_results
))
21 results0
= all_results
.page_results
[0]
22 if results0
['first_paint'] == 'unsupported':
23 # This test can't run on content_shell.
25 self
.assertTrue(results0
['first_paint'] > 0)
27 def testScrollingWithGpuBenchmarkingExtension(self
):
28 ps
= self
.CreatePageSetFromFileInUnittestDataDir('scrollable_page.html')
30 benchmark
= smoothness_benchmark
.SmoothnessBenchmark()
31 all_results
= self
.RunBenchmark(benchmark
, ps
)
33 self
.assertEqual(0, len(all_results
.page_failures
))
34 self
.assertEqual(1, len(all_results
.page_results
))
35 results0
= all_results
.page_results
[0]
37 self
.assertTrue('dropped_percent' in results0
)
38 self
.assertTrue('mean_frame_time' in results0
)
40 def testCalcResultsFromRAFRenderStats(self
):
41 rendering_stats
= {'droppedFrameCount': 5,
42 'totalTimeInSeconds': 1,
43 'numAnimationFrames': 10,
44 'numFramesSentToScreen': 10}
45 res
= PageBenchmarkResults()
46 res
.WillMeasurePage(page
.Page('http://foo.com/', None))
47 smoothness_benchmark
.CalcScrollResults(rendering_stats
, res
)
49 self
.assertEquals(50, res
.page_results
[0]['dropped_percent'].value
)
50 self
.assertAlmostEquals(
52 res
.page_results
[0]['mean_frame_time'].value
, 2)
54 def testCalcResultsRealRenderStats(self
):
55 rendering_stats
= {'numFramesSentToScreen': 60,
56 'globalTotalTextureUploadTimeInSeconds': 0,
57 'totalProcessingCommandsTimeInSeconds': 0,
58 'globalTextureUploadCount': 0,
59 'droppedFrameCount': 0,
60 'textureUploadCount': 0,
61 'numAnimationFrames': 10,
62 'totalPaintTimeInSeconds': 0.35374299999999986,
63 'globalTotalProcessingCommandsTimeInSeconds': 0,
64 'totalTextureUploadTimeInSeconds': 0,
65 'totalRasterizeTimeInSeconds': 0,
66 'totalTimeInSeconds': 1.0}
67 res
= PageBenchmarkResults()
68 res
.WillMeasurePage(page
.Page('http://foo.com/', None))
69 smoothness_benchmark
.CalcScrollResults(rendering_stats
, res
)
71 self
.assertEquals(0, res
.page_results
[0]['dropped_percent'].value
)
72 self
.assertAlmostEquals(
74 res
.page_results
[0]['mean_frame_time'].value
, 2)
76 def testDoesImplThreadScroll(self
):
77 ps
= self
.CreatePageSetFromFileInUnittestDataDir('scrollable_page.html')
79 benchmark
= smoothness_benchmark
.SmoothnessBenchmark()
80 benchmark
.force_enable_threaded_compositing
= True
81 all_results
= self
.RunBenchmark(benchmark
, ps
)
83 results0
= all_results
.page_results
[0]
84 self
.assertTrue(results0
['percent_impl_scrolled'].value
> 0)
86 def testScrollingWithoutGpuBenchmarkingExtension(self
):
87 ps
= self
.CreatePageSetFromFileInUnittestDataDir('scrollable_page.html')
89 benchmark
= smoothness_benchmark
.SmoothnessBenchmark()
90 benchmark
.use_gpu_benchmarking_extension
= False
91 all_results
= self
.RunBenchmark(benchmark
, ps
)
93 self
.assertEqual(0, len(all_results
.page_failures
))
94 self
.assertEqual(1, len(all_results
.page_results
))
95 results0
= all_results
.page_results
[0]
97 self
.assertTrue('dropped_percent' in results0
)
98 self
.assertTrue('mean_frame_time' in results0
)