OLD | NEW |
| (Empty) |
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 | |
3 # found in the LICENSE file. | |
4 import os | |
5 import random | |
6 | |
7 from gpu_tests import gpu_test_base | |
8 from gpu_tests import path_util | |
9 from gpu_tests import screenshot_sync_expectations | |
10 | |
11 from telemetry.page import legacy_page_test | |
12 from telemetry.story import story_set as story_set_module | |
13 from telemetry.util import image_util | |
14 from telemetry.util import rgba_color | |
15 | |
16 data_path = os.path.join( | |
17 path_util.GetChromiumSrcDir(), 'content', 'test', 'data', 'gpu') | |
18 | |
19 | |
20 class SoftwareRasterSharedPageState(gpu_test_base.GpuSharedPageState): | |
21 def __init__(self, test, finder_options, story_set): | |
22 super(SoftwareRasterSharedPageState, self).__init__( | |
23 test, finder_options, story_set) | |
24 finder_options.browser_options.AppendExtraBrowserArgs( | |
25 ['--disable-gpu-rasterization']) | |
26 | |
27 | |
28 class GPURasterSharedPageState(gpu_test_base.GpuSharedPageState): | |
29 def __init__(self, test, finder_options, story_set): | |
30 super(GPURasterSharedPageState, self).__init__( | |
31 test, finder_options, story_set) | |
32 finder_options.browser_options.AppendExtraBrowserArgs( | |
33 ['--force-gpu-rasterization']) | |
34 | |
35 | |
36 class ScreenshotSyncValidator(gpu_test_base.ValidatorBase): | |
37 def CustomizeBrowserOptions(self, options): | |
38 # --test-type=gpu is used only to suppress the "Google API Keys are missing" | |
39 # infobar, which causes flakiness in tests. | |
40 options.AppendExtraBrowserArgs(['--test-type=gpu']) | |
41 | |
42 def ValidateAndMeasurePage(self, page, tab, results): | |
43 if not tab.screenshot_supported: | |
44 raise legacy_page_test.Failure( | |
45 'Browser does not support screenshot capture') | |
46 | |
47 def CheckColorMatchAtLocation(expectedRGB, screenshot, x, y): | |
48 pixel_value = image_util.GetPixelColor(screenshot, x, y) | |
49 if not expectedRGB.IsEqual(pixel_value): | |
50 error_message = ('Color mismatch at (%d, %d): expected (%d, %d, %d), ' + | |
51 'got (%d, %d, %d)') % ( | |
52 x, y, expectedRGB.r, expectedRGB.g, expectedRGB.b, | |
53 pixel_value.r, pixel_value.g, pixel_value.b) | |
54 raise legacy_page_test.Failure(error_message) | |
55 | |
56 def CheckScreenshot(): | |
57 canvasRGB = rgba_color.RgbaColor(random.randint(0, 255), | |
58 random.randint(0, 255), | |
59 random.randint(0, 255), | |
60 255) | |
61 tab.EvaluateJavaScript("window.draw(%d, %d, %d);" % ( | |
62 canvasRGB.r, canvasRGB.g, canvasRGB.b)) | |
63 screenshot = tab.Screenshot(5) | |
64 start_x = 10 | |
65 start_y = 0 | |
66 outer_size = 256 | |
67 skip = 10 | |
68 for y in range(start_y, outer_size, skip): | |
69 for x in range(start_x, outer_size, skip): | |
70 CheckColorMatchAtLocation(canvasRGB, screenshot, x, y) | |
71 | |
72 repetitions = 20 | |
73 for _ in range(0, repetitions): | |
74 CheckScreenshot() | |
75 | |
76 | |
77 class ScreenshotSyncPage(gpu_test_base.PageBase): | |
78 def __init__(self, story_set, base_dir, | |
79 shared_page_state_class, | |
80 url, name, expectations): | |
81 super(ScreenshotSyncPage, self).__init__( | |
82 url=url, | |
83 page_set=story_set, | |
84 base_dir=base_dir, | |
85 name=name, | |
86 shared_page_state_class=shared_page_state_class, | |
87 expectations=expectations) | |
88 | |
89 | |
90 class ScreenshotSyncStorySet(story_set_module.StorySet): | |
91 """Test cases for screenshots being in sync with content updates.""" | |
92 def __init__(self, base_dir=None, serving_dirs=None): | |
93 super(ScreenshotSyncStorySet, self).__init__( | |
94 base_dir=base_dir, serving_dirs=serving_dirs) | |
95 | |
96 @property | |
97 def allow_mixed_story_states(self): | |
98 # Return True here in order to be able to run the same tests with | |
99 # both software and GPU rasterization. | |
100 return True | |
101 | |
102 | |
103 class ScreenshotSyncProcess(gpu_test_base.TestBase): | |
104 """Tests that screenhots are properly synchronized with the frame one which | |
105 they were requested""" | |
106 test = ScreenshotSyncValidator | |
107 | |
108 @classmethod | |
109 def Name(cls): | |
110 return 'screenshot_sync' | |
111 | |
112 def _CreateExpectations(self): | |
113 return screenshot_sync_expectations.ScreenshotSyncExpectations() | |
114 | |
115 def CreateStorySet(self, options): | |
116 ps = ScreenshotSyncStorySet(base_dir=data_path, serving_dirs=['']) | |
117 ps.AddStory(ScreenshotSyncPage(ps, ps.base_dir, | |
118 SoftwareRasterSharedPageState, | |
119 'file://screenshot_sync_canvas.html', | |
120 'ScreenshotSync.SWRasterWithCanvas', | |
121 self.GetExpectations())) | |
122 ps.AddStory(ScreenshotSyncPage(ps, ps.base_dir, | |
123 SoftwareRasterSharedPageState, | |
124 'file://screenshot_sync_divs.html', | |
125 'ScreenshotSync.SWRasterWithDivs', | |
126 self.GetExpectations())) | |
127 ps.AddStory(ScreenshotSyncPage(ps, ps.base_dir, | |
128 GPURasterSharedPageState, | |
129 'file://screenshot_sync_canvas.html', | |
130 'ScreenshotSync.GPURasterWithCanvas', | |
131 self.GetExpectations())) | |
132 ps.AddStory(ScreenshotSyncPage(ps, ps.base_dir, | |
133 GPURasterSharedPageState, | |
134 'file://screenshot_sync_divs.html', | |
135 'ScreenshotSync.GPURasterWithDivs', | |
136 self.GetExpectations())) | |
137 return ps | |
OLD | NEW |