Add test duplicate check in presubmit

This CL adds a presubmit check to avoid adding both .in and .pdf file to
javascript and pixel tests.

Change-Id: If2f252d20c3bfd3f9cd5963bb3428b57f6bee1b5
Reviewed-on: https://pdfium-review.googlesource.com/5710
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Nicolás Peña <npm@chromium.org>
diff --git a/PRESUBMIT.py b/PRESUBMIT.py
index db1bf00..26d559a 100644
--- a/PRESUBMIT.py
+++ b/PRESUBMIT.py
@@ -249,6 +249,33 @@
                                                       warnings))
   return results
 
+def _CheckTestDuplicates(input_api, output_api):
+  """Checks that pixel and javascript tests don't contain duplicates.
+  We use .in and .pdf files, having both can cause race conditions on the bots,
+  which run the tests in parallel.
+  """
+  tests_added = []
+  results = []
+  for f in input_api.AffectedFiles():
+    if not f.LocalPath().startswith(('testing/resources/pixel/',
+        'testing/resources/javascript/')):
+      continue
+    end_len = 0
+    if f.LocalPath().endswith('.in'):
+      end_len = 3
+    elif f.LocalPath().endswith('.pdf'):
+      end_len = 4
+    else:
+      continue
+    path = f.LocalPath()[:-end_len];
+    if path in tests_added:
+      results.append(output_api.PresubmitError(
+          'Remove %s to prevent shadowing %s' % (path + '.pdf',
+            path + '.in')))
+    else:
+      tests_added.append(path)
+  return results
+
 
 def CheckChangeOnUpload(input_api, output_api):
   results = []
@@ -257,5 +284,6 @@
   results += input_api.canned_checks.CheckChangeLintsClean(
       input_api, output_api, None, LINT_FILTERS)
   results += _CheckIncludeOrder(input_api, output_api)
+  results += _CheckTestDuplicates(input_api, output_api)
 
   return results