diff options
author | alokp@chromium.org <alokp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-12 18:45:56 +0000 |
---|---|---|
committer | alokp@chromium.org <alokp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-12 18:45:56 +0000 |
commit | fb2b85d6fee6175887e8804e9f0620abb9495eb9 (patch) | |
tree | 24c082cfbc67477098d5eae1f09fc114f7e2836b /tools | |
parent | 71049e4a1656e31cad1c88d942c540ebfe03b07b (diff) | |
download | chromium_src-fb2b85d6fee6175887e8804e9f0620abb9495eb9.zip chromium_src-fb2b85d6fee6175887e8804e9f0620abb9495eb9.tar.gz chromium_src-fb2b85d6fee6175887e8804e9f0620abb9495eb9.tar.bz2 |
Implemented print-to-skpicture using chrome-remote-control.
Review URL: https://chromiumcodereview.appspot.com/10915017
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@156340 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools')
-rw-r--r-- | tools/gpu/gpu_tools/multi_page_benchmark.py | 5 | ||||
-rw-r--r-- | tools/gpu/gpu_tools/skpicture_printer.py | 34 | ||||
-rw-r--r-- | tools/gpu/gpu_tools/skpicture_printer_unittest.py | 46 | ||||
-rw-r--r-- | tools/gpu/run_skpicture_printer | 12 |
4 files changed, 97 insertions, 0 deletions
diff --git a/tools/gpu/gpu_tools/multi_page_benchmark.py b/tools/gpu/gpu_tools/multi_page_benchmark.py index c876421..ff1ac66 100644 --- a/tools/gpu/gpu_tools/multi_page_benchmark.py +++ b/tools/gpu/gpu_tools/multi_page_benchmark.py @@ -214,6 +214,10 @@ class MultiPageBenchmarkUnitTest(unittest.TestCase): ps.pages.append(page) return ps + def CustomizeOptionsForTest(self, options): + """Override to customize default options.""" + pass + def RunBenchmark(self, benchmark, ps): """Runs a benchmark against a pageset, returning the rows its outputs.""" rows = [] @@ -233,6 +237,7 @@ class MultiPageBenchmarkUnitTest(unittest.TestCase): setattr(options, k, v) benchmark.CustomizeBrowserOptions(options) + self.CustomizeOptionsForTest(options) possible_browser = chrome_remote_control.FindBrowser(options) with possible_browser.Create() as browser: with browser.CreateTemporaryHTTPServer(self.unittest_data_dir) as server: diff --git a/tools/gpu/gpu_tools/skpicture_printer.py b/tools/gpu/gpu_tools/skpicture_printer.py new file mode 100644 index 0000000..161b112 --- /dev/null +++ b/tools/gpu/gpu_tools/skpicture_printer.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python +# Copyright (c) 2012 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +import os +import re + +import multi_page_benchmark + +_JS = 'chrome.gpuBenchmarking.printToSkPicture("{0}");' + +class SkPicturePrinter(multi_page_benchmark.MultiPageBenchmark): + def AddOptions(self, parser): + parser.add_option('-o', '--outdir', help='Output directory') + + def CustomizeBrowserOptions(self, options): + options.extra_browser_args.extend(['--enable-gpu-benchmarking', + '--no-sandbox']) + + def MeasurePage(self, page, tab): + # Derive output path from the URL. The pattern just replaces all special + # characters in the url with underscore. + outpath = re.sub('://|[.~!*\:@&=+$,/?%#]', '_', page.url) + if self.options.outdir is not None: + outpath = os.path.join(self.options.outdir, outpath) + outpath = os.path.abspath(outpath) + # Replace win32 path separator char '\' with '\\'. + js = _JS.format(outpath.replace('\\', '\\\\')) + tab.runtime.Evaluate(js) + return {"output_path": outpath} + +def Main(): + return multi_page_benchmark.Main(SkPicturePrinter()) diff --git a/tools/gpu/gpu_tools/skpicture_printer_unittest.py b/tools/gpu/gpu_tools/skpicture_printer_unittest.py new file mode 100644 index 0000000..0a8b3dc --- /dev/null +++ b/tools/gpu/gpu_tools/skpicture_printer_unittest.py @@ -0,0 +1,46 @@ +#!/usr/bin/env python +# Copyright (c) 2012 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +import os +import tempfile +import shutil + +import multi_page_benchmark +import skpicture_printer + +class SkPicturePrinterUnitTest(multi_page_benchmark.MultiPageBenchmarkUnitTest): + def setUp(self): + super(SkPicturePrinterUnitTest, self).setUp() + self._outdir = tempfile.mkdtemp() + + def tearDown(self): + shutil.rmtree(self._outdir) + super(SkPicturePrinterUnitTest, self).tearDown() + + def CustomizeOptionsForTest(self, options): + options.outdir = self._outdir + + def testPrintToSkPicture(self): + ps = self.CreatePageSetFromFileInUnittestDataDir('non_scrollable_page.html') + printer = skpicture_printer.SkPicturePrinter() + rows = self.RunBenchmark(printer, ps) + + self.assertEqual(0, len(printer.page_failures)) + header = rows[0] + results = rows[1:] + self.assertEqual(['url', 'output_path'], header) + self.assertEqual(1, len(results)) + + url = results[0][0] + self.assertTrue('non_scrollable_page.html' in url) + + outdir = results[0][1] + self.assertTrue('non_scrollable_page_html' in outdir) + self.assertTrue(os.path.isdir(outdir)) + self.assertEqual(['layer_0.skp'], os.listdir(outdir)) + + skp_file = os.path.join(outdir, 'layer_0.skp') + self.assertTrue(os.path.isfile(skp_file)) + self.assertTrue(os.path.getsize(skp_file) > 0) diff --git a/tools/gpu/run_skpicture_printer b/tools/gpu/run_skpicture_printer new file mode 100644 index 0000000..164609a --- /dev/null +++ b/tools/gpu/run_skpicture_printer @@ -0,0 +1,12 @@ +#!/usr/bin/env python +# Copyright (c) 2012 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +import os +import sys + +import gpu_tools.skpicture_printer + +if __name__ == "__main__": + sys.exit(gpu_tools.skpicture_printer.Main()) |