aboutsummaryrefslogtreecommitdiff
path: root/client/bin/autologin.py
blob: 681b14405e7adad572ff68e02c362c7b548056a2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/python2
#
# Copyright 2016 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

'''Make Chrome automatically log in.'''

# This sets up import paths for autotest.
import common
import argparse
import getpass
import sys

from autotest_lib.client.common_lib.cros import chrome


def main(args):
    '''The main function.

    @param args: list of string args passed to program
    '''

    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument('-a', '--arc', action='store_true',
                        help='Enable ARC and wait for it to start.')
    parser.add_argument('--arc_timeout', type=int, default=None,
                        help='Enable ARC and wait for it to start.')
    parser.add_argument('-d', '--dont_override_profile', action='store_true',
                        help='Keep files from previous sessions.')
    parser.add_argument('-u', '--username',
                        help='Log in as provided username.')
    parser.add_argument('--enable_default_apps', action='store_true',
                        help='Enable default applications.')
    parser.add_argument('-p', '--password',
                        help='Log in with provided password.')
    parser.add_argument('-w', '--no-startup-window', action='store_true',
                        help='Prevent startup window from opening (no doodle).')
    parser.add_argument('--no-arc-syncs', action='store_true',
                        help='Prevent ARC sync behavior as much as possible.')
    parser.add_argument('--toggle_ndk', action='store_true',
                        help='Toggle the translation from houdini to ndk')
    parser.add_argument('--nativebridge64', action='store_true',
                        help='Enables the experiment for 64-bit native bridges')
    parser.add_argument('--url', help='Navigate to URL.')
    args = parser.parse_args(args)

    if args.password:
        password = args.password
    elif args.username:
        password = getpass.getpass()

    browser_args = []
    if args.no_startup_window:
        browser_args.append('--no-startup-window')
    if args.toggle_ndk:
        browser_args.append('--enable-features=ArcNativeBridgeExperiment')
    if args.nativebridge64:
        browser_args.append(
            '--enable-features=ArcNativeBridge64BitSupportExperiment')

    # Avoid calling close() on the Chrome object; this keeps the session active.
    cr = chrome.Chrome(
        extra_browser_args=browser_args,
        arc_mode=('enabled' if args.arc else None),
        arc_timeout=args.arc_timeout,
        disable_app_sync=args.no_arc_syncs,
        disable_play_auto_install=args.no_arc_syncs,
        username=args.username,
        password=(password if args.username else None),
        gaia_login=(args.username is not None),
        disable_default_apps=(not args.enable_default_apps),
        dont_override_profile=args.dont_override_profile)
    if args.url:
      tab = cr.browser.tabs[0]
      tab.Navigate(args.url)


if __name__ == '__main__':
    sys.exit(main(sys.argv[1:]))