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 | 6 |
6 import screenshot_sync_expectations as expectations | 7 import screenshot_sync_expectations as expectations |
7 | 8 |
8 from telemetry import test | 9 from telemetry import test |
9 from telemetry.core import util | 10 from telemetry.core import util |
10 from telemetry.page import page | 11 from telemetry.page import page |
11 from telemetry.page import page_set | 12 from telemetry.page import page_set |
12 from telemetry.page import page_test | 13 from telemetry.page import page_test |
13 # pylint: disable=W0401,W0614 | 14 # pylint: disable=W0401,W0614 |
14 from telemetry.page.actions.all_page_actions import * | 15 from telemetry.page.actions.all_page_actions import * |
15 | 16 |
16 data_path = os.path.join( | 17 data_path = os.path.join( |
17 util.GetChromiumSrcDir(), 'content', 'test', 'data', 'gpu') | 18 util.GetChromiumSrcDir(), 'content', 'test', 'data', 'gpu') |
18 | 19 |
19 class _ScreenshotSyncValidator(page_test.PageTest): | 20 class _ScreenshotSyncValidator(page_test.PageTest): |
20 def CustomizeBrowserOptions(self, options): | 21 def ValidatePage(self, page, tab, results): |
21 options.AppendExtraBrowserArgs('--enable-gpu-benchmarking') | 22 if not tab.screenshot_supported: |
| 23 raise page_test.Failure('Browser does not support screenshot capture') |
22 | 24 |
23 def ValidatePage(self, page, tab, results): | 25 def CheckColorMatch(canvasRGB, screenshotRGB): |
24 test_success = tab.EvaluateJavaScript('window.__testSuccess') | 26 for i in range(0, 3): |
25 if not test_success: | 27 if abs(canvasRGB[i] - screenshotRGB[i]) > 1: |
26 message = tab.EvaluateJavaScript('window.__testMessage') | 28 raise page_test.Failure('Color mismatch in component #%d: %d vs %d' % |
27 raise page_test.Failure(message) | 29 (i, canvasRGB[i], screenshotRGB[i])) |
| 30 |
| 31 def CheckScreenshot(): |
| 32 canvasRGB = []; |
| 33 for i in range(0, 3): |
| 34 canvasRGB.append(random.randint(0, 255)) |
| 35 tab.EvaluateJavaScript("window.draw(%d, %d, %d);" % tuple(canvasRGB)) |
| 36 screenshot = tab.Screenshot(5) |
| 37 CheckColorMatch(canvasRGB, screenshot.pixels) |
| 38 |
| 39 repetitions = 50 |
| 40 for n in range(0, repetitions): |
| 41 CheckScreenshot() |
28 | 42 |
29 | 43 |
30 class ScreenshotSyncPage(page.Page): | 44 class ScreenshotSyncPage(page.Page): |
31 def __init__(self, page_set, base_dir): | 45 def __init__(self, page_set, base_dir): |
32 super(ScreenshotSyncPage, self).__init__( | 46 super(ScreenshotSyncPage, self).__init__( |
33 url='file://screenshot_sync.html', | 47 url='file://screenshot_sync.html', |
34 page_set=page_set, | 48 page_set=page_set, |
35 base_dir=base_dir, | 49 base_dir=base_dir, |
36 name='ScreenshotSync') | 50 name='ScreenshotSync') |
37 self.user_agent_type = 'desktop' | 51 self.user_agent_type = 'desktop' |
38 | 52 |
39 def RunNavigateSteps(self, action_runner): | 53 def RunNavigateSteps(self, action_runner): |
40 action_runner.NavigateToPage(self) | 54 action_runner.NavigateToPage(self) |
41 action_runner.RunAction(WaitAction({ | |
42 'javascript': 'window.__testComplete', | |
43 'timeout': 120})) | |
44 | 55 |
45 | 56 |
46 class ScreenshotSyncProcess(test.Test): | 57 class ScreenshotSyncProcess(test.Test): |
47 """Tests that screenhots are properly synchronized with the frame one which | 58 """Tests that screenhots are properly synchronized with the frame one which |
48 they were requested""" | 59 they were requested""" |
49 test = _ScreenshotSyncValidator | 60 test = _ScreenshotSyncValidator |
50 | 61 |
51 def CreateExpectations(self, page_set): | 62 def CreateExpectations(self, page_set): |
52 return expectations.ScreenshotSyncExpectations() | 63 return expectations.ScreenshotSyncExpectations() |
53 | 64 |
54 def CreatePageSet(self, options): | 65 def CreatePageSet(self, options): |
55 ps = page_set.PageSet( | 66 ps = page_set.PageSet( |
56 file_path=data_path, | 67 file_path=data_path, |
57 description='Test cases for screenshot synchronization', | 68 description='Test cases for screenshot synchronization', |
58 serving_dirs=['']) | 69 serving_dirs=['']) |
59 ps.AddPage(ScreenshotSyncPage(ps, ps.base_dir)) | 70 ps.AddPage(ScreenshotSyncPage(ps, ps.base_dir)) |
60 return ps | 71 return ps |
OLD | NEW |