| OLD | NEW |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 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 json | 5 import json |
| 6 import logging | 6 import logging |
| 7 import mock | 7 import mock |
| 8 import os | 8 import os |
| 9 import tempfile | 9 import tempfile |
| 10 import unittest | 10 import unittest |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 # This test causes the browser to try and restart the browser 3 times. | 121 # This test causes the browser to try and restart the browser 3 times. |
| 122 yield ('restart', 'restart.html', ()) | 122 yield ('restart', 'restart.html', ()) |
| 123 | 123 |
| 124 def RunActualGpuTest(self, file_path, *args): | 124 def RunActualGpuTest(self, file_path, *args): |
| 125 # The logic of this test is run when the browser starts, it fails twice | 125 # The logic of this test is run when the browser starts, it fails twice |
| 126 # and then succeeds on the third time so we are just testing that this | 126 # and then succeeds on the third time so we are just testing that this |
| 127 # is successful based on the parameters. | 127 # is successful based on the parameters. |
| 128 pass | 128 pass |
| 129 | 129 |
| 130 | 130 |
| 131 class BrowserCrashAfterStartIntegrationUnittest( |
| 132 gpu_integration_test.GpuIntegrationTest): |
| 133 |
| 134 _num_browser_crashes = 0 |
| 135 _num_browser_starts = 0 |
| 136 |
| 137 @classmethod |
| 138 def setUpClass(cls): |
| 139 cls._fake_browser_options = fakes.CreateBrowserFinderOptions( |
| 140 execute_after_browser_creation=cls.CrashAfterStart) |
| 141 cls._fake_browser_options.browser_options.platform = \ |
| 142 fakes.FakeLinuxPlatform() |
| 143 cls._fake_browser_options.output_formats = ['none'] |
| 144 cls._fake_browser_options.suppress_gtest_report = True |
| 145 cls._fake_browser_options.output_dir = None |
| 146 cls._fake_browser_options .upload_bucket = 'public' |
| 147 cls._fake_browser_options .upload_results = False |
| 148 cls._finder_options = cls._fake_browser_options |
| 149 cls.platform = None |
| 150 cls.browser = None |
| 151 cls.SetBrowserOptions(cls._finder_options) |
| 152 cls.StartBrowser() |
| 153 |
| 154 @classmethod |
| 155 def _CreateExpectations(cls): |
| 156 return gpu_test_expectations.GpuTestExpectations() |
| 157 |
| 158 @classmethod |
| 159 def CrashAfterStart(cls, browser): |
| 160 cls._num_browser_starts += 1 |
| 161 if cls._num_browser_crashes < 2: |
| 162 cls._num_browser_crashes += 1 |
| 163 # This simulates the first tab's renderer process crashing upon |
| 164 # startup. The try/catch forces the GpuIntegrationTest's first |
| 165 # fetch of this tab to fail. crbug.com/682819 |
| 166 try: |
| 167 browser.tabs[0].Navigate('chrome://crash') |
| 168 except Exception: |
| 169 pass |
| 170 |
| 171 @classmethod |
| 172 def Name(cls): |
| 173 return 'browser_crash_after_start_integration_unittest' |
| 174 |
| 175 @classmethod |
| 176 def GenerateGpuTests(cls, options): |
| 177 # This test causes the browser to try and restart the browser 3 times. |
| 178 yield ('restart', 'restart.html', ()) |
| 179 |
| 180 def RunActualGpuTest(self, file_path, *args): |
| 181 # The logic of this test is run when the browser starts, it fails twice |
| 182 # and then succeeds on the third time so we are just testing that this |
| 183 # is successful based on the parameters. |
| 184 pass |
| 185 |
| 186 |
| 131 class GpuIntegrationTestUnittest(unittest.TestCase): | 187 class GpuIntegrationTestUnittest(unittest.TestCase): |
| 132 @mock.patch('telemetry.internal.util.binary_manager.InitDependencyManager') | 188 @mock.patch('telemetry.internal.util.binary_manager.InitDependencyManager') |
| 133 def testSimpleIntegrationUnittest(self, mockInitDependencyManager): | 189 def testSimpleIntegrationUnittest(self, mockInitDependencyManager): |
| 134 self._RunIntegrationTest( | 190 self._RunIntegrationTest( |
| 135 'simple_integration_unittest', [ | 191 'simple_integration_unittest', [ |
| 136 'unexpected_error', | 192 'unexpected_error', |
| 137 'unexpected_failure' | 193 'unexpected_failure' |
| 138 ], [ | 194 ], [ |
| 139 'expected_failure', | 195 'expected_failure', |
| 140 'expected_flaky', | 196 'expected_flaky', |
| 141 ]) | 197 ]) |
| 142 # It might be nice to be more precise about the order of operations | 198 # It might be nice to be more precise about the order of operations |
| 143 # with these browser restarts, but this is at least a start. | 199 # with these browser restarts, but this is at least a start. |
| 144 self.assertEquals(SimpleIntegrationUnittest._num_browser_starts, 6) | 200 self.assertEquals(SimpleIntegrationUnittest._num_browser_starts, 6) |
| 145 | 201 |
| 146 @mock.patch('telemetry.internal.util.binary_manager.InitDependencyManager') | 202 @mock.patch('telemetry.internal.util.binary_manager.InitDependencyManager') |
| 147 def testIntegrationUnittestWithBrowserFailure( | 203 def testIntegrationUnittestWithBrowserFailure( |
| 148 self, mockInitDependencyManager): | 204 self, mockInitDependencyManager): |
| 149 self._RunIntegrationTest( | 205 self._RunIntegrationTest( |
| 150 'browser_start_failure_integration_unittest', [], ['restart']) | 206 'browser_start_failure_integration_unittest', [], ['restart']) |
| 151 self.assertEquals( \ | 207 self.assertEquals( \ |
| 152 BrowserStartFailureIntegrationUnittest._num_browser_crashes, 2) | 208 BrowserStartFailureIntegrationUnittest._num_browser_crashes, 2) |
| 153 self.assertEquals( \ | 209 self.assertEquals( \ |
| 154 BrowserStartFailureIntegrationUnittest._num_browser_starts, 3) | 210 BrowserStartFailureIntegrationUnittest._num_browser_starts, 3) |
| 155 | 211 |
| 156 # TODO(kbr): write a new test utilizing the | 212 @mock.patch('telemetry.internal.util.binary_manager.InitDependencyManager') |
| 157 # execute_after_browser_creation argument to | 213 def testIntegrationUnittestWithBrowserCrashUponStart( |
| 158 # fakes.CreateBrowserFinderOptions once that is available. | 214 self, mockInitDependencyManager): |
| 159 # crbug.com/682819 | 215 self._RunIntegrationTest( |
| 216 'browser_crash_after_start_integration_unittest', [], ['restart']) |
| 217 self.assertEquals( \ |
| 218 BrowserCrashAfterStartIntegrationUnittest._num_browser_crashes, 2) |
| 219 self.assertEquals( \ |
| 220 BrowserCrashAfterStartIntegrationUnittest._num_browser_starts, 3) |
| 160 | 221 |
| 161 def _RunIntegrationTest(self, test_name, failures, successes): | 222 def _RunIntegrationTest(self, test_name, failures, successes): |
| 162 options = browser_test_runner.TestRunOptions() | 223 options = browser_test_runner.TestRunOptions() |
| 163 # Suppress printing out information for passing tests. | 224 # Suppress printing out information for passing tests. |
| 164 options.verbosity = 0 | 225 options.verbosity = 0 |
| 165 config = gpu_project_config.CONFIG | 226 config = gpu_project_config.CONFIG |
| 166 temp_file = tempfile.NamedTemporaryFile(delete=False) | 227 temp_file = tempfile.NamedTemporaryFile(delete=False) |
| 167 temp_file.close() | 228 temp_file.close() |
| 168 temp_file_name = temp_file.name | 229 temp_file_name = temp_file.name |
| 169 try: | 230 try: |
| 170 browser_test_runner.Run( | 231 browser_test_runner.Run( |
| 171 config, options, | 232 config, options, |
| 172 [test_name, | 233 [test_name, |
| 173 '--write-abbreviated-json-results-to=%s' % temp_file_name]) | 234 '--write-abbreviated-json-results-to=%s' % temp_file_name]) |
| 174 with open(temp_file_name) as f: | 235 with open(temp_file_name) as f: |
| 175 test_result = json.load(f) | 236 test_result = json.load(f) |
| 176 self.assertEquals(test_result['failures'], failures) | 237 self.assertEquals(test_result['failures'], failures) |
| 177 self.assertEquals(test_result['successes'], successes) | 238 self.assertEquals(test_result['successes'], successes) |
| 178 self.assertEquals(test_result['valid'], True) | 239 self.assertEquals(test_result['valid'], True) |
| 179 | 240 |
| 180 finally: | 241 finally: |
| 181 os.remove(temp_file_name) | 242 os.remove(temp_file_name) |
| OLD | NEW |