Revert "Reland "Support grdp files in translation screenshot presubmit""

This reverts commit 12e7fee2b99bbc315357579e96eb12bd00b9c2bd.

Reason for revert: crbug/1025982 

Original change's description:
> Reland "Support grdp files in translation screenshot presubmit"
> 
> This is a reland of 2308d0744fa1d8554c8891529eba4e857a990b78
> 
> Original change's description:
> > Support grdp files in translation screenshot presubmit
> > 
> > Translation screenshots project requires Chrome devs to upload UI
> > screenshots along with string changes in .grd and .grdp files. These
> > are XML files containing all user visible strings in Chrome.
> > 
> > Translation screenshots has a presubmit checks that extracts the
> > list of modified strings, looks for image files associated with these
> > strings and warns the developer to add them if they are missing.
> > 
> > This presubmit parses .grds to extract the list of modified strings but
> > it skips <part> tags which are used to reference .grdp files. As a
> > result, the presubmit currently ignores string changes in .grdp files.
> > .grdp files contain the majority of UI strings in Chrome, so the lack of
> > presubmit checks for them results in low translation screenshot coverage.
> > 
> > This CL changes how .grdp files are loaded in the presubmit: Previously,
> > they were written in a temporary directory alongside a fake .grd file
> > that referenced the loaded .grdp file. The code loaded the fake .grd file
> > which resulted in loading the strings in the actual .grdp file. However,
> > test mocks override all os.path methods which in turn breaks temporary
> > directory creation. As a result, it was not possible to properly test
> > the .grdp loading code, so we skipped <part> tags as a workaround.
> > 
> > The new loading code writes a temporary copy of the .grdp file and wraps
> > its contents with proper tags so that it can be loaded as a .grd file
> > instead. This avoids the need to create a temporary directory and is
> > fully testable.
> > 
> > The end result is that Translation Screenshots presubmit will now ask
> > Chrome devs to upload screenshots for changes in .grdp files. This should
> > significantly increase the coverage of strings with translation screenshots,
> > leading to better quality in string localizations.
> > 
> > Bug: 924652
> > Change-Id: Iae7933e8147cefdabc15ef21d2b6daa43d5002bc
> > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1875554
> > Reviewed-by: anthonyvd <[email protected]>
> > Reviewed-by: Jochen Eisinger <[email protected]>
> > Commit-Queue: Mustafa Emre Acer <[email protected]>
> > Cr-Commit-Position: refs/heads/master@{#714550}
> 
> Bug: 924652
> Change-Id: Iaf0f68f8abdccd3bca66b4b611bf53d8337d347b
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1912835
> Reviewed-by: anthonyvd <[email protected]>
> Reviewed-by: Jochen Eisinger <[email protected]>
> Commit-Queue: Mustafa Emre Acer <[email protected]>
> Cr-Commit-Position: refs/heads/master@{#716224}

[email protected],[email protected],[email protected]

Change-Id: Id5265d9bffe86e3179784325eff357f9ac758967
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 924652
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1923155
Reviewed-by: Mustafa Emre Acer <[email protected]>
Commit-Queue: Mustafa Emre Acer <[email protected]>
Cr-Commit-Position: refs/heads/master@{#716498}
diff --git a/PRESUBMIT_test.py b/PRESUBMIT_test.py
index 711de2cc..8848c37 100755
--- a/PRESUBMIT_test.py
+++ b/PRESUBMIT_test.py
@@ -2427,31 +2427,6 @@
            </grit>
         """.splitlines()
 
-  OLD_GRDP_CONTENTS = (
-    '<?xml version="1.0" encoding="utf-8"?>',
-      '<grit-part>',
-    '</grit-part>'
-  )
-
-  NEW_GRDP_CONTENTS1 = (
-    '<?xml version="1.0" encoding="utf-8"?>',
-      '<grit-part>',
-        '<message name="IDS_PART_TEST1">',
-          'Part string 1',
-        '</message>',
-    '</grit-part>')
-
-  NEW_GRDP_CONTENTS2 = (
-    '<?xml version="1.0" encoding="utf-8"?>',
-      '<grit-part>',
-        '<message name="IDS_PART_TEST1">',
-          'Part string 1',
-        '</message>',
-        '<message name="IDS_PART_TEST2">',
-          'Part string 2',
-      '</message>',
-    '</grit-part>')
-
   DO_NOT_UPLOAD_PNG_MESSAGE = ('Do not include actual screenshots in the '
                                'changelist. Run '
                                'tools/translate/upload_screenshots.py to '
@@ -2473,57 +2448,33 @@
         [x.LocalPath() for x in input_api.AffectedFiles(include_deletes=True)])
     return input_api
 
-  """ CL modified and added messages, but didn't add any screenshots."""
   def testNoScreenshots(self):
-    # No new strings (file contents same). Should not warn.
-    input_api = self.makeInputApi([
-      MockAffectedFile('test.grd', self.NEW_GRD_CONTENTS1,
-                       self.NEW_GRD_CONTENTS1, action='M'),
-      MockAffectedFile('part.grdp', self.NEW_GRDP_CONTENTS1,
-                       self.NEW_GRDP_CONTENTS1, action='M')])
-    warnings = PRESUBMIT._CheckTranslationScreenshots(input_api,
-                                                      MockOutputApi())
-    self.assertEqual(0, len(warnings))
-
-    # Add two new strings. Should have two warnings.
+    # CL modified and added messages, but didn't add any screenshots.
     input_api = self.makeInputApi([
       MockAffectedFile('test.grd', self.NEW_GRD_CONTENTS2,
-                       self.NEW_GRD_CONTENTS1, action='M'),
-      MockAffectedFile('part.grdp', self.NEW_GRDP_CONTENTS2,
-                       self.NEW_GRDP_CONTENTS1, action='M')])
+                       self.OLD_GRD_CONTENTS, action='M')])
     warnings = PRESUBMIT._CheckTranslationScreenshots(input_api,
                                                       MockOutputApi())
     self.assertEqual(1, len(warnings))
     self.assertEqual(self.GENERATE_SIGNATURES_MESSAGE, warnings[0].message)
     self.assertEqual([
-      os.path.join('part_grdp', 'IDS_PART_TEST2.png.sha1'),
-      os.path.join('test_grd', 'IDS_TEST2.png.sha1')],
-                     warnings[0].items)
-
-    # Add four new strings. Should have four warnings.
-    input_api = self.makeInputApi([
-      MockAffectedFile('test.grd', self.NEW_GRD_CONTENTS2,
-                       self.OLD_GRD_CONTENTS, action='M'),
-      MockAffectedFile('part.grdp', self.NEW_GRDP_CONTENTS2,
-                       self.OLD_GRDP_CONTENTS, action='M')])
-    warnings = PRESUBMIT._CheckTranslationScreenshots(input_api,
-                                                      MockOutputApi())
-    self.assertEqual(1, len(warnings))
-    self.assertEqual(self.GENERATE_SIGNATURES_MESSAGE, warnings[0].message)
-    self.assertEqual([
-        os.path.join('part_grdp', 'IDS_PART_TEST1.png.sha1'),
-        os.path.join('part_grdp', 'IDS_PART_TEST2.png.sha1'),
         os.path.join('test_grd', 'IDS_TEST1.png.sha1'),
-        os.path.join('test_grd', 'IDS_TEST2.png.sha1'),
+        os.path.join('test_grd', 'IDS_TEST2.png.sha1')
     ], warnings[0].items)
 
-  def testPngAddedSha1NotAdded(self):
-    # CL added one new message in a grd file and added the png file associated
-    # with it, but did not add the corresponding sha1 file. This should warn
-    # twice:
-    # - Once for the added png file (because we don't want developers to upload
-    #   actual images)
-    # - Once for the missing .sha1 file
+    input_api = self.makeInputApi([
+      MockAffectedFile('test.grd', self.NEW_GRD_CONTENTS2,
+                       self.NEW_GRD_CONTENTS1, action='M')])
+    warnings = PRESUBMIT._CheckTranslationScreenshots(input_api,
+                                                      MockOutputApi())
+    self.assertEqual(1, len(warnings))
+    self.assertEqual(self.GENERATE_SIGNATURES_MESSAGE, warnings[0].message)
+    self.assertEqual([os.path.join('test_grd', 'IDS_TEST2.png.sha1')],
+                     warnings[0].items)
+
+
+  def testUnnecessaryScreenshots(self):
+    # CL added a single message and added the png file, but not the sha1 file.
     input_api = self.makeInputApi([
         MockAffectedFile(
             'test.grd',
@@ -2543,59 +2494,38 @@
     self.assertEqual([os.path.join('test_grd', 'IDS_TEST1.png.sha1')],
                      warnings[1].items)
 
-    # CL added two messages (one in grd, one in grdp) and added the png files
-    # associated with the messages, but did not add the corresponding sha1
-    # files. This should warn twice:
-    # - Once for the added png files (because we don't want developers to upload
-    #   actual images)
-    # - Once for the missing .sha1 files
+    # CL added two messages, one has a png. Expect two messages:
+    # - One for the unnecessary png.
+    # - Another one for missing .sha1 files.
     input_api = self.makeInputApi([
-        # Modified files:
-        MockAffectedFile(
-            'test.grd',
-            self.NEW_GRD_CONTENTS1,
-            self.OLD_GRD_CONTENTS,
-            action='M'),
-        MockAffectedFile(
-            'part.grdp',
-            self.NEW_GRDP_CONTENTS1,
-            self.OLD_GRDP_CONTENTS,
-            action='M'),
-        # Added files:
-        MockAffectedFile(
-            os.path.join('test_grd', 'IDS_TEST1.png'), 'binary', action='A'),
-        MockAffectedFile(
-            os.path.join('part_grdp', 'IDS_PART_TEST1.png'), 'binary',
-            action='A')
-    ])
-    warnings = PRESUBMIT._CheckTranslationScreenshots(input_api,
-                                                      MockOutputApi())
-    self.assertEqual(2, len(warnings))
-    self.assertEqual(self.DO_NOT_UPLOAD_PNG_MESSAGE, warnings[0].message)
-    self.assertEqual([os.path.join('part_grdp', 'IDS_PART_TEST1.png'),
-                      os.path.join('test_grd', 'IDS_TEST1.png')],
-                     warnings[0].items)
-    self.assertEqual(self.GENERATE_SIGNATURES_MESSAGE, warnings[1].message)
-    self.assertEqual([os.path.join('part_grdp', 'IDS_PART_TEST1.png.sha1'),
-                      os.path.join('test_grd', 'IDS_TEST1.png.sha1')],
-                      warnings[1].items)
-
-  def testScreenshotsWithSha1(self):
-    # CL added four messages (two each in a grd and grdp) and their
-    # corresponding .sha1 files. No warnings.
-    input_api = self.makeInputApi([
-        # Modified files:
         MockAffectedFile(
             'test.grd',
             self.NEW_GRD_CONTENTS2,
             self.OLD_GRD_CONTENTS,
             action='M'),
         MockAffectedFile(
-            'part.grdp',
-            self.NEW_GRDP_CONTENTS2,
-            self.OLD_GRDP_CONTENTS,
+            os.path.join('test_grd', 'IDS_TEST1.png'), 'binary', action='A')
+    ])
+    warnings = PRESUBMIT._CheckTranslationScreenshots(input_api,
+                                                      MockOutputApi())
+    self.assertEqual(2, len(warnings))
+    self.assertEqual(self.DO_NOT_UPLOAD_PNG_MESSAGE, warnings[0].message)
+    self.assertEqual([os.path.join('test_grd', 'IDS_TEST1.png')],
+                     warnings[0].items)
+    self.assertEqual(self.GENERATE_SIGNATURES_MESSAGE, warnings[1].message)
+    self.assertEqual([
+        os.path.join('test_grd', 'IDS_TEST1.png.sha1'),
+        os.path.join('test_grd', 'IDS_TEST2.png.sha1')
+    ], warnings[1].items)
+
+  def testScreenshotsWithSha1(self):
+    # CL added two messages and their corresponding .sha1 files. No warnings.
+    input_api = self.makeInputApi([
+        MockAffectedFile(
+            'test.grd',
+            self.NEW_GRD_CONTENTS2,
+            self.OLD_GRD_CONTENTS,
             action='M'),
-        # Added files:
         MockFile(
             os.path.join('test_grd', 'IDS_TEST1.png.sha1'),
             'binary',
@@ -2603,106 +2533,61 @@
         MockFile(
             os.path.join('test_grd', 'IDS_TEST2.png.sha1'),
             'binary',
-            action='A'),
-        MockFile(
-            os.path.join('part_grdp', 'IDS_PART_TEST1.png.sha1'),
-            'binary',
-            action='A'),
-        MockFile(
-            os.path.join('part_grdp', 'IDS_PART_TEST2.png.sha1'),
-            'binary',
-            action='A'),
+            action='A')
     ])
     warnings = PRESUBMIT._CheckTranslationScreenshots(input_api,
                                                       MockOutputApi())
     self.assertEqual([], warnings)
 
   def testScreenshotsRemovedWithSha1(self):
-    # Replace new contents with old contents in grd and grp files, removing
-    # IDS_TEST1, IDS_TEST2, IDS_PART_TEST1 and IDS_PART_TEST2.
-    # Should warn to remove the sha1 files associated with these strings.
+    # Swap old contents with new contents, remove IDS_TEST1 and IDS_TEST2. The
+    # sha1 files associated with the messages should also be removed by the CL.
     input_api = self.makeInputApi([
-        # Modified files:
         MockAffectedFile(
             'test.grd',
-            self.OLD_GRD_CONTENTS, # new_contents
-            self.NEW_GRD_CONTENTS2, # old_contents
+            self.OLD_GRD_CONTENTS,
+            self.NEW_GRD_CONTENTS2,
             action='M'),
-        MockAffectedFile(
-            'part.grdp',
-            self.OLD_GRDP_CONTENTS, # new_contents
-            self.NEW_GRDP_CONTENTS2, # old_contents
-            action='M'),
-        # Unmodified files:
-        MockFile(os.path.join('test_grd', 'IDS_TEST1.png.sha1'), 'binary', ''),
-        MockFile(os.path.join('test_grd', 'IDS_TEST2.png.sha1'), 'binary', ''),
-        MockFile(os.path.join('part_grdp', 'IDS_PART_TEST1.png.sha1'),
-                 'binary', ''),
-        MockFile(os.path.join('part_grdp', 'IDS_PART_TEST2.png.sha1'),
-                 'binary', '')
+        MockFile(os.path.join('test_grd', 'IDS_TEST1.png.sha1'), 'binary', ""),
+        MockFile(os.path.join('test_grd', 'IDS_TEST2.png.sha1'), 'binary', "")
     ])
     warnings = PRESUBMIT._CheckTranslationScreenshots(input_api,
                                                       MockOutputApi())
     self.assertEqual(1, len(warnings))
     self.assertEqual(self.REMOVE_SIGNATURES_MESSAGE, warnings[0].message)
     self.assertEqual([
-        os.path.join('part_grdp', 'IDS_PART_TEST1.png.sha1'),
-        os.path.join('part_grdp', 'IDS_PART_TEST2.png.sha1'),
         os.path.join('test_grd', 'IDS_TEST1.png.sha1'),
         os.path.join('test_grd', 'IDS_TEST2.png.sha1')
     ], warnings[0].items)
 
-    # Same as above, but this time one of the .sha1 files is also removed.
+    # Same as above, but this time one of the .sha1 files is removed.
     input_api = self.makeInputApi([
-        # Modified files:
         MockAffectedFile(
             'test.grd',
-            self.OLD_GRD_CONTENTS, # new_contents
-            self.NEW_GRD_CONTENTS2, # old_contents
+            self.OLD_GRD_CONTENTS,
+            self.NEW_GRD_CONTENTS2,
             action='M'),
-        MockAffectedFile(
-            'part.grdp',
-            self.OLD_GRDP_CONTENTS, # new_contents
-            self.NEW_GRDP_CONTENTS2, # old_contents
-            action='M'),
-        # Unmodified files:
         MockFile(os.path.join('test_grd', 'IDS_TEST1.png.sha1'), 'binary', ''),
-        MockFile(os.path.join('part_grdp', 'IDS_PART_TEST1.png.sha1'),
-                 'binary', ''),
-        # Deleted files:
         MockAffectedFile(
             os.path.join('test_grd', 'IDS_TEST2.png.sha1'),
             '',
             'old_contents',
-            action='D'),
-        MockAffectedFile(
-            os.path.join('part_grdp', 'IDS_PART_TEST2.png.sha1'),
-            '',
-            'old_contents',
             action='D')
     ])
     warnings = PRESUBMIT._CheckTranslationScreenshots(input_api,
                                                       MockOutputApi())
     self.assertEqual(1, len(warnings))
     self.assertEqual(self.REMOVE_SIGNATURES_MESSAGE, warnings[0].message)
-    self.assertEqual([os.path.join('part_grdp', 'IDS_PART_TEST1.png.sha1'),
-                      os.path.join('test_grd', 'IDS_TEST1.png.sha1')
-                     ], warnings[0].items)
+    self.assertEqual([os.path.join('test_grd', 'IDS_TEST1.png.sha1')],
+                     warnings[0].items)
 
-    # Remove all sha1 files. There should be no warnings.
+    # Remove both sha1 files. No presubmit warnings.
     input_api = self.makeInputApi([
-        # Modified files:
         MockAffectedFile(
             'test.grd',
             self.OLD_GRD_CONTENTS,
             self.NEW_GRD_CONTENTS2,
             action='M'),
-        MockAffectedFile(
-            'part.grdp',
-            self.OLD_GRDP_CONTENTS,
-            self.NEW_GRDP_CONTENTS2,
-            action='M'),
-        # Deleted files:
         MockFile(
             os.path.join('test_grd', 'IDS_TEST1.png.sha1'),
             'binary',
@@ -2710,14 +2595,6 @@
         MockFile(
             os.path.join('test_grd', 'IDS_TEST2.png.sha1'),
             'binary',
-            action='D'),
-        MockFile(
-            os.path.join('part_grdp', 'IDS_PART_TEST1.png.sha1'),
-            'binary',
-            action='D'),
-        MockFile(
-            os.path.join('part_grdp', 'IDS_PART_TEST2.png.sha1'),
-            'binary',
             action='D')
     ])
     warnings = PRESUBMIT._CheckTranslationScreenshots(input_api,