Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / content / test / gpu / gpu_tests / screenshot_sync.py
blob867d7213049dd3104e6302c3cfa9cbfc57d01c31
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 import random
7 import gpu_test_base
8 import screenshot_sync_expectations as expectations
10 from telemetry import benchmark
11 from telemetry.core import util
12 from telemetry.page import page_test
13 from telemetry.story import story_set as story_set_module
14 from telemetry.util import image_util
16 data_path = os.path.join(
17 util.GetChromiumSrcDir(), 'content', 'test', 'data', 'gpu')
19 class ScreenshotSyncValidator(gpu_test_base.ValidatorBase):
20 def CustomizeBrowserOptions(self, options):
21 options.AppendExtraBrowserArgs('--force-gpu-rasterization')
23 def ValidateAndMeasurePage(self, page, tab, results):
24 if not tab.screenshot_supported:
25 raise page_test.Failure('Browser does not support screenshot capture')
27 def CheckColorMatch(canvasRGB, screenshotRGB):
28 for i in range(0, 3):
29 if abs(canvasRGB[i] - screenshotRGB[i]) > 1:
30 raise page_test.Failure('Color mismatch in component #%d: %d vs %d' %
31 (i, canvasRGB[i], screenshotRGB[i]))
33 def CheckScreenshot():
34 canvasRGB = [];
35 for i in range(0, 3):
36 canvasRGB.append(random.randint(0, 255))
37 tab.EvaluateJavaScript("window.draw(%d, %d, %d);" % tuple(canvasRGB))
38 screenshot = tab.Screenshot(5)
39 CheckColorMatch(canvasRGB, image_util.Pixels(screenshot))
41 repetitions = 50
42 for n in range(0, repetitions):
43 CheckScreenshot()
45 class ScreenshotSyncPage(gpu_test_base.PageBase):
46 def __init__(self, story_set, base_dir, expectations):
47 super(ScreenshotSyncPage, self).__init__(
48 url='file://screenshot_sync.html',
49 page_set=story_set,
50 base_dir=base_dir,
51 name='ScreenshotSync',
52 expectations=expectations)
55 @benchmark.Disabled('linux', 'mac', 'win')
56 class ScreenshotSyncProcess(gpu_test_base.TestBase):
57 """Tests that screenhots are properly synchronized with the frame one which
58 they were requested"""
59 test = ScreenshotSyncValidator
61 @classmethod
62 def Name(cls):
63 return 'screenshot_sync'
65 def _CreateExpectations(self):
66 return expectations.ScreenshotSyncExpectations()
68 def CreateStorySet(self, options):
69 ps = story_set_module.StorySet(base_dir=data_path, serving_dirs=[''])
70 ps.AddStory(ScreenshotSyncPage(ps, ps.base_dir, self.GetExpectations()))
71 return ps