1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 """TestEnvironment classes.
7 These classes abstract away the various setups needed to run the WebDriver java
8 tests in various environments.
17 _THIS_DIR = os.path.abspath(os.path.dirname(__file__))
20 sys.path.insert(0, os.path.join(chrome_paths.GetSrc(), 'build', 'android'))
21 from pylib import android_commands
22 from pylib import forwarder
23 from pylib import valgrind_tools
25 ANDROID_TEST_HTTP_PORT = 2311
26 ANDROID_TEST_HTTPS_PORT = 2411
29 execfile(os.path.join(_THIS_DIR, 'test_expectations'), _EXPECTATIONS)
32 class BaseTestEnvironment(object):
33 """Manages the environment java tests require to run."""
35 def __init__(self, chrome_version='HEAD'):
36 """Initializes a desktop test environment.
39 chrome_version: Optionally a chrome version to run the tests against.
41 self._chrome_version = chrome_version
45 raise NotImplementedError
47 def GlobalSetUp(self):
48 """Sets up the global test environment state."""
51 def GlobalTearDown(self):
52 """Tears down the global test environment state."""
55 def GetDisabledJavaTestMatchers(self):
56 """Get the list of disabled java test matchers.
59 List of disabled test matchers, which may contain '*' wildcards.
61 return _EXPECTATIONS['GetDisabledTestMatchers'](
62 self.GetOS(), self._chrome_version)
64 def GetPassedJavaTests(self):
65 """Get the list of passed java tests.
68 List of passed test names.
70 with open(os.path.join(_THIS_DIR, 'java_tests.txt'), 'r') as f:
71 return _EXPECTATIONS['ApplyJavaTestFilter'](
72 self.GetOS(), self._chrome_version,
73 [t.strip('\n') for t in f.readlines()])
76 class DesktopTestEnvironment(BaseTestEnvironment):
77 """Manages the environment java tests require to run on Desktop."""
81 return util.GetPlatformName()
84 class AndroidTestEnvironment(DesktopTestEnvironment):
85 """Manages the environment java tests require to run on Android."""
87 def __init__(self, package, chrome_version='HEAD'):
88 super(AndroidTestEnvironment, self).__init__(chrome_version)
89 self._package = package
91 self._forwarder = None
94 def GlobalSetUp(self):
95 os.putenv('TEST_HTTP_PORT', str(ANDROID_TEST_HTTP_PORT))
96 os.putenv('TEST_HTTPS_PORT', str(ANDROID_TEST_HTTPS_PORT))
97 self._adb = android_commands.AndroidCommands()
98 forwarder.Forwarder.Map(
99 [(ANDROID_TEST_HTTP_PORT, ANDROID_TEST_HTTP_PORT),
100 (ANDROID_TEST_HTTPS_PORT, ANDROID_TEST_HTTPS_PORT)],
104 def GlobalTearDown(self):
105 forwarder.Forwarder.UnmapAllDevicePorts(self._adb)
109 return 'android:%s' % self._package