webkitpy: 'iPhone SE' should match 'iPhone SE 1st generation'
authorjbedard@apple.com <jbedard@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 8 May 2020 22:56:48 +0000 (22:56 +0000)
committerjbedard@apple.com <jbedard@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 8 May 2020 22:56:48 +0000 (22:56 +0000)
https://bugs.webkit.org/show_bug.cgi?id=211642
<rdar://problems/62986242>

Rubber-stamped by Aakash Jain.

* Scripts/webkitpy/xcode/device_type.py:
(DeviceType):
(DeviceType.standardized_hardware_type): Strip '1st generation' from models.
(DeviceType.__eq__): Use standardized hardware type.
(DeviceType.__contains__): Ditto.
(DeviceType.__hash__): Ditto.
* Scripts/webkitpy/xcode/device_type_unittest.py:
(DeviceTypeTest):
(DeviceTypeTest.test_generation_matching):
* Scripts/webkitpy/xcode/simulated_device.py:
(SimulatedDeviceManager._get_device_identifier_for_type): Handle case where the requests model does not
end with '(1st generation)', but the simctl model does.
* Scripts/webkitpy/xcode/simulated_device_unittest.py:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@261421 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Tools/ChangeLog
Tools/Scripts/webkitpy/xcode/device_type.py
Tools/Scripts/webkitpy/xcode/device_type_unittest.py
Tools/Scripts/webkitpy/xcode/simulated_device.py
Tools/Scripts/webkitpy/xcode/simulated_device_unittest.py

index 69ce957..bf6d438 100644 (file)
@@ -1,3 +1,25 @@
+2020-05-08  Jonathan Bedard  <jbedard@apple.com>
+
+        webkitpy: 'iPhone SE' should match 'iPhone SE 1st generation'
+        https://bugs.webkit.org/show_bug.cgi?id=211642
+        <rdar://problems/62986242>
+
+        Rubber-stamped by Aakash Jain.
+
+        * Scripts/webkitpy/xcode/device_type.py:
+        (DeviceType):
+        (DeviceType.standardized_hardware_type): Strip '1st generation' from models.
+        (DeviceType.__eq__): Use standardized hardware type.
+        (DeviceType.__contains__): Ditto.
+        (DeviceType.__hash__): Ditto.
+        * Scripts/webkitpy/xcode/device_type_unittest.py:
+        (DeviceTypeTest):
+        (DeviceTypeTest.test_generation_matching):
+        * Scripts/webkitpy/xcode/simulated_device.py:
+        (SimulatedDeviceManager._get_device_identifier_for_type): Handle case where the requests model does not
+        end with '(1st generation)', but the simctl model does.
+        * Scripts/webkitpy/xcode/simulated_device_unittest.py:
+
 2020-05-08  Ryan Haddad  <ryanhaddad@apple.com>
 
         TestWebKitAPI.WebKit.AllowsContentJavaScript fails on iPad simulator
index 7130384..0d0c80f 100644 (file)
@@ -26,6 +26,7 @@ from webkitpy.port.config import apple_additions
 
 # This class is designed to match device types. Because it is used for matching, 'None' is treated as a wild-card.
 class DeviceType(object):
+    FIRST_GENERATION = ' (1st generation)'
 
     @classmethod
     def from_string(cls, device_string, version=None):
@@ -108,6 +109,15 @@ class DeviceType(object):
         self._define_software_variant_from_hardware_family()
         self.check_consistency()
 
+    @property
+    def standardized_hardware_type(self):
+        if not self.hardware_type:
+            return None
+
+        if self.hardware_type.lower().endswith(self.FIRST_GENERATION):
+            return self.hardware_type[:-len(self.FIRST_GENERATION)]
+        return self.hardware_type
+
     def __str__(self):
         version = None
         if self.software_version and apple_additions():
@@ -126,7 +136,7 @@ class DeviceType(object):
         assert isinstance(other, DeviceType)
         if self.hardware_family is not None and other.hardware_family is not None and self.hardware_family.lower() != other.hardware_family.lower():
             return False
-        if self.hardware_type is not None and other.hardware_type is not None and self.hardware_type.lower() != other.hardware_type.lower():
+        if self.standardized_hardware_type is not None and other.standardized_hardware_type is not None and self.standardized_hardware_type.lower() != other.standardized_hardware_type.lower():
             return False
         if self.software_variant is not None and other.software_variant is not None and self.software_variant.lower() != other.software_variant.lower():
             return False
@@ -138,7 +148,7 @@ class DeviceType(object):
         assert isinstance(other, DeviceType)
         if self.hardware_family is not None and (not other.hardware_family or self.hardware_family.lower() != other.hardware_family.lower()):
             return False
-        if self.hardware_type is not None and (not other.hardware_type or self.hardware_type.lower() != other.hardware_type.lower()):
+        if self.standardized_hardware_type is not None and (not other.standardized_hardware_type or self.standardized_hardware_type.lower() != other.standardized_hardware_type.lower()):
             return False
         if self.software_variant is not None and (not other.software_variant or self.software_variant.lower() != other.software_variant.lower()):
             return False
@@ -147,4 +157,4 @@ class DeviceType(object):
         return True
 
     def __hash__(self):
-        return hash((self.hardware_family, self.hardware_type, self.software_variant, self.software_version))
+        return hash((self.hardware_family, self.standardized_hardware_type, self.software_variant, self.software_version))
index 533f602..82961f8 100644 (file)
@@ -158,3 +158,8 @@ class DeviceTypeTest(unittest.TestCase):
 
     def test_unmapped_version(self):
         self.assertEqual('iPhone running iOS', str(DeviceType.from_string('iPhone', Version(9))))
+
+    def test_generation_matching(self):
+        self.assertEqual(DeviceType.from_string('iPhone SE (1st generation)').standardized_hardware_type, 'SE')
+        self.assertTrue(DeviceType.from_string('iPhone SE') == DeviceType.from_string('iPhone SE (1st generation)'))
+        self.assertTrue(DeviceType.from_string('iPhone SE') != DeviceType.from_string('iPhone SE (2nd generation)'))
index 6882f65..609bfc2 100644 (file)
@@ -249,8 +249,11 @@ class SimulatedDeviceManager(object):
 
     @staticmethod
     def _get_device_identifier_for_type(device_type):
+        type_name_for_request = u'{} {}'.format(device_type.hardware_family.lower(), device_type.standardized_hardware_type.lower())
         for type_id, type_name in SimulatedDeviceManager._device_identifier_to_name.items():
-            if type_name.lower() == u'{} {}'.format(device_type.hardware_family.lower(), device_type.hardware_type.lower()):
+            if type_name.lower() == type_name_for_request:
+                return type_id
+            if type_name.lower().endswith(DeviceType.FIRST_GENERATION) and type_name.lower()[:-len(DeviceType.FIRST_GENERATION)] == type_name_for_request:
                 return type_id
         return None
 
index 960c836..4e7e626 100644 (file)
@@ -67,7 +67,7 @@ simctl_json_output = """{
      "identifier" : "com.apple.CoreSimulator.SimDeviceType.iPhone-8-Plus"
    },
    {
-     "name" : "iPhone SE",
+     "name" : "iPhone SE (1st generation)",
      "identifier" : "com.apple.CoreSimulator.SimDeviceType.iPhone-SE"
    },
    {
@@ -373,7 +373,7 @@ simctl_json_output = """{
      {
        "state" : "Shutdown",
        "availability" : "(available)",
-       "name" : "iPhone SE",
+       "name" : "iPhone SE (1st generation)",
        "udid" : "DB46D0DB-510E-4928-BDB4-1A0192ED4A38"
      },
      {