Merge "Revert "Remove failure test that broke presubmit and build""

This commit is contained in:
TreeHugger Robot
2019-01-17 10:50:35 +00:00
committed by Android (Google) Code Review

View File

@@ -25,6 +25,13 @@ import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.any;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.anyBoolean;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.anyInt;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.doAnswer;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.doCallRealMethod;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.mock;
import static com.android.server.wm.WindowContainer.POSITION_TOP;
import static org.hamcrest.Matchers.not;
@@ -46,6 +53,7 @@ import android.platform.test.annotations.Presubmit;
import android.service.voice.IVoiceInteractionSession;
import android.util.Xml;
import android.view.DisplayInfo;
import android.view.Surface;
import androidx.test.filters.MediumTest;
@@ -276,6 +284,51 @@ public class TaskRecordTests extends ActivityTestsBase {
assertEquals(freeformBounds, task.getBounds());
}
@Test
public void testUpdatesForcedOrientationInBackground() {
final DisplayInfo info = new DisplayInfo();
info.logicalWidth = 1920;
info.logicalHeight = 1080;
final ActivityDisplay display = addNewActivityDisplayAt(info, POSITION_TOP);
doCallRealMethod().when(display.mDisplayContent).setDisplayRotation(any());
display.mDisplayContent.setDisplayRotation(mock(DisplayRotation.class));
doCallRealMethod().when(display.mDisplayContent).onDescendantOrientationChanged(any(),
any());
doCallRealMethod().when(display.mDisplayContent).setRotation(anyInt());
doAnswer(invocation -> {
display.mDisplayContent.setRotation(Surface.ROTATION_0);
return null;
}).when(display.mDisplayContent).updateOrientationFromAppTokens(any(), any(), anyBoolean());
final ActivityStack stack = new StackBuilder(mRootActivityContainer)
.setWindowingMode(WINDOWING_MODE_FULLSCREEN).setDisplay(display).build();
final TaskRecord task = stack.getChildAt(0);
final ActivityRecord activity = task.getRootActivity();
// Wire up app window token and task.
doCallRealMethod().when(activity.mAppWindowToken).setOrientation(anyInt(), any(), any());
doCallRealMethod().when(activity.mAppWindowToken).onDescendantOrientationChanged(any(),
any());
doReturn(task.mTask).when(activity.mAppWindowToken).getParent();
// Wire up task and stack.
task.mTask.mTaskRecord = task;
doCallRealMethod().when(task.mTask).onDescendantOrientationChanged(any(), any());
doReturn(stack.getTaskStack()).when(task.mTask).getParent();
// Wire up stack and display content.
doCallRealMethod().when(stack.mTaskStack).onDescendantOrientationChanged(any(), any());
doReturn(display.mDisplayContent).when(stack.mTaskStack).getParent();
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
assertTrue("Bounds of the task should be pillarboxed.",
task.getBounds().width() < task.getBounds().height());
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
assertTrue("Bounds of the task should be fullscreen.",
task.getBounds().equals(new Rect(0, 0, 1920, 1080)));
}
/** Ensures that the alias intent won't have target component resolved. */
@Test
public void testTaskIntentActivityAlias() {