| OLD | NEW |
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 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 | 4 |
| 5 import logging | 5 import logging |
| 6 import time | |
| 7 | 6 |
| 8 from telemetry.core import util | 7 from telemetry.core import util |
| 9 from telemetry.core import exceptions | 8 from telemetry.core import exceptions |
| 10 from telemetry.unittest import tab_test_case | 9 from telemetry.unittest import tab_test_case |
| 11 from telemetry.unittest import DisabledTest | |
| 12 | 10 |
| 13 | 11 |
| 14 def _IsDocumentVisible(tab): | 12 def _IsDocumentVisible(tab): |
| 15 state = tab.EvaluateJavaScript('document.webkitVisibilityState') | 13 state = tab.EvaluateJavaScript('document.webkitVisibilityState') |
| 16 # TODO(dtu): Remove when crbug.com/166243 is fixed. | 14 # TODO(dtu): Remove when crbug.com/166243 is fixed. |
| 17 tab.Disconnect() | 15 tab.Disconnect() |
| 18 return state == 'visible' | 16 return state == 'visible' |
| 19 | 17 |
| 20 | 18 |
| 21 class TabTest(tab_test_case.TabTestCase): | 19 class TabTest(tab_test_case.TabTestCase): |
| (...skipping 27 matching lines...) Expand all Loading... |
| 49 self._tab.Activate() | 47 self._tab.Activate() |
| 50 util.WaitFor(lambda: _IsDocumentVisible(self._tab), timeout=5) | 48 util.WaitFor(lambda: _IsDocumentVisible(self._tab), timeout=5) |
| 51 self.assertFalse(_IsDocumentVisible(new_tab)) | 49 self.assertFalse(_IsDocumentVisible(new_tab)) |
| 52 | 50 |
| 53 | 51 |
| 54 class GpuTabTest(tab_test_case.TabTestCase): | 52 class GpuTabTest(tab_test_case.TabTestCase): |
| 55 def setUp(self): | 53 def setUp(self): |
| 56 self._extra_browser_args = ['--enable-gpu-benchmarking'] | 54 self._extra_browser_args = ['--enable-gpu-benchmarking'] |
| 57 super(GpuTabTest, self).setUp() | 55 super(GpuTabTest, self).setUp() |
| 58 | 56 |
| 59 @DisabledTest | |
| 60 def testScreenshot(self): | 57 def testScreenshot(self): |
| 61 if not self._tab.screenshot_supported: | 58 if not self._tab.screenshot_supported: |
| 62 logging.warning('Browser does not support screenshots, skipping test.') | 59 logging.warning('Browser does not support screenshots, skipping test.') |
| 63 return | 60 return |
| 64 | 61 |
| 65 self._browser.SetHTTPServerDirectories(util.GetUnittestDataDir()) | 62 self._browser.SetHTTPServerDirectories(util.GetUnittestDataDir()) |
| 66 self._tab.Navigate( | 63 self._tab.Navigate( |
| 67 self._browser.http_server.UrlOf('green_rect.html')) | 64 self._browser.http_server.UrlOf('green_rect.html')) |
| 68 self._tab.WaitForDocumentReadyStateToBeComplete() | 65 self._tab.WaitForDocumentReadyStateToBeComplete() |
| 69 pixel_ratio = self._tab.EvaluateJavaScript('window.devicePixelRatio || 1') | 66 pixel_ratio = self._tab.EvaluateJavaScript('window.devicePixelRatio || 1') |
| 70 | 67 |
| 71 # TODO(bajones): Sleep for a bit to counter BUG 260878. | |
| 72 time.sleep(0.5) | |
| 73 screenshot = self._tab.Screenshot(5) | 68 screenshot = self._tab.Screenshot(5) |
| 74 assert screenshot | 69 assert screenshot |
| 75 screenshot.GetPixelColor(0 * pixel_ratio, 0 * pixel_ratio).AssertIsRGB( | 70 screenshot.GetPixelColor(0 * pixel_ratio, 0 * pixel_ratio).AssertIsRGB( |
| 76 0, 255, 0, tolerance=2) | 71 0, 255, 0, tolerance=2) |
| 77 screenshot.GetPixelColor(31 * pixel_ratio, 31 * pixel_ratio).AssertIsRGB( | 72 screenshot.GetPixelColor(31 * pixel_ratio, 31 * pixel_ratio).AssertIsRGB( |
| 78 0, 255, 0, tolerance=2) | 73 0, 255, 0, tolerance=2) |
| 79 screenshot.GetPixelColor(32 * pixel_ratio, 32 * pixel_ratio).AssertIsRGB( | 74 screenshot.GetPixelColor(32 * pixel_ratio, 32 * pixel_ratio).AssertIsRGB( |
| 80 255, 255, 255, tolerance=2) | 75 255, 255, 255, tolerance=2) |
| OLD | NEW |