Move login_status_ext to autotest_private_ext.
A number of tests need access to autotestPrivate-
now chrome.py provides access to an extension with this api by simply setting a boolean.
A number of tests could use login_status as well, so add a property for this.
Add support for oobe access.
Refactor telemetry_LoginTest to use the new properties.
BUG=chromium:233834
TEST=telemetry_LoginTest
Change-Id: Ia6474ff9b280a7bbda2ebeb9edbdc8c20169cfde
Reviewed-on: https://chromium-review.googlesource.com/172507
Reviewed-by: Achuith Bhandarkar <achuith@chromium.org>
Commit-Queue: Achuith Bhandarkar <achuith@chromium.org>
Tested-by: Achuith Bhandarkar <achuith@chromium.org>
diff --git a/client/common_lib/cros/chrome.py b/client/common_lib/cros/chrome.py
index c59d3e5..427ca5f 100644
--- a/client/common_lib/cros/chrome.py
+++ b/client/common_lib/cros/chrome.py
@@ -2,6 +2,8 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+import os
+
from telemetry.core import browser_finder, browser_options, exceptions
from telemetry.core import extension_to_load, util
@@ -18,23 +20,31 @@
BROWSER_TYPE_GUEST = 'system-guest'
- def __init__(self, logged_in=True, extension_paths=[]):
+ def __init__(self, logged_in=True, extension_paths=[], autotest_ext=False):
+ self._autotest_ext_path = None
+ if autotest_ext:
+ self._autotest_ext_path = os.path.join(os.path.dirname(__file__),
+ 'autotest_private_ext')
+ extension_paths.append(self._autotest_ext_path)
+
finder_options = browser_options.BrowserFinderOptions()
self._browser_type = (self.BROWSER_TYPE_LOGIN
if logged_in else self.BROWSER_TYPE_GUEST)
finder_options.browser_type = self.browser_type
- b_options = finder_options.browser_options
- b_options.disable_component_extensions_with_background_pages = False
-
if logged_in:
+ extensions_to_load = finder_options.extensions_to_load
for path in extension_paths:
extension = extension_to_load.ExtensionToLoad(
path, self.browser_type, is_component=True)
- finder_options.extensions_to_load.append(extension)
- self._extensions_to_load = finder_options.extensions_to_load
+ extensions_to_load.append(extension)
+ self._extensions_to_load = extensions_to_load
finder_options.CreateParser().parse_args(args=[])
+ b_options = finder_options.browser_options
+ b_options.disable_component_extensions_with_background_pages = False
+ b_options.create_browser_with_oobe = True
+
browser_to_create = browser_finder.FindBrowser(finder_options)
self._browser = browser_to_create.Create()
self._browser.Start()
@@ -63,6 +73,28 @@
@property
+ def autotest_ext(self):
+ """Returns the autotest extension."""
+ return self.get_extension(self._autotest_ext_path)
+
+
+ @property
+ def login_status(self):
+ """Returns login status."""
+ ext = self.autotest_ext
+ if not ext:
+ return None
+
+ ext.ExecuteJavaScript('''
+ window.__login_status = null;
+ chrome.autotestPrivate.loginStatus(function(s) {
+ window.__login_status = s;
+ });
+ ''')
+ return ext.EvaluateJavaScript('window.__login_status')
+
+
+ @property
def browser_type(self):
"""Returns the browser_type."""
return self._browser_type