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