summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorstanleyw@chromium.org <stanleyw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-01 18:58:24 +0000
committerstanleyw@chromium.org <stanleyw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-01 18:58:24 +0000
commitefdd4bf2f05461e45df5703852f8c0eaa5becc95 (patch)
treefe58a96b0229bb925922509d5e1125ec0344d3ba /chrome
parentf43fd974d2fa750fcfd706bc08b95bdbdcd155f3 (diff)
downloadchromium_src-efdd4bf2f05461e45df5703852f8c0eaa5becc95.zip
chromium_src-efdd4bf2f05461e45df5703852f8c0eaa5becc95.tar.gz
chromium_src-efdd4bf2f05461e45df5703852f8c0eaa5becc95.tar.bz2
Added hidden network support to wifi compliance tests.
Also modified the checking of service_order. There are some problems where if the service is not present, it will not show after calling GetServiceOrder even though it was specifically set. The current method is to make sure the order of the common elements of what we set and what is retrieved from the device is in the same order. TODO: We need to clear the network list before running the tests. Otherwise, hidden networks suddenly become visible if they are remembered and this will throw off the hidden network test. BUG=None TEST=Run it with one of the hidden networks Review URL: http://codereview.chromium.org/7078017 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@87512 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/test/functional/chromeos_wifi_compliance.py16
-rw-r--r--chrome/test/pyautolib/chromeos_network.py93
-rw-r--r--chrome/test/pyautolib/pyauto.py2
3 files changed, 79 insertions, 32 deletions
diff --git a/chrome/test/functional/chromeos_wifi_compliance.py b/chrome/test/functional/chromeos_wifi_compliance.py
index 5ae3b07..edeb629 100644
--- a/chrome/test/functional/chromeos_wifi_compliance.py
+++ b/chrome/test/functional/chromeos_wifi_compliance.py
@@ -24,8 +24,18 @@ class ChromeosWifiCompliance(chromeos_network.PyNetworkUITest):
router = self.GetRouterConfig(router_name)
self.RouterPower(router_name, True)
- self.assertTrue(self.WaitUntilWifiNetworkAvailable(router['ssid']),
- 'Wifi network %s never showed up.' % router['ssid'])
+ # If the wifi network is expected to be invisible, the following
+ # line should timeout which is expected.
+ wifi_visible = self.WaitUntilWifiNetworkAvailable(router['ssid'],
+ is_hidden=router.get('hidden'))
+
+ # Note, we expect wifi_visible and 'hidden' status to be opposites.
+ # The test fails if the network visibility is not as expected.
+ if wifi_visible == router.get('hidden', False):
+ self.fail('We expected wifi network "%s" to be %s, but it was not.' %
+ (router['ssid'],
+ {True: 'hidden', False: 'visible'}[router.get('hidden',
+ False)]))
# Verify connect did not have any errors.
error = self.ConnectToWifiRouter(router_name)
@@ -78,7 +88,7 @@ class ChromeosWifiCompliance(chromeos_network.PyNetworkUITest):
def testConnectNfiniti(self):
"""Test connecting to the Nfiniti router."""
- self._BasicConnectRouterCompliance('Belkin_N+')
+ self._BasicConnectRouterCompliance('Nfiniti')
def testConnectSMCWBR145(self):
"""Test connecting to the SMC WBR 145 router."""
diff --git a/chrome/test/pyautolib/chromeos_network.py b/chrome/test/pyautolib/chromeos_network.py
index bcbb91c..49611c7 100644
--- a/chrome/test/pyautolib/chromeos_network.py
+++ b/chrome/test/pyautolib/chromeos_network.py
@@ -47,6 +47,11 @@ class WifiPowerStrip(PowerStrip):
for router_info in self._router_dict.values():
router_info['WifiPowerStrip_UsableTime'] = time.time()
+ # _routers_used keeps track of which routers were used during the lifetime
+ # of the WifiPowerStrip instance. Adding used routers occurs when
+ # a wifi router has been turned on. Otherwise, it get clears upon
+ # the TurnOffUsedRouters call.
+ self._routers_used = set()
PowerStrip.__init__(self, host)
def GetRouterConfig(self, router_name):
@@ -79,11 +84,17 @@ class WifiPowerStrip(PowerStrip):
router = self.GetRouterConfig(router_name)
if not router: raise Exception('Invalid router name \'%s\'.' % router_name)
+ # Hidden routers will always be on. Don't allow controlling of the power
+ # for these networks.
+ if router.get('hidden'):
+ return
+
sleep_time = router['WifiPowerStrip_UsableTime'] - time.time()
if sleep_time > 0:
- sleep(sleep_time)
+ time.sleep(sleep_time)
if power_state:
+ self._routers_used |= set([router_name])
logging.debug('Turning on router %s:%s.' %
(router['strip_id'], router_name))
self.PowerOn(router['strip_id'])
@@ -101,6 +112,13 @@ class WifiPowerStrip(PowerStrip):
for router in self._router_dict:
self.RouterPower(router, False, pause_after=0)
+ def TurnOffUsedRouters(self):
+ """Turns off the routers that were once turned on."""
+ for router in self._routers_used:
+ self.RouterPower(router, False, pause_after=0)
+
+ self._routers_used = set()
+
class PyNetworkUITest(pyauto.PyUITest):
"""A subclass of PyUITest for Chrome OS network tests.
@@ -128,11 +146,7 @@ class PyNetworkUITest(pyauto.PyUITest):
def tearDown(self):
pyauto.PyUITest.tearDown(self)
self._PopServiceOrder()
-
- # If the test case used the WifiPowerStrip, make sure
- # everything is clean by turning all the routers off.
- if self._wifi_power_strip:
- self._wifi_power_strip.TurnOffAllRouters()
+ self._wifi_power_strip.TurnOffUsedRouters()
def _SetServiceOrder(self, service_order):
self._manager.SetServiceOrder(service_order)
@@ -148,15 +162,35 @@ class PyNetworkUITest(pyauto.PyUITest):
def _PushServiceOrder(self, service_order):
self._old_service_order = self._manager.GetServiceOrder()
self._SetServiceOrder(service_order)
- assert service_order == self._manager.GetServiceOrder(), \
+ service_order = service_order.split(',')
+
+ # Verify services that are present in both the service_order
+ # we set and the one retrieved from device are in the correct order.
+ set_service_order = self._manager.GetServiceOrder().split(',')
+ union_service = set(service_order).union(set(set_service_order))
+
+ service_order = [s for s in service_order if s in union_service]
+ set_service_order = [s for s in set_service_order if s in union_service]
+
+ assert service_order == set_service_order, \
'Flimflam service order not set properly. %s != %s' % \
- (self._old_service_order, self._manager.GetServiceOrder())
+ (service_order, set_service_order)
def _PopServiceOrder(self):
self._SetServiceOrder(self._old_service_order)
- assert self._old_service_order == self._manager.GetServiceOrder(), \
- 'Flimflam service order not reset properly. %s != %s' % \
- (self._old_service_order, self._manager.GetServiceOrder())
+
+ # Verify services that are present in both the service_order
+ # we set and the one retrieved from device are in the correct order.
+ old_service_order = self._old_service_order.split(',')
+ set_service_order = self._manager.GetServiceOrder().split(',')
+ union_service = set(old_service_order).union(set(set_service_order))
+
+ old_service_order = [s for s in old_service_order if s in union_service]
+ set_service_order = [s for s in set_service_order if s in union_service]
+
+ assert old_service_order == set_service_order, \
+ 'Flimflam service order not set properly. %s != %s' % \
+ (old_service_order, set_service_order)
def InitWifiPowerStrip(self):
"""Initializes the router controller using the specified config file."""
@@ -173,7 +207,7 @@ class PyNetworkUITest(pyauto.PyUITest):
self.TurnOffAllRouters = self._wifi_power_strip.TurnOffAllRouters
self.GetRouterConfig = self._wifi_power_strip.GetRouterConfig
- def WaitUntilWifiNetworkAvailable(self, ssid, timeout=60):
+ def WaitUntilWifiNetworkAvailable(self, ssid, timeout=60, is_hidden=False):
"""Waits until the given network is available.
Routers that are just turned on may take up to 1 minute upon turning them
@@ -203,6 +237,11 @@ class PyNetworkUITest(pyauto.PyUITest):
# this method.
return False
+ # The hidden AP's will always be on, thus we will assume it is ready to
+ # connect to.
+ if is_hidden:
+ return bool(_GotWifiNetwork())
+
return self.WaitUntil(_GotWifiNetwork, timeout=timeout, retry_sleep=1)
def GetConnectedWifi(self):
@@ -243,22 +282,20 @@ class PyNetworkUITest(pyauto.PyUITest):
router = self._wifi_power_strip.GetRouterConfig(router_name)
assert router, 'Router with name %s is not defined ' \
'in the router configuration.' % router_name
-
- service_path = self.GetServicePath(router['ssid'])
- assert service_path, 'Service with SSID %s is not present.' % router['ssid']
-
+ security = router.get('security', 'SECURITY_NONE')
passphrase = router.get('passphrase', '')
- logging.debug('Connecting to router %s.' % router_name)
- return self.ConnectToWifiNetwork(service_path, passphrase)
-
- def PowerDownAllRouters(self):
- """Turns off all of the routers.
-
- Convenience method that allows all subclasses to turn everything off and
- start fresh.
-
- """
- if self._wifi_power_strip:
- self._wifi_power_strip.TurnOffAllRouters()
+ # Branch off the connect calls depending on if the wifi network is hidden
+ # or not.
+ error_string = None
+ if router.get('hidden'):
+ error_string = self.ConnectToHiddenWifiNetwork(router['ssid'], security,
+ passphrase)
+ else:
+ service_path = self.GetServicePath(router['ssid'])
+ assert service_path, 'Service with SSID %s is not present.' % \
+ router['ssid']
+ logging.debug('Connecting to router %s.' % router_name)
+ error_string = self.ConnectToWifiNetwork(service_path, passphrase)
+ return error_string
diff --git a/chrome/test/pyautolib/pyauto.py b/chrome/test/pyautolib/pyauto.py
index f263f76..d2d2017 100644
--- a/chrome/test/pyautolib/pyauto.py
+++ b/chrome/test/pyautolib/pyauto.py
@@ -422,7 +422,7 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
data_file = os.path.join(filename)
contents = open(data_file).read()
try:
- ret = eval(contents, {'__builtins__': None}, None)
+ ret = eval(contents)
except:
print >>sys.stderr, '%s is an invalid data file.' % data_file
raise