Chromium Code Reviews| 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 """Test fixture for tests involving installing/updating Chrome. | 5 """Test fixture for tests involving installing/updating Chrome. |
| 6 | 6 |
| 7 Provides an interface to install or update chrome from within a testcase, and | 7 Provides an interface to install or update chrome from within a testcase, and |
| 8 allows users to run tests using installed version of Chrome. User and system | 8 allows users to run tests using installed version of Chrome. User and system |
| 9 level installations are supported, and either one can be used for running the | 9 level installations are supported, and either one can be used for running the |
| 10 tests. Currently the only platform it supports is Windows. | 10 tests. Currently the only platform it supports is Windows. |
| 11 """ | 11 """ |
| 12 | 12 |
| 13 import atexit | |
| 14 import os | 13 import os |
| 15 import platform | |
| 16 import stat | |
| 17 import sys | 14 import sys |
| 18 import tempfile | |
| 19 import unittest | 15 import unittest |
| 20 import urllib | 16 import urllib |
| 21 | 17 |
| 22 import chrome_installer_win | 18 import chrome_installer_win |
| 23 | 19 |
| 24 _DIRECTORY = os.path.dirname(os.path.abspath(__file__)) | 20 _DIRECTORY = os.path.dirname(os.path.abspath(__file__)) |
| 25 sys.path.append(os.path.join(os.path.dirname(_DIRECTORY), 'pyautolib')) | |
| 26 sys.path.append(os.path.join(_DIRECTORY, os.path.pardir, os.path.pardir, | 21 sys.path.append(os.path.join(_DIRECTORY, os.path.pardir, os.path.pardir, |
| 27 os.path.pardir, 'third_party', 'webdriver', | 22 os.path.pardir, 'third_party', 'webdriver', |
| 28 'pylib')) | 23 'pylib')) |
| 24 sys.path.append(os.path.join(_DIRECTORY, os.path.pardir, 'pylib')) | |
| 29 | 25 |
| 30 # This import should go after sys.path is set appropriately. | 26 # This import should go after sys.path is set appropriately. |
| 31 from chrome import Chrome | 27 from chrome import Chrome |
| 32 from selenium import webdriver | 28 from selenium import webdriver |
| 33 import selenium.webdriver.chrome.service as service | 29 import selenium.webdriver.chrome.service as service |
| 34 from selenium.webdriver.chrome.service import WebDriverException | 30 from selenium.webdriver.chrome.service import WebDriverException |
| 35 | 31 |
| 36 import pyauto_utils | 32 from common import util |
| 37 | |
| 38 | |
| 39 def MakeTempDir(parent_dir=None): | |
| 40 """Creates a temporary directory and returns an absolute path to it. | |
| 41 | |
| 42 The temporary directory is automatically deleted when the python interpreter | |
| 43 exits normally. | |
| 44 | |
| 45 Args: | |
| 46 parent_dir: the directory to create the temp dir in. If None, the system | |
| 47 temp dir is used. | |
| 48 | |
| 49 Returns: | |
| 50 The absolute path to the temporary directory. | |
| 51 """ | |
| 52 path = tempfile.mkdtemp(dir=parent_dir) | |
| 53 def DeleteDir(): | |
| 54 # Don't use shutil.rmtree because it can't delete read-only files on Win. | |
| 55 for root, dirs, files in os.walk(path, topdown=False): | |
| 56 for name in files: | |
| 57 filename = os.path.join(root, name) | |
| 58 os.chmod(filename, stat.S_IWRITE) | |
| 59 os.remove(filename) | |
| 60 for name in dirs: | |
| 61 os.rmdir(os.path.join(root, name)) | |
| 62 # Delete parent directory after its contents have been removed. | |
| 63 os.rmdir(path) | |
| 64 atexit.register(DeleteDir) | |
| 65 return path | |
| 66 | 33 |
| 67 | 34 |
| 68 class InstallTest(unittest.TestCase): | 35 class InstallTest(unittest.TestCase): |
| 69 """Base updater test class. | 36 """Base updater test class. |
| 70 | 37 |
| 71 All dependencies, like Chrome installers and ChromeDriver, are downloaded at | 38 All dependencies, like Chrome installers and ChromeDriver, are downloaded at |
| 72 the beginning of the test. Dependencies are downloaded in the temp directory. | 39 the beginning of the test. Dependencies are downloaded in the temp directory. |
| 73 This download occurs only once, before the first test is executed. Each test | 40 This download occurs only once, before the first test is executed. Each test |
| 74 case starts an instance of ChromeDriver and terminates it upon completion. | 41 case starts an instance of ChromeDriver and terminates it upon completion. |
| 75 All updater tests should derive from this class. | 42 All updater tests should derive from this class. |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 147 if self._driver: | 114 if self._driver: |
| 148 try: | 115 try: |
| 149 self._driver.quit() | 116 self._driver.quit() |
| 150 except WebDriverException: | 117 except WebDriverException: |
| 151 pass | 118 pass |
| 152 options = [] | 119 options = [] |
| 153 options.extend(self._installer_options) | 120 options.extend(self._installer_options) |
| 154 if self._install_type == chrome_installer_win.InstallationType.SYSTEM: | 121 if self._install_type == chrome_installer_win.InstallationType.SYSTEM: |
| 155 options.append('--system-level') | 122 options.append('--system-level') |
| 156 if master_pref: | 123 if master_pref: |
| 157 options.append('--installerdata="%s"' % master_pref) | 124 options.append('--installerdata=%s' % master_pref) |
|
Paweł Hajdan Jr.
2012/12/13 19:28:02
What's the problem with quotes here?
nkang1
2012/12/13 19:45:59
The installer doesn't load the master preferences
| |
| 158 self._installation = chrome_installer_win.Install( | 125 self._installation = chrome_installer_win.Install( |
| 159 self._installer_paths[build], | 126 self._installer_paths[build], |
| 160 self._install_type, | 127 self._install_type, |
| 161 build, | 128 build, |
| 162 options) | 129 options) |
| 163 | 130 |
| 164 def GetInstallBuild(self): | 131 def GetInstallBuild(self): |
| 165 """Returns Chorme build to be used for install test scenarios.""" | 132 """Returns Chorme build to be used for install test scenarios.""" |
| 166 return self._install_build | 133 return self._install_build |
| 167 | 134 |
| 168 def GetUpdateBuilds(self): | 135 def GetUpdateBuilds(self): |
| 169 """Returns Chrome builds to be used for update test scenarios.""" | 136 """Returns Chrome builds to be used for update test scenarios.""" |
| 170 return self._update_builds | 137 return self._update_builds |
| 171 | 138 |
| 172 @staticmethod | 139 @staticmethod |
| 173 def _Download(url, path): | 140 def _Download(url, path): |
| 174 """Downloads a file from the specified URL. | 141 """Downloads a file from the specified URL. |
| 175 | 142 |
| 176 Args: | 143 Args: |
| 177 url: URL where the file is located. | 144 url: URL where the file is located. |
| 178 path: Location where file will be downloaded. | 145 path: Location where file will be downloaded. |
| 179 """ | 146 """ |
| 180 if not pyauto_utils.DoesUrlExist(url): | 147 if not util.DoesUrlExist(url): |
| 181 raise RuntimeError('Either the URL or the file name is invalid.') | 148 raise RuntimeError('Either the URL or the file name is invalid.') |
| 182 urllib.urlretrieve(url, path) | 149 urllib.urlretrieve(url, path) |
| 183 | 150 |
| 184 @staticmethod | 151 @staticmethod |
| 185 def SetInstallType(install_type): | 152 def SetInstallType(install_type): |
| 186 """Sets Chrome installation type. | 153 """Sets Chrome installation type. |
| 187 | 154 |
| 188 Args: | 155 Args: |
| 189 install_type: Type of installation(i.e., user or system). | 156 install_type: Type of installation(i.e., user or system). |
| 190 """ | 157 """ |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 202 Args: | 169 Args: |
| 203 install_build: A string representing the Chrome build to be used for | 170 install_build: A string representing the Chrome build to be used for |
| 204 install testing. Pass this argument only if testing | 171 install testing. Pass this argument only if testing |
| 205 fresh install scenarios. | 172 fresh install scenarios. |
| 206 update_builds: A list that contains the Chrome builds to be used for | 173 update_builds: A list that contains the Chrome builds to be used for |
| 207 testing update scenarios. Pass this argument only if | 174 testing update scenarios. Pass this argument only if |
| 208 testing upgrade scenarios. | 175 testing upgrade scenarios. |
| 209 base_url: Base url of the 'official chrome builds' page. | 176 base_url: Base url of the 'official chrome builds' page. |
| 210 options: A list that contains options to be passed to Chrome installer. | 177 options: A list that contains options to be passed to Chrome installer. |
| 211 """ | 178 """ |
| 212 system = ({'Windows': 'win', | 179 system = util.GetPlatformName() |
| 213 'Darwin': 'mac', | |
| 214 'Linux': 'linux'}).get(platform.system()) | |
| 215 InstallTest._install_build = install_build | 180 InstallTest._install_build = install_build |
| 216 InstallTest._update_builds = update_builds | 181 InstallTest._update_builds = update_builds |
| 217 InstallTest._installer_options = options | 182 InstallTest._installer_options = options |
| 218 tempdir = MakeTempDir() | 183 tempdir = util.MakeTempDir() |
| 219 builds = [] | 184 builds = [] |
| 220 if InstallTest._install_build: | 185 if InstallTest._install_build: |
| 221 builds.append(InstallTest._install_build) | 186 builds.append(InstallTest._install_build) |
| 222 if InstallTest._update_builds: | 187 if InstallTest._update_builds: |
| 223 builds.extend(InstallTest._update_builds) | 188 builds.extend(InstallTest._update_builds) |
| 224 # Remove any duplicate build numbers. | 189 # Remove any duplicate build numbers. |
| 225 builds = list(frozenset(builds)) | 190 builds = list(frozenset(builds)) |
| 226 for build in builds: | 191 for build in builds: |
| 227 url = '%s%s/%s/mini_installer.exe' % (base_url, build, system) | 192 url = '%s%s/%s/mini_installer.exe' % (base_url, build, system) |
| 228 installer_path = os.path.join(tempdir, 'mini_installer_%s.exe' % build) | 193 installer_path = os.path.join(tempdir, 'mini_installer_%s.exe' % build) |
| 229 InstallTest._installer_paths[build] = installer_path | 194 InstallTest._installer_paths[build] = installer_path |
| 230 InstallTest._Download(url, installer_path) | 195 InstallTest._Download(url, installer_path) |
| 231 InstallTest._chrome_driver = os.path.join(tempdir, 'chromedriver.exe') | 196 InstallTest._chrome_driver = os.path.join(tempdir, 'chromedriver.exe') |
| 232 url = '%s%s/%s/%s/chromedriver.exe' % (base_url, build, system, | 197 url = '%s%s/%s/%s/chromedriver.exe' % (base_url, build, system, |
| 233 'chrome-win32.test') | 198 'chrome-win32.test') |
| 234 InstallTest._Download(url, InstallTest._chrome_driver) | 199 InstallTest._Download(url, InstallTest._chrome_driver) |
| OLD | NEW |