1# Copyright (c) 2013 The Chromium OS Authors. All rights reserved. 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5import logging 6 7from autotest_lib.client.bin import test 8from autotest_lib.client.common_lib import error 9from autotest_lib.client.cros.networking.chrome_testing \ 10 import chrome_networking_test_context as cntc 11from autotest_lib.client.cros.networking.chrome_testing import test_utils 12 13class network_ChromeWifiConfigure(test.test): 14 """ 15 Tests wifi configuration using chrome.networkingPrivate. 16 This test appears fairly trivial, but actually tests that Shill and Chrome 17 are communicating successfully, and that Shill can successfully configure 18 a WiFi network and retreive the properties of that network. 19 20 """ 21 version = 1 22 23 def _test_property(self, network, property_name, expected_value): 24 value = test_utils.get_ui_property(network, property_name) 25 if value != expected_value: 26 raise error.TestFail('Expected value for "' + property_name + 27 '" to be "' + str(expected_value) + 28 '", found "' + str(value)) + '"' 29 30 def _create_wifi(self, ssid, security): 31 logging.info('create_wifi') 32 shared = 'false' 33 properties = { 34 'Type': 'WiFi', 35 'WiFi': { 36 'SSID': ssid, 37 'Security': security 38 } 39 } 40 logging.info('Calling createNetwork') 41 guid = test_utils.call_test_function_check_success( 42 self._chrome_testing, 43 'createNetwork', 44 (shared, properties)) 45 logging.info(' guid: ' + guid) 46 47 logging.info('Calling getNetworkInfo') 48 network = test_utils.call_test_function_check_success( 49 self._chrome_testing, 50 'getNetworkInfo', 51 ('"' + guid + '"',)) 52 logging.info(' result: ' + str(network)) 53 54 self._test_property(network, 'Type', 'WiFi') 55 self._test_property(network, 'WiFi.Security', security) 56 57 58 def _run_once_internal(self): 59 logging.info('run_once_internal') 60 self._create_wifi('test_wifi1', 'WEP-PSK') 61 62 63 def run_once(self): 64 """ 65 Entry point of the test. 66 """ 67 with cntc.ChromeNetworkingTestContext() as testing_context: 68 self._chrome_testing = testing_context 69 self._run_once_internal() 70