Remove and ban UiThreadTestRule usage
The non-androidx version of UiThreadTestRule has surprising semantics,
like causing the @Before and @After methods to run on the UI thread,
even when not annotated.
Almost none of the tests that use UiThreadTestRule are aware of this,
and do things like poll the UI thread (causing flaky deadlocks), or
redundantly post tasks to the UI thread.
This change replicates what the androidx junit4 test runner does,
processing the @UiThreadTest annotation when running test methods to
run only the test method on the UI thread without causing other rules
or @Before/@After to run on the UI thread as well.
Bug: 1111893
Change-Id: Ib0a067e24fec0fd1a2a5b1558d30e5f85e5f37a8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2332301
Commit-Queue: Michael Thiessen <[email protected]>
Reviewed-by: Paul Jensen <[email protected]>
Reviewed-by: Ted Choc <[email protected]>
Reviewed-by: Andrew Grieve <[email protected]>
Cr-Commit-Position: refs/heads/master@{#796032}
diff --git a/PRESUBMIT.py b/PRESUBMIT.py
index 9f61883..be1c69e 100644
--- a/PRESUBMIT.py
+++ b/PRESUBMIT.py
@@ -101,6 +101,24 @@
'third_party/robolectric/local/',
),
),
+ (
+ 'android.support.test.rule.UiThreadTestRule;',
+ (
+ 'Do not use UiThreadTestRule, just use '
+ '@org.chromium.base.test.UiThreadTest on test methods that should run on '
+ 'the UI thread. See https://crbug.com/1111893.',
+ ),
+ (),
+ ),
+ (
+ 'android.support.test.annotation.UiThreadTest;',
+ (
+ 'Do not use android.support.test.annotation.UiThreadTest, use '
+ 'org.chromium.base.test.UiThreadTest instead. See '
+ 'https://crbug.com/1111893.',
+ ),
+ ()
+ )
)
# Format: Sequence of tuples containing: