Index: tools/telemetry/telemetry/extension_unittest.py |
=================================================================== |
--- tools/telemetry/telemetry/extension_unittest.py (revision 0) |
+++ tools/telemetry/telemetry/extension_unittest.py (revision 0) |
@@ -0,0 +1,78 @@ |
+# Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+# Use of this source code is governed by a BSD-style license that can be |
+# found in the LICENSE file. |
+import os |
+import shutil |
+import tempfile |
+import unittest |
+ |
+from telemetry import browser_finder |
+from telemetry import browser_options |
+from telemetry import crx_id |
+from telemetry import options_for_unittests |
+from telemetry import run_tests |
+from telemetry import util |
+ |
+class ExtensionTest(unittest.TestCase): |
+ @run_tests.RequiresBrowserOfType('cros-chrome') |
+ def testDefaultCrosExtensions(self): |
+ options = options_for_unittests.GetCopy() |
+ browser_to_create = browser_finder.FindBrowser(options) |
+ with browser_to_create.Create() as b: |
+ # file_manager, wallpaper_manager, echo extension. |
+ default_extensions = ['hhaomjibdihmijegdhdafkllkbggdgoj', |
nduca
2013/02/01 00:25:50
No!!! I explained my issue with this in a previous
achuithb
2013/02/06 00:23:03
Done.
|
+ 'obklkkbkpaoaejdabbfldmcfplpdgolj', |
+ 'kddnkjkcjddckihglkfcickdhbmaodcn'] |
+ self.assertEquals(default_extensions, b.extensions.GetExtensionIds()) |
+ |
+ def testExtension(self): |
+ options = options_for_unittests.GetCopy() |
+ extension_path = os.path.join(os.path.dirname(__file__), |
+ '..', 'unittest_data', 'simple_extension') |
+ options = options_for_unittests.GetCopy() |
+ options.extensions_to_load = [browser_options.ExtensionToLoad( |
+ extension_path, False)] |
+ browser_to_create = browser_finder.FindBrowser(options) |
+ if browser_to_create: |
+ with browser_to_create.Create() as b: |
+ # Wait for the extension to load. |
+ util.WaitFor(lambda: b.extensions.GetExtensionByPath(extension_path), |
+ timeout=10) |
+ extension = b.extensions.GetExtensionByPath(extension_path) |
+ assert extension |
+ extension.WaitForDocumentReadyStateToBeInteractiveOrBetter() |
+ extension.ExecuteJavaScript("setTestVar('abcdef')") |
+ self.assertEquals('abcdef', extension.EvaluateJavaScript("_testVar")) |
+ |
+ def testMultipleExtensions(self): |
+ extension_dirs = [tempfile.mkdtemp() for i in range(5)] |
nduca
2013/02/01 00:25:50
why 5?
please, just do 2. no loops. dont copy. ju
achuithb
2013/02/06 00:23:03
You do see certain failures with 5 that you don't
|
+ src_extension_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), |
+ '..', 'unittest_data', 'simple_extension')) |
+ manifest_path = os.path.join(src_extension_dir, 'manifest.json') |
+ script_path = os.path.join(src_extension_dir, 'background.js') |
+ for d in extension_dirs: |
+ shutil.copy(manifest_path, d) |
+ shutil.copy(script_path, d) |
+ extension_ids = [crx_id.GetCRXAppID(d) for d in extension_dirs] |
+ options = options_for_unittests.GetCopy() |
+ options.extensions_to_load = [browser_options.ExtensionToLoad( |
+ d, False) for d in extension_dirs] |
+ browser_to_create = browser_finder.FindBrowser(options) |
+ if browser_to_create: |
+ with browser_to_create.Create() as b: |
+ def AllExtensionsLoaded(): |
+ # Test iterator |
+ ids = filter(lambda e: e in b.extensions, extension_ids) |
+ return len(ids) == len(extension_ids) |
+ # Wait for all extensions to load. |
+ util.WaitFor(AllExtensionsLoaded, timeout=10) |
+ |
+ self.assertTrue(AllExtensionsLoaded) |
+ # Test len() |
+ self.assertTrue(len(b.extensions) >= len(extension_ids)) |
+ |
nduca
2013/02/01 00:25:50
why not running setTestVar?
achuithb
2013/02/06 00:23:03
It is tested in the first test. I didn't see the p
|
+ # Test GetExtensionByPath and getitem. |
+ for i in range(len(extension_ids)): |
+ e = b.extensions.GetExtensionByPath(extension_dirs[i]) |
+ self.assertTrue(e) |
+ self.assertEquals(e, b.extensions[extension_ids[i]]) |
Property changes on: tools/telemetry/telemetry/extension_unittest.py |
___________________________________________________________________ |
Added: svn:eol-style |
+ LF |