Delete chrome.mediaGalleriesPrivate because the functionality unique to it has since...
[chromium-blink-merge.git] / tools / perf / measurements / screenshot.py
blob37936f8a90a80482afc629d3eb589ea3d61ac48f
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
6 from telemetry.image_processing import image_util
7 from telemetry.page import page_test
8 from telemetry.page import page_test
9 from telemetry.value import scalar
12 class Screenshot(page_test.PageTest):
13 def __init__(self, png_outdir):
14 super(Screenshot, self).__init__(
15 action_name_to_run = 'RunPageInteractions',
16 is_action_name_to_run_optional=True)
17 self._png_outdir = png_outdir
19 def ValidateAndMeasurePage(self, page, tab, results):
20 if not tab.screenshot_supported:
21 raise page_test.TestNotSupportedOnPlatformError(
22 'Browser does not support screenshotting')
24 tab.WaitForDocumentReadyStateToBeComplete()
25 screenshot = tab.Screenshot(60)
27 outpath = os.path.abspath(
28 os.path.join(self._png_outdir, page.file_safe_name)) + '.png'
30 if os.path.exists(outpath):
31 previous_mtime = os.path.getmtime(outpath)
32 else:
33 previous_mtime = -1
35 image_util.WritePngFile(screenshot, outpath)
37 saved_picture_count = 0
38 if os.path.exists(outpath) and os.path.getmtime(outpath) > previous_mtime:
39 saved_picture_count = 1
40 results.AddValue(scalar.ScalarValue(
41 results.current_page, 'saved_picture_count', 'count',
42 saved_picture_count))