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.
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
):
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():
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
))
42 for n
in range(0, repetitions
):
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',
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
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()))