blob: f703fbc755b538732c9e984d2f8af7f2804547dd [file] [log] [blame]
/*
* Copyright (C) 2016 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 android.transition.cts;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import android.graphics.Rect;
import android.transition.ChangeClipBounds;
import android.transition.TransitionManager;
import android.view.View;
import androidx.test.filters.MediumTest;
import androidx.test.runner.AndroidJUnit4;
import com.android.compatibility.common.util.PollingCheck;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@MediumTest
@RunWith(AndroidJUnit4.class)
public class ChangeClipBoundsTest extends BaseTransitionTest {
private ChangeClipBounds mChangeClipBounds;
@Override
@Before
public void setup() {
super.setup();
mChangeClipBounds = new ChangeClipBounds();
mTransition = mChangeClipBounds;
resetListener();
}
@Test
public void testChangeClipBounds() throws Throwable {
enterScene(R.layout.scene1);
final View redSquare = mActivity.findViewById(R.id.redSquare);
final Rect newClip = new Rect(redSquare.getLeft() + 10, redSquare.getTop() + 10,
redSquare.getRight() - 10, redSquare.getBottom() - 10);
mActivityRule.runOnUiThread(() -> {
assertNull(redSquare.getClipBounds());
TransitionManager.beginDelayedTransition(mSceneRoot, mChangeClipBounds);
redSquare.setClipBounds(newClip);
});
waitForStart();
PollingCheck.waitFor(isMiddleOfClipping(redSquare, newClip));
waitForEnd(600);
mActivityRule.runOnUiThread(() -> {
final Rect endRect = redSquare.getClipBounds();
assertNotNull(endRect);
assertEquals(newClip, endRect);
});
resetListener();
mActivityRule.runOnUiThread(() -> {
TransitionManager.beginDelayedTransition(mSceneRoot, mChangeClipBounds);
redSquare.setClipBounds(null);
});
waitForStart();
PollingCheck.waitFor(isMiddleOfClipping(redSquare, newClip));
waitForEnd(600);
mActivityRule.runOnUiThread(() -> assertNull(redSquare.getClipBounds()));
}
private static PollingCheck.PollingCheckCondition isMiddleOfClipping(final View redSquare,
final Rect newClip) {
return () -> {
Rect midClip = redSquare.getClipBounds();
return midClip.left > 0 && midClip.left < newClip.left
&& midClip.top > 0 && midClip.top < newClip.top
&& midClip.right < redSquare.getRight() && midClip.right > newClip.right
&& midClip.bottom < redSquare.getBottom() && midClip.bottom > newClip.bottom;
};
}
}