Dennis Jeffrey | dffc0bd | 2013-05-03 13:24:31 -0700 | [diff] [blame] | 1 | # Copyright (c) 2013 The Chromium OS 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. |
| 4 | |
Achuith Bhandarkar | f3469ec | 2016-06-08 16:58:57 -0700 | [diff] [blame] | 5 | import logging, os, re |
Achuith Bhandarkar | a2df47b | 2013-10-09 21:23:15 -0700 | [diff] [blame] | 6 | |
Nicolas Boichat | 451e466 | 2016-07-16 07:51:01 +0800 | [diff] [blame] | 7 | from autotest_lib.client.common_lib.cros import arc_util |
Don Garrett | 11b1397 | 2015-09-11 17:37:53 +0000 | [diff] [blame] | 8 | from autotest_lib.client.cros import constants |
Achuith Bhandarkar | 88a2bab | 2015-07-09 17:36:25 -0700 | [diff] [blame] | 9 | from autotest_lib.client.bin import utils |
Prathmesh Prabhu | c3961df | 2015-07-21 10:44:54 -0700 | [diff] [blame] | 10 | from telemetry.core import cros_interface, exceptions, util |
Achuith Bhandarkar | b058a8f | 2015-07-02 01:29:05 -0700 | [diff] [blame] | 11 | from telemetry.internal.browser import browser_finder, browser_options |
| 12 | from telemetry.internal.browser import extension_to_load |
Achuith Bhandarkar | 704134d | 2015-03-05 17:31:57 -0800 | [diff] [blame] | 13 | |
| 14 | Error = exceptions.Error |
Dennis Jeffrey | dffc0bd | 2013-05-03 13:24:31 -0700 | [diff] [blame] | 15 | |
| 16 | |
Victor Hsieh | 43651ac | 2016-04-20 12:52:21 -0700 | [diff] [blame] | 17 | # Cached result of whether ARC is available on current device. |
| 18 | _arc_available = None |
| 19 | |
| 20 | |
Nicolas Norvez | 56f9b23 | 2016-06-23 17:58:59 -0700 | [diff] [blame] | 21 | def is_arc_available(): |
Victor Hsieh | 000240b | 2016-04-11 16:04:31 -0700 | [diff] [blame] | 22 | """Returns true if ARC is available on current device.""" |
Victor Hsieh | 43651ac | 2016-04-20 12:52:21 -0700 | [diff] [blame] | 23 | global _arc_available |
| 24 | if _arc_available is not None: |
| 25 | return _arc_available |
| 26 | |
| 27 | def _check_lsb_release(): |
| 28 | lsb_release = '/etc/lsb-release' |
| 29 | if not os.path.exists(lsb_release): |
| 30 | return False |
| 31 | with open(lsb_release) as f: |
| 32 | for line in f: |
| 33 | if line.startswith('CHROMEOS_ARC_VERSION='): |
| 34 | return True |
| 35 | return False |
| 36 | |
| 37 | _arc_available = _check_lsb_release() |
| 38 | return _arc_available |
| 39 | |
| 40 | |
Achuith Bhandarkar | f3469ec | 2016-06-08 16:58:57 -0700 | [diff] [blame] | 41 | def NormalizeEmail(username): |
| 42 | """Remove dots from username. Add @gmail.com if necessary. |
| 43 | |
| 44 | TODO(achuith): Get rid of this when crbug.com/358427 is fixed. |
| 45 | |
| 46 | @param username: username/email to be scrubbed. |
| 47 | """ |
| 48 | parts = re.split('@', username) |
| 49 | parts[0] = re.sub('\.', '', parts[0]) |
| 50 | |
| 51 | if len(parts) == 1: |
| 52 | parts.append('gmail.com') |
| 53 | return '@'.join(parts) |
| 54 | |
| 55 | |
Achuith Bhandarkar | ed49893 | 2013-07-16 17:01:40 -0700 | [diff] [blame] | 56 | class Chrome(object): |
Ricky Liang | 2bfa564 | 2016-11-09 10:18:37 +0800 | [diff] [blame] | 57 | """Wrapper for creating a telemetry browser instance with extensions. |
| 58 | |
| 59 | The recommended way to use this class is to create the instance using the |
| 60 | with statement: |
| 61 | |
| 62 | >>> with chrome.Chrome(...) as cr: |
| 63 | >>> # Do whatever you need with cr. |
| 64 | >>> pass |
| 65 | |
| 66 | This will make sure all the clean-up functions are called. If you really |
| 67 | need to use this class without the with statement, make sure to call the |
| 68 | close() method once you're done with the Chrome instance. |
| 69 | """ |
Achuith Bhandarkar | 86c4681 | 2013-07-15 17:13:39 -0700 | [diff] [blame] | 70 | |
| 71 | |
Achuith Bhandarkar | ed49893 | 2013-07-16 17:01:40 -0700 | [diff] [blame] | 72 | BROWSER_TYPE_LOGIN = 'system' |
| 73 | BROWSER_TYPE_GUEST = 'system-guest' |
Achuith Bhandarkar | 86c4681 | 2013-07-15 17:13:39 -0700 | [diff] [blame] | 74 | |
| 75 | |
Achuith Bhandarkar | b0e9907 | 2013-11-18 16:15:03 -0800 | [diff] [blame] | 76 | def __init__(self, logged_in=True, extension_paths=[], autotest_ext=False, |
Achuith Bhandarkar | b7ef5e5 | 2014-03-20 14:18:45 -0700 | [diff] [blame] | 77 | is_component=True, num_tries=3, extra_browser_args=None, |
Achuith Bhandarkar | 882a8ab | 2014-08-26 15:51:20 -0700 | [diff] [blame] | 78 | clear_enterprise_policy=True, dont_override_profile=False, |
Achuith Bhandarkar | a2bceaf | 2014-11-14 12:10:16 -0800 | [diff] [blame] | 79 | disable_gaia_services=True, disable_default_apps = True, |
| 80 | auto_login=True, gaia_login=False, |
Victor Hsieh | 000240b | 2016-04-11 16:04:31 -0700 | [diff] [blame] | 81 | username=None, password=None, gaia_id=None, |
F#m | d6d56ba | 2016-06-10 14:40:52 -0700 | [diff] [blame] | 82 | arc_mode=None, disable_arc_opt_in=True): |
Dean Liao | b12e2ee | 2013-11-19 16:49:12 +0800 | [diff] [blame] | 83 | """ |
Achuith Bhandarkar | 944405a | 2013-11-21 14:47:48 -0800 | [diff] [blame] | 84 | Constructor of telemetry wrapper. |
| 85 | |
| 86 | @param logged_in: Regular user (True) or guest user (False). |
| 87 | @param extension_paths: path of unpacked extension to install. |
| 88 | @param autotest_ext: Load a component extension with privileges to |
| 89 | invoke chrome.autotestPrivate. |
| 90 | @param is_component: Whether extensions should be loaded as component |
| 91 | extensions. |
Achuith Bhandarkar | b7ef5e5 | 2014-03-20 14:18:45 -0700 | [diff] [blame] | 92 | @param num_tries: Number of attempts to log in. |
Dean Liao | b12e2ee | 2013-11-19 16:49:12 +0800 | [diff] [blame] | 93 | @param extra_browser_args: Additional argument(s) to pass to the |
Achuith Bhandarkar | 3875e0c | 2014-03-20 14:17:31 -0700 | [diff] [blame] | 94 | browser. It can be a string or a list. |
Achuith Bhandarkar | 5d6c26c | 2014-04-25 11:19:38 -0700 | [diff] [blame] | 95 | @param clear_enterprise_policy: Clear enterprise policy before |
| 96 | logging in. |
Achuith Bhandarkar | 882a8ab | 2014-08-26 15:51:20 -0700 | [diff] [blame] | 97 | @param dont_override_profile: Don't delete cryptohome before login. |
| 98 | Telemetry will output a warning with this |
| 99 | option. |
Achuith Bhandarkar | 3c654f3 | 2014-09-29 06:33:35 -0700 | [diff] [blame] | 100 | @param disable_gaia_services: For enterprise autotests, this option may |
| 101 | be used to enable policy fetch. |
Achuith Bhandarkar | a2bceaf | 2014-11-14 12:10:16 -0800 | [diff] [blame] | 102 | @param disable_default_apps: For tests that exercise default apps. |
Achuith Bhandarkar | 1cce9dc | 2014-02-05 14:23:34 -0800 | [diff] [blame] | 103 | @param auto_login: Does not login automatically if this is False. |
Achuith Bhandarkar | 3875e0c | 2014-03-20 14:17:31 -0700 | [diff] [blame] | 104 | Useful if you need to examine oobe. |
| 105 | @param gaia_login: Logs in to real gaia. |
Achuith Bhandarkar | 1cce9dc | 2014-02-05 14:23:34 -0800 | [diff] [blame] | 106 | @param username: Log in using this username instead of the default. |
Alexander Alekseev | d968286 | 2015-10-01 22:42:49 -0700 | [diff] [blame] | 107 | @param password: Log in using this password instead of the default. |
| 108 | @param gaia_id: Log in using this gaia_id instead of the default. |
Victor Hsieh | 43651ac | 2016-04-20 12:52:21 -0700 | [diff] [blame] | 109 | @param arc_mode: How ARC instance should be started. Default is to not |
| 110 | start. |
F#m | d6d56ba | 2016-06-10 14:40:52 -0700 | [diff] [blame] | 111 | @param disable_arc_opt_in: For opt in flow autotest. This option is used |
| 112 | to disable the arc opt in flow. |
Dean Liao | b12e2ee | 2013-11-19 16:49:12 +0800 | [diff] [blame] | 113 | """ |
Achuith Bhandarkar | a2df47b | 2013-10-09 21:23:15 -0700 | [diff] [blame] | 114 | self._autotest_ext_path = None |
| 115 | if autotest_ext: |
| 116 | self._autotest_ext_path = os.path.join(os.path.dirname(__file__), |
| 117 | 'autotest_private_ext') |
| 118 | extension_paths.append(self._autotest_ext_path) |
| 119 | |
Achuith Bhandarkar | 7fb57f7 | 2013-08-29 15:29:06 -0700 | [diff] [blame] | 120 | finder_options = browser_options.BrowserFinderOptions() |
Nicolas Norvez | 56f9b23 | 2016-06-23 17:58:59 -0700 | [diff] [blame] | 121 | if is_arc_available() and arc_util.should_start_arc(arc_mode): |
F#m | d6d56ba | 2016-06-10 14:40:52 -0700 | [diff] [blame] | 122 | if disable_arc_opt_in: |
| 123 | finder_options.browser_options.AppendExtraBrowserArgs( |
| 124 | arc_util.get_extra_chrome_flags()) |
Victor Hsieh | 43651ac | 2016-04-20 12:52:21 -0700 | [diff] [blame] | 125 | logged_in = True |
| 126 | |
Achuith Bhandarkar | ed49893 | 2013-07-16 17:01:40 -0700 | [diff] [blame] | 127 | self._browser_type = (self.BROWSER_TYPE_LOGIN |
| 128 | if logged_in else self.BROWSER_TYPE_GUEST) |
Achuith Bhandarkar | f130c40 | 2013-09-11 14:39:22 -0700 | [diff] [blame] | 129 | finder_options.browser_type = self.browser_type |
Dean Liao | b12e2ee | 2013-11-19 16:49:12 +0800 | [diff] [blame] | 130 | if extra_browser_args: |
| 131 | finder_options.browser_options.AppendExtraBrowserArgs( |
| 132 | extra_browser_args) |
Achuith Bhandarkar | f130c40 | 2013-09-11 14:39:22 -0700 | [diff] [blame] | 133 | |
Achuith Bhandarkar | 3e5051d | 2013-10-15 15:20:12 -0700 | [diff] [blame] | 134 | # finder options must be set before parse_args(), browser options must |
| 135 | # be set before Create(). |
Todd Broch | eb6f481 | 2014-04-29 16:04:28 -0700 | [diff] [blame] | 136 | # TODO(crbug.com/360890) Below MUST be '2' so that it doesn't inhibit |
| 137 | # autotest debug logs |
| 138 | finder_options.verbosity = 2 |
Achuith Bhandarkar | dafc9a5 | 2013-09-24 15:26:33 +0200 | [diff] [blame] | 139 | finder_options.CreateParser().parse_args(args=[]) |
Achuith Bhandarkar | a2df47b | 2013-10-09 21:23:15 -0700 | [diff] [blame] | 140 | b_options = finder_options.browser_options |
| 141 | b_options.disable_component_extensions_with_background_pages = False |
| 142 | b_options.create_browser_with_oobe = True |
Achuith Bhandarkar | 5d6c26c | 2014-04-25 11:19:38 -0700 | [diff] [blame] | 143 | b_options.clear_enterprise_policy = clear_enterprise_policy |
Achuith Bhandarkar | 882a8ab | 2014-08-26 15:51:20 -0700 | [diff] [blame] | 144 | b_options.dont_override_profile = dont_override_profile |
Achuith Bhandarkar | 3c654f3 | 2014-09-29 06:33:35 -0700 | [diff] [blame] | 145 | b_options.disable_gaia_services = disable_gaia_services |
Achuith Bhandarkar | a2bceaf | 2014-11-14 12:10:16 -0800 | [diff] [blame] | 146 | b_options.disable_default_apps = disable_default_apps |
| 147 | b_options.disable_component_extensions_with_background_pages = disable_default_apps |
Achuith Bhandarkar | 1cce9dc | 2014-02-05 14:23:34 -0800 | [diff] [blame] | 148 | |
| 149 | b_options.auto_login = auto_login |
Achuith Bhandarkar | 3875e0c | 2014-03-20 14:17:31 -0700 | [diff] [blame] | 150 | b_options.gaia_login = gaia_login |
F#m | d6d56ba | 2016-06-10 14:40:52 -0700 | [diff] [blame] | 151 | |
Nicolas Norvez | 56f9b23 | 2016-06-23 17:58:59 -0700 | [diff] [blame] | 152 | if is_arc_available() and not disable_arc_opt_in: |
F#m | d6d56ba | 2016-06-10 14:40:52 -0700 | [diff] [blame] | 153 | arc_util.set_browser_options_for_opt_in(b_options) |
| 154 | |
Achuith Bhandarkar | 1cce9dc | 2014-02-05 14:23:34 -0800 | [diff] [blame] | 155 | self.username = b_options.username if username is None else username |
| 156 | self.password = b_options.password if password is None else password |
Achuith Bhandarkar | f3469ec | 2016-06-08 16:58:57 -0700 | [diff] [blame] | 157 | self.username = NormalizeEmail(self.username) |
Achuith Bhandarkar | 1cce9dc | 2014-02-05 14:23:34 -0800 | [diff] [blame] | 158 | b_options.username = self.username |
| 159 | b_options.password = self.password |
Achuith Bhandarkar | 6f4accc | 2016-08-23 14:03:44 -0700 | [diff] [blame] | 160 | self.gaia_id = b_options.gaia_id if gaia_id is None else gaia_id |
| 161 | b_options.gaia_id = self.gaia_id |
Achuith Bhandarkar | a2df47b | 2013-10-09 21:23:15 -0700 | [diff] [blame] | 162 | |
Shuhei Takahashi | 8462b88 | 2016-05-31 17:27:32 +0900 | [diff] [blame] | 163 | self.arc_mode = arc_mode |
| 164 | |
Achuith Bhandarkar | 531a62a | 2016-04-13 11:09:43 -0700 | [diff] [blame] | 165 | if logged_in: |
Achuith Bhandarkar | 6f4accc | 2016-08-23 14:03:44 -0700 | [diff] [blame] | 166 | extensions_to_load = b_options.extensions_to_load |
| 167 | for path in extension_paths: |
| 168 | extension = extension_to_load.ExtensionToLoad( |
| 169 | path, self.browser_type, is_component=is_component) |
| 170 | extensions_to_load.append(extension) |
| 171 | self._extensions_to_load = extensions_to_load |
Achuith Bhandarkar | 531a62a | 2016-04-13 11:09:43 -0700 | [diff] [blame] | 172 | |
David James | 54a830e | 2015-05-06 17:21:47 -0700 | [diff] [blame] | 173 | # Turn on collection of Chrome coredumps via creation of a magic file. |
| 174 | # (Without this, Chrome coredumps are trashed.) |
Don Garrett | 11b1397 | 2015-09-11 17:37:53 +0000 | [diff] [blame] | 175 | open(constants.CHROME_CORE_MAGIC_FILE, 'w').close() |
David James | 54a830e | 2015-05-06 17:21:47 -0700 | [diff] [blame] | 176 | |
Achuith Bhandarkar | b0e9907 | 2013-11-18 16:15:03 -0800 | [diff] [blame] | 177 | for i in range(num_tries): |
| 178 | try: |
| 179 | browser_to_create = browser_finder.FindBrowser(finder_options) |
Achuith Bhandarkar | a2bceaf | 2014-11-14 12:10:16 -0800 | [diff] [blame] | 180 | self._browser = browser_to_create.Create(finder_options) |
Nicolas Norvez | 56f9b23 | 2016-06-23 17:58:59 -0700 | [diff] [blame] | 181 | if is_arc_available(): |
khmel | e043429 | 2016-11-10 13:27:57 -0800 | [diff] [blame^] | 182 | if disable_arc_opt_in: |
| 183 | if arc_util.should_start_arc(arc_mode): |
| 184 | arc_util.enable_arc_setting(self.browser) |
| 185 | else: |
F#m | d6d56ba | 2016-06-10 14:40:52 -0700 | [diff] [blame] | 186 | arc_util.opt_in(self.browser) |
Ricky Zhou | cf350ee | 2016-06-13 15:47:33 -0700 | [diff] [blame] | 187 | arc_util.post_processing_after_browser(self) |
Achuith Bhandarkar | b0e9907 | 2013-11-18 16:15:03 -0800 | [diff] [blame] | 188 | break |
khmel | a7cf9dd | 2016-09-20 10:50:23 -0700 | [diff] [blame] | 189 | except exceptions.LoginException as e: |
Achuith Bhandarkar | f800edf | 2013-12-06 13:37:52 -0800 | [diff] [blame] | 190 | logging.error('Timed out logging in, tries=%d, error=%s', |
| 191 | i, repr(e)) |
Achuith Bhandarkar | b0e9907 | 2013-11-18 16:15:03 -0800 | [diff] [blame] | 192 | if i == num_tries-1: |
| 193 | raise |
John Budorick | 0038e10 | 2016-11-08 10:39:15 -0800 | [diff] [blame] | 194 | self._browser.platform.network_controller.InitializeIfNeeded() |
Achuith Bhandarkar | ed49893 | 2013-07-16 17:01:40 -0700 | [diff] [blame] | 195 | |
| 196 | def __enter__(self): |
| 197 | return self |
| 198 | |
| 199 | |
| 200 | def __exit__(self, *args): |
Derek Basehore | 41acbf8 | 2014-07-11 18:34:30 -0700 | [diff] [blame] | 201 | self.close() |
Achuith Bhandarkar | ed49893 | 2013-07-16 17:01:40 -0700 | [diff] [blame] | 202 | |
| 203 | |
| 204 | @property |
| 205 | def browser(self): |
| 206 | """Returns a telemetry browser instance.""" |
| 207 | return self._browser |
| 208 | |
| 209 | |
| 210 | def get_extension(self, extension_path): |
| 211 | """Fetches a telemetry extension instance given the extension path.""" |
| 212 | for ext in self._extensions_to_load: |
| 213 | if extension_path == ext.path: |
| 214 | return self.browser.extensions[ext] |
| 215 | return None |
| 216 | |
| 217 | |
| 218 | @property |
Achuith Bhandarkar | a2df47b | 2013-10-09 21:23:15 -0700 | [diff] [blame] | 219 | def autotest_ext(self): |
| 220 | """Returns the autotest extension.""" |
| 221 | return self.get_extension(self._autotest_ext_path) |
| 222 | |
| 223 | |
| 224 | @property |
| 225 | def login_status(self): |
| 226 | """Returns login status.""" |
| 227 | ext = self.autotest_ext |
| 228 | if not ext: |
| 229 | return None |
| 230 | |
| 231 | ext.ExecuteJavaScript(''' |
| 232 | window.__login_status = null; |
| 233 | chrome.autotestPrivate.loginStatus(function(s) { |
| 234 | window.__login_status = s; |
| 235 | }); |
| 236 | ''') |
| 237 | return ext.EvaluateJavaScript('window.__login_status') |
| 238 | |
| 239 | |
Victor Hsieh | fc3417e | 2016-03-25 16:49:59 -0700 | [diff] [blame] | 240 | def get_visible_notifications(self): |
| 241 | """Returns an array of visible notifications of Chrome. |
| 242 | |
| 243 | For specific type of each notification, please refer to Chromium's |
| 244 | chrome/common/extensions/api/autotest_private.idl. |
| 245 | """ |
| 246 | ext = self.autotest_ext |
| 247 | if not ext: |
| 248 | return None |
| 249 | |
| 250 | ext.ExecuteJavaScript(''' |
| 251 | window.__items = null; |
| 252 | chrome.autotestPrivate.getVisibleNotifications(function(items) { |
| 253 | window.__items = items; |
| 254 | }); |
| 255 | ''') |
| 256 | if ext.EvaluateJavaScript('window.__items') is None: |
| 257 | return None |
| 258 | return ext.EvaluateJavaScript('window.__items') |
| 259 | |
| 260 | |
Achuith Bhandarkar | a2df47b | 2013-10-09 21:23:15 -0700 | [diff] [blame] | 261 | @property |
Achuith Bhandarkar | ed49893 | 2013-07-16 17:01:40 -0700 | [diff] [blame] | 262 | def browser_type(self): |
| 263 | """Returns the browser_type.""" |
| 264 | return self._browser_type |
Achuith Bhandarkar | 49c72d9 | 2013-07-25 11:10:10 -0700 | [diff] [blame] | 265 | |
| 266 | |
Achuith Bhandarkar | 16ee977 | 2015-01-23 17:18:18 -0800 | [diff] [blame] | 267 | @staticmethod |
| 268 | def did_browser_crash(func): |
Achuith Bhandarkar | 7fb57f7 | 2013-08-29 15:29:06 -0700 | [diff] [blame] | 269 | """Runs func, returns True if the browser crashed, False otherwise. |
| 270 | |
| 271 | @param func: function to run. |
| 272 | |
| 273 | """ |
Achuith Bhandarkar | 5abf60b | 2013-08-01 12:35:53 -0700 | [diff] [blame] | 274 | try: |
| 275 | func() |
khmel | a7cf9dd | 2016-09-20 10:50:23 -0700 | [diff] [blame] | 276 | except Error: |
Achuith Bhandarkar | 5abf60b | 2013-08-01 12:35:53 -0700 | [diff] [blame] | 277 | return True |
| 278 | return False |
Derek Basehore | 41acbf8 | 2014-07-11 18:34:30 -0700 | [diff] [blame] | 279 | |
| 280 | |
Achuith Bhandarkar | 88a2bab | 2015-07-09 17:36:25 -0700 | [diff] [blame] | 281 | @staticmethod |
| 282 | def wait_for_browser_restart(func): |
| 283 | """Runs func, and waits for a browser restart. |
| 284 | |
| 285 | @param func: function to run. |
| 286 | |
| 287 | """ |
| 288 | _cri = cros_interface.CrOSInterface() |
| 289 | pid = _cri.GetChromePid() |
| 290 | Chrome.did_browser_crash(func) |
| 291 | utils.poll_for_condition(lambda: pid != _cri.GetChromePid(), timeout=60) |
| 292 | |
| 293 | |
Achuith Bhandarkar | 16ee977 | 2015-01-23 17:18:18 -0800 | [diff] [blame] | 294 | def wait_for_browser_to_come_up(self): |
| 295 | """Waits for the browser to come up. This should only be called after a |
| 296 | browser crash. |
| 297 | """ |
| 298 | def _BrowserReady(cr): |
| 299 | tabs = [] # Wrapper for pass by reference. |
| 300 | if self.did_browser_crash( |
| 301 | lambda: tabs.append(cr.browser.tabs.New())): |
| 302 | return False |
| 303 | try: |
| 304 | tabs[0].Close() |
Achuith Bhandarkar | fab82d1 | 2015-02-26 11:05:35 -0800 | [diff] [blame] | 305 | except: |
Achuith Bhandarkar | 16ee977 | 2015-01-23 17:18:18 -0800 | [diff] [blame] | 306 | # crbug.com/350941 |
| 307 | logging.error('Timed out closing tab') |
| 308 | return True |
| 309 | util.WaitFor(lambda: _BrowserReady(self), timeout=10) |
| 310 | |
| 311 | |
Derek Basehore | 41acbf8 | 2014-07-11 18:34:30 -0700 | [diff] [blame] | 312 | def close(self): |
Achuith Bhandarkar | 1cc4157 | 2016-09-30 09:47:46 -0700 | [diff] [blame] | 313 | """Closes the browser. |
| 314 | """ |
khmel | a7cf9dd | 2016-09-20 10:50:23 -0700 | [diff] [blame] | 315 | try: |
Nicolas Norvez | 56f9b23 | 2016-06-23 17:58:59 -0700 | [diff] [blame] | 316 | if is_arc_available(): |
Shuhei Takahashi | 8462b88 | 2016-05-31 17:27:32 +0900 | [diff] [blame] | 317 | arc_util.pre_processing_before_close(self) |
Hidehiko Abe | 202ed32 | 2016-04-14 15:08:43 +0900 | [diff] [blame] | 318 | finally: |
Ricky Liang | 2bfa564 | 2016-11-09 10:18:37 +0800 | [diff] [blame] | 319 | # Calling platform.StopAllLocalServers() to tear down the telemetry |
| 320 | # server processes such as the one started by |
| 321 | # platform.SetHTTPServerDirectories(). Not calling this function |
| 322 | # will leak the process and may affect test results. |
| 323 | # (crbug.com/663387) |
| 324 | self._browser.platform.StopAllLocalServers() |
Hidehiko Abe | 202ed32 | 2016-04-14 15:08:43 +0900 | [diff] [blame] | 325 | self._browser.Close() |
John Budorick | 0038e10 | 2016-11-08 10:39:15 -0800 | [diff] [blame] | 326 | self._browser.platform.network_controller.Close() |