Prevent further uses of old downcast helpers
Type casting related functions like IsHTMLXXXXElement,
ToHTMLXXXXElement, and ToHTMLXXXXElementOrNull are being phased out in
favor of new downcast helpers in t_p/blink/renderer/platform/casting.h.
There is still a long run to fully remove old type casting mechanism,
but this CL aims at preventing new uses to take place.
Bug: 891908
Change-Id: I6a079b9524d2e94805528bdcf17baaa66fe091da
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1879628
Reviewed-by: Daniel Cheng <[email protected]>
Commit-Queue: Abhijeet Kandalkar <[email protected]>
Cr-Commit-Position: refs/heads/master@{#710345}
diff --git a/PRESUBMIT_test.py b/PRESUBMIT_test.py
index f307519..1f41719 100755
--- a/PRESUBMIT_test.py
+++ b/PRESUBMIT_test.py
@@ -1932,6 +1932,38 @@
self.assertTrue('some/cpp/problematic/file.c' in errors[0].message)
self.assertTrue('some/cpp/ok/file.cc' not in errors[0].message)
+ def testBannedBlinkDowncastHelpers(self):
+ input_api = MockInputApi()
+ input_api.files = [
+ MockFile('some/cpp/problematic/file1.cc',
+ ['DEFINE_TYPE_CASTS(ToType, FromType, from_argument,'
+ 'PointerPredicate(), ReferencePredicate());']),
+ MockFile('some/cpp/problematic/file2.cc',
+ ['bool is_test_ele = IsHTMLTestElement(n);']),
+ MockFile('some/cpp/problematic/file3.cc',
+ ['auto* html_test_ele = ToHTMLTestElement(n);']),
+ MockFile('some/cpp/problematic/file4.cc',
+ ['auto* html_test_ele_or_null = ToHTMLTestElementOrNull(n);']),
+ MockFile('some/cpp/ok/file1.cc',
+ ['bool is_test_ele = IsA<HTMLTestElement>(n);']),
+ MockFile('some/cpp/ok/file2.cc',
+ ['auto* html_test_ele = To<HTMLTestElement>(n);']),
+ MockFile('some/cpp/ok/file3.cc',
+ ['auto* html_test_ele_or_null = ',
+ 'DynamicTo<HTMLTestElement>(n);']),
+ ]
+
+ # warnings are errors[0], errors are errors[1]
+ errors = PRESUBMIT._CheckNoBannedFunctions(input_api, MockOutputApi())
+ self.assertEqual(2, len(errors))
+ self.assertTrue('some/cpp/problematic/file1.cc' in errors[1].message)
+ self.assertTrue('some/cpp/problematic/file2.cc' in errors[0].message)
+ self.assertTrue('some/cpp/problematic/file3.cc' in errors[0].message)
+ self.assertTrue('some/cpp/problematic/file4.cc' in errors[0].message)
+ self.assertTrue('some/cpp/ok/file1.cc' not in errors[0].message)
+ self.assertTrue('some/cpp/ok/file2.cc' not in errors[0].message)
+ self.assertTrue('some/cpp/ok/file3.cc' not in errors[0].message)
+
def testBannedIosObjcFunctions(self):
input_api = MockInputApi()
input_api.files = [