OLD | NEW |
(Empty) | |
| 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. |
| 4 import os |
| 5 |
| 6 from telemetry.page import page_measurement |
| 7 from telemetry.page import page_test |
| 8 |
| 9 |
| 10 class Screenshot(page_measurement.PageMeasurement): |
| 11 def __init__(self): |
| 12 super(Screenshot, self).__init__( |
| 13 action_name_to_run = 'RunPrepareForScreenshot', |
| 14 is_action_name_to_run_optional=True) |
| 15 |
| 16 @classmethod |
| 17 def AddCommandLineArgs(cls, parser): |
| 18 parser.add_option('--png-outdir', |
| 19 help='Output directory for the PNG files') |
| 20 |
| 21 @classmethod |
| 22 def ProcessCommandLineArgs(cls, parser, args): |
| 23 if not args.png_outdir: |
| 24 parser.error('Please specify --png-outdir') |
| 25 cls._png_outdir = args.png_outdir |
| 26 |
| 27 def MeasurePage(self, page, tab, results): |
| 28 if not tab.screenshot_supported: |
| 29 raise page_test.TestNotSupportedOnPlatformFailure( |
| 30 'Browser does not support screenshotting') |
| 31 |
| 32 tab.WaitForDocumentReadyStateToBeComplete() |
| 33 screenshot = tab.Screenshot(60) |
| 34 |
| 35 outpath = os.path.abspath( |
| 36 os.path.join(self._png_outdir, page.file_safe_name)) + '.png' |
| 37 |
| 38 if os.path.exists(outpath): |
| 39 previous_mtime = os.path.getmtime(outpath) |
| 40 else: |
| 41 previous_mtime = -1 |
| 42 |
| 43 screenshot.WritePngFile(outpath) |
| 44 |
| 45 saved_picture_count = 0 |
| 46 if os.path.exists(outpath) and os.path.getmtime(outpath) > previous_mtime: |
| 47 saved_picture_count = 1 |
| 48 results.Add('saved_picture_count', 'count', saved_picture_count) |
OLD | NEW |