OLD | NEW |
1 # Copyright 2017 The Chromium Authors. All rights reserved. | 1 # Copyright 2017 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import json | 5 import json |
6 import os | 6 import os |
7 import sys | 7 import sys |
8 | 8 |
9 from gpu_tests import gpu_integration_test | 9 from gpu_tests import gpu_integration_test |
10 from gpu_tests import cloud_storage_integration_test_base | 10 from gpu_tests import cloud_storage_integration_test_base |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 'http://map-test/performance.html', | 79 'http://map-test/performance.html', |
80 ('maps_004_expectations.json')) | 80 ('maps_004_expectations.json')) |
81 | 81 |
82 def _ReadPixelExpectations(self, expectations_file): | 82 def _ReadPixelExpectations(self, expectations_file): |
83 expectations_path = os.path.join(data_path, expectations_file) | 83 expectations_path = os.path.join(data_path, expectations_file) |
84 with open(expectations_path, 'r') as f: | 84 with open(expectations_path, 'r') as f: |
85 json_contents = json.load(f) | 85 json_contents = json.load(f) |
86 return json_contents | 86 return json_contents |
87 | 87 |
88 def _SpinWaitOnRAF(self, iterations, timeout=60): | 88 def _SpinWaitOnRAF(self, iterations, timeout=60): |
89 self.tab.ExecuteJavaScript2(""" | 89 self.tab.ExecuteJavaScript(""" |
90 window.__spinWaitOnRAFDone = false; | 90 window.__spinWaitOnRAFDone = false; |
91 var iterationsLeft = {{ iterations }}; | 91 var iterationsLeft = {{ iterations }}; |
92 | 92 |
93 function spin() { | 93 function spin() { |
94 iterationsLeft--; | 94 iterationsLeft--; |
95 if (iterationsLeft == 0) { | 95 if (iterationsLeft == 0) { |
96 window.__spinWaitOnRAFDone = true; | 96 window.__spinWaitOnRAFDone = true; |
97 return; | 97 return; |
98 } | 98 } |
99 window.requestAnimationFrame(spin); | 99 window.requestAnimationFrame(spin); |
100 } | 100 } |
101 window.requestAnimationFrame(spin); | 101 window.requestAnimationFrame(spin); |
102 """, iterations=iterations) | 102 """, iterations=iterations) |
103 self.tab.WaitForJavaScriptCondition2( | 103 self.tab.WaitForJavaScriptCondition( |
104 'window.__spinWaitOnRAFDone', timeout=timeout) | 104 'window.__spinWaitOnRAFDone', timeout=timeout) |
105 | 105 |
106 def RunActualGpuTest(self, url, *args): | 106 def RunActualGpuTest(self, url, *args): |
107 tab = self.tab | 107 tab = self.tab |
108 pixel_expectations_file = args[0] | 108 pixel_expectations_file = args[0] |
109 action_runner = tab.action_runner | 109 action_runner = tab.action_runner |
110 action_runner.Navigate(url) | 110 action_runner.Navigate(url) |
111 action_runner.WaitForJavaScriptCondition2( | 111 action_runner.WaitForJavaScriptCondition( |
112 'window.testDone', timeout=180) | 112 'window.testDone', timeout=180) |
113 | 113 |
114 # TODO(kbr): This should not be necessary, but it's not clear if the test | 114 # TODO(kbr): This should not be necessary, but it's not clear if the test |
115 # is failing on the bots in its absence. Remove once we can verify that | 115 # is failing on the bots in its absence. Remove once we can verify that |
116 # it's safe to do so. | 116 # it's safe to do so. |
117 self._SpinWaitOnRAF(3) | 117 self._SpinWaitOnRAF(3) |
118 | 118 |
119 if not tab.screenshot_supported: | 119 if not tab.screenshot_supported: |
120 self.fail('Browser does not support screenshot capture') | 120 self.fail('Browser does not support screenshot capture') |
121 screenshot = tab.Screenshot(5) | 121 screenshot = tab.Screenshot(5) |
122 if screenshot is None: | 122 if screenshot is None: |
123 self.fail('Could not capture screenshot') | 123 self.fail('Could not capture screenshot') |
124 | 124 |
125 dpr = tab.EvaluateJavaScript2('window.devicePixelRatio') | 125 dpr = tab.EvaluateJavaScript('window.devicePixelRatio') |
126 print 'Maps\' devicePixelRatio is ' + str(dpr) | 126 print 'Maps\' devicePixelRatio is ' + str(dpr) |
127 # Even though the Maps test uses a fixed devicePixelRatio so that | 127 # Even though the Maps test uses a fixed devicePixelRatio so that |
128 # it fetches all of the map tiles at the same resolution, on two | 128 # it fetches all of the map tiles at the same resolution, on two |
129 # different devices with the same devicePixelRatio (a Retina | 129 # different devices with the same devicePixelRatio (a Retina |
130 # MacBook Pro and a Nexus 9), different scale factors of the final | 130 # MacBook Pro and a Nexus 9), different scale factors of the final |
131 # screenshot are observed. Hack around this by specifying a scale | 131 # screenshot are observed. Hack around this by specifying a scale |
132 # factor for these bots in the test expectations. This relies on | 132 # factor for these bots in the test expectations. This relies on |
133 # the test-machine-name argument being specified on the command | 133 # the test-machine-name argument being specified on the command |
134 # line. | 134 # line. |
135 expected = self._ReadPixelExpectations(pixel_expectations_file) | 135 expected = self._ReadPixelExpectations(pixel_expectations_file) |
136 self._ValidateScreenshotSamples(tab, url, screenshot, expected, dpr) | 136 self._ValidateScreenshotSamples(tab, url, screenshot, expected, dpr) |
137 | 137 |
138 def load_tests(loader, tests, pattern): | 138 def load_tests(loader, tests, pattern): |
139 del loader, tests, pattern # Unused. | 139 del loader, tests, pattern # Unused. |
140 return gpu_integration_test.LoadAllTestsInModule(sys.modules[__name__]) | 140 return gpu_integration_test.LoadAllTestsInModule(sys.modules[__name__]) |
OLD | NEW |