| 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 |
| 11 from gpu_tests import maps_expectations | 11 from gpu_tests import maps_expectations |
| 12 from gpu_tests import path_util | 12 from gpu_tests import path_util |
| 13 | 13 |
| 14 import py_utils | |
| 15 from py_utils import cloud_storage | 14 from py_utils import cloud_storage |
| 16 | 15 |
| 17 data_path = os.path.join(path_util.GetChromiumSrcDir(), | 16 data_path = os.path.join(path_util.GetChromiumSrcDir(), |
| 18 'content', 'test', 'gpu', 'page_sets', 'data') | 17 'content', 'test', 'gpu', 'page_sets', 'data') |
| 19 | 18 |
| 20 class MapsIntegrationTest( | 19 class MapsIntegrationTest( |
| 21 cloud_storage_integration_test_base.CloudStorageIntegrationTestBase): | 20 cloud_storage_integration_test_base.CloudStorageIntegrationTestBase): |
| 22 """Google Maps pixel tests. | 21 """Google Maps pixel tests. |
| 23 | 22 |
| 24 Note: the WPR for this test was recorded from the smoothness.maps | 23 Note: the WPR for this test was recorded from the smoothness.maps |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 'http://map-test/performance.html', | 79 'http://map-test/performance.html', |
| 81 ('maps_004_expectations.json')) | 80 ('maps_004_expectations.json')) |
| 82 | 81 |
| 83 def _ReadPixelExpectations(self, expectations_file): | 82 def _ReadPixelExpectations(self, expectations_file): |
| 84 expectations_path = os.path.join(data_path, expectations_file) | 83 expectations_path = os.path.join(data_path, expectations_file) |
| 85 with open(expectations_path, 'r') as f: | 84 with open(expectations_path, 'r') as f: |
| 86 json_contents = json.load(f) | 85 json_contents = json.load(f) |
| 87 return json_contents | 86 return json_contents |
| 88 | 87 |
| 89 def _SpinWaitOnRAF(self, iterations, timeout=60): | 88 def _SpinWaitOnRAF(self, iterations, timeout=60): |
| 90 tab = self.tab | 89 self.tab.ExecuteJavaScript2(""" |
| 91 waitScript = r""" | 90 window.__spinWaitOnRAFDone = false; |
| 92 window.__spinWaitOnRAFDone = false; | 91 var iterationsLeft = {{ iterations }}; |
| 93 var iterationsLeft = %d; | |
| 94 | 92 |
| 95 function spin() { | 93 function spin() { |
| 96 iterationsLeft--; | 94 iterationsLeft--; |
| 97 if (iterationsLeft == 0) { | 95 if (iterationsLeft == 0) { |
| 98 window.__spinWaitOnRAFDone = true; | 96 window.__spinWaitOnRAFDone = true; |
| 99 return; | 97 return; |
| 98 } |
| 99 window.requestAnimationFrame(spin); |
| 100 } | 100 } |
| 101 window.requestAnimationFrame(spin); | 101 window.requestAnimationFrame(spin); |
| 102 } | 102 """, iterations=iterations) |
| 103 window.requestAnimationFrame(spin); | 103 self.tab.WaitForJavaScriptCondition2( |
| 104 """ % iterations | 104 'window.__spinWaitOnRAFDone', timeout=timeout) |
| 105 | |
| 106 def IsWaitComplete(): | |
| 107 return tab.EvaluateJavaScript('window.__spinWaitOnRAFDone') | |
| 108 | |
| 109 tab.ExecuteJavaScript(waitScript) | |
| 110 py_utils.WaitFor(IsWaitComplete, timeout) | |
| 111 | 105 |
| 112 def RunActualGpuTest(self, url, *args): | 106 def RunActualGpuTest(self, url, *args): |
| 113 tab = self.tab | 107 tab = self.tab |
| 114 pixel_expectations_file = args[0] | 108 pixel_expectations_file = args[0] |
| 115 action_runner = tab.action_runner | 109 action_runner = tab.action_runner |
| 116 action_runner.Navigate(url) | 110 action_runner.Navigate(url) |
| 117 action_runner.WaitForJavaScriptCondition( | 111 action_runner.WaitForJavaScriptCondition2( |
| 118 'window.testDone', timeout_in_seconds=180) | 112 'window.testDone', timeout=180) |
| 119 | 113 |
| 120 # 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 |
| 121 # 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 |
| 122 # it's safe to do so. | 116 # it's safe to do so. |
| 123 self._SpinWaitOnRAF(3) | 117 self._SpinWaitOnRAF(3) |
| 124 | 118 |
| 125 if not tab.screenshot_supported: | 119 if not tab.screenshot_supported: |
| 126 self.fail('Browser does not support screenshot capture') | 120 self.fail('Browser does not support screenshot capture') |
| 127 screenshot = tab.Screenshot(5) | 121 screenshot = tab.Screenshot(5) |
| 128 if screenshot is None: | 122 if screenshot is None: |
| 129 self.fail('Could not capture screenshot') | 123 self.fail('Could not capture screenshot') |
| 130 | 124 |
| 131 dpr = tab.EvaluateJavaScript('window.devicePixelRatio') | 125 dpr = tab.EvaluateJavaScript2('window.devicePixelRatio') |
| 132 print 'Maps\' devicePixelRatio is ' + str(dpr) | 126 print 'Maps\' devicePixelRatio is ' + str(dpr) |
| 133 # Even though the Maps test uses a fixed devicePixelRatio so that | 127 # Even though the Maps test uses a fixed devicePixelRatio so that |
| 134 # 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 |
| 135 # different devices with the same devicePixelRatio (a Retina | 129 # different devices with the same devicePixelRatio (a Retina |
| 136 # 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 |
| 137 # screenshot are observed. Hack around this by specifying a scale | 131 # screenshot are observed. Hack around this by specifying a scale |
| 138 # factor for these bots in the test expectations. This relies on | 132 # factor for these bots in the test expectations. This relies on |
| 139 # the test-machine-name argument being specified on the command | 133 # the test-machine-name argument being specified on the command |
| 140 # line. | 134 # line. |
| 141 expected = self._ReadPixelExpectations(pixel_expectations_file) | 135 expected = self._ReadPixelExpectations(pixel_expectations_file) |
| 142 self._ValidateScreenshotSamples(tab, url, screenshot, expected, dpr) | 136 self._ValidateScreenshotSamples(tab, url, screenshot, expected, dpr) |
| 143 | 137 |
| 144 def load_tests(loader, tests, pattern): | 138 def load_tests(loader, tests, pattern): |
| 145 del loader, tests, pattern # Unused. | 139 del loader, tests, pattern # Unused. |
| 146 return gpu_integration_test.LoadAllTestsInModule(sys.modules[__name__]) | 140 return gpu_integration_test.LoadAllTestsInModule(sys.modules[__name__]) |
| OLD | NEW |