Home | History | Annotate | Download | only in cts
      1 /*
      2  * Copyright (C) 2016 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
      5  * use this file except in compliance with the License. You may obtain a copy of
      6  * the License at
      7  *
      8  * http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
     12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
     13  * License for the specific language governing permissions and limitations under
     14  * the License.
     15  */
     16 package android.app.cts;
     17 
     18 import static org.junit.Assert.assertEquals;
     19 import static org.junit.Assert.assertNull;
     20 import static org.junit.Assert.assertTrue;
     21 
     22 import android.app.PictureInPictureParams;
     23 import android.app.PictureInPictureParams.Builder;
     24 import android.graphics.Rect;
     25 import android.support.test.filters.SmallTest;
     26 import android.support.test.runner.AndroidJUnit4;
     27 import android.util.Rational;
     28 
     29 import org.junit.Test;
     30 import org.junit.runner.RunWith;
     31 
     32 import java.util.ArrayList;
     33 
     34 /**
     35  * Tests the {@link PictureInPictureParams} builder.
     36  */
     37 @SmallTest
     38 @RunWith(AndroidJUnit4.class)
     39 public class PictureInPictureParamsBuilderTest {
     40 
     41     @Test
     42     public void testBuildParams() throws Exception {
     43         // Set the params
     44         Builder builder = new Builder()
     45                 .setAspectRatio(new Rational(1, 2))
     46                 .setActions(new ArrayList<>())
     47                 .setSourceRectHint(new Rect(0, 0, 100, 100));
     48 
     49         PictureInPictureParams params = builder.build();
     50         assertTrue(Float.compare(0.5f, params.getAspectRatio()) == 0);
     51         assertTrue(params.getActions().isEmpty());
     52         assertEquals(new Rect(0, 0, 100, 100), params.getSourceRectHint());
     53 
     54         // Reset the params
     55         builder.setAspectRatio(null)
     56                 .setActions(null)
     57                 .setSourceRectHint(null);
     58         params = builder.build();
     59 
     60         assertTrue(Float.compare(0f, params.getAspectRatio()) == 0);
     61         assertNull(params.getActions());
     62         assertNull(params.getSourceRectHint());
     63     }
     64 }
     65