1 # Copyright 2015 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 os 6 import tempfile 7 8 from telemetry import decorators 9 from telemetry.core import os_version 10 from telemetry.util import image_util 11 from telemetry.testing import tab_test_case 12 13 14 class PlatformScreenshotTest(tab_test_case.TabTestCase): 15 16 @decorators.Disabled('win') # crbug.com/570955 17 def testScreenshotSupported(self): 18 if self._platform.GetOSName() == 'android': 19 self.assertTrue(self._platform.CanTakeScreenshot()) 20 21 # Run this test in serial to avoid multiple browsers pop up on the screen. 22 @decorators.Isolated 23 @decorators.Disabled('linux') # crbug.com/563656 24 @decorators.Disabled('win') # crbug.com/570955 25 def testScreenshot(self): 26 if not self._platform.CanTakeScreenshot(): 27 self.skipTest('Platform does not support screenshots, skipping test.') 28 # Skip the test on Mac 10.5, 10.6, 10.7 because png format isn't 29 # recognizable on Mac < 10.8 (crbug.com/369490#c13) 30 if (self._platform.GetOSName() == 'mac' and 31 self._platform.GetOSVersionName() in 32 (os_version.LEOPARD, os_version.SNOWLEOPARD, os_version.LION)): 33 self.skipTest('OS X version %s too old' % self._platform.GetOSName()) 34 tf = tempfile.NamedTemporaryFile(delete=False, suffix='.png') 35 tf.close() 36 try: 37 self.Navigate('screenshot_test.html') 38 self._platform.TakeScreenshot(tf.name) 39 # Assert that screenshot image contains the color of the triangle defined 40 # in screenshot_test.html. 41 img = image_util.FromPngFile(tf.name) 42 screenshot_pixels = image_util.Pixels(img) 43 special_colored_pixel = bytearray([217, 115, 43]) 44 self.assertTrue(special_colored_pixel in screenshot_pixels) 45 finally: 46 os.remove(tf.name) 47