Chromium Code Reviews| Index: tools/chrome_remote_control/chrome_remote_control/credentials_backend.py |
| diff --git a/tools/chrome_remote_control/chrome_remote_control/credentials_backend.py b/tools/chrome_remote_control/chrome_remote_control/credentials_backend.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..426e5b21f224e81fb83ccbcb66e207cd78a9fbbc |
| --- /dev/null |
| +++ b/tools/chrome_remote_control/chrome_remote_control/credentials_backend.py |
| @@ -0,0 +1,58 @@ |
| +# Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +import json |
| +import util |
| + |
| +class CredentialsBackend(object): |
| + label = None |
| + _config_file = 'page_sets/credentials.json' |
|
Ian Vollick
2012/09/25 02:00:41
This makes an assumption about where the script is
nduca
2012/09/25 02:36:07
ah good point. The right way to write this is:
os.
hartmanng
2012/09/26 22:06:15
Done.
|
| + _config = None |
| + |
| + def LoginNeeded(self): |
| + pass |
|
dtu
2012/09/24 21:35:10
raise NotImplementedError() is the Pythonic way of
hartmanng
2012/09/26 22:06:15
Done.
|
| + |
| + def LoginNoLongerNeeded(self): |
| + pass |
|
dtu
2012/09/24 21:35:10
raise NotImplementedError()
hartmanng
2012/09/26 22:06:15
Done.
|
| + |
| + @staticmethod |
| + def _ReadConfigFile(): |
| + try: |
| + with open(CredentialsBackend._config_file, 'r') as f: |
| + contents = f.read() |
|
tonyg
2012/09/24 20:41:01
extra space before =
hartmanng
2012/09/26 22:06:15
Done.
|
| + return json.loads(contents) |
| + except SyntaxError, e: |
| + logging.info('Could not read %s: %s', CredentialsBackend._config_file, |
| + str(e)) |
| + |
| + @staticmethod |
| + def _GetConfig(config): |
| + if CredentialsBackend._config is None: |
| + CredentialsBackend._config = CredentialsBackend._ReadConfigFile() |
| + |
| + for key in CredentialsBackend._config: |
| + if CredentialsBackend._config.get(key) is not None and key in config: |
| + config[key] = CredentialsBackend._config.get(key) |
| + |
| + return config |
| + |
| + def SubmitForm(self, form_id): |
| + """Submits the given form ID, and returns after it has been submitted. |
| + |
| + Args: |
| + form_id: the id attribute of the form to submit. |
| + """ |
| + js = "document.getElementById(\"%s\").submit();" % form_id |
|
tonyg
2012/09/24 20:41:01
use single tics for consistency and then you can d
hartmanng
2012/09/26 22:06:15
Done.
|
| + |
| + self._tab.runtime.Execute(js) |
| + |
| + def SubmitFormAndWait(self, form_id): |
| + self.SubmitForm(form_id) |
| + |
| + def IsLoginStillHappening(): |
| + return self._tab.runtime.Evaluate( |
| + 'document.querySelector("#%s")!== null' % form_id) |
| + |
| + # Wait until the form is submitted and the page completes loading. |
| + util.WaitFor(lambda: not IsLoginStillHappening(), 60) |