autotest: Remove WiFi entries from the default profile in tests

Prevent WiFi entries from previous tests from interfering with future
tests by removing them from default profiles.  Other sources of WiFi
entries are already addressed by popping and removing other profiles.

TEST=Manually added a WiFi entry to the default profile in a DUT, then
ran network_WiFi_SimpleConnect.wifi_checkWPA_TKIP, which removed that
entry from the default profile.
BUG=chromium:332421

Change-Id: Ia3832fada48fefbaf682e643b99754eb577fb34f
Reviewed-on: https://chromium-review.googlesource.com/181891
Tested-by: Christopher Wiley <wiley@chromium.org>
Reviewed-by: Paul Stewart <pstew@chromium.org>
Commit-Queue: Christopher Wiley <wiley@chromium.org>
diff --git a/client/common_lib/cros/network/shill_xmlrpc_server.py b/client/common_lib/cros/network/shill_xmlrpc_server.py
index 0f01b4d..5faefc3 100755
--- a/client/common_lib/cros/network/shill_xmlrpc_server.py
+++ b/client/common_lib/cros/network/shill_xmlrpc_server.py
@@ -229,17 +229,14 @@
     def init_test_network_state(self):
         """Create a clean slate for tests with respect to remembered networks.
 
-        For shill, this means popping and removing profiles before adding a
-        'test' profile.
+        For shill, this means popping and removing profiles, removing all WiFi
+        entries from the default profile, and pushing a 'test' profile.
 
         @return True iff operation succeeded, False otherwise.
 
         """
-        # TODO(wiley) We've not seen this problem before, but there could
-        #             still be remembered networks in the default profile.
-        #             at the very least, this profile has the ethernet
-        #             entry.
         self.clean_profiles()
+        self._wifi_proxy.remove_all_wifi_entries()
         self.remove_profile(self.DEFAULT_TEST_PROFILE_NAME)
         worked = self.create_profile(self.DEFAULT_TEST_PROFILE_NAME)
         if worked:
diff --git a/client/cros/networking/shill_proxy.py b/client/cros/networking/shill_proxy.py
index ca0a4c5..b8811ad 100644
--- a/client/cros/networking/shill_proxy.py
+++ b/client/cros/networking/shill_proxy.py
@@ -32,6 +32,7 @@
     DBUS_TYPE_SERVICE = 'org.chromium.flimflam.Service'
 
     ENTRY_FIELD_NAME = 'Name'
+    ENTRY_FIELD_TYPE = 'Type'
 
     MANAGER_PROPERTY_ACTIVE_PROFILE = 'ActiveProfile'
     MANAGER_PROPERTY_DEVICES = 'Devices'
diff --git a/client/cros/networking/wifi_proxy.py b/client/cros/networking/wifi_proxy.py
index 562de10..d8ee8ef 100644
--- a/client/cros/networking/wifi_proxy.py
+++ b/client/cros/networking/wifi_proxy.py
@@ -39,6 +39,17 @@
         self.set_logging_for_test(self.TECHNOLOGY_WIFI)
 
 
+    def remove_all_wifi_entries(self):
+        """Iterate over all pushed profiles and remove WiFi entries."""
+        profiles = self.get_profiles()
+        for profile in profiles:
+            profile_properties = profile.GetProperties(utf8_strings=True)
+            entries = profile_properties[self.PROFILE_PROPERTY_ENTRIES]
+            for entry_id in entries:
+                if profile.GetEntry(entry_id)[self.ENTRY_FIELD_TYPE] == 'wifi':
+                    profile.DeleteEntry(entry_id)
+
+
     def configure_wifi_service(self, ssid, security, security_parameters={},
                                save_credentials=True, station_type=None,
                                hidden_network=False, guid=None,