• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/python2
2#
3# Copyright 2016 The Chromium OS Authors. All rights reserved.
4# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6
7'''Make Chrome automatically log in.'''
8
9# This sets up import paths for autotest.
10import common
11import argparse
12import getpass
13import sys
14
15from autotest_lib.client.common_lib.cros import chrome
16
17
18def main(args):
19    '''The main function.
20
21    @param args: list of string args passed to program
22    '''
23
24    parser = argparse.ArgumentParser(description=__doc__)
25    parser.add_argument('-a', '--arc', action='store_true',
26                        help='Enable ARC and wait for it to start.')
27    parser.add_argument('--arc_timeout', type=int, default=None,
28                        help='Enable ARC and wait for it to start.')
29    parser.add_argument('-d', '--dont_override_profile', action='store_true',
30                        help='Keep files from previous sessions.')
31    parser.add_argument('-u', '--username',
32                        help='Log in as provided username.')
33    parser.add_argument('--enable_default_apps', action='store_true',
34                        help='Enable default applications.')
35    parser.add_argument('-p', '--password',
36                        help='Log in with provided password.')
37    parser.add_argument('-w', '--no-startup-window', action='store_true',
38                        help='Prevent startup window from opening (no doodle).')
39    parser.add_argument('--no-arc-syncs', action='store_true',
40                        help='Prevent ARC sync behavior as much as possible.')
41    parser.add_argument('--toggle_ndk', action='store_true',
42                        help='Toggle the translation from houdini to ndk')
43    parser.add_argument('--nativebridge64', action='store_true',
44                        help='Enables the experiment for 64-bit native bridges')
45    parser.add_argument('--url', help='Navigate to URL.')
46    args = parser.parse_args(args)
47
48    if args.password:
49        password = args.password
50    elif args.username:
51        password = getpass.getpass()
52
53    browser_args = []
54    if args.no_startup_window:
55        browser_args.append('--no-startup-window')
56    if args.toggle_ndk:
57        browser_args.append('--enable-features=ArcNativeBridgeExperiment')
58    if args.nativebridge64:
59        browser_args.append(
60            '--enable-features=ArcNativeBridge64BitSupportExperiment')
61
62    # Avoid calling close() on the Chrome object; this keeps the session active.
63    cr = chrome.Chrome(
64        extra_browser_args=browser_args,
65        arc_mode=('enabled' if args.arc else None),
66        arc_timeout=args.arc_timeout,
67        disable_app_sync=args.no_arc_syncs,
68        disable_play_auto_install=args.no_arc_syncs,
69        username=args.username,
70        password=(password if args.username else None),
71        gaia_login=(args.username is not None),
72        disable_default_apps=(not args.enable_default_apps),
73        dont_override_profile=args.dont_override_profile)
74    if args.url:
75      tab = cr.browser.tabs[0]
76      tab.Navigate(args.url)
77
78
79if __name__ == '__main__':
80    sys.exit(main(sys.argv[1:]))
81