Index: functional/chromeos_gsm_compliance.py |
=================================================================== |
--- functional/chromeos_gsm_compliance.py (revision 0) |
+++ functional/chromeos_gsm_compliance.py (revision 0) |
@@ -0,0 +1,115 @@ |
+#!/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 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', |
dennis_jeffrey
2011/10/20 23:49:14
nit: maybe change the variable name "process" to s
deepakg
2011/10/21 00:31:55
Done.
|
+ 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']) |
+ self._GetEthernet() |
+ if self._ethernet: |
+ sub.call(['sudo', '/bin/sh', '/usr/local/lib/flimflam/test/backchannel', |
+ 'setup', self._ethernet, 'pseudo-modem0']) |
+ else: |
dennis_jeffrey
2011/10/20 23:49:14
Will we ever enter the "else" case? Because at li
deepakg
2011/10/21 00:31:55
Done.
|
+ # If there is no eth check if we have pseudo-modem0. |
dennis_jeffrey
2011/10/20 23:49:14
nit: 'eth' --> 'ethernet'
deepakg
2011/10/21 00:31:55
This part is removed.
|
+ process = sub.Popen('ifconfig | cut -d\' \' -f 1 | grep pseudo', |
dennis_jeffrey
2011/10/20 23:49:14
Similar comment as line 22 above.
deepakg
2011/10/21 00:31:55
This part is removed.
|
+ 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): |
dennis_jeffrey
2011/10/20 23:49:14
Maybe this function name is more descriptive:
_Is
deepakg
2011/10/21 00:31:55
Done.
|
+ """Check if fake-gsm-modem is running.""" |
dennis_jeffrey
2011/10/20 23:49:14
Add a "Returns:" section to this docstring, since
deepakg
2011/10/21 00:31:55
Done.
|
+ ps = sub.Popen('ps -ef | grep fake-gsm-modem | grep -v grep', |
dennis_jeffrey
2011/10/20 23:49:14
change to call?
deepakg
2011/10/21 00:31:55
Done.
|
+ shell=True, stdout=sub.PIPE).stdout.read() |
dennis_jeffrey
2011/10/20 23:49:14
Does calling ".stdout.read()" here ensure that the
deepakg
2011/10/21 00:31:55
Done.
|
+ if len(ps.split('fake-gsm-modem')) > 0: |
+ return True |
+ return False |
dennis_jeffrey
2011/10/20 23:49:14
I think it'll be have the same if we replace lines
deepakg
2011/10/21 00:31:55
Done.
|
+ |
+ 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 |
+ # Wait for the fake GSM to connect. |
+ cellular = 'cellular_networks' |
+ self.WaitUntil(lambda:cellular in self.NetworkScan().keys(), |
dennis_jeffrey
2011/10/20 23:49:14
nit: add a space right after the ':'
dennis_jeffrey
2011/10/20 23:49:14
The WaitUntil function will return False if the th
deepakg
2011/10/21 00:31:55
Done.
|
+ timeout=10, retry_sleep=1) |
+ network_info = self.NetworkScan()[cellular] |
+ for key in network_info.keys(): |
+ if network_info[key]['name'] == cellular_name: |
+ result = True |
+ break |
dennis_jeffrey
2011/10/20 23:49:14
I think can replace lines 71-74 with this:
result
deepakg
2011/10/21 00:31:55
Done. Thanks, I didn't know about any().
|
+ |
+ 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() |