| OLD | NEW |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 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 import os | 4 import os |
| 5 import random | 5 import random |
| 6 | 6 |
| 7 import gpu_test_base | 7 from gpu_tests import gpu_test_base |
| 8 import path_util | 8 from gpu_tests import path_util |
| 9 import screenshot_sync_expectations as expectations | 9 from gpu_tests import screenshot_sync_expectations |
| 10 | 10 |
| 11 from telemetry import benchmark | 11 from telemetry import benchmark |
| 12 from telemetry.page import page_test | 12 from telemetry.page import page_test |
| 13 from telemetry.story import story_set as story_set_module | 13 from telemetry.story import story_set as story_set_module |
| 14 from telemetry.util import image_util | 14 from telemetry.util import image_util |
| 15 | 15 |
| 16 data_path = os.path.join( | 16 data_path = os.path.join( |
| 17 path_util.GetChromiumSrcDir(), 'content', 'test', 'data', 'gpu') | 17 path_util.GetChromiumSrcDir(), 'content', 'test', 'data', 'gpu') |
| 18 | 18 |
| 19 class ScreenshotSyncValidator(gpu_test_base.ValidatorBase): | 19 class ScreenshotSyncValidator(gpu_test_base.ValidatorBase): |
| 20 def CustomizeBrowserOptions(self, options): | 20 def CustomizeBrowserOptions(self, options): |
| 21 # --test-type=gpu is used only to suppress the "Google API Keys are missing" | 21 # --test-type=gpu is used only to suppress the "Google API Keys are missing" |
| 22 # infobar, which causes flakiness in tests. | 22 # infobar, which causes flakiness in tests. |
| 23 options.AppendExtraBrowserArgs(['--force-gpu-rasterization', | 23 options.AppendExtraBrowserArgs(['--force-gpu-rasterization', |
| 24 '--test-type=gpu']) | 24 '--test-type=gpu']) |
| 25 | 25 |
| 26 def ValidateAndMeasurePage(self, page, tab, results): | 26 def ValidateAndMeasurePage(self, page, tab, results): |
| 27 if not tab.screenshot_supported: | 27 if not tab.screenshot_supported: |
| 28 raise page_test.Failure('Browser does not support screenshot capture') | 28 raise page_test.Failure('Browser does not support screenshot capture') |
| 29 | 29 |
| 30 def CheckColorMatch(canvasRGB, screenshotRGB): | 30 def CheckColorMatch(canvasRGB, screenshotRGB): |
| 31 for i in range(0, 3): | 31 for i in range(0, 3): |
| 32 if abs(canvasRGB[i] - screenshotRGB[i]) > 1: | 32 if abs(canvasRGB[i] - screenshotRGB[i]) > 1: |
| 33 raise page_test.Failure('Color mismatch in component #%d: %d vs %d' % | 33 raise page_test.Failure('Color mismatch in component #%d: %d vs %d' % |
| 34 (i, canvasRGB[i], screenshotRGB[i])) | 34 (i, canvasRGB[i], screenshotRGB[i])) |
| 35 | 35 |
| 36 def CheckScreenshot(): | 36 def CheckScreenshot(): |
| 37 canvasRGB = []; | 37 canvasRGB = [] |
| 38 for i in range(0, 3): | 38 for _ in range(0, 3): |
| 39 canvasRGB.append(random.randint(0, 255)) | 39 canvasRGB.append(random.randint(0, 255)) |
| 40 tab.EvaluateJavaScript("window.draw(%d, %d, %d);" % tuple(canvasRGB)) | 40 tab.EvaluateJavaScript("window.draw(%d, %d, %d);" % tuple(canvasRGB)) |
| 41 screenshot = tab.Screenshot(5) | 41 screenshot = tab.Screenshot(5) |
| 42 CheckColorMatch(canvasRGB, image_util.Pixels(screenshot)) | 42 CheckColorMatch(canvasRGB, image_util.Pixels(screenshot)) |
| 43 | 43 |
| 44 repetitions = 50 | 44 repetitions = 50 |
| 45 for n in range(0, repetitions): | 45 for _ in range(0, repetitions): |
| 46 CheckScreenshot() | 46 CheckScreenshot() |
| 47 | 47 |
| 48 class ScreenshotSyncPage(gpu_test_base.PageBase): | 48 class ScreenshotSyncPage(gpu_test_base.PageBase): |
| 49 def __init__(self, story_set, base_dir, expectations): | 49 def __init__(self, story_set, base_dir, expectations): |
| 50 super(ScreenshotSyncPage, self).__init__( | 50 super(ScreenshotSyncPage, self).__init__( |
| 51 url='file://screenshot_sync.html', | 51 url='file://screenshot_sync.html', |
| 52 page_set=story_set, | 52 page_set=story_set, |
| 53 base_dir=base_dir, | 53 base_dir=base_dir, |
| 54 name='ScreenshotSync', | 54 name='ScreenshotSync', |
| 55 expectations=expectations) | 55 expectations=expectations) |
| 56 | 56 |
| 57 | 57 |
| 58 @benchmark.Disabled('linux', 'mac', 'win') | 58 @benchmark.Disabled('linux', 'mac', 'win') |
| 59 class ScreenshotSyncProcess(gpu_test_base.TestBase): | 59 class ScreenshotSyncProcess(gpu_test_base.TestBase): |
| 60 """Tests that screenhots are properly synchronized with the frame one which | 60 """Tests that screenhots are properly synchronized with the frame one which |
| 61 they were requested""" | 61 they were requested""" |
| 62 test = ScreenshotSyncValidator | 62 test = ScreenshotSyncValidator |
| 63 | 63 |
| 64 @classmethod | 64 @classmethod |
| 65 def Name(cls): | 65 def Name(cls): |
| 66 return 'screenshot_sync' | 66 return 'screenshot_sync' |
| 67 | 67 |
| 68 def _CreateExpectations(self): | 68 def _CreateExpectations(self): |
| 69 return expectations.ScreenshotSyncExpectations() | 69 return screenshot_sync_expectations.ScreenshotSyncExpectations() |
| 70 | 70 |
| 71 def CreateStorySet(self, options): | 71 def CreateStorySet(self, options): |
| 72 ps = story_set_module.StorySet(base_dir=data_path, serving_dirs=['']) | 72 ps = story_set_module.StorySet(base_dir=data_path, serving_dirs=['']) |
| 73 ps.AddStory(ScreenshotSyncPage(ps, ps.base_dir, self.GetExpectations())) | 73 ps.AddStory(ScreenshotSyncPage(ps, ps.base_dir, self.GetExpectations())) |
| 74 return ps | 74 return ps |
| OLD | NEW |