Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 import os | 6 import os |
| 7 | 7 |
| 8 import pyauto_functional | 8 import pyauto_functional |
| 9 import chromeos_network # pyauto_functional must come before chromeos_network | 9 import chromeos_network # pyauto_functional must come before chromeos_network |
| 10 import pyauto_utils | 10 import pyauto_utils |
| 11 | 11 |
| 12 | 12 |
| 13 class ChromeosWifiFunctional(chromeos_network.PyNetworkUITest): | 13 class ChromeosWifiFunctional(chromeos_network.PyNetworkUITest): |
| 14 """Tests for ChromeOS wifi functionality. | 14 """Tests for ChromeOS wifi functionality. |
| 15 | 15 |
| 16 These tests should be run within vacinity of the power strip where the wifi | 16 These tests should be run within vacinity of the power strip where the wifi |
| 17 routers are attached. | 17 routers are attached. |
| 18 """ | 18 """ |
| 19 | 19 |
| 20 def _LoginDevice(self): | 20 def _LoginDevice(self, test_account='test_google_account'): |
| 21 """Logs into the device and cleans up flimflam profile.""" | 21 """Logs into the device and cleans up flimflam profile. |
| 22 | |
| 23 Args: | |
| 24 test_account: The account used to login to the device. | |
| 25 """ | |
| 22 if not self.GetLoginInfo()['is_logged_in']: | 26 if not self.GetLoginInfo()['is_logged_in']: |
| 23 credentials = self.GetPrivateInfo()['test_google_account'] | 27 credentials = self.GetPrivateInfo()[test_account] |
| 24 self.Login(credentials['username'], credentials['password']) | 28 self.Login(credentials['username'], credentials['password']) |
| 25 login_info = self.GetLoginInfo() | 29 login_info = self.GetLoginInfo() |
| 26 self.assertTrue(login_info['is_logged_in'], msg='Login failed.') | 30 self.assertTrue(login_info['is_logged_in'], msg='Login failed.') |
| 27 | 31 |
| 28 ff_dir = '/home/chronos/user/flimflam' | 32 ff_dir = '/home/chronos/user/flimflam' |
| 29 self.assertTrue(os.path.isdir(ff_dir), 'User is logged in but user ' | 33 self.assertTrue(os.path.isdir(ff_dir), 'User is logged in but user ' |
| 30 'flimflam profile is not present.') | 34 'flimflam profile is not present.') |
| 31 | 35 |
| 32 # Clean up the items in the flimflam profile directory. | 36 # Clean up the items in the flimflam profile directory. |
| 33 for item in os.listdir(ff_dir): | 37 for item in os.listdir(ff_dir): |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 51 self.InitWifiPowerStrip() | 55 self.InitWifiPowerStrip() |
| 52 router = self.GetRouterConfig(router_name) | 56 router = self.GetRouterConfig(router_name) |
| 53 self.RouterPower(router_name, True) | 57 self.RouterPower(router_name, True) |
| 54 | 58 |
| 55 # When we connect to a wifi service, it should be added to the | 59 # When we connect to a wifi service, it should be added to the |
| 56 # remembered_wifi list. | 60 # remembered_wifi list. |
| 57 self.WaitUntilWifiNetworkAvailable(router['ssid'], | 61 self.WaitUntilWifiNetworkAvailable(router['ssid'], |
| 58 is_hidden=router.get('hidden')) | 62 is_hidden=router.get('hidden')) |
| 59 return router | 63 return router |
| 60 | 64 |
| 65 def _VerifyIfConnectedToNetwork(self, network_ssid, status='Online state'): | |
| 66 """Verify if we are connected to the network. | |
| 67 | |
| 68 The test calling this function will fail for one of these three reasons: | |
| 69 1. The server path for the SSID is not found. | |
| 70 2. If we are not connected to the network. | |
| 71 3. If we did not find the network in the wifi_networks list. | |
| 72 | |
| 73 Args: | |
| 74 newtork_ssid: The network to which we are supposed to be connected to. | |
| 75 status: The status that we expect the network to have, by default it | |
| 76 would be 'Online state'. | |
| 77 """ | |
| 78 service_path = self.GetServicePath(network_ssid) | |
| 79 self.assertTrue(service_path is not None, | |
| 80 msg='Could not find a service path for the given ssid %s.' % | |
| 81 network_ssid) | |
| 82 for path in self.NetworkScan()['wifi_networks']: | |
| 83 if path == service_path: | |
| 84 self.assertTrue( | |
| 85 self.NetworkScan()['wifi_networks'][path]['status'] == status, | |
| 86 msg='Not connected to the network %s.' % network_ssid) | |
|
dennis_jeffrey
2011/11/22 00:32:23
Maybe this error should be something like "Unexpec
deepakg
2011/11/22 01:06:22
Done.
| |
| 87 break; | |
| 88 else: | |
| 89 self.assertTrue(False, msg='Did not find the network %s in the' | |
|
dennis_jeffrey
2011/11/22 00:32:23
You can just directly do a "self.fail" here.
dennis_jeffrey
2011/11/22 00:32:23
add a space right after 'the' at the end of this s
deepakg
2011/11/22 01:06:22
Done.
deepakg
2011/11/22 01:06:22
Done.
| |
| 90 'wifi_networks list.' % network_ssid) | |
| 91 | |
| 61 def testConnectShareEncryptedNetwork(self): | 92 def testConnectShareEncryptedNetwork(self): |
| 62 """A shared encrypted network can connect and is remembered. | 93 """A shared encrypted network can connect and is remembered. |
| 63 | 94 |
| 64 Note: This test does not verify that the network is added to the public | 95 Note: This test does not verify that the network is added to the public |
| 65 profile | 96 profile |
| 66 """ | 97 """ |
| 67 router_name = 'D-Link_N150' | 98 router_name = 'D-Link_N150' |
| 68 self._LoginDevice() | 99 self._LoginDevice() |
| 69 router = self._SetupRouter(router_name) | 100 router = self._SetupRouter(router_name) |
| 70 error = self.ConnectToWifiRouter(router_name, shared=True) | 101 error = self.ConnectToWifiRouter(router_name, shared=True) |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 89 error = self.ConnectToWifiRouter(router_name, shared=False) | 120 error = self.ConnectToWifiRouter(router_name, shared=False) |
| 90 self.assertFalse(error, 'Failed to connect to wifi network %s. ' | 121 self.assertFalse(error, 'Failed to connect to wifi network %s. ' |
| 91 'Reason: %s.' % (router['ssid'], error)) | 122 'Reason: %s.' % (router['ssid'], error)) |
| 92 service_path = self.GetServicePath(router['ssid']) | 123 service_path = self.GetServicePath(router['ssid']) |
| 93 self.assertTrue(service_path in self.GetNetworkInfo()['remembered_wifi'], | 124 self.assertTrue(service_path in self.GetNetworkInfo()['remembered_wifi'], |
| 94 'Connected wifi was not added to the remembered list.') | 125 'Connected wifi was not added to the remembered list.') |
| 95 self.ForgetWifiNetwork(service_path) | 126 self.ForgetWifiNetwork(service_path) |
| 96 self.assertFalse(service_path in self.GetNetworkInfo()['remembered_wifi'], | 127 self.assertFalse(service_path in self.GetNetworkInfo()['remembered_wifi'], |
| 97 'Connected wifi was not removed from the remembered list.') | 128 'Connected wifi was not removed from the remembered list.') |
| 98 | 129 |
| 130 def testConnectToSharedOpenNetwork(self): | |
| 131 """Can connect to a shared open network. | |
| 132 | |
| 133 Verify that the connected network is in the remembered network list | |
| 134 for all the users. | |
| 135 """ | |
| 136 router_name = 'Trendnet_639gr_4' | |
| 137 self._LoginDevice() | |
| 138 router = self._SetupRouter(router_name) | |
| 139 error = self.ConnectToWifiRouter(router_name) | |
| 140 self.assertFalse(error, msg='Failed to connect to wifi network %s. ' | |
| 141 'Reason: %s.' % (router['ssid'], error)) | |
| 142 service_path = self.GetServicePath(router['ssid']) | |
| 143 self.assertTrue(service_path in self.GetNetworkInfo()['remembered_wifi'], | |
| 144 msg='Open wifi is not remembered for the current user.') | |
| 145 self.Logout() | |
| 146 self._LoginDevice(test_account='test_google_account_2') | |
| 147 self.assertTrue(service_path in self.NetworkScan()['remembered_wifi'], | |
| 148 msg='Open network is not shared with other users.') | |
| 149 | |
| 150 def testConnectToSharedHiddenNetwork(self): | |
| 151 """Can connect to shared hidden network and verify that it's shared.""" | |
| 152 router_name = "Netgear_WGR614" | |
|
dennis_jeffrey
2011/11/22 00:32:23
prefer single quotes over double quotes when defin
deepakg
2011/11/22 01:06:22
Done.
| |
| 153 self._LoginDevice() | |
| 154 router = self._SetupRouter(router_name) | |
| 155 error = self.ConnectToWifiRouter(router_name) | |
| 156 self.assertFalse(error, msg='Failed to connect to hidden network %s. ' | |
| 157 'Reason: %s.' % (router['ssid'], error)) | |
| 158 service_path = self.GetServicePath(router['ssid']) | |
| 159 self.assertTrue(service_path in self.NetworkScan()['remembered_wifi'], | |
| 160 msg='Hidden network is not added to the remembered list.') | |
| 161 self.Logout() | |
| 162 self._LoginDevice(test_account='test_google_account_2') | |
| 163 self.assertTrue(service_path in self.NetworkScan()['remembered_wifi'], | |
| 164 msg='Shared hidden network is not in other user\'s ' | |
| 165 'remembered list.') | |
| 166 | |
| 167 def testConnectToNonSharedHiddenNetwork(self): | |
| 168 """Can connect to a non-shared hidden network. | |
| 169 | |
| 170 Verify that it is not shared with other users. | |
| 171 """ | |
| 172 router_name = "Linksys_WRT54GL" | |
|
dennis_jeffrey
2011/11/22 00:32:23
prefer single quotes over double quotes when defin
deepakg
2011/11/22 01:06:22
Done.
| |
| 173 self._LoginDevice() | |
| 174 router = self._SetupRouter(router_name) | |
| 175 error = self.ConnectToWifiRouter(router_name, shared=False) | |
| 176 self.assertFalse(error, msg='Failed to connect to hidden network %s. ' | |
| 177 'Reason: %s.' % (router['ssid'], error)) | |
| 178 service_path = self.GetServicePath(router['ssid']) | |
| 179 self.assertTrue(service_path in self.NetworkScan()['remembered_wifi'], | |
| 180 msg='Hidden network is not added to the remembered list.') | |
| 181 self.Logout() | |
| 182 self._LoginDevice(test_account='test_google_account_2') | |
| 183 self.assertFalse(service_path in self.NetworkScan()['remembered_wifi'], | |
| 184 msg='Non-shared hidden network %s is shared.' | |
| 185 % router['ssid']) | |
| 186 | |
| 187 def testConnectToEncryptedNetworkInLoginScreen(self): | |
| 188 """Can connect to encrypted network in login screen. | |
| 189 | |
| 190 Verify that this network is in the remembered list after login. | |
| 191 """ | |
| 192 router_name = 'Belkin_G' | |
| 193 if self.GetLoginInfo()['is_logged_in']: | |
| 194 self.Logout() | |
| 195 router = self._SetupRouter(router_name) | |
| 196 error = self.ConnectToWifiRouter(router_name) | |
| 197 self.assertFalse(error, 'Failed to connect to wifi network %s. ' | |
| 198 'Reason: %s.' % (router['ssid'], error)) | |
| 199 service_path = self.GetServicePath(router['ssid']) | |
| 200 self._VerifyIfConnectedToNetwork(router['ssid'], 'Connected') | |
| 201 self._LoginDevice() | |
| 202 self.assertTrue(service_path in self.NetworkScan()['remembered_wifi'], | |
| 203 msg='Network is not added to the remembered list.') | |
| 204 | |
| 99 | 205 |
| 100 if __name__ == '__main__': | 206 if __name__ == '__main__': |
| 101 pyauto_functional.Main() | 207 pyauto_functional.Main() |
| OLD | NEW |