| 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 os | 6 import os |
| 7 import re | 7 import re |
| 8 import shutil | 8 import shutil |
| 9 import tempfile | 9 import tempfile |
| 10 import unittest | 10 import unittest |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 | 187 |
| 188 | 188 |
| 189 class BrowserLoggingTest(browser_test_case.BrowserTestCase): | 189 class BrowserLoggingTest(browser_test_case.BrowserTestCase): |
| 190 @classmethod | 190 @classmethod |
| 191 def CustomizeBrowserOptions(cls, options): | 191 def CustomizeBrowserOptions(cls, options): |
| 192 options.logging_verbosity = options.VERBOSE_LOGGING | 192 options.logging_verbosity = options.VERBOSE_LOGGING |
| 193 | 193 |
| 194 @decorators.Disabled('chromeos', 'android') | 194 @decorators.Disabled('chromeos', 'android') |
| 195 def testLogFileExist(self): | 195 def testLogFileExist(self): |
| 196 self.assertTrue( | 196 self.assertTrue( |
| 197 os.path.isfile(self._browser._browser_backend.log_file_path)) | 197 os.path.isfile(self._browser._browser_backend.log_file_path)) |
| 198 | 198 |
| 199 | 199 |
| 200 def _GenerateBrowserProfile(number_of_tabs): | 200 def _GenerateBrowserProfile(number_of_tabs): |
| 201 """ Generate a browser profile which browser had |number_of_tabs| number of | 201 """ Generate a browser profile which browser had |number_of_tabs| number of |
| 202 tabs opened before it was closed. | 202 tabs opened before it was closed. |
| 203 Returns: | 203 Returns: |
| 204 profile_dir: the directory of profile. | 204 profile_dir: the directory of profile. |
| 205 """ | 205 """ |
| 206 profile_dir = tempfile.mkdtemp() | 206 profile_dir = tempfile.mkdtemp() |
| 207 options = options_for_unittests.GetCopy() | 207 options = options_for_unittests.GetCopy() |
| (...skipping 19 matching lines...) Expand all Loading... |
| 227 class BrowserCreationTest(unittest.TestCase): | 227 class BrowserCreationTest(unittest.TestCase): |
| 228 def setUp(self): | 228 def setUp(self): |
| 229 self.mock_browser_backend = mock.MagicMock() | 229 self.mock_browser_backend = mock.MagicMock() |
| 230 self.mock_platform_backend = mock.MagicMock() | 230 self.mock_platform_backend = mock.MagicMock() |
| 231 | 231 |
| 232 def testCleanedUpCalledWhenExceptionRaisedInBrowserCreation(self): | 232 def testCleanedUpCalledWhenExceptionRaisedInBrowserCreation(self): |
| 233 self.mock_platform_backend.platform.FlushDnsCache.side_effect = ( | 233 self.mock_platform_backend.platform.FlushDnsCache.side_effect = ( |
| 234 IntentionalException('Boom!')) | 234 IntentionalException('Boom!')) |
| 235 with self.assertRaises(IntentionalException): | 235 with self.assertRaises(IntentionalException): |
| 236 browser_module.Browser( | 236 browser_module.Browser( |
| 237 self.mock_browser_backend, self.mock_platform_backend, | 237 self.mock_browser_backend, self.mock_platform_backend, |
| 238 credentials_path=None) | 238 credentials_path=None) |
| 239 self.assertTrue(self.mock_platform_backend.WillCloseBrowser.called) | 239 self.assertTrue(self.mock_platform_backend.WillCloseBrowser.called) |
| 240 | 240 |
| 241 def testOriginalExceptionNotSwallow(self): | 241 def testOriginalExceptionNotSwallow(self): |
| 242 self.mock_platform_backend.platform.FlushDnsCache.side_effect = ( | 242 self.mock_platform_backend.platform.FlushDnsCache.side_effect = ( |
| 243 IntentionalException('Boom!')) | 243 IntentionalException('Boom!')) |
| 244 self.mock_platform_backend.WillCloseBrowser.side_effect = ( | 244 self.mock_platform_backend.WillCloseBrowser.side_effect = ( |
| 245 IntentionalException('Cannot close browser!')) | 245 IntentionalException('Cannot close browser!')) |
| 246 with self.assertRaises(IntentionalException) as context: | 246 with self.assertRaises(IntentionalException) as context: |
| 247 browser_module.Browser( | 247 browser_module.Browser( |
| 248 self.mock_browser_backend, self.mock_platform_backend, | 248 self.mock_browser_backend, self.mock_platform_backend, |
| 249 credentials_path=None) | 249 credentials_path=None) |
| 250 self.assertIn('Boom!', context.exception.message) | 250 self.assertIn('Boom!', context.exception.message) |
| 251 | 251 |
| 252 | 252 |
| 253 class BrowserRestoreSessionTest(unittest.TestCase): | 253 class BrowserRestoreSessionTest(unittest.TestCase): |
| 254 | 254 |
| 255 @classmethod | 255 @classmethod |
| 256 def setUpClass(cls): | 256 def setUpClass(cls): |
| 257 cls._number_of_tabs = 4 | 257 cls._number_of_tabs = 4 |
| 258 cls._profile_dir = _GenerateBrowserProfile(cls._number_of_tabs) | 258 cls._profile_dir = _GenerateBrowserProfile(cls._number_of_tabs) |
| 259 cls._options = options_for_unittests.GetCopy() | 259 cls._options = options_for_unittests.GetCopy() |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 try: | 300 try: |
| 301 with browser_to_create.Create(options) as browser: | 301 with browser_to_create.Create(options) as browser: |
| 302 tab = browser.tabs.New() | 302 tab = browser.tabs.New() |
| 303 tab.Navigate('about:blank') | 303 tab.Navigate('about:blank') |
| 304 self.assertEquals(2, tab.EvaluateJavaScript('1 + 1')) | 304 self.assertEquals(2, tab.EvaluateJavaScript('1 + 1')) |
| 305 after_browser_run_temp_dir_content = os.listdir(tempfile.tempdir) | 305 after_browser_run_temp_dir_content = os.listdir(tempfile.tempdir) |
| 306 self.assertEqual(before_browser_run_temp_dir_content, | 306 self.assertEqual(before_browser_run_temp_dir_content, |
| 307 after_browser_run_temp_dir_content) | 307 after_browser_run_temp_dir_content) |
| 308 finally: | 308 finally: |
| 309 browser_to_create.platform.network_controller.Close() | 309 browser_to_create.platform.network_controller.Close() |
| OLD | NEW |