Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8cc0ab9c authored by Matt Casey's avatar Matt Casey
Browse files

Make ScrollCaptureControllerTest stricter

- Ensure requested rect overlaps with total rect.
- Ensure sequential tiles are adjacent

Test: atest ScrolCaptureControllerTest
Change-Id: Ib722b7b65a81df30930467cd5758d8e37bb71f4d
parent 177d8e36
Loading
Loading
Loading
Loading
+6 −1
Original line number Original line Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.systemui.screenshot;
package com.android.systemui.screenshot;


import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyFloat;
import static org.mockito.ArgumentMatchers.anyFloat;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyInt;
@@ -57,13 +58,17 @@ public class ScrollCaptureControllerTest extends SysuiTestCase {
        public int availableBottom = Integer.MAX_VALUE;
        public int availableBottom = Integer.MAX_VALUE;
        // If true, return an empty rect any time a partial result would have been returned.
        // If true, return an empty rect any time a partial result would have been returned.
        public boolean emptyInsteadOfPartial = false;
        public boolean emptyInsteadOfPartial = false;
        private int mPreviousTopRequested = 0;


        @Override
        @Override
        public ListenableFuture<ScrollCaptureClient.CaptureResult> requestTile(int top) {
        public ListenableFuture<ScrollCaptureClient.CaptureResult> requestTile(int top) {
            // Ensure we don't request a tile more than a tile away.
            assertTrue(Math.abs(top - mPreviousTopRequested) <= getTileHeight());
            mPreviousTopRequested = top;
            Rect requested = new Rect(0, top, getPageWidth(), top + getTileHeight());
            Rect requested = new Rect(0, top, getPageWidth(), top + getTileHeight());
            Rect fullContent = new Rect(0, availableTop, getPageWidth(), availableBottom);
            Rect fullContent = new Rect(0, availableTop, getPageWidth(), availableBottom);
            Rect captured = new Rect(requested);
            Rect captured = new Rect(requested);
            captured.intersect(fullContent);
            assertTrue(captured.intersect(fullContent));
            if (emptyInsteadOfPartial && captured.height() != getTileHeight()) {
            if (emptyInsteadOfPartial && captured.height() != getTileHeight()) {
                captured = new Rect();
                captured = new Rect();
            }
            }