| 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 | 4 |
| 5 import os | 5 import os |
| 6 import re | 6 import re |
| 7 import shutil | 7 import shutil |
| 8 import sys | 8 import sys |
| 9 import StringIO | 9 import StringIO |
| 10 import tempfile | 10 import tempfile |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 self.formatted_exception, | 138 self.formatted_exception, |
| 139 re.DOTALL | re.MULTILINE) | 139 re.DOTALL | re.MULTILINE) |
| 140 self.assertEquals([expected_exception_name], actual_exception_names, | 140 self.assertEquals([expected_exception_name], actual_exception_names, |
| 141 msg='Full formatted exception: %s' % '\n > '.join( | 141 msg='Full formatted exception: %s' % '\n > '.join( |
| 142 self.formatted_exception.split('\n'))) | 142 self.formatted_exception.split('\n'))) |
| 143 | 143 |
| 144 def testRaiseBrowserGoneExceptionFromRestartBrowserBeforeEachPage(self): | 144 def testRaiseBrowserGoneExceptionFromRestartBrowserBeforeEachPage(self): |
| 145 self.CaptureFormattedException() | 145 self.CaptureFormattedException() |
| 146 story_set = story.StorySet() | 146 story_set = story.StorySet() |
| 147 story_set.AddStory(page_module.Page( | 147 story_set.AddStory(page_module.Page( |
| 148 'file://blank.html', story_set, base_dir=util.GetUnittestDataDir())) | 148 'file://blank.html', story_set, base_dir=util.GetUnittestDataDir(), |
| 149 name='foo')) |
| 149 story_set.AddStory(page_module.Page( | 150 story_set.AddStory(page_module.Page( |
| 150 'file://blank.html', story_set, base_dir=util.GetUnittestDataDir())) | 151 'file://blank.html', story_set, base_dir=util.GetUnittestDataDir(), |
| 152 name='bar')) |
| 151 story_set.AddStory(page_module.Page( | 153 story_set.AddStory(page_module.Page( |
| 152 'file://blank.html', story_set, base_dir=util.GetUnittestDataDir())) | 154 'file://blank.html', story_set, base_dir=util.GetUnittestDataDir(), |
| 155 name='baz')) |
| 153 | 156 |
| 154 class Test(legacy_page_test.LegacyPageTest): | 157 class Test(legacy_page_test.LegacyPageTest): |
| 155 | 158 |
| 156 def __init__(self, *args): | 159 def __init__(self, *args): |
| 157 super(Test, self).__init__( | 160 super(Test, self).__init__( |
| 158 *args, needs_browser_restart_after_each_page=True) | 161 *args, needs_browser_restart_after_each_page=True) |
| 159 self.run_count = 0 | 162 self.run_count = 0 |
| 160 | 163 |
| 161 def RestartBrowserBeforeEachPage(self): | 164 def RestartBrowserBeforeEachPage(self): |
| 162 # This will only be called twice with 3 pages. | 165 # This will only be called twice with 3 pages. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 178 story_runner.Run(test, story_set, options, results) | 181 story_runner.Run(test, story_set, options, results) |
| 179 self.assertEquals(2, test.run_count) | 182 self.assertEquals(2, test.run_count) |
| 180 self.assertEquals(2, len(GetSuccessfulPageRuns(results))) | 183 self.assertEquals(2, len(GetSuccessfulPageRuns(results))) |
| 181 self.assertEquals(1, len(results.failures)) | 184 self.assertEquals(1, len(results.failures)) |
| 182 self.assertFormattedExceptionIsEmpty() | 185 self.assertFormattedExceptionIsEmpty() |
| 183 | 186 |
| 184 def testNeedsBrowserRestartAfterEachPage(self): | 187 def testNeedsBrowserRestartAfterEachPage(self): |
| 185 self.CaptureFormattedException() | 188 self.CaptureFormattedException() |
| 186 story_set = story.StorySet() | 189 story_set = story.StorySet() |
| 187 story_set.AddStory(page_module.Page( | 190 story_set.AddStory(page_module.Page( |
| 188 'file://blank.html', story_set, base_dir=util.GetUnittestDataDir())) | 191 'file://blank.html', story_set, base_dir=util.GetUnittestDataDir(), |
| 192 name='foo')) |
| 189 story_set.AddStory(page_module.Page( | 193 story_set.AddStory(page_module.Page( |
| 190 'file://blank.html', story_set, base_dir=util.GetUnittestDataDir())) | 194 'file://blank.html', story_set, base_dir=util.GetUnittestDataDir(), |
| 195 name='bar')) |
| 191 | 196 |
| 192 class Test(legacy_page_test.LegacyPageTest): | 197 class Test(legacy_page_test.LegacyPageTest): |
| 193 | 198 |
| 194 def __init__(self, *args, **kwargs): | 199 def __init__(self, *args, **kwargs): |
| 195 super(Test, self).__init__(*args, **kwargs) | 200 super(Test, self).__init__(*args, **kwargs) |
| 196 self.browser_starts = 0 | 201 self.browser_starts = 0 |
| 197 | 202 |
| 198 def DidStartBrowser(self, *args): | 203 def DidStartBrowser(self, *args): |
| 199 super(Test, self).DidStartBrowser(*args) | 204 super(Test, self).DidStartBrowser(*args) |
| 200 self.browser_starts += 1 | 205 self.browser_starts += 1 |
| (...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 564 finally: | 569 finally: |
| 565 shutil.rmtree(options.output_dir) | 570 shutil.rmtree(options.output_dir) |
| 566 | 571 |
| 567 def _RunPageTestThatRaisesAppCrashException(self, test, max_failures): | 572 def _RunPageTestThatRaisesAppCrashException(self, test, max_failures): |
| 568 class TestPage(page_module.Page): | 573 class TestPage(page_module.Page): |
| 569 | 574 |
| 570 def RunNavigateSteps(self, _): | 575 def RunNavigateSteps(self, _): |
| 571 raise exceptions.AppCrashException | 576 raise exceptions.AppCrashException |
| 572 | 577 |
| 573 story_set = story.StorySet() | 578 story_set = story.StorySet() |
| 574 for _ in range(5): | 579 for i in range(5): |
| 575 story_set.AddStory( | 580 story_set.AddStory( |
| 576 TestPage('file://blank.html', story_set, | 581 TestPage('file://blank.html', story_set, |
| 577 base_dir=util.GetUnittestDataDir())) | 582 base_dir=util.GetUnittestDataDir(), name='foo%d' % i)) |
| 578 options = options_for_unittests.GetCopy() | 583 options = options_for_unittests.GetCopy() |
| 579 options.output_formats = ['none'] | 584 options.output_formats = ['none'] |
| 580 options.suppress_gtest_report = True | 585 options.suppress_gtest_report = True |
| 581 SetUpStoryRunnerArguments(options) | 586 SetUpStoryRunnerArguments(options) |
| 582 results = results_options.CreateResults(EmptyMetadataForTest(), options) | 587 results = results_options.CreateResults(EmptyMetadataForTest(), options) |
| 583 story_runner.Run(test, story_set, options, results, | 588 story_runner.Run(test, story_set, options, results, |
| 584 max_failures=max_failures) | 589 max_failures=max_failures) |
| 585 return results | 590 return results |
| 586 | 591 |
| 587 def testSingleTabMeansCrashWillCauseFailureValue(self): | 592 def testSingleTabMeansCrashWillCauseFailureValue(self): |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 773 results.pages_to_profiling_files) | 778 results.pages_to_profiling_files) |
| 774 screenshot_file_path = ( | 779 screenshot_file_path = ( |
| 775 results.pages_to_profiling_files[failing_page][0].GetAbsPath()) | 780 results.pages_to_profiling_files[failing_page][0].GetAbsPath()) |
| 776 try: | 781 try: |
| 777 actual_screenshot_img = image_util.FromPngFile(screenshot_file_path) | 782 actual_screenshot_img = image_util.FromPngFile(screenshot_file_path) |
| 778 self.assertTrue(image_util.AreEqual( | 783 self.assertTrue(image_util.AreEqual( |
| 779 image_util.FromBase64Png(expected_png_base64), | 784 image_util.FromBase64Png(expected_png_base64), |
| 780 actual_screenshot_img)) | 785 actual_screenshot_img)) |
| 781 finally: # Must clean up screenshot file if exists. | 786 finally: # Must clean up screenshot file if exists. |
| 782 os.remove(screenshot_file_path) | 787 os.remove(screenshot_file_path) |
| OLD | NEW |