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"""
13 import cloud_storage_test_base
14 import maps_expectations
16 from telemetry import test
17 from telemetry.core import bitmap
18 from telemetry.core import util
19 from telemetry.page import page
20 from telemetry.page import page_set
21 from telemetry.page import page_test
22 # pylint: disable=W0401,W0614
23 from telemetry.page.actions.all_page_actions import *
25 class _MapsValidator(cloud_storage_test_base.ValidatorBase):
26 def CustomizeBrowserOptions(self, options):
27 options.AppendExtraBrowserArgs('--enable-gpu-benchmarking')
29 def ValidatePage(self, page, tab, results):
30 # TODO: This should not be necessary, but it's not clear if the test is
31 # failing on the bots in it's absence. Remove once we can verify that it's
33 _MapsValidator.SpinWaitOnRAF(tab, 3)
35 if not tab.screenshot_supported:
36 raise page_test.Failure('Browser does not support screenshot capture')
37 screenshot = tab.Screenshot(5)
39 raise page_test.Failure('Could not capture screenshot')
41 dpr = tab.EvaluateJavaScript('window.devicePixelRatio')
42 expected = self._ReadPixelExpectations(page)
43 self._ValidateScreenshotSamples(
44 page.display_name, screenshot, expected, dpr)
47 def SpinWaitOnRAF(tab, iterations, timeout = 60):
49 window.__spinWaitOnRAFDone = false;
50 var iterationsLeft = %d;
54 if (iterationsLeft == 0) {
55 window.__spinWaitOnRAFDone = true;
58 window.requestAnimationFrame(spin);
60 window.requestAnimationFrame(spin);
64 return tab.EvaluateJavaScript('window.__spinWaitOnRAFDone')
66 tab.ExecuteJavaScript(waitScript)
67 util.WaitFor(IsWaitComplete, timeout)
69 def _ReadPixelExpectations(self, page):
70 expectations_path = os.path.join(page._base_dir, page.pixel_expectations)
71 with open(expectations_path, 'r') as f:
72 json_contents = json.load(f)
76 class MapsPage(page.Page):
77 def __init__(self, page_set, base_dir):
78 super(MapsPage, self).__init__(
79 url='http://localhost:10020/tracker.html',
83 self.pixel_expectations = 'data/maps_002_expectations.json'
85 def RunNavigateSteps(self, action_runner):
86 action_runner.RunAction(NavigateAction())
87 action_runner.RunAction(WaitAction({'javascript': 'window.testDone'}))
90 class Maps(cloud_storage_test_base.TestBase):
91 """Google Maps pixel tests."""
94 def CreateExpectations(self, page_set):
95 return maps_expectations.MapsExpectations()
97 def CreatePageSet(self, options):
98 page_set_path = os.path.join(
99 util.GetChromiumSrcDir(), 'content', 'test', 'gpu', 'page_sets')
100 ps = page_set.PageSet(archive_data_file='data/maps.json',
101 make_javascript_deterministic=False,
102 file_path=page_set_path)
103 ps.AddPage(MapsPage(ps, ps.base_dir))