| OLD | NEW |
| (Empty) |
| 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 telemetry import multi_page_benchmark | |
| 5 from telemetry import multi_page_benchmark_unittest_base | |
| 6 from perf_tools import scrolling_benchmark | |
| 7 | |
| 8 from telemetry import browser_finder | |
| 9 from telemetry import options_for_unittests | |
| 10 | |
| 11 import os | |
| 12 import urlparse | |
| 13 | |
| 14 class ScrollingBenchmarkUnitTest( | |
| 15 multi_page_benchmark_unittest_base.MultiPageBenchmarkUnitTestBase): | |
| 16 | |
| 17 def testScrollingWithGpuBenchmarkingExtension(self): | |
| 18 ps = self.CreatePageSetFromFileInUnittestDataDir('scrollable_page.html') | |
| 19 | |
| 20 benchmark = scrolling_benchmark.ScrollingBenchmark() | |
| 21 all_results = self.RunBenchmark(benchmark, ps) | |
| 22 | |
| 23 self.assertEqual(0, len(all_results.page_failures)) | |
| 24 self.assertEqual(1, len(all_results.page_results)) | |
| 25 results0 = all_results.page_results[0] | |
| 26 | |
| 27 self.assertTrue('dropped_percent' in results0) | |
| 28 self.assertTrue('mean_frame_time' in results0) | |
| 29 | |
| 30 def testCalcResultsFromRAFRenderStats(self): | |
| 31 rendering_stats = {'droppedFrameCount': 5, | |
| 32 'totalTimeInSeconds': 1, | |
| 33 'numAnimationFrames': 10, | |
| 34 'numFramesSentToScreen': 10} | |
| 35 res = multi_page_benchmark.BenchmarkResults() | |
| 36 res.WillMeasurePage(True) | |
| 37 scrolling_benchmark.CalcScrollResults(rendering_stats, res) | |
| 38 res.DidMeasurePage() | |
| 39 self.assertEquals(50, res.page_results[0]['dropped_percent']) | |
| 40 self.assertAlmostEquals(100, res.page_results[0]['mean_frame_time'], 2) | |
| 41 | |
| 42 def testCalcResultsRealRenderStats(self): | |
| 43 rendering_stats = {'numFramesSentToScreen': 60, | |
| 44 'globalTotalTextureUploadTimeInSeconds': 0, | |
| 45 'totalProcessingCommandsTimeInSeconds': 0, | |
| 46 'globalTextureUploadCount': 0, | |
| 47 'droppedFrameCount': 0, | |
| 48 'textureUploadCount': 0, | |
| 49 'numAnimationFrames': 10, | |
| 50 'totalPaintTimeInSeconds': 0.35374299999999986, | |
| 51 'globalTotalProcessingCommandsTimeInSeconds': 0, | |
| 52 'totalTextureUploadTimeInSeconds': 0, | |
| 53 'totalRasterizeTimeInSeconds': 0, | |
| 54 'totalTimeInSeconds': 1.0} | |
| 55 res = multi_page_benchmark.BenchmarkResults() | |
| 56 res.WillMeasurePage(True) | |
| 57 scrolling_benchmark.CalcScrollResults(rendering_stats, res) | |
| 58 res.DidMeasurePage() | |
| 59 self.assertEquals(0, res.page_results[0]['dropped_percent']) | |
| 60 self.assertAlmostEquals(1000/60., res.page_results[0]['mean_frame_time'], 2) | |
| 61 | |
| 62 def testBoundingClientRect(self): | |
| 63 options = options_for_unittests.Get() | |
| 64 browser_to_create = browser_finder.FindBrowser(options) | |
| 65 if not browser_to_create: | |
| 66 raise Exception('No browser found, cannot continue test.') | |
| 67 | |
| 68 with browser_to_create.Create() as browser: | |
| 69 with browser.ConnectToNthTab(0) as tab: | |
| 70 ps = self.CreatePageSetFromFileInUnittestDataDir('blank.html') | |
| 71 parsed_url = urlparse.urlparse(ps.pages[0].url) | |
| 72 path = os.path.join(parsed_url.netloc, parsed_url.path) | |
| 73 dirname, filename = os.path.split(path) | |
| 74 browser.SetHTTPServerDirectory(dirname) | |
| 75 target_side_url = browser.http_server.UrlOf(filename) | |
| 76 tab.page.Navigate(target_side_url) | |
| 77 | |
| 78 # Verify that the rect returned by getBoundingVisibleRect() in | |
| 79 # scroll.js is completely contained within the viewport. Scroll | |
| 80 # events dispatched by the benchmarks use the center of this rect | |
| 81 # as their location, and this location needs to be within the | |
| 82 # viewport bounds to correctly decide between main-thread and | |
| 83 # impl-thread scrolling. If the scrollable area were not clipped | |
| 84 # to the viewport bounds, then the instance used here (the scrollable | |
| 85 # area being more than twice as tall as the viewport) would | |
| 86 # result in a scroll location outside of the viewport bounds. | |
| 87 tab.runtime.Execute("""document.body.style.height = | |
| 88 (2 * window.innerHeight + 1) + 'px';""") | |
| 89 scroll_js_path = os.path.join(os.path.dirname(__file__), 'scroll.js') | |
| 90 scroll_js = open(scroll_js_path, 'r').read() | |
| 91 tab.runtime.Evaluate(scroll_js) | |
| 92 | |
| 93 rect_bottom = int(tab.runtime.Evaluate(""" | |
| 94 __ScrollTest_GetBoundingVisibleRect(document.body).top + | |
| 95 __ScrollTest_GetBoundingVisibleRect(document.body).height""")) | |
| 96 rect_right = int(tab.runtime.Evaluate(""" | |
| 97 __ScrollTest_GetBoundingVisibleRect(document.body).left + | |
| 98 __ScrollTest_GetBoundingVisibleRect(document.body).width""")) | |
| 99 viewport_width = int(tab.runtime.Evaluate('window.innerWidth')) | |
| 100 viewport_height = int(tab.runtime.Evaluate('window.innerHeight')) | |
| 101 | |
| 102 self.assertTrue(rect_bottom <= viewport_height) | |
| 103 self.assertTrue(rect_right <= viewport_width) | |
| 104 | |
| 105 class ScrollingBenchmarkWithoutGpuBenchmarkingUnitTest( | |
| 106 multi_page_benchmark_unittest_base.MultiPageBenchmarkUnitTestBase): | |
| 107 | |
| 108 def CustomizeOptionsForTest(self, options): | |
| 109 options.no_gpu_benchmarking_extension = True | |
| 110 | |
| 111 def testScrollingWithoutGpuBenchmarkingExtension(self): | |
| 112 ps = self.CreatePageSetFromFileInUnittestDataDir('scrollable_page.html') | |
| 113 | |
| 114 benchmark = scrolling_benchmark.ScrollingBenchmark() | |
| 115 benchmark.use_gpu_benchmarking_extension = False | |
| 116 | |
| 117 all_results = self.RunBenchmark(benchmark, ps) | |
| 118 | |
| 119 self.assertEqual(0, len(all_results.page_failures)) | |
| 120 self.assertEqual(1, len(all_results.page_results)) | |
| 121 results0 = all_results.page_results[0] | |
| 122 | |
| 123 self.assertTrue('dropped_percent' in results0) | |
| 124 self.assertTrue('mean_frame_time' in results0) | |
| OLD | NEW |