Check for obsolete screenshot test goldens on PRESUBMIT

Porting the internal script to devtools-frontend. Folders are created for each platform to prevent file not found errors.

The implementation is almost identical to the internal version, except:

  - Support for windows presubmit bots, on which this didn't run before.
  - Interactions root folder is passed as an argument to the script.

Bug: 1407638
Change-Id: Ia373ad258071cdcc0f7e5b417fcc2301d43084ce
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/4207837
Reviewed-by: Jack Franklin <jacktfranklin@chromium.org>
Commit-Queue: Andres Olivares <andoli@chromium.org>
diff --git a/PRESUBMIT.py b/PRESUBMIT.py
index 7a3ad05..c161748 100644
--- a/PRESUBMIT.py
+++ b/PRESUBMIT.py
@@ -543,6 +543,33 @@
         return []
 
 
+def _CheckObsoleteScreenshotGoldens(input_api, output_api):
+    results = [
+        output_api.PresubmitNotifyResult('Obsolete screenshot images check')
+    ]
+    interaction_test_root_path = input_api.os_path.join(
+        input_api.PresubmitLocalPath(), 'test', 'interactions')
+    interaction_test_files = [interaction_test_root_path]
+
+    interaction_test_files_changed = _getAffectedFiles(input_api,
+                                                       interaction_test_files,
+                                                       [], [])
+
+    if len(interaction_test_files_changed) > 0:
+        script_path = input_api.os_path.join(input_api.PresubmitLocalPath(),
+                                             'scripts', 'test',
+                                             'check_obsolete_goldens.js')
+        eslint_rules_dir_path = input_api.os_path.join(
+            input_api.PresubmitLocalPath(), 'scripts', 'eslint_rules')
+
+        script_args = ["--interaction-test-root", interaction_test_root_path]
+        errors_from_script = _checkWithNodeScript(input_api, output_api,
+                                                  script_path, script_args)
+        results.extend(errors_from_script)
+
+    return results
+
+
 def _RunCannedChecks(input_api, output_api):
     results = []
     results.extend(
@@ -580,6 +607,7 @@
     results.extend(_CheckFormat(input_api, output_api))
     results.extend(_CheckESBuildVersion(input_api, output_api))
     results.extend(_CheckChangesAreExclusiveToDirectory(input_api, output_api))
+    results.extend(_CheckObsoleteScreenshotGoldens(input_api, output_api))
     # Run the canned checks from `depot_tools` after the custom DevTools checks.
     # The canned checks for example check that lines have line endings. The
     # DevTools presubmit checks automatically fix these issues. If we would run