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