Fix wm test rule to rethrow exceptions and update StubTransaction

Test: presubmit
Test: atest WmTests:SystemServicesTestRuleTest
Change-Id: I412093ea0e7fcbe47c2f33d0588c26626ea01b65
This commit is contained in:
Vishnu Nair
2020-02-18 11:18:46 -08:00
parent 5a99280ce7
commit cf786c012f
6 changed files with 86 additions and 0 deletions

View File

@@ -209,6 +209,7 @@ public class AppWindowTokenTests extends WindowTestsBase {
}
@Test
@FlakyTest(bugId = 149760957)
public void testSizeCompatBounds() {
// Disable the real configuration resolving because we only simulate partial flow.
// TODO: Have test use full flow.

View File

@@ -40,6 +40,8 @@ import static java.util.stream.Collectors.toList;
import android.platform.test.annotations.Presubmit;
import android.view.SurfaceControl;
import androidx.test.filters.FlakyTest;
import org.hamcrest.CustomTypeSafeMatcher;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
@@ -65,6 +67,7 @@ public class DisplayAreaPolicyBuilderTest {
private TestWindowManagerPolicy mPolicy = new TestWindowManagerPolicy(null, null);
@Test
@FlakyTest(bugId = 149760939)
public void testBuilder() {
WindowManagerService wms = mSystemServices.getWindowManagerService();
DisplayArea.Root root = new SurfacelessDisplayAreaRoot(wms);

View File

@@ -599,6 +599,7 @@ public class DisplayPolicyLayoutTests extends DisplayPolicyTestsBase {
}
@Test
@FlakyTest(bugId = 149760800)
public void layoutWindowLw_withLongEdgeDisplayCutout() {
addLongEdgeDisplayCutout();
@@ -618,6 +619,7 @@ public class DisplayPolicyLayoutTests extends DisplayPolicyTestsBase {
}
@Test
@FlakyTest(bugId = 149760800)
public void layoutWindowLw_withLongEdgeDisplayCutout_never() {
addLongEdgeDisplayCutout();

View File

@@ -255,4 +255,9 @@ public class StubTransaction extends SurfaceControl.Transaction {
int priority) {
return this;
}
@Override
public SurfaceControl.Transaction unsetColor(SurfaceControl sc) {
return this;
}
}

View File

@@ -137,6 +137,7 @@ public class SystemServicesTestRule implements TestRule {
}
throw t;
}
if (throwable != null) throw throwable;
}
}
};

View File

@@ -0,0 +1,74 @@
/*
* Copyright (C) 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.server.wm;
import static junit.framework.Assert.assertTrue;
import android.platform.test.annotations.Presubmit;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runners.model.Statement;
import java.io.IOException;
@Presubmit
public class SystemServicesTestRuleTest {
@Rule
public ExpectedException mExpectedException = ExpectedException.none();
@Test
public void testRule_rethrows_unchecked_exceptions() throws Throwable {
final SystemServicesTestRule mWmsRule = new SystemServicesTestRule();
Statement statement = new Statement() {
@Override
public void evaluate() throws Throwable {
throw new RuntimeException("A failing test!");
}
};
mExpectedException.expect(RuntimeException.class);
mWmsRule.apply(statement, null /* Description*/).evaluate();
}
@Test
public void testRule_rethrows_checked_exceptions() throws Throwable {
final SystemServicesTestRule mWmsRule = new SystemServicesTestRule();
Statement statement = new Statement() {
@Override
public void evaluate() throws Throwable {
throw new IOException("A failing test!");
}
};
mExpectedException.expect(IOException.class);
mWmsRule.apply(statement, null /* Description*/).evaluate();
}
@Test
public void testRule_ranSuccessfully() throws Throwable {
final boolean[] testRan = {false};
final SystemServicesTestRule mWmsRule = new SystemServicesTestRule();
Statement statement = new Statement() {
@Override
public void evaluate() throws Throwable {
testRan[0] = true;
}
};
mWmsRule.apply(statement, null /* Description*/).evaluate();
assertTrue(testRan[0]);
}
}