blob: 2b878835110a0b71ef96fc215a30ffbf0d77f2f5 [file] [log] [blame]
# Copyright (c) 2013 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.
import dbus
import logging
from autotest_lib.client.bin import test
from autotest_lib.client.common_lib import error
from autotest_lib.client.cros.networking.chrome_testing \
import chrome_networking_test_context as cntc
from autotest_lib.client.cros.networking.chrome_testing import test_utils
from autotest_lib.client.cros.cellular.pseudomodem import mm1
from autotest_lib.client.cros.cellular.pseudomodem import pseudomodem
class network_ChromeCellularSmokeTest(test.test):
Tests that Chrome can bring the network to a connected state and effectively
access the internet through the cellular network. The test repeats a
connect/disconnect sequence several times and makes sure that Chrome can
always connect to the network via chrome.networkingPrivate.
version = 1
def _setup_modem_proxy(self):
self._bus = dbus.SystemBus()
manager = self._bus.get_object(mm1.I_MODEM_MANAGER, mm1.MM1)
imanager = dbus.Interface(manager, mm1.I_OBJECT_MANAGER)
devices = imanager.GetManagedObjects().keys()
if len(devices) != 1:
raise error.TestFail('Expected exactly one modem object, found: ' +
self._modem = self._bus.get_object(mm1.I_MODEM_MANAGER, devices[0])
def _get_modem_state(self):
iprops = dbus.Interface(self._modem, mm1.I_PROPERTIES)
return iprops.Get(mm1.I_MODEM, mm1.MM_MODEM_PROPERTY_NAME_STATE)
def _get_cellular_network(self):
networks = self._chrome_testing.find_cellular_networks()
if len(networks) != 1:
raise error.TestFail(
'Expected 1 cellular network, found ' + str(len(networks)))
network = networks[0]
network, pseudomodem.DEFAULT_TEST_NETWORK_PREFIX,
return network
def _assert_modem_state(self, expected_state):
modem_state = self._get_modem_state()
if modem_state != expected_state:
raise error.TestFail(
'Expected modem state to be "' +
mm1.ModemStateToString(expected_state) + '", found: ' +
def _ensure_network_status(self, network_id, status, timeout):
self._chrome_testing, network_id, 'ConnectionState', status)
def _disconnect_cellular_network(self):
# Make sure that the network becomes disconnected.
network_id = self._network['GUID']'Disconnecting from network: ' + network_id)
call_status = self._chrome_testing.call_test_function(
'"' + network_id + '"')'Checking that the network is disconnected.')
network_id, 'NotConnected', test_utils.LONG_TIMEOUT)'The network is disconnected. Checking that the modem is '
'in the REGISTERED state.')
self._assert_modem_state(mm1.MM_MODEM_STATE_REGISTERED)'Modem is disconnected. Disconnect was successful.')
def _connect_cellular_network(self):
# Make sure that the network becomes connected.
network_id = self._network['GUID']'Connecting to network: ' + network_id)
call_status = self._chrome_testing.call_test_function(
'"' + network_id + '"')'Checking that the network is connected.')
network_id, 'Connected', test_utils.LONG_TIMEOUT)'The network is connected. Checking that the modem is in '
'the CONNECTED state.')
self._assert_modem_state(mm1.MM_MODEM_STATE_CONNECTED)'Modem is connected. Connect was successful.')
def _run_once_internal(self):
# Set up a ModemManager proxy to use to verify the modem state.
# Make sure that there is a single cellular network and it matches
# the data from pseudomm.
self._network = self._get_cellular_network()
# Disconnect from the network before doing any operations.
self._disconnect_cellular_network()'Starting connect/disconnect sequence.')
for _ in xrange(self.CONNECT_COUNT):
def run_once(self, family):
with pseudomodem.TestModemManagerContext(
True, family) as manager_context:
with cntc.ChromeNetworkingTestContext() as testing_context:
self._manager_context = manager_context
self._chrome_testing = testing_context