Chromium Code Reviews| Index: functional/chromeos_gsm_compliance.py |
| =================================================================== |
| --- functional/chromeos_gsm_compliance.py (revision 0) |
| +++ functional/chromeos_gsm_compliance.py (revision 0) |
| @@ -0,0 +1,119 @@ |
| +#!/usr/bin/python |
| +# Copyright (c) 2011 The Chromium 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 re |
|
stanleyw
2011/10/18 01:24:47
re does not appear to be used so I think we can re
deepakg
2011/10/20 23:20:57
Done.
|
| +import subprocess as sub |
| + |
| +import pyauto_functional # Must be imported before pyauto |
| +import pyauto |
| + |
| + |
| +class ChromeosGSMCompliance(pyauto.PyUITest): |
| + """Tests for ChromeOS GSM compliance. |
| + |
| + Fakes connection to a network and verifies that the network name is correct. |
| + """ |
| + |
| + _ethernet = None |
| + |
| + def _GetEthernet(self): |
| + """Get the ethernet to which the device is connected.""" |
| + process = sub.Popen('ifconfig | cut -d\' \' -f 1 | grep eth', |
| + stdout=sub.PIPE, shell=True).communicate() |
| + self.assertNotEqual(process[0], '', msg='Not connected to Ethernet.') |
| + self._ethernet = process[0].rstrip() |
| + |
| + def setUp(self): |
| + pyauto.PyUITest.setUp(self) |
| + sub.call(['sudo', 'stop', 'cromo']) |
| + _ethernet = self._GetEthernet() |
|
stanleyw
2011/10/18 01:24:47
GetEthernet returns nothing. You don't need _ether
deepakg
2011/10/20 23:20:57
Done.
|
| + if self._ethernet: |
| + sub.call(['sudo', '/bin/sh', '/usr/local/lib/flimflam/test/backchannel', |
| + 'setup', self._ethernet, 'pseudo-modem0']) |
| + else: |
| + # If there is no eth check if we have pseudo-modem0. |
| + process = sub.Popen('ifconfig | cut -d\' \' -f 1 | grep pseudo', |
| + stdout=sub.PIPE, shell=True).communicate() |
| + self.assertNotEqual(process[0].rstrip(), 'pseudo-modem0', |
| + msg='Could not setup a pseudo-modem') |
| + |
| + def tearDown(self): |
| + if self._ethernet: |
| + sub.call(['sudo', '/bin/sh', '/usr/local/lib/flimflam/test/backchannel', |
| + 'teardown', self._ethernet, 'pseudo-modem0']) |
| + pyauto.PyUITest.tearDown(self) |
| + |
| + def _CheckFakeGSM(self): |
| + """Check if fake-gsm-modem is running.""" |
| + ps = sub.Popen('ps -ef | grep fake-gsm-modem | grep -v grep', |
| + shell=True, stdout=sub.PIPE).stdout.read() |
| + if len(ps.split('fake-gsm-modem')) > 0: |
| + return True |
| + return False |
| + |
| + def _VerifyBasicCarrierCompliance(self, carrier_name, cellular_name): |
| + """Faking the specified carrier and checking the name. |
| + |
| + Args: |
| + carrier_name: The name of the carrier. |
| + cellular_name: The name in the icon of the cellular network. |
| + """ |
| + fake_gsm = sub.Popen(['sudo', '/usr/bin/python', |
| + '/usr/local/lib/flimflam/test/fake-gsm-modem', |
| + '-c', carrier_name]) |
| + result = False |
| + try: |
| + for counter in range(10): # Wait for the fake GSM to connect. |
|
stanleyw
2011/10/18 01:24:47
We have a subroutine for this in pyauto.py. It's
deepakg
2011/10/20 23:20:57
Done.
|
| + if self._CheckFakeGSM(): |
| + for network in self.NetworkScan().keys(): |
| + if network == 'cellular_networks': |
| + network_info = self.NetworkScan()[network] |
| + for key in network_info.keys(): |
| + if network_info[key]['name'] == cellular_name: |
| + result = True |
| + raise StopIteration() |
| + except StopIteration: |
| + pass |
| + |
| + self.assertTrue(self._CheckFakeGSM(), msg='Fake GSM is not running.') |
| + fake_gsm.terminate() |
| + self.assertTrue(result, msg='Did not connect to cellular network %s.' |
| + % cellular_name) |
| + |
| + def testConnectThree(self): |
| + """Testing connection to Three.""" |
| + self._VerifyBasicCarrierCompliance('three', '3') |
| + |
| + def testConnectSFR(self): |
| + """Testing connection to SFR.""" |
| + self._VerifyBasicCarrierCompliance('SFR', 'SFR') |
| + |
| + def testConnectKPN(self): |
| + """Testing connection to KPN.""" |
| + self._VerifyBasicCarrierCompliance('KPN', 'KPN NL') |
| + |
| + def testConnectSimyo(self): |
| + """Testing connection to Simyo.""" |
| + self._VerifyBasicCarrierCompliance('Simyo', 'E-Plus') |
| + |
| + def testConnectMovistar(self): |
| + """Testing connection to Movistar.""" |
| + self._VerifyBasicCarrierCompliance('Movistar', 'Movistar') |
| + |
| + def testConnectThreeita(self): |
| + """Testing connection to threeita.""" |
| + self._VerifyBasicCarrierCompliance('threeita', '3ITA') |
| + |
| + def testConnectAtt(self): |
| + """Testing connection to att.""" |
| + self._VerifyBasicCarrierCompliance('att', 'AT&T') |
| + |
| + def testConnectTmobile(self): |
| + """Testing connection to Tmobile.""" |
| + self._VerifyBasicCarrierCompliance('Tmobile', 'T-Mobile') |
| + |
| + |
| +if __name__ == '__main__': |
| + pyauto_functional.Main() |