1 /* 2 * Copyright (C) 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of 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, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License 15 */ 16 17 package com.android.server.wm; 18 19 import static org.junit.Assert.assertEquals; 20 import static org.junit.Assert.assertSame; 21 import static org.mockito.Mockito.mock; 22 23 import android.app.ActivityOptions; 24 import android.platform.test.annotations.Presubmit; 25 import android.window.WindowContainerToken; 26 27 import androidx.test.filters.MediumTest; 28 29 import org.junit.Test; 30 31 /** 32 * Build/Install/Run: 33 * atest WmTests:SafeActivityOptionsTest 34 */ 35 @MediumTest 36 @Presubmit 37 public class SafeActivityOptionsTest { 38 39 @Test testMerge()40 public void testMerge() { 41 final ActivityOptions opts1 = ActivityOptions.makeBasic(); 42 opts1.setLaunchDisplayId(5); 43 final ActivityOptions opts2 = ActivityOptions.makeBasic(); 44 opts2.setLaunchDisplayId(6); 45 final SafeActivityOptions options = new SafeActivityOptions(opts1); 46 final ActivityOptions result = options.mergeActivityOptions(opts1, opts2); 47 assertEquals(6, result.getLaunchDisplayId()); 48 } 49 50 @Test test_selectiveCloneDisplayOptions()51 public void test_selectiveCloneDisplayOptions() { 52 final WindowContainerToken token = mock(WindowContainerToken.class); 53 final int launchDisplayId = 5; 54 final int callerDisplayId = 6; 55 56 final SafeActivityOptions clone = new SafeActivityOptions(ActivityOptions.makeBasic() 57 .setLaunchTaskDisplayArea(token) 58 .setLaunchDisplayId(launchDisplayId) 59 .setCallerDisplayId(callerDisplayId)) 60 .selectiveCloneLaunchOptions(); 61 62 assertSame(clone.getOriginalOptions().getLaunchTaskDisplayArea(), token); 63 assertEquals(clone.getOriginalOptions().getLaunchDisplayId(), launchDisplayId); 64 assertEquals(clone.getOriginalOptions().getCallerDisplayId(), callerDisplayId); 65 } 66 67 @Test test_selectiveCloneLunchRootTask()68 public void test_selectiveCloneLunchRootTask() { 69 final WindowContainerToken token = mock(WindowContainerToken.class); 70 final SafeActivityOptions clone = new SafeActivityOptions(ActivityOptions.makeBasic() 71 .setLaunchRootTask(token)) 72 .selectiveCloneLaunchOptions(); 73 74 assertSame(clone.getOriginalOptions().getLaunchRootTask(), token); 75 } 76 } 77