| OLD | NEW |
| 1 # Copyright 2012 The Chromium Authors. All rights reserved. | 1 # Copyright 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 tempfile | 6 import tempfile |
| 7 | 7 |
| 8 from telemetry import benchmark | 8 from telemetry import benchmark |
| 9 from telemetry.core import bitmap | 9 from telemetry.core import bitmap |
| 10 from telemetry.core import exceptions | 10 from telemetry.core import exceptions |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 def StopVideoCapture(self): | 41 def StopVideoCapture(self): |
| 42 self._is_video_capture_running = False | 42 self._is_video_capture_running = False |
| 43 return video.Video(tempfile.NamedTemporaryFile()) | 43 return video.Video(tempfile.NamedTemporaryFile()) |
| 44 | 44 |
| 45 @property | 45 @property |
| 46 def is_video_capture_running(self): | 46 def is_video_capture_running(self): |
| 47 return self._is_video_capture_running | 47 return self._is_video_capture_running |
| 48 | 48 |
| 49 | 49 |
| 50 class TabTest(tab_test_case.TabTestCase): | 50 class TabTest(tab_test_case.TabTestCase): |
| 51 def testNavigateAndWaitToForCompleteState(self): | 51 def testNavigateAndWaitForCompleteState(self): |
| 52 self._browser.SetHTTPServerDirectories(util.GetUnittestDataDir()) | 52 self._tab.Navigate(self.UrlOfUnittestFile('blank.html')) |
| 53 self._tab.Navigate(self._browser.http_server.UrlOf('blank.html')) | |
| 54 self._tab.WaitForDocumentReadyStateToBeComplete() | 53 self._tab.WaitForDocumentReadyStateToBeComplete() |
| 55 | 54 |
| 56 def testNavigateAndWaitToForInteractiveState(self): | 55 def testNavigateAndWaitForInteractiveState(self): |
| 57 self._browser.SetHTTPServerDirectories(util.GetUnittestDataDir()) | 56 self._tab.Navigate(self.UrlOfUnittestFile('blank.html')) |
| 58 self._tab.Navigate(self._browser.http_server.UrlOf('blank.html')) | |
| 59 self._tab.WaitForDocumentReadyStateToBeInteractiveOrBetter() | 57 self._tab.WaitForDocumentReadyStateToBeInteractiveOrBetter() |
| 60 | 58 |
| 61 def testTabBrowserIsRightBrowser(self): | 59 def testTabBrowserIsRightBrowser(self): |
| 62 self.assertEquals(self._tab.browser, self._browser) | 60 self.assertEquals(self._tab.browser, self._browser) |
| 63 | 61 |
| 64 def testRendererCrash(self): | 62 def testRendererCrash(self): |
| 65 self.assertRaises(exceptions.TabCrashException, | 63 self.assertRaises(exceptions.TabCrashException, |
| 66 lambda: self._tab.Navigate('chrome://crash', | 64 lambda: self._tab.Navigate('chrome://crash', |
| 67 timeout=5)) | 65 timeout=5)) |
| 68 | 66 |
| 69 @benchmark.Enabled('has tabs') | 67 @benchmark.Enabled('has tabs') |
| 70 def testActivateTab(self): | 68 def testActivateTab(self): |
| 71 util.WaitFor(lambda: _IsDocumentVisible(self._tab), timeout=5) | 69 util.WaitFor(lambda: _IsDocumentVisible(self._tab), timeout=5) |
| 72 new_tab = self._browser.tabs.New() | 70 new_tab = self._browser.tabs.New() |
| 73 new_tab.Navigate('about:blank') | 71 new_tab.Navigate('about:blank') |
| 74 util.WaitFor(lambda: _IsDocumentVisible(new_tab), timeout=5) | 72 util.WaitFor(lambda: _IsDocumentVisible(new_tab), timeout=5) |
| 75 self.assertFalse(_IsDocumentVisible(self._tab)) | 73 self.assertFalse(_IsDocumentVisible(self._tab)) |
| 76 self._tab.Activate() | 74 self._tab.Activate() |
| 77 util.WaitFor(lambda: _IsDocumentVisible(self._tab), timeout=5) | 75 util.WaitFor(lambda: _IsDocumentVisible(self._tab), timeout=5) |
| 78 self.assertFalse(_IsDocumentVisible(new_tab)) | 76 self.assertFalse(_IsDocumentVisible(new_tab)) |
| 79 | 77 |
| 80 def testTabUrl(self): | 78 def testTabUrl(self): |
| 81 self.assertEquals(self._tab.url, 'about:blank') | 79 self.assertEquals(self._tab.url, 'about:blank') |
| 82 self.Navigate('blank.html') | 80 url = self.UrlOfUnittestFile('blank.html') |
| 83 self.assertEquals(self._tab.url, self.test_url) | 81 self._tab.Navigate(url) |
| 82 self.assertEquals(self._tab.url, url) |
| 84 | 83 |
| 85 def testIsTimelineRecordingRunningTab(self): | 84 def testIsTimelineRecordingRunningTab(self): |
| 86 self.assertFalse(self._tab.is_timeline_recording_running) | 85 self.assertFalse(self._tab.is_timeline_recording_running) |
| 87 self._tab.StartTimelineRecording() | 86 self._tab.StartTimelineRecording() |
| 88 self.assertTrue(self._tab.is_timeline_recording_running) | 87 self.assertTrue(self._tab.is_timeline_recording_running) |
| 89 self._tab.StopTimelineRecording() | 88 self._tab.StopTimelineRecording() |
| 90 self.assertFalse(self._tab.is_timeline_recording_running) | 89 self.assertFalse(self._tab.is_timeline_recording_running) |
| 91 | 90 |
| 92 #pylint: disable=W0212 | 91 #pylint: disable=W0212 |
| 93 def testIsVideoCaptureRunning(self): | 92 def testIsVideoCaptureRunning(self): |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 renderer_thread.IterAllSlicesOfName('second-tab-marker')] | 156 renderer_thread.IterAllSlicesOfName('second-tab-marker')] |
| 158 self.assertEquals(1, len(second_tab_markers)) | 157 self.assertEquals(1, len(second_tab_markers)) |
| 159 | 158 |
| 160 # Third tab wasn't available when we start tracing, so there is no | 159 # Third tab wasn't available when we start tracing, so there is no |
| 161 # renderer_thread corresponding to it in the the trace. | 160 # renderer_thread corresponding to it in the the trace. |
| 162 self.assertIs(None, timeline_model.GetRendererThreadFromTabId(third_tab.id)) | 161 self.assertIs(None, timeline_model.GetRendererThreadFromTabId(third_tab.id)) |
| 163 | 162 |
| 164 | 163 |
| 165 class GpuTabTest(tab_test_case.TabTestCase): | 164 class GpuTabTest(tab_test_case.TabTestCase): |
| 166 @classmethod | 165 @classmethod |
| 167 def setUpClass(cls): | 166 def CustomizeBrowserOptions(cls, options): |
| 168 cls._extra_browser_args = ['--enable-gpu-benchmarking'] | 167 options.AppendExtraBrowserArgs('--enable-gpu-benchmarking') |
| 169 super(GpuTabTest, cls).setUpClass() | |
| 170 | 168 |
| 171 # Test flaky on mac: http://crbug.com/358664 | 169 # Test flaky on mac: http://crbug.com/358664 |
| 172 @benchmark.Disabled('android', 'mac') | 170 @benchmark.Disabled('android', 'mac') |
| 173 def testScreenshot(self): | 171 def testScreenshot(self): |
| 174 if not self._tab.screenshot_supported: | 172 if not self._tab.screenshot_supported: |
| 175 logging.warning('Browser does not support screenshots, skipping test.') | 173 logging.warning('Browser does not support screenshots, skipping test.') |
| 176 return | 174 return |
| 177 | 175 |
| 178 self.Navigate('green_rect.html') | 176 self.Navigate('green_rect.html') |
| 179 pixel_ratio = self._tab.EvaluateJavaScript('window.devicePixelRatio || 1') | 177 pixel_ratio = self._tab.EvaluateJavaScript('window.devicePixelRatio || 1') |
| 180 | 178 |
| 181 screenshot = self._tab.Screenshot(5) | 179 screenshot = self._tab.Screenshot(5) |
| 182 assert screenshot | 180 assert screenshot |
| 183 screenshot.GetPixelColor(0 * pixel_ratio, 0 * pixel_ratio).AssertIsRGB( | 181 screenshot.GetPixelColor(0 * pixel_ratio, 0 * pixel_ratio).AssertIsRGB( |
| 184 0, 255, 0, tolerance=2) | 182 0, 255, 0, tolerance=2) |
| 185 screenshot.GetPixelColor(31 * pixel_ratio, 31 * pixel_ratio).AssertIsRGB( | 183 screenshot.GetPixelColor(31 * pixel_ratio, 31 * pixel_ratio).AssertIsRGB( |
| 186 0, 255, 0, tolerance=2) | 184 0, 255, 0, tolerance=2) |
| 187 screenshot.GetPixelColor(32 * pixel_ratio, 32 * pixel_ratio).AssertIsRGB( | 185 screenshot.GetPixelColor(32 * pixel_ratio, 32 * pixel_ratio).AssertIsRGB( |
| 188 255, 255, 255, tolerance=2) | 186 255, 255, 255, tolerance=2) |
| OLD | NEW |