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
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
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
)
44 def SpinWaitOnRAF(tab
, iterations
, timeout
= 60):
46 window.__spinWaitOnRAFDone = false;
47 var iterationsLeft = %d;
51 if (iterationsLeft == 0) {
52 window.__spinWaitOnRAFDone = true;
55 window.requestAnimationFrame(spin);
57 window.requestAnimationFrame(spin);
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
)
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',
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."""
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()))