Fix OOP <webview> resize and autosize.
[chromium-blink-merge.git] / tools / perf / page_sets / login_helpers / chrome_login.py
blob33dad0fcc27159deea6d7694942dce3aead8adcc
1 # Copyright 2015 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 from page_sets.login_helpers import login_utils
6 from telemetry.core import util
7 from telemetry.page import action_runner as action_runner_module
10 def GetGaiaContext(tab):
11 """Returns Gaia's login page context."""
12 for context in tab.GetWebviewContexts():
13 if context.GetUrl().startswith('https://accounts.google.com/'):
14 return context
15 return None
18 def LoginChromeAccount(action_runner, credential,
19 credentials_path=login_utils.DEFAULT_CREDENTIAL_PATH):
20 """Logs in a Gaia account into Chrome.
22 This function navigates the tab into Chrome's login page and logs in a user
23 using credentials in |credential| part of the |credentials_path| file.
25 Args:
26 action_runner: Action runner responsible for running actions on the page.
27 credential: The credential to retrieve from the credentials file
28 (type string).
29 credentials_path: The string that specifies the path to credential file.
31 Raises:
32 exceptions.Error: See GetWebviewContexts() and ExecuteJavaScript()
33 for a detailed list of possible exceptions.
34 """
35 account_name, password = login_utils.GetAccountNameAndPassword(
36 credential, credentials_path=credentials_path)
38 action_runner.Navigate('chrome://chrome-signin')
40 # Get the Gaia webview context within the sign in extension to create a Gaia
41 # action_runner. The action runner will then execute JS in the Gaia context.
42 gaia_context = util.WaitFor(lambda: GetGaiaContext(action_runner.tab), 5)
43 if not gaia_context:
44 raise RuntimeError('Can not find GAIA webview context for sign in.')
45 gaia_action_runner = action_runner_module.ActionRunner(gaia_context)
47 new_flow = gaia_action_runner.EvaluateJavaScript(
48 'document.querySelector("#gaia_firsform") != null')
49 gaia_form_id = 'gaia_firstform' if new_flow else 'gaia_loginform'
50 login_utils.InputForm(gaia_action_runner, account_name, input_id='Email',
51 form_id=gaia_form_id)
52 if new_flow:
53 gaia_action_runner.ClickElement(selector='#%s #next' % gaia_form_id)
54 login_utils.InputForm(gaia_action_runner, password, input_id='Passwd',
55 form_id=gaia_form_id)
56 gaia_action_runner.ClickElement(selector='#signIn')
57 action_runner.WaitForNavigate()