Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / content / test / gpu / gpu_tests / maps.py
blob939fc575b56bfd82cc08ab8e945ec02e3def3ef1
1 # Copyright 2013 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.
5 """Runs a Google Maps pixel test.
6 Performs several common navigation actions on the map (pan, zoom, rotate) then
7 captures a screenshot and compares selected pixels against expected values"""
9 import json
10 import optparse
11 import os
13 import cloud_storage_test_base
14 import gpu_test_base
15 import maps_expectations
17 from telemetry.core import util
18 from telemetry.page import page_test
19 from telemetry import story as story_module
20 from telemetry.story import story_set as story_set_module
22 class MapsValidator(cloud_storage_test_base.ValidatorBase):
23 def CustomizeBrowserOptions(self, options):
24 options.AppendExtraBrowserArgs('--enable-gpu-benchmarking')
26 def ValidateAndMeasurePage(self, page, tab, results):
27 # TODO: This should not be necessary, but it's not clear if the test is
28 # failing on the bots in it's absence. Remove once we can verify that it's
29 # safe to do so.
30 MapsValidator.SpinWaitOnRAF(tab, 3)
32 if not tab.screenshot_supported:
33 raise page_test.Failure('Browser does not support screenshot capture')
34 screenshot = tab.Screenshot(5)
35 if screenshot is None:
36 raise page_test.Failure('Could not capture screenshot')
38 dpr = tab.EvaluateJavaScript('window.devicePixelRatio')
39 expected = self._ReadPixelExpectations(page)
40 self._ValidateScreenshotSamples(
41 page.display_name, screenshot, expected, dpr)
43 @staticmethod
44 def SpinWaitOnRAF(tab, iterations, timeout = 60):
45 waitScript = r"""
46 window.__spinWaitOnRAFDone = false;
47 var iterationsLeft = %d;
49 function spin() {
50 iterationsLeft--;
51 if (iterationsLeft == 0) {
52 window.__spinWaitOnRAFDone = true;
53 return;
55 window.requestAnimationFrame(spin);
57 window.requestAnimationFrame(spin);
58 """ % iterations
60 def IsWaitComplete():
61 return tab.EvaluateJavaScript('window.__spinWaitOnRAFDone')
63 tab.ExecuteJavaScript(waitScript)
64 util.WaitFor(IsWaitComplete, timeout)
66 def _ReadPixelExpectations(self, page):
67 expectations_path = os.path.join(page._base_dir, page.pixel_expectations)
68 with open(expectations_path, 'r') as f:
69 json_contents = json.load(f)
70 return json_contents
73 class MapsPage(gpu_test_base.PageBase):
74 def __init__(self, story_set, base_dir, expectations):
75 super(MapsPage, self).__init__(
76 url='http://localhost:10020/tracker.html',
77 page_set=story_set,
78 base_dir=base_dir,
79 name='Maps.maps_002',
80 make_javascript_deterministic=False,
81 expectations=expectations)
82 self.pixel_expectations = 'data/maps_002_expectations.json'
84 def RunNavigateSteps(self, action_runner):
85 super(MapsPage, self).RunNavigateSteps(action_runner)
86 action_runner.WaitForJavaScriptCondition(
87 'window.testDone', timeout_in_seconds=180)
90 class Maps(cloud_storage_test_base.TestBase):
91 """Google Maps pixel tests."""
92 test = MapsValidator
94 @classmethod
95 def Name(cls):
96 return 'maps'
98 def _CreateExpectations(self):
99 return maps_expectations.MapsExpectations()
101 def CreateStorySet(self, options):
102 story_set_path = os.path.join(
103 util.GetChromiumSrcDir(), 'content', 'test', 'gpu', 'page_sets')
104 ps = story_set_module.StorySet(
105 archive_data_file='data/maps.json',
106 base_dir=story_set_path,
107 cloud_storage_bucket=story_module.PUBLIC_BUCKET)
108 ps.AddStory(MapsPage(ps, ps.base_dir, self.GetExpectations()))
109 return ps