| OLD | NEW |
| (Empty) |
| 1 #!/usr/bin/env python | |
| 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 | |
| 4 # found in the LICENSE file. | |
| 5 | |
| 6 import subprocess as sub | |
| 7 | |
| 8 import pyauto_functional # Must be imported before pyauto | |
| 9 import pyauto | |
| 10 | |
| 11 | |
| 12 class ChromeosGSMCompliance(pyauto.PyUITest): | |
| 13 """Tests for ChromeOS GSM compliance. | |
| 14 | |
| 15 Fakes connection to a network and verifies that the network name is correct. | |
| 16 """ | |
| 17 | |
| 18 _ethernet = None | |
| 19 | |
| 20 def _GetEthernet(self): | |
| 21 """Get the ethernet to which the device is connected.""" | |
| 22 result = sub.Popen('ifconfig | cut -d\' \' -f 1 | grep eth', | |
| 23 stdout=sub.PIPE, shell=True).communicate() | |
| 24 self.assertNotEqual(result[0], '', msg='Not connected to Ethernet.') | |
| 25 self._ethernet = result[0].rstrip() | |
| 26 | |
| 27 def setUp(self): | |
| 28 pyauto.PyUITest.setUp(self) | |
| 29 sub.call(['sudo', 'stop', 'cromo']) | |
| 30 self._GetEthernet() | |
| 31 sub.call(['sudo', '/bin/sh', '/usr/local/lib/flimflam/test/backchannel', | |
| 32 'setup', self._ethernet, 'pseudo-modem0']) | |
| 33 | |
| 34 def tearDown(self): | |
| 35 if self._ethernet: | |
| 36 sub.call(['sudo', '/bin/sh', '/usr/local/lib/flimflam/test/backchannel', | |
| 37 'teardown', self._ethernet, 'pseudo-modem0']) | |
| 38 pyauto.PyUITest.tearDown(self) | |
| 39 | |
| 40 def _IsFakeGSMRunning(self): | |
| 41 """Check if fake-gsm-modem is running. | |
| 42 | |
| 43 Returns: | |
| 44 True if fake-gsm-modem process is running and False if not. | |
| 45 """ | |
| 46 ps = sub.Popen('ps -ef | grep fake-gsm-modem | grep -v grep', | |
| 47 shell=True, stdout=sub.PIPE).communicate() | |
| 48 return len(ps[0].split('fake-gsm-modem')) > 0 | |
| 49 | |
| 50 def _VerifyBasicCarrierCompliance(self, carrier_name, cellular_name): | |
| 51 """Faking the specified carrier and checking the name. | |
| 52 | |
| 53 Args: | |
| 54 carrier_name: The name of the carrier. | |
| 55 cellular_name: The name in the icon of the cellular network. | |
| 56 """ | |
| 57 fake_gsm = sub.Popen(['sudo', '/usr/bin/python', | |
| 58 '/usr/local/lib/flimflam/test/fake-gsm-modem', | |
| 59 '-c', carrier_name]) | |
| 60 self.assertTrue(self._IsFakeGSMRunning(), msg='Fake GSM is not running.') | |
| 61 # Wait for the fake GSM to connect. | |
| 62 cellular = 'cellular_networks' | |
| 63 try: | |
| 64 self.assertTrue(self.WaitUntil(lambda: cellular in | |
| 65 self.NetworkScan().keys(),timeout=10, retry_sleep=1)) | |
| 66 except AssertionError: | |
| 67 fake_gsm.terminate() | |
| 68 self.assertTrue(False, msg='No cellular networks appeared on scan.') | |
| 69 network_info = self.NetworkScan()[cellular] | |
| 70 result = any([network_info[key]['name'] == cellular_name | |
| 71 for key in network_info.keys()]) | |
| 72 fake_gsm.terminate() | |
| 73 self.assertTrue(result, msg='The cellular network name did not match %s.' | |
| 74 % cellular_name) | |
| 75 | |
| 76 def testConnectThree(self): | |
| 77 """Testing connection to Three.""" | |
| 78 self._VerifyBasicCarrierCompliance('three', '3') | |
| 79 | |
| 80 def testConnectSFR(self): | |
| 81 """Testing connection to SFR.""" | |
| 82 self._VerifyBasicCarrierCompliance('SFR', 'SFR') | |
| 83 | |
| 84 def testConnectKPN(self): | |
| 85 """Testing connection to KPN.""" | |
| 86 self._VerifyBasicCarrierCompliance('KPN', 'KPN NL') | |
| 87 | |
| 88 def testConnectSimyo(self): | |
| 89 """Testing connection to Simyo.""" | |
| 90 self._VerifyBasicCarrierCompliance('Simyo', 'E-Plus') | |
| 91 | |
| 92 def testConnectMovistar(self): | |
| 93 """Testing connection to Movistar.""" | |
| 94 self._VerifyBasicCarrierCompliance('Movistar', 'Movistar') | |
| 95 | |
| 96 def testConnectThreeita(self): | |
| 97 """Testing connection to threeita.""" | |
| 98 self._VerifyBasicCarrierCompliance('threeita', '3ITA') | |
| 99 | |
| 100 def testConnectAtt(self): | |
| 101 """Testing connection to att.""" | |
| 102 self._VerifyBasicCarrierCompliance('att', 'AT&T') | |
| 103 | |
| 104 def testConnectTmobile(self): | |
| 105 """Testing connection to Tmobile.""" | |
| 106 self._VerifyBasicCarrierCompliance('Tmobile', 'T-Mobile') | |
| 107 | |
| 108 | |
| 109 if __name__ == '__main__': | |
| 110 pyauto_functional.Main() | |
| OLD | NEW |