diff options
-rw-r--r-- | chrome/browser/automation/testing_automation_provider_chromeos.cc | 20 | ||||
-rw-r--r-- | chrome/test/data/chromeos/cros/network-multiple-unknown.onc | 30 | ||||
-rw-r--r-- | chrome/test/data/chromeos/cros/network-wifi-none.onc | 16 | ||||
-rw-r--r-- | chrome/test/data/chromeos/cros/network-wifi-wep.onc | 17 | ||||
-rw-r--r-- | chrome/test/data/chromeos/cros/network-wifi-wpa-remove.onc | 14 | ||||
-rw-r--r-- | chrome/test/data/chromeos/cros/network-wifi-wpa.onc | 17 | ||||
-rw-r--r-- | chrome/test/functional/PYAUTO_TESTS | 1 | ||||
-rw-r--r-- | chrome/test/functional/chromeos_onc.py | 121 | ||||
-rwxr-xr-x | chrome/test/functional/chromeos_wifi_functional.py | 14 | ||||
-rwxr-xr-x | chrome/test/pyautolib/chromeos/suid_actions.py | 29 | ||||
-rwxr-xr-x | chrome/test/pyautolib/pyauto.py | 34 |
11 files changed, 274 insertions, 39 deletions
diff --git a/chrome/browser/automation/testing_automation_provider_chromeos.cc b/chrome/browser/automation/testing_automation_provider_chromeos.cc index 4e28b9f..f6c426f 100644 --- a/chrome/browser/automation/testing_automation_provider_chromeos.cc +++ b/chrome/browser/automation/testing_automation_provider_chromeos.cc @@ -62,6 +62,14 @@ DictionaryValue* GetNetworkInfoDict(const chromeos::Network* network) { return item; } +DictionaryValue* GetWifiInfoDict(const chromeos::WifiNetwork* wifi) { + DictionaryValue* item = GetNetworkInfoDict(wifi); + item->SetInteger("strength", wifi->strength()); + item->SetBoolean("encrypted", wifi->encrypted()); + item->SetString("encryption", wifi->GetEncryptionString()); + return item; +} + base::Value* GetProxySetting(Browser* browser, const std::string& setting_name) { std::string setting_path = "cros.session.proxy."; @@ -421,10 +429,7 @@ void TestingAutomationProvider::GetNetworkInfo(DictionaryValue* args, for (chromeos::WifiNetworkVector::const_iterator iter = wifi_networks.begin(); iter != wifi_networks.end(); ++iter) { const chromeos::WifiNetwork* wifi = *iter; - DictionaryValue* item = GetNetworkInfoDict(wifi); - item->SetInteger("strength", wifi->strength()); - item->SetBoolean("encrypted", wifi->encrypted()); - item->SetString("encryption", wifi->GetEncryptionString()); + DictionaryValue* item = GetWifiInfoDict(wifi); items->Set(wifi->service_path(), item); } return_value->Set("wifi_networks", items); @@ -460,14 +465,15 @@ void TestingAutomationProvider::GetNetworkInfo(DictionaryValue* args, // Remembered Wifi Networks. const chromeos::WifiNetworkVector& remembered_wifi = network_library->remembered_wifi_networks(); - ListValue* items = new ListValue; + DictionaryValue* remembered_wifi_items = new DictionaryValue; for (chromeos::WifiNetworkVector::const_iterator iter = remembered_wifi.begin(); iter != remembered_wifi.end(); ++iter) { const chromeos::WifiNetwork* wifi = *iter; - items->Append(base::Value::CreateStringValue(wifi->service_path())); + DictionaryValue* item = GetWifiInfoDict(wifi); + remembered_wifi_items->Set(wifi->service_path(), item); } - return_value->Set("remembered_wifi", items); + return_value->Set("remembered_wifi", remembered_wifi_items); AutomationJSONReply(this, reply_message).SendSuccess(return_value.get()); } diff --git a/chrome/test/data/chromeos/cros/network-multiple-unknown.onc b/chrome/test/data/chromeos/cros/network-multiple-unknown.onc new file mode 100644 index 0000000..39183d1 --- /dev/null +++ b/chrome/test/data/chromeos/cros/network-multiple-unknown.onc @@ -0,0 +1,30 @@ +// Test ONC file that contains unknown fields. +{ + "NetworkConfigurations": [ + { + "GUID": "{485d6076-dd44-6b6d-69787465725f5045}", + "Type": "WiFi", + "Name": "My WiFi Network", + "UnknownField1": "Value1", + "UnknownField2": { + "UnknownSubField": "Value2" + }, + "WiFi": { + "SSID": "ssid-none", + "Security": "None" + } + }, + { + "GUID": "{485d6076-dd44-6b6d-69787465725f5046}", + "Type": "WiFi", + "Name": "My WiFi Network2", + "WiFi": { + "SSID": "ssid-wpa", + "Security": "WPA-PSK" + } + } + ], + "Certificates": [], + "Type": "UnencryptedConfiguration", + "UnknownField3": [], +} diff --git a/chrome/test/data/chromeos/cros/network-wifi-none.onc b/chrome/test/data/chromeos/cros/network-wifi-none.onc new file mode 100644 index 0000000..2b338c4 --- /dev/null +++ b/chrome/test/data/chromeos/cros/network-wifi-none.onc @@ -0,0 +1,16 @@ +// Test ONC file for importing an open network. +{ + "NetworkConfigurations": [ + { + "GUID": "{485d6076-dd44-6b6d-69787465725f5040}", + "Type": "WiFi", + "Name": "My WiFi Network", + "WiFi": { + "SSID": "ssid-none", + "Security": "None" + } + } + ], + "Certificates": [], + "Type": "UnencryptedConfiguration" +} diff --git a/chrome/test/data/chromeos/cros/network-wifi-wep.onc b/chrome/test/data/chromeos/cros/network-wifi-wep.onc new file mode 100644 index 0000000..66602b2 --- /dev/null +++ b/chrome/test/data/chromeos/cros/network-wifi-wep.onc @@ -0,0 +1,17 @@ +// Test ONC file for importing a WEP network. +{ + "NetworkConfigurations": [ + { + "GUID": "{485d6076-dd44-6b6d-69787465725f5041}", + "Type": "WiFi", + "Name": "My WiFi Network", + "WiFi": { + "Passphrase": "z123456789012", + "SSID": "ssid-wep", + "Security": "WEP-PSK" + } + } + ], + "Certificates": [], + "Type": "UnencryptedConfiguration" +} diff --git a/chrome/test/data/chromeos/cros/network-wifi-wpa-remove.onc b/chrome/test/data/chromeos/cros/network-wifi-wpa-remove.onc new file mode 100644 index 0000000..8ed5d57 --- /dev/null +++ b/chrome/test/data/chromeos/cros/network-wifi-wpa-remove.onc @@ -0,0 +1,14 @@ +// Test ONC file that removes a network with the indicated GUID. +// This should be used in conjunction with network-wifi-wpa.onc. +{ + "NetworkConfigurations": [ + { + "GUID": "{485d6076-dd44-6b6d-69787465725f5042}", + "Type": "WiFi", + "Name": "My WiFi Network", + "Remove": true, + } + ], + "Certificates": [], + "Type": "UnencryptedConfiguration" +} diff --git a/chrome/test/data/chromeos/cros/network-wifi-wpa.onc b/chrome/test/data/chromeos/cros/network-wifi-wpa.onc new file mode 100644 index 0000000..3d2e7b9 --- /dev/null +++ b/chrome/test/data/chromeos/cros/network-wifi-wpa.onc @@ -0,0 +1,17 @@ +// Test ONC file for adding a WPA-PSK wifi network. +{ + "NetworkConfigurations": [ + { + "GUID": "{485d6076-dd44-6b6d-69787465725f5042}", + "Type": "WiFi", + "Name": "My WiFi Network", + "WiFi": { + "Passphrase": "12345678", + "SSID": "ssid-wpa", + "Security": "WPA-PSK" + } + } + ], + "Certificates": [], + "Type": "UnencryptedConfiguration" +} diff --git a/chrome/test/functional/PYAUTO_TESTS b/chrome/test/functional/PYAUTO_TESTS index 48b9652..5abd671 100644 --- a/chrome/test/functional/PYAUTO_TESTS +++ b/chrome/test/functional/PYAUTO_TESTS @@ -661,6 +661,7 @@ # require custom setup on ChromeOS. 'CHROMEOS_POLICY': { 'chromeos': [ + 'chromeos_onc', 'policy', 'policy_prefs_ui', ], diff --git a/chrome/test/functional/chromeos_onc.py b/chrome/test/functional/chromeos_onc.py new file mode 100644 index 0000000..ef33870 --- /dev/null +++ b/chrome/test/functional/chromeos_onc.py @@ -0,0 +1,121 @@ +#!/usr/bin/env python +# Copyright (c) 2012 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 os + +import pyauto_functional # must come before pyauto. +import policy_base +import pyauto + + +class ChromeosONC(policy_base.PolicyTestBase): + """ + Tests for Open Network Configuration (ONC). + + Open Network Configuration (ONC) files is a json dictionary + that contains network configurations and is pulled via policies. + These tests verify that ONC files that are formatted correctly + add the network/certificate to the device. + """ + + ONC_PATH = os.path.join(pyauto.PyUITest.DataDir(), 'chromeos', 'cros') + + def setUp(self): + policy_base.PolicyTestBase.setUp(self) + pyauto.PyUITest.RunSuperuserActionOnChromeOS('CleanFlimflamDir') + + def _ReadONCFileAndSet(self, filename): + """Reads the specified ONC file and sends it as a policy. + + Inputs: + filename: The filename of the ONC file. ONC files should + all be stored in the path defined by ONC_PATH. + """ + with open(os.path.join(self.ONC_PATH, filename)) as fp: + self.SetPolicies({'OpenNetworkConfiguration': fp.read()}) + + def _VerifyRememberedWifiNetworks(self, wifi_expect): + """Verify the list of remembered networks contains those in wifi_expect. + + Inputs: + wifi_expect: A dictionary of wifi networks where the key is the ssid + and the value is the encryption type of the network. + """ + # Sometimes there is a race condition where upon restarting chrome + # NetworkScan has not populated the network lists yet. We should + # scan until the device is online. + self.WaitUntil(lambda: not self.NetworkScan().get('offline_mode', True)) + networks = self.NetworkScan() + + # Temprorary dictionary to keep track of which wifi networks + # have been visited by removing them as we see them. + wifi_expect_temp = dict(wifi_expect) + + for service, wifi_dict in networks['remembered_wifi'].iteritems(): + msg = ('Wifi network %s was in the remembered_network list but ' + 'shouldn\'t be.' % wifi_dict['name']) + + # wifi_dict['encryption'] will always be a string and not None. + self.assertTrue(wifi_expect.get(wifi_dict['name'], None) == + wifi_dict['encryption'], msg) + + del wifi_expect_temp[wifi_dict['name']] + + # Error if wifi_expect_temp is not empty. + self.assertFalse(wifi_expect_temp, 'The following networks ' + 'were not remembered: %s' % self.pformat(wifi_expect_temp)) + + def testONCAddOpenWifi(self): + """Test adding open network.""" + wifi_networks = { + 'ssid-none': '', + } + + self._ReadONCFileAndSet('network-wifi-none.onc') + self._VerifyRememberedWifiNetworks(wifi_networks) + + def testONCAddWEPWifi(self): + """Test adding WEP network.""" + wifi_networks = { + 'ssid-wep': 'WEP', + } + + self._ReadONCFileAndSet('network-wifi-wep.onc') + self._VerifyRememberedWifiNetworks(wifi_networks) + + def testONCAddPSKWifi(self): + """Test adding WPA network.""" + wifi_networks = { + 'ssid-wpa': 'PSK', + } + self._ReadONCFileAndSet('network-wifi-wpa.onc') + self._VerifyRememberedWifiNetworks(wifi_networks) + + def testAddBacktoBackONC(self): + """Test adding three different ONC files one after the other.""" + wifi_networks = { + 'ssid-none': '', + 'ssid-wep': 'WEP', + 'ssid-wpa': 'PSK', + } + + self._ReadONCFileAndSet('network-wifi-none.onc') + self._ReadONCFileAndSet('network-wifi-wep.onc') + self._ReadONCFileAndSet('network-wifi-wpa.onc') + self._VerifyRememberedWifiNetworks(wifi_networks) + + def testAddONCWithUnknownFields(self): + """Test adding an ONC file with unknown fields.""" + wifi_networks = { + 'ssid-none': '', + 'ssid-wpa': 'PSK' + } + + self._ReadONCFileAndSet('network-multiple-unknown.onc') + self._VerifyRememberedWifiNetworks(wifi_networks) + + +if __name__ == '__main__': + pyauto_functional.Main() diff --git a/chrome/test/functional/chromeos_wifi_functional.py b/chrome/test/functional/chromeos_wifi_functional.py index fa517bb..0cd941f 100755 --- a/chrome/test/functional/chromeos_wifi_functional.py +++ b/chrome/test/functional/chromeos_wifi_functional.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -# Copyright (c) 2011 The Chromium Authors. All rights reserved. +# Copyright (c) 2012 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. @@ -17,7 +17,7 @@ class ChromeosWifiFunctional(chromeos_network.PyNetworkUITest): These tests should be run within vacinity of the power strip where the wifi routers are attached. """ - + def setUp(self): chromeos_network.PyNetworkUITest.setUp(self) if self.GetLoginInfo().get('is_logged_in'): @@ -45,7 +45,7 @@ class ChromeosWifiFunctional(chromeos_network.PyNetworkUITest): def _VerifyIfConnectedToNetwork(self, network_ssid, status='Online state'): """Verify if we are connected to the network. - + The test calling this function will fail for one of these three reasons: 1. The server path for the SSID is not found. 2. If we are not connected to the network. @@ -114,7 +114,7 @@ class ChromeosWifiFunctional(chromeos_network.PyNetworkUITest): def testConnectToSharedOpenNetwork(self): """Can connect to a shared open network. - Verify that the connected network is in the remembered network list + Verify that the connected network is in the remembered network list for all the users. """ router_name = 'Trendnet_639gr_4' @@ -152,7 +152,7 @@ class ChromeosWifiFunctional(chromeos_network.PyNetworkUITest): """Can connect to a non-shared hidden network. Verify that it is not shared with other users. - """ + """ router_name = 'Linksys_WRT54GL' test_utils.LoginToDevice(self) router = self._SetupRouter(router_name) @@ -170,7 +170,7 @@ class ChromeosWifiFunctional(chromeos_network.PyNetworkUITest): def testConnectToEncryptedNetworkInLoginScreen(self): """Can connect to encrypted network in login screen. - + Verify that this network is in the remembered list after login. """ router_name = 'Belkin_G' @@ -181,7 +181,7 @@ class ChromeosWifiFunctional(chromeos_network.PyNetworkUITest): self.assertFalse(error, 'Failed to connect to wifi network %s. ' 'Reason: %s.' % (router['ssid'], error)) service_path = self.GetServicePath(router['ssid']) - self._VerifyIfConnectedToNetwork(router['ssid'], 'Connected') + self._VerifyIfConnectedToNetwork(router['ssid'], 'Connected') test_utils.LoginToDevice(self) self.assertTrue(service_path in self.NetworkScan()['remembered_wifi'], msg='Network is not added to the remembered list.') diff --git a/chrome/test/pyautolib/chromeos/suid_actions.py b/chrome/test/pyautolib/chromeos/suid_actions.py index 824b8cc..df39e08 100755 --- a/chrome/test/pyautolib/chromeos/suid_actions.py +++ b/chrome/test/pyautolib/chromeos/suid_actions.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -# Copyright (c) 2011 The Chromium Authors. All rights reserved. +# Copyright (c) 2012 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. @@ -39,18 +39,23 @@ class SuidAction(object): return 0 ## Actions ## - def CleanFlimflamDir(self): - """Clean the contents of /home/chronos/user/flimflam.""" - flimflam_dir = '/home/chronos/user/flimflam' - if not os.path.exists(flimflam_dir): - return - for item in os.listdir(flimflam_dir): - path = os.path.join(flimflam_dir, item) - if os.path.isdir(path): - shutil.rmtree(path) - else: - os.remove(path) + """Clean the contents of all flimflam profiles.""" + flimflam_dir = ['/home/chronos/user/flimflam', + '/var/cache/flimflam'] + os.system('stop flimflam') + try: + for profile in flimflam_dir: + if not os.path.exists(profile): + continue + for item in os.listdir(profile): + path = os.path.join(profile, item) + if os.path.isdir(path): + shutil.rmtree(path) + else: + os.remove(path) + finally: + os.system('start flimflam') if __name__ == '__main__': diff --git a/chrome/test/pyautolib/pyauto.py b/chrome/test/pyautolib/pyauto.py index 74861b4..988f812 100755 --- a/chrome/test/pyautolib/pyauto.py +++ b/chrome/test/pyautolib/pyauto.py @@ -322,7 +322,7 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase): 'Did not find suid-root python at %s' % PyUITest.SuidPythonPath() file_path = os.path.join(os.path.dirname(__file__), 'chromeos', 'suid_actions.py') - args = [PyUITest.SuidPythonPath(), file_path, '--action=CleanFlimflamDir'] + args = [PyUITest.SuidPythonPath(), file_path, '--action=%s' % action] proc = subprocess.Popen( args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, stderr = proc.communicate() @@ -3893,12 +3893,12 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase): Sample: { u'cellular_available': True, u'cellular_enabled': False, - u'connected_ethernet': u'/profile/default/ethernet_abcd', - u'connected_wifi': u'/profile/default/wifi_abcd_1234_managed_none', + u'connected_ethernet': u'/service/ethernet_abcd', + u'connected_wifi': u'/service/wifi_abcd_1234_managed_none', u'ethernet_available': True, u'ethernet_enabled': True, u'ethernet_networks': - { u'/profile/default/ethernet_abcd': + { u'/service/ethernet_abcd': { u'device_path': u'/device/abcdeth', u'ip_address': u'11.22.33.44', u'name': u'', @@ -3906,12 +3906,20 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase): u'/profile/default/ethernet_abcd', u'status': u'Connected'}}, u'ip_address': u'11.22.33.44', - u'remembered_wifi': [ u'/profile/default/ethernet_abcd', - u'/profile/default/ethernet_efgh'], + u'remembered_wifi': + { u'/service/wifi_abcd_1234_managed_none': + { u'device_path': u'', + u'encrypted': False, + u'encryption': u'', + u'ip_address': '', + u'name': u'WifiNetworkName1', + u'status': u'Unknown', + u'strength': 0}, + }, u'wifi_available': True, u'wifi_enabled': True, u'wifi_networks': - { u'/profile/default/wifi_abcd_1234_managed_none': + { u'/service/wifi_abcd_1234_managed_none': { u'device_path': u'/device/abcdwifi', u'encrypted': False, u'encryption': u'', @@ -3919,13 +3927,11 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase): u'name': u'WifiNetworkName1', u'status': u'Connected', u'strength': 76}, - u'/profile/default/wifi_abcd_1234_managed_802_1x': - { u'device_path': u'/device/abcdwifi', - u'encrypted': True, + u'/service/wifi_abcd_1234_managed_802_1x': + { u'encrypted': True, u'encryption': u'8021X', u'ip_address': u'', u'name': u'WifiNetworkName2', - u'service_path': u'status': u'Idle', u'strength': 79}}} @@ -3939,8 +3945,10 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase): # Remembered networks do not have /service/ prepended to the service path # even though wifi_networks does. We want this prepended to allow for # consistency and easy string comparison with wifi_networks. - network_info['remembered_wifi'] = ['/service/' + service for service in - network_info['remembered_wifi']] + remembered_wifi = {} + network_info['remembered_wifi'] = dict([('/service/' + k, v) for k, v in + network_info['remembered_wifi'].iteritems()]) + return network_info def NetworkScan(self): |