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 screenshot_sync_expectations as expectations | 7 import screenshot_sync_expectations as expectations |
8 | 8 |
9 from telemetry import benchmark | 9 from telemetry import benchmark |
10 from telemetry.core import util | 10 from telemetry.core import util |
11 from telemetry.image_processing import image_util | 11 from telemetry.image_processing import image_util |
12 from telemetry.page import page | 12 from telemetry.page import page |
13 from telemetry.page import page_set | 13 from telemetry.page import page_set |
14 from telemetry.page import page_test | 14 from telemetry.page import page_test |
15 | 15 |
16 data_path = os.path.join( | 16 data_path = os.path.join( |
17 util.GetChromiumSrcDir(), 'content', 'test', 'data', 'gpu') | 17 util.GetChromiumSrcDir(), 'content', 'test', 'data', 'gpu') |
18 | 18 |
19 @benchmark.Disabled('mac') | |
Ken Russell (switch to Gerrit)
2015/02/19 01:16:57
These annotations were bogus.
| |
20 class _ScreenshotSyncValidator(page_test.PageTest): | 19 class _ScreenshotSyncValidator(page_test.PageTest): |
21 def CustomizeBrowserOptions(self, options): | 20 def CustomizeBrowserOptions(self, options): |
22 options.AppendExtraBrowserArgs('--force-gpu-rasterization') | 21 options.AppendExtraBrowserArgs('--force-gpu-rasterization') |
23 | 22 |
24 def ValidateAndMeasurePage(self, page, tab, results): | 23 def ValidateAndMeasurePage(self, page, tab, results): |
25 if not tab.screenshot_supported: | 24 if not tab.screenshot_supported: |
26 raise page_test.Failure('Browser does not support screenshot capture') | 25 raise page_test.Failure('Browser does not support screenshot capture') |
27 | 26 |
28 def CheckColorMatch(canvasRGB, screenshotRGB): | 27 def CheckColorMatch(canvasRGB, screenshotRGB): |
29 for i in range(0, 3): | 28 for i in range(0, 3): |
30 if abs(canvasRGB[i] - screenshotRGB[i]) > 1: | 29 if abs(canvasRGB[i] - screenshotRGB[i]) > 1: |
31 raise page_test.Failure('Color mismatch in component #%d: %d vs %d' % | 30 raise page_test.Failure('Color mismatch in component #%d: %d vs %d' % |
32 (i, canvasRGB[i], screenshotRGB[i])) | 31 (i, canvasRGB[i], screenshotRGB[i])) |
33 | 32 |
34 def CheckScreenshot(): | 33 def CheckScreenshot(): |
35 canvasRGB = []; | 34 canvasRGB = []; |
36 for i in range(0, 3): | 35 for i in range(0, 3): |
37 canvasRGB.append(random.randint(0, 255)) | 36 canvasRGB.append(random.randint(0, 255)) |
38 tab.EvaluateJavaScript("window.draw(%d, %d, %d);" % tuple(canvasRGB)) | 37 tab.EvaluateJavaScript("window.draw(%d, %d, %d);" % tuple(canvasRGB)) |
39 screenshot = tab.Screenshot(5) | 38 screenshot = tab.Screenshot(5) |
40 CheckColorMatch(canvasRGB, image_util.Pixels(screenshot)) | 39 CheckColorMatch(canvasRGB, image_util.Pixels(screenshot)) |
41 | 40 |
42 repetitions = 50 | 41 repetitions = 50 |
43 for n in range(0, repetitions): | 42 for n in range(0, repetitions): |
44 CheckScreenshot() | 43 CheckScreenshot() |
45 | 44 |
46 @benchmark.Disabled('mac') | |
47 class ScreenshotSyncPage(page.Page): | 45 class ScreenshotSyncPage(page.Page): |
48 def __init__(self, page_set, base_dir): | 46 def __init__(self, page_set, base_dir): |
49 super(ScreenshotSyncPage, self).__init__( | 47 super(ScreenshotSyncPage, self).__init__( |
50 url='file://screenshot_sync.html', | 48 url='file://screenshot_sync.html', |
51 page_set=page_set, | 49 page_set=page_set, |
52 base_dir=base_dir, | 50 base_dir=base_dir, |
53 name='ScreenshotSync') | 51 name='ScreenshotSync') |
54 self.user_agent_type = 'desktop' | 52 self.user_agent_type = 'desktop' |
55 | 53 |
56 def RunNavigateSteps(self, action_runner): | 54 def RunNavigateSteps(self, action_runner): |
57 super(ScreenshotSyncPage, self).RunNavigateSteps(action_runner) | 55 super(ScreenshotSyncPage, self).RunNavigateSteps(action_runner) |
58 | 56 |
59 | 57 |
60 @benchmark.Disabled('mac') | 58 @benchmark.Disabled('linux', 'mac', 'win') |
61 class ScreenshotSyncProcess(benchmark.Benchmark): | 59 class ScreenshotSyncProcess(benchmark.Benchmark): |
62 """Tests that screenhots are properly synchronized with the frame one which | 60 """Tests that screenhots are properly synchronized with the frame one which |
63 they were requested""" | 61 they were requested""" |
64 test = _ScreenshotSyncValidator | 62 test = _ScreenshotSyncValidator |
65 | 63 |
66 @classmethod | 64 @classmethod |
67 def Name(cls): | 65 def Name(cls): |
68 return 'screenshot_sync' | 66 return 'screenshot_sync' |
69 | 67 |
70 def CreateExpectations(self): | 68 def CreateExpectations(self): |
71 return expectations.ScreenshotSyncExpectations() | 69 return expectations.ScreenshotSyncExpectations() |
72 | 70 |
73 def CreatePageSet(self, options): | 71 def CreatePageSet(self, options): |
74 ps = page_set.PageSet(file_path=data_path, serving_dirs=['']) | 72 ps = page_set.PageSet(file_path=data_path, serving_dirs=['']) |
75 ps.AddUserStory(ScreenshotSyncPage(ps, ps.base_dir)) | 73 ps.AddUserStory(ScreenshotSyncPage(ps, ps.base_dir)) |
76 return ps | 74 return ps |
OLD | NEW |