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 benchmark
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
23 class _MapsValidator(cloud_storage_test_base
.ValidatorBase
):
24 def CustomizeBrowserOptions(self
, options
):
25 options
.AppendExtraBrowserArgs('--enable-gpu-benchmarking')
27 def ValidateAndMeasurePage(self
, page
, tab
, results
):
28 # TODO: This should not be necessary, but it's not clear if the test is
29 # failing on the bots in it's absence. Remove once we can verify that it's
31 _MapsValidator
.SpinWaitOnRAF(tab
, 3)
33 if not tab
.screenshot_supported
:
34 raise page_test
.Failure('Browser does not support screenshot capture')
35 screenshot
= tab
.Screenshot(5)
37 raise page_test
.Failure('Could not capture screenshot')
39 dpr
= tab
.EvaluateJavaScript('window.devicePixelRatio')
40 expected
= self
._ReadPixelExpectations
(page
)
41 self
._ValidateScreenshotSamples
(
42 page
.display_name
, screenshot
, expected
, dpr
)
45 def SpinWaitOnRAF(tab
, iterations
, timeout
= 60):
47 window.__spinWaitOnRAFDone = false;
48 var iterationsLeft = %d;
52 if (iterationsLeft == 0) {
53 window.__spinWaitOnRAFDone = true;
56 window.requestAnimationFrame(spin);
58 window.requestAnimationFrame(spin);
62 return tab
.EvaluateJavaScript('window.__spinWaitOnRAFDone')
64 tab
.ExecuteJavaScript(waitScript
)
65 util
.WaitFor(IsWaitComplete
, timeout
)
67 def _ReadPixelExpectations(self
, page
):
68 expectations_path
= os
.path
.join(page
._base
_dir
, page
.pixel_expectations
)
69 with
open(expectations_path
, 'r') as f
:
70 json_contents
= json
.load(f
)
74 class MapsPage(page
.Page
):
75 def __init__(self
, page_set
, base_dir
):
76 super(MapsPage
, self
).__init
__(
77 url
='http://localhost:10020/tracker.html',
81 self
.pixel_expectations
= 'data/maps_002_expectations.json'
83 def RunNavigateSteps(self
, action_runner
):
84 action_runner
.NavigateToPage(self
)
85 action_runner
.WaitForJavaScriptCondition(
86 'window.testDone', timeout_in_seconds
=180)
89 class Maps(cloud_storage_test_base
.TestBase
):
90 """Google Maps pixel tests."""
93 def CreateExpectations(self
, page_set
):
94 return maps_expectations
.MapsExpectations()
96 def CreatePageSet(self
, options
):
97 page_set_path
= os
.path
.join(
98 util
.GetChromiumSrcDir(), 'content', 'test', 'gpu', 'page_sets')
99 ps
= page_set
.PageSet(archive_data_file
='data/maps.json',
100 make_javascript_deterministic
=False,
101 file_path
=page_set_path
)
102 ps
.AddPage(MapsPage(ps
, ps
.base_dir
))