Check more cases in android log tag PRESUBMIT

Relax a regex to catch Log.e("log message", ..) as a bad/missing TAG
instead of silently accepting it. Also add a rough TAG-change detection
regex to try and make changes that only touch a TAG also run the checks.
Adjust tests to match.

Bug: 1063573
Change-Id: I6a5c302d581aa76ebfc86a286e6048412641f4de
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2113572
Auto-Submit: Tomasz Śniatowski <[email protected]>
Commit-Queue: Andrew Grieve <[email protected]>
Reviewed-by: Andrew Grieve <[email protected]>
Cr-Commit-Position: refs/heads/master@{#752441}
diff --git a/PRESUBMIT.py b/PRESUBMIT.py
index d19b670..c939886 100644
--- a/PRESUBMIT.py
+++ b/PRESUBMIT.py
@@ -3269,9 +3269,10 @@
   has_some_log_import_pattern = input_api.re.compile(
       r'^import .*\.Log;$', input_api.re.MULTILINE)
   # Extract the tag from lines like `Log.d(TAG, "*");` or `Log.d("TAG", "*");`
-  log_call_pattern = input_api.re.compile(r'^\s*Log\.\w\((?P<tag>\"?\w+\"?)\,')
+  log_call_pattern = input_api.re.compile(r'\bLog\.\w\((?P<tag>\"?\w+)')
   log_decl_pattern = input_api.re.compile(
       r'static final String TAG = "(?P<name>(.*))"')
+  rough_log_decl_pattern = input_api.re.compile(r'\bString TAG\s*=')
 
   REF_MSG = ('See docs/android_logging.md for more info.')
   sources = lambda x: input_api.FilterSourceFile(x, white_list=[r'.*\.java$'],
@@ -3286,13 +3287,14 @@
   for f in input_api.AffectedSourceFiles(sources):
     file_content = input_api.ReadFile(f)
     has_modified_logs = False
-
     # Per line checks
     if (cr_log_import_pattern.search(file_content) or
         (class_in_base_pattern.search(file_content) and
             not has_some_log_import_pattern.search(file_content))):
       # Checks to run for files using cr log
       for line_num, line in f.ChangedContents():
+        if rough_log_decl_pattern.search(line):
+          has_modified_logs = True
 
         # Check if the new line is doing some logging
         match = log_call_pattern.search(line)