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.
4import os
5
6import screenshot_sync_expectations as expectations
7
8from telemetry import benchmark
9from telemetry.core import util
10from telemetry.page import page
11from telemetry.page import page_set
12from telemetry.page import page_test
13
14data_path = os.path.join(
15    util.GetChromiumSrcDir(), 'content', 'test', 'data', 'gpu')
16
17@benchmark.Disabled('mac')
18class _ScreenshotSyncValidator(page_test.PageTest):
19  def CustomizeBrowserOptions(self, options):
20    options.AppendExtraBrowserArgs('--enable-gpu-benchmarking')
21
22  def ValidateAndMeasurePage(self, page, tab, results):
23    test_success = tab.EvaluateJavaScript('window.__testSuccess')
24    if not test_success:
25      message = tab.EvaluateJavaScript('window.__testMessage')
26      raise page_test.Failure(message)
27
28
29@benchmark.Disabled('mac')
30class ScreenshotSyncPage(page.Page):
31  def __init__(self, page_set, base_dir):
32    super(ScreenshotSyncPage, self).__init__(
33      url='file://screenshot_sync.html',
34      page_set=page_set,
35      base_dir=base_dir,
36      name='ScreenshotSync')
37    self.user_agent_type = 'desktop'
38
39  def RunNavigateSteps(self, action_runner):
40    action_runner.NavigateToPage(self)
41    action_runner.WaitForJavaScriptCondition(
42        'window.__testComplete', timeout_in_seconds=120)
43
44
45@benchmark.Disabled('mac')
46class ScreenshotSyncProcess(benchmark.Benchmark):
47  """Tests that screenhots are properly synchronized with the frame one which
48  they were requested"""
49  test = _ScreenshotSyncValidator
50
51  def CreateExpectations(self, page_set):
52    return expectations.ScreenshotSyncExpectations()
53
54  def CreatePageSet(self, options):
55    ps = page_set.PageSet(file_path=data_path, serving_dirs=[''])
56    ps.AddPage(ScreenshotSyncPage(ps, ps.base_dir))
57    return ps
58