OSDN Git Service

Workaround the issue that parameterized test don't support @UiThreadTest
authorTeng-Hui Zhu <ztenghui@google.com>
Tue, 30 Aug 2016 22:06:26 +0000 (15:06 -0700)
committerTeng-Hui Zhu <ztenghui@google.com>
Tue, 30 Aug 2016 22:06:28 +0000 (15:06 -0700)
When the test infrastructure support it, this change should be reverted.
b/30746303

Change-Id: Ice181d93f4f1210bcd2c8566e61c90035fe12ec5

apct-tests/perftests/core/src/android/widget/LayoutPerfTest.java

index ea412eb..d570ef3 100644 (file)
@@ -78,29 +78,31 @@ public class LayoutPerfTest {
 
     @Test
     @UiThreadTest
-    public void testLayoutPerf() {
-        assertTrue("We should be running on the main thread",
-                Looper.getMainLooper().getThread() == Thread.currentThread());
-        assertTrue("We should be running on the main thread",
-                Looper.myLooper() == Looper.getMainLooper());
-
-        Activity activity = mActivityRule.getActivity();
-        activity.setContentView(mLayoutId);
-
-        ViewGroup viewGroup = (ViewGroup) activity.findViewById(mViewId);
-
-        List<View> allNodes = gatherViewTree(viewGroup);
-        BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
-
-        int length = mMeasureSpecs.length;
-        while (state.keepRunning()) {
-            for (int i = 0; i < length; i++) {
-                // The overhead of this call is ignorable, like within 1% difference.
-                requestLayoutForAllNodes(allNodes);
-
-                viewGroup.measure(mMeasureSpecs[i % length], mMeasureSpecs[i % length]);
-                viewGroup.layout(0, 0, viewGroup.getMeasuredWidth(), viewGroup.getMeasuredHeight());
+    public void testLayoutPerf() throws Throwable {
+        mActivityRule.runOnUiThread(() -> {
+            assertTrue("We should be running on the main thread",
+                    Looper.getMainLooper().getThread() == Thread.currentThread());
+            assertTrue("We should be running on the main thread",
+                    Looper.myLooper() == Looper.getMainLooper());
+
+            Activity activity = mActivityRule.getActivity();
+            activity.setContentView(mLayoutId);
+
+            ViewGroup viewGroup = (ViewGroup) activity.findViewById(mViewId);
+
+            List<View> allNodes = gatherViewTree(viewGroup);
+            BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+
+            int length = mMeasureSpecs.length;
+            while (state.keepRunning()) {
+                for (int i = 0; i < length; i++) {
+                    // The overhead of this call is ignorable, like within 1% difference.
+                    requestLayoutForAllNodes(allNodes);
+
+                    viewGroup.measure(mMeasureSpecs[i % length], mMeasureSpecs[i % length]);
+                    viewGroup.layout(0, 0, viewGroup.getMeasuredWidth(), viewGroup.getMeasuredHeight());
+                }
             }
-        }
+        });
     }
 }