| 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 os | 6 import os |
| 7 import shutil | 7 import shutil |
| 8 import tempfile | 8 import tempfile |
| 9 import unittest | 9 import unittest |
| 10 | 10 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 extension_path, options.browser_type)) | 70 extension_path, options.browser_type)) |
| 71 | 71 |
| 72 def testExtensionNotLoaded(self): | 72 def testExtensionNotLoaded(self): |
| 73 """Querying an extension that was not loaded will return None""" | 73 """Querying an extension that was not loaded will return None""" |
| 74 extension_path = os.path.join(util.GetUnittestDataDir(), 'simple_extension') | 74 extension_path = os.path.join(util.GetUnittestDataDir(), 'simple_extension') |
| 75 options = options_for_unittests.GetCopy() | 75 options = options_for_unittests.GetCopy() |
| 76 load_extension = extension_to_load.ExtensionToLoad( | 76 load_extension = extension_to_load.ExtensionToLoad( |
| 77 extension_path, options.browser_type) | 77 extension_path, options.browser_type) |
| 78 browser_to_create = browser_finder.FindBrowser(options) | 78 browser_to_create = browser_finder.FindBrowser(options) |
| 79 with browser_to_create.Create() as b: | 79 with browser_to_create.Create() as b: |
| 80 b.Start() | |
| 81 if b.supports_extensions: | 80 if b.supports_extensions: |
| 82 self.assertRaises(extension_dict_backend.ExtensionNotFoundException, | 81 self.assertRaises(extension_dict_backend.ExtensionNotFoundException, |
| 83 lambda: b.extensions[load_extension]) | 82 lambda: b.extensions[load_extension]) |
| 84 | 83 |
| 85 class MultipleExtensionTest(unittest.TestCase): | 84 class MultipleExtensionTest(unittest.TestCase): |
| 86 def setUp(self): | 85 def setUp(self): |
| 87 """ Copy the manifest and background.js files of simple_extension to a | 86 """ Copy the manifest and background.js files of simple_extension to a |
| 88 number of temporary directories to load as extensions""" | 87 number of temporary directories to load as extensions""" |
| 89 self._extension_dirs = [tempfile.mkdtemp() | 88 self._extension_dirs = [tempfile.mkdtemp() |
| 90 for i in range(3)] # pylint: disable=W0612 | 89 for i in range(3)] # pylint: disable=W0612 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 extension_path, options.browser_type, is_component=True) | 141 extension_path, options.browser_type, is_component=True) |
| 143 | 142 |
| 144 options.extensions_to_load = [load_extension] | 143 options.extensions_to_load = [load_extension] |
| 145 browser_to_create = browser_finder.FindBrowser(options) | 144 browser_to_create = browser_finder.FindBrowser(options) |
| 146 if not browser_to_create: | 145 if not browser_to_create: |
| 147 logging.warning('Did not find a browser that supports extensions, ' | 146 logging.warning('Did not find a browser that supports extensions, ' |
| 148 'skipping test.') | 147 'skipping test.') |
| 149 return | 148 return |
| 150 | 149 |
| 151 with browser_to_create.Create() as b: | 150 with browser_to_create.Create() as b: |
| 152 b.Start() | |
| 153 extension = b.extensions[load_extension] | 151 extension = b.extensions[load_extension] |
| 154 self.assertTrue( | 152 self.assertTrue( |
| 155 extension.EvaluateJavaScript('chrome.runtime != null')) | 153 extension.EvaluateJavaScript('chrome.runtime != null')) |
| 156 extension.ExecuteJavaScript('setTestVar("abcdef")') | 154 extension.ExecuteJavaScript('setTestVar("abcdef")') |
| 157 self.assertEquals('abcdef', extension.EvaluateJavaScript('_testVar')) | 155 self.assertEquals('abcdef', extension.EvaluateJavaScript('_testVar')) |
| 158 | 156 |
| 159 def testComponentExtensionNoPublicKey(self): | 157 def testComponentExtensionNoPublicKey(self): |
| 160 # simple_extension does not have a public key. | 158 # simple_extension does not have a public key. |
| 161 extension_path = os.path.join(util.GetUnittestDataDir(), 'simple_extension') | 159 extension_path = os.path.join(util.GetUnittestDataDir(), 'simple_extension') |
| 162 options = options_for_unittests.GetCopy() | 160 options = options_for_unittests.GetCopy() |
| 163 self.assertRaises(extension_to_load.MissingPublicKeyException, | 161 self.assertRaises(extension_to_load.MissingPublicKeyException, |
| 164 lambda: extension_to_load.ExtensionToLoad( | 162 lambda: extension_to_load.ExtensionToLoad( |
| 165 extension_path, | 163 extension_path, |
| 166 browser_type=options.browser_type, | 164 browser_type=options.browser_type, |
| 167 is_component=True)) | 165 is_component=True)) |
| OLD | NEW |