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 from gpu_tests import gpu_test_base | 7 from gpu_tests import gpu_test_base |
8 from gpu_tests import path_util | 8 from gpu_tests import path_util |
9 from gpu_tests import screenshot_sync_expectations | 9 from gpu_tests import screenshot_sync_expectations |
10 | 10 |
11 from telemetry.page import page_test | 11 from telemetry.page import page_test |
12 from telemetry.story import story_set as story_set_module | 12 from telemetry.story import story_set as story_set_module |
13 from telemetry.util import image_util | 13 from telemetry.util import image_util |
| 14 from telemetry.util import rgba_color |
14 | 15 |
15 data_path = os.path.join( | 16 data_path = os.path.join( |
16 path_util.GetChromiumSrcDir(), 'content', 'test', 'data', 'gpu') | 17 path_util.GetChromiumSrcDir(), 'content', 'test', 'data', 'gpu') |
17 | 18 |
18 class ScreenshotSyncValidator(gpu_test_base.ValidatorBase): | 19 class ScreenshotSyncValidator(gpu_test_base.ValidatorBase): |
19 def CustomizeBrowserOptions(self, options): | 20 def CustomizeBrowserOptions(self, options): |
20 # --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" |
21 # infobar, which causes flakiness in tests. | 22 # infobar, which causes flakiness in tests. |
22 options.AppendExtraBrowserArgs(['--force-gpu-rasterization', | 23 options.AppendExtraBrowserArgs(['--force-gpu-rasterization', |
23 '--test-type=gpu']) | 24 '--test-type=gpu']) |
24 | 25 |
25 def ValidateAndMeasurePage(self, page, tab, results): | 26 def ValidateAndMeasurePage(self, page, tab, results): |
26 if not tab.screenshot_supported: | 27 if not tab.screenshot_supported: |
27 raise page_test.Failure('Browser does not support screenshot capture') | 28 raise page_test.Failure('Browser does not support screenshot capture') |
28 | 29 |
29 def CheckColorMatch(canvasRGB, screenshotRGB): | 30 def CheckColorMatchAtLocation(expectedRGB, screenshot, x, y): |
30 for i in range(0, 3): | 31 pixel_value = image_util.GetPixelColor(screenshot, x, y) |
31 if abs(canvasRGB[i] - screenshotRGB[i]) > 1: | 32 if not expectedRGB.IsEqual(pixel_value): |
32 raise page_test.Failure('Color mismatch in component #%d: %d vs %d' % | 33 error_message = ('Color mismatch at (%d, %d): expected (%d, %d, %d), ' + |
33 (i, canvasRGB[i], screenshotRGB[i])) | 34 'got (%d, %d, %d)') % ( |
| 35 x, y, expectedRGB.r, expectedRGB.g, expectedRGB.b, |
| 36 pixel_value.r, pixel_value.g, pixel_value.b) |
| 37 raise page_test.Failure(error_message) |
34 | 38 |
35 def CheckScreenshot(): | 39 def CheckScreenshot(): |
36 canvasRGB = [] | 40 canvasRGB = rgba_color.RgbaColor(random.randint(0, 255), |
37 for _ in range(0, 3): | 41 random.randint(0, 255), |
38 canvasRGB.append(random.randint(0, 255)) | 42 random.randint(0, 255), |
39 tab.EvaluateJavaScript("window.draw(%d, %d, %d);" % tuple(canvasRGB)) | 43 255) |
| 44 tab.EvaluateJavaScript("window.draw(%d, %d, %d);" % ( |
| 45 canvasRGB.r, canvasRGB.g, canvasRGB.b)) |
40 screenshot = tab.Screenshot(5) | 46 screenshot = tab.Screenshot(5) |
41 CheckColorMatch(canvasRGB, image_util.Pixels(screenshot)) | 47 inset = 10 |
| 48 outer_size = 256 |
| 49 skip = 10 |
| 50 for y in range(inset, outer_size - inset, skip): |
| 51 for x in range(inset, outer_size - inset, skip): |
| 52 CheckColorMatchAtLocation(canvasRGB, screenshot, x, y) |
42 | 53 |
43 repetitions = 50 | 54 repetitions = 20 |
44 for _ in range(0, repetitions): | 55 for _ in range(0, repetitions): |
45 CheckScreenshot() | 56 CheckScreenshot() |
46 | 57 |
47 class ScreenshotSyncPage(gpu_test_base.PageBase): | 58 class ScreenshotSyncPage(gpu_test_base.PageBase): |
48 def __init__(self, story_set, base_dir, expectations): | 59 def __init__(self, story_set, base_dir, url, name, expectations): |
49 super(ScreenshotSyncPage, self).__init__( | 60 super(ScreenshotSyncPage, self).__init__( |
50 url='file://screenshot_sync.html', | 61 url=url, |
51 page_set=story_set, | 62 page_set=story_set, |
52 base_dir=base_dir, | 63 base_dir=base_dir, |
53 name='ScreenshotSync', | 64 name=name, |
54 expectations=expectations) | 65 expectations=expectations) |
55 | 66 |
56 | 67 |
57 class ScreenshotSyncProcess(gpu_test_base.TestBase): | 68 class ScreenshotSyncProcess(gpu_test_base.TestBase): |
58 """Tests that screenhots are properly synchronized with the frame one which | 69 """Tests that screenhots are properly synchronized with the frame one which |
59 they were requested""" | 70 they were requested""" |
60 test = ScreenshotSyncValidator | 71 test = ScreenshotSyncValidator |
61 | 72 |
62 @classmethod | 73 @classmethod |
63 def Name(cls): | 74 def Name(cls): |
64 return 'screenshot_sync' | 75 return 'screenshot_sync' |
65 | 76 |
66 def _CreateExpectations(self): | 77 def _CreateExpectations(self): |
67 return screenshot_sync_expectations.ScreenshotSyncExpectations() | 78 return screenshot_sync_expectations.ScreenshotSyncExpectations() |
68 | 79 |
69 def CreateStorySet(self, options): | 80 def CreateStorySet(self, options): |
70 ps = story_set_module.StorySet(base_dir=data_path, serving_dirs=['']) | 81 ps = story_set_module.StorySet(base_dir=data_path, serving_dirs=['']) |
71 ps.AddStory(ScreenshotSyncPage(ps, ps.base_dir, self.GetExpectations())) | 82 ps.AddStory(ScreenshotSyncPage(ps, ps.base_dir, |
| 83 'file://screenshot_sync_canvas.html', |
| 84 'ScreenshotSync.WithCanvas', |
| 85 self.GetExpectations())) |
| 86 ps.AddStory(ScreenshotSyncPage(ps, ps.base_dir, |
| 87 'file://screenshot_sync_divs.html', |
| 88 'ScreenshotSync.WithDivs', |
| 89 self.GetExpectations())) |
72 return ps | 90 return ps |
OLD | NEW |