Commit 07190030 authored by achuith@chromium.org's avatar achuith@chromium.org

Split cros_test_case.py.

BUG=None
TEST=manual
NOTRY=True

Review URL: https://codereview.chromium.org/254143002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@267003 0039d316-1c4b-4281-b951-d872f2087c98
parent a5f1bcec
# Copyright 2014 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 os
import unittest
from telemetry.core import browser_finder
from telemetry.core import extension_to_load
from telemetry.core import util
from telemetry.core.backends.chrome import cros_interface
from telemetry.unittest import options_for_unittests
class CrOSTestCase(unittest.TestCase):
def setUp(self):
options = options_for_unittests.GetCopy()
self._cri = cros_interface.CrOSInterface(options.cros_remote,
options.cros_ssh_identity)
self._is_guest = options.browser_type == 'cros-chrome-guest'
self._username = options.browser_options.username
self._password = options.browser_options.password
self._load_extension = None
def _CreateBrowser(self, autotest_ext=False, auto_login=True,
gaia_login=False, username=None, password=None):
"""Finds and creates a browser for tests. if autotest_ext is True,
also loads the autotest extension"""
options = options_for_unittests.GetCopy()
if autotest_ext:
extension_path = os.path.join(util.GetUnittestDataDir(), 'autotest_ext')
assert os.path.isdir(extension_path)
self._load_extension = extension_to_load.ExtensionToLoad(
path=extension_path,
browser_type=options.browser_type,
is_component=True)
options.extensions_to_load = [self._load_extension]
browser_to_create = browser_finder.FindBrowser(options)
self.assertTrue(browser_to_create)
options.browser_options.create_browser_with_oobe = True
options.browser_options.auto_login = auto_login
options.browser_options.gaia_login = gaia_login
if username is not None:
options.browser_options.username = username
if password is not None:
options.browser_options.password = password
return browser_to_create.Create()
def _GetAutotestExtension(self, browser):
"""Returns the autotest extension instance"""
extension = browser.extensions[self._load_extension]
self.assertTrue(extension)
return extension
def _IsCryptohomeMounted(self):
"""Returns True if cryptohome is mounted. as determined by the cmd
cryptohome --action=is_mounted"""
return self._cri.RunCmdOnDevice(
['/usr/sbin/cryptohome', '--action=is_mounted'])[0].strip() == 'true'
def _GetLoginStatus(self, browser):
extension = self._GetAutotestExtension(browser)
self.assertTrue(extension.EvaluateJavaScript(
"typeof('chrome.autotestPrivate') != 'undefined'"))
extension.ExecuteJavaScript('''
window.__login_status = null;
chrome.autotestPrivate.loginStatus(function(s) {
window.__login_status = s;
});
''')
return util.WaitFor(
lambda: extension.EvaluateJavaScript('window.__login_status'), 10)
...@@ -3,81 +3,14 @@ ...@@ -3,81 +3,14 @@
# found in the LICENSE file. # found in the LICENSE file.
import logging import logging
import os
import unittest
from telemetry import test from telemetry import test
from telemetry.core import browser_finder
from telemetry.core import exceptions from telemetry.core import exceptions
from telemetry.core import extension_to_load
from telemetry.core import util from telemetry.core import util
from telemetry.core.backends.chrome import cros_interface from telemetry.core.backends.chrome import cros_test_case
from telemetry.unittest import options_for_unittests
class CrOSTestCase(unittest.TestCase): class CrOSCryptohomeTest(cros_test_case.CrOSTestCase):
def setUp(self):
options = options_for_unittests.GetCopy()
self._cri = cros_interface.CrOSInterface(options.cros_remote,
options.cros_ssh_identity)
self._is_guest = options.browser_type == 'cros-chrome-guest'
self._username = options.browser_options.username
self._password = options.browser_options.password
self._load_extension = None
def _CreateBrowser(self, autotest_ext=False, auto_login=True,
gaia_login=False, username=None, password=None):
"""Finds and creates a browser for tests. if autotest_ext is True,
also loads the autotest extension"""
options = options_for_unittests.GetCopy()
if autotest_ext:
extension_path = os.path.join(util.GetUnittestDataDir(), 'autotest_ext')
assert os.path.isdir(extension_path)
self._load_extension = extension_to_load.ExtensionToLoad(
path=extension_path,
browser_type=options.browser_type,
is_component=True)
options.extensions_to_load = [self._load_extension]
browser_to_create = browser_finder.FindBrowser(options)
self.assertTrue(browser_to_create)
options.browser_options.create_browser_with_oobe = True
options.browser_options.auto_login = auto_login
options.browser_options.gaia_login = gaia_login
if username is not None:
options.browser_options.username = username
if password is not None:
options.browser_options.password = password
return browser_to_create.Create()
def _GetAutotestExtension(self, browser):
"""Returns the autotest extension instance"""
extension = browser.extensions[self._load_extension]
self.assertTrue(extension)
return extension
def _IsCryptohomeMounted(self):
"""Returns True if cryptohome is mounted. as determined by the cmd
cryptohome --action=is_mounted"""
return self._cri.RunCmdOnDevice(
['/usr/sbin/cryptohome', '--action=is_mounted'])[0].strip() == 'true'
def _GetLoginStatus(self, browser):
extension = self._GetAutotestExtension(browser)
self.assertTrue(extension.EvaluateJavaScript(
"typeof('chrome.autotestPrivate') != 'undefined'"))
extension.ExecuteJavaScript('''
window.__login_status = null;
chrome.autotestPrivate.loginStatus(function(s) {
window.__login_status = s;
});
''')
return util.WaitFor(
lambda: extension.EvaluateJavaScript('window.__login_status'), 10)
class CrOSCryptohomeTest(CrOSTestCase):
@test.Enabled('chromeos') @test.Enabled('chromeos')
def testCryptohome(self): def testCryptohome(self):
"""Verifies cryptohome mount status for regular and guest user and when """Verifies cryptohome mount status for regular and guest user and when
...@@ -102,7 +35,7 @@ class CrOSCryptohomeTest(CrOSTestCase): ...@@ -102,7 +35,7 @@ class CrOSCryptohomeTest(CrOSTestCase):
'/dev/mapper/encstateful') '/dev/mapper/encstateful')
class CrOSLoginTest(CrOSTestCase): class CrOSLoginTest(cros_test_case.CrOSTestCase):
@test.Enabled('chromeos') @test.Enabled('chromeos')
def testLoginStatus(self): def testLoginStatus(self):
"""Tests autotestPrivate.loginStatus""" """Tests autotestPrivate.loginStatus"""
...@@ -132,7 +65,7 @@ class CrOSLoginTest(CrOSTestCase): ...@@ -132,7 +65,7 @@ class CrOSLoginTest(CrOSTestCase):
util.WaitFor(lambda: not self._IsCryptohomeMounted(), 20) util.WaitFor(lambda: not self._IsCryptohomeMounted(), 20)
class CrOSScreenLockerTest(CrOSTestCase): class CrOSScreenLockerTest(cros_test_case.CrOSTestCase):
def _IsScreenLocked(self, browser): def _IsScreenLocked(self, browser):
return self._GetLoginStatus(browser)['isScreenLocked'] return self._GetLoginStatus(browser)['isScreenLocked']
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment