Home | History | Annotate | Download | only in measurements
      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 
      5 import logging
      6 import shutil
      7 import tempfile
      8 
      9 from measurements import screenshot
     10 from telemetry.page import page_measurement_unittest_base
     11 from telemetry.page import page_test
     12 from telemetry.unittest import options_for_unittests
     13 
     14 
     15 class ScreenshotUnitTest(
     16       page_measurement_unittest_base.PageMeasurementUnitTestBase):
     17   def setUp(self):
     18     self._options = options_for_unittests.GetCopy()
     19     self._options.png_outdir = tempfile.mkdtemp('_png_test')
     20 
     21   def tearDown(self):
     22     shutil.rmtree(self._options.png_outdir)
     23 
     24   def testScreenshot(self):
     25     ps = self.CreatePageSetFromFileInUnittestDataDir('blank.html')
     26     measurement = screenshot.Screenshot()
     27     try:
     28       results = self.RunMeasurement(measurement, ps, options=self._options)
     29     except page_test.TestNotSupportedOnPlatformFailure as failure:
     30       logging.warning(str(failure))
     31       return
     32 
     33     saved_picture_count = results.FindAllPageSpecificValuesNamed(
     34         'saved_picture_count')
     35     self.assertEquals(len(saved_picture_count), 1)
     36     self.assertGreater(saved_picture_count[0].GetRepresentativeNumber(), 0)
     37