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 legacy_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 from telemetry.util import rgba_color |
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 | 19 |
20 class SoftwareRasterSharedPageState(gpu_test_base.GpuSharedPageState): | 20 class SoftwareRasterSharedPageState(gpu_test_base.GpuSharedPageState): |
21 def __init__(self, test, finder_options, story_set): | 21 def __init__(self, test, finder_options, story_set): |
(...skipping 12 matching lines...) Expand all Loading... |
34 | 34 |
35 | 35 |
36 class ScreenshotSyncValidator(gpu_test_base.ValidatorBase): | 36 class ScreenshotSyncValidator(gpu_test_base.ValidatorBase): |
37 def CustomizeBrowserOptions(self, options): | 37 def CustomizeBrowserOptions(self, options): |
38 # --test-type=gpu is used only to suppress the "Google API Keys are missing" | 38 # --test-type=gpu is used only to suppress the "Google API Keys are missing" |
39 # infobar, which causes flakiness in tests. | 39 # infobar, which causes flakiness in tests. |
40 options.AppendExtraBrowserArgs(['--test-type=gpu']) | 40 options.AppendExtraBrowserArgs(['--test-type=gpu']) |
41 | 41 |
42 def ValidateAndMeasurePage(self, page, tab, results): | 42 def ValidateAndMeasurePage(self, page, tab, results): |
43 if not tab.screenshot_supported: | 43 if not tab.screenshot_supported: |
44 raise page_test.Failure('Browser does not support screenshot capture') | 44 raise legacy_page_test.Failure( |
| 45 'Browser does not support screenshot capture') |
45 | 46 |
46 def CheckColorMatchAtLocation(expectedRGB, screenshot, x, y): | 47 def CheckColorMatchAtLocation(expectedRGB, screenshot, x, y): |
47 pixel_value = image_util.GetPixelColor(screenshot, x, y) | 48 pixel_value = image_util.GetPixelColor(screenshot, x, y) |
48 if not expectedRGB.IsEqual(pixel_value): | 49 if not expectedRGB.IsEqual(pixel_value): |
49 error_message = ('Color mismatch at (%d, %d): expected (%d, %d, %d), ' + | 50 error_message = ('Color mismatch at (%d, %d): expected (%d, %d, %d), ' + |
50 'got (%d, %d, %d)') % ( | 51 'got (%d, %d, %d)') % ( |
51 x, y, expectedRGB.r, expectedRGB.g, expectedRGB.b, | 52 x, y, expectedRGB.r, expectedRGB.g, expectedRGB.b, |
52 pixel_value.r, pixel_value.g, pixel_value.b) | 53 pixel_value.r, pixel_value.g, pixel_value.b) |
53 raise page_test.Failure(error_message) | 54 raise legacy_page_test.Failure(error_message) |
54 | 55 |
55 def CheckScreenshot(): | 56 def CheckScreenshot(): |
56 canvasRGB = rgba_color.RgbaColor(random.randint(0, 255), | 57 canvasRGB = rgba_color.RgbaColor(random.randint(0, 255), |
57 random.randint(0, 255), | 58 random.randint(0, 255), |
58 random.randint(0, 255), | 59 random.randint(0, 255), |
59 255) | 60 255) |
60 tab.EvaluateJavaScript("window.draw(%d, %d, %d);" % ( | 61 tab.EvaluateJavaScript("window.draw(%d, %d, %d);" % ( |
61 canvasRGB.r, canvasRGB.g, canvasRGB.b)) | 62 canvasRGB.r, canvasRGB.g, canvasRGB.b)) |
62 screenshot = tab.Screenshot(5) | 63 screenshot = tab.Screenshot(5) |
63 start_x = 10 | 64 start_x = 10 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 GPURasterSharedPageState, | 128 GPURasterSharedPageState, |
128 'file://screenshot_sync_canvas.html', | 129 'file://screenshot_sync_canvas.html', |
129 'ScreenshotSync.GPURasterWithCanvas', | 130 'ScreenshotSync.GPURasterWithCanvas', |
130 self.GetExpectations())) | 131 self.GetExpectations())) |
131 ps.AddStory(ScreenshotSyncPage(ps, ps.base_dir, | 132 ps.AddStory(ScreenshotSyncPage(ps, ps.base_dir, |
132 GPURasterSharedPageState, | 133 GPURasterSharedPageState, |
133 'file://screenshot_sync_divs.html', | 134 'file://screenshot_sync_divs.html', |
134 'ScreenshotSync.GPURasterWithDivs', | 135 'ScreenshotSync.GPURasterWithDivs', |
135 self.GetExpectations())) | 136 self.GetExpectations())) |
136 return ps | 137 return ps |
OLD | NEW |