1 /* 2 * Copyright (C) 2019 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 package android.view.contentcapture; 17 18 import static com.google.common.truth.Truth.assertThat; 19 20 import android.app.assist.ActivityId; 21 import android.content.ComponentName; 22 import android.os.Binder; 23 import android.os.IBinder; 24 25 import org.junit.Test; 26 import org.junit.runner.RunWith; 27 import org.junit.runners.JUnit4; 28 29 /** 30 * Unit test for {@link ContentCaptureContext}. 31 * 32 * <p>To run it: 33 * {@code atest FrameworksCoreTests:android.view.contentcapture.ContentCaptureContextTest} 34 */ 35 @RunWith(JUnit4.class) 36 public class ContentCaptureContextTest { 37 38 @Test testConstructorAdditionalFlags()39 public void testConstructorAdditionalFlags() { 40 final ComponentName componentName = new ComponentName("component", "name"); 41 final IBinder token = new Binder(); 42 final IBinder windowToken = new Binder(); 43 final ContentCaptureContext ctx = new ContentCaptureContext(/* clientContext= */ null, 44 new ActivityId(/* taskId= */ 666, token), componentName, /* displayId= */ 45 42, windowToken, /* flags= */ 1); 46 final ContentCaptureContext newCtx = new ContentCaptureContext(ctx, /* extraFlags= */ 2); 47 assertThat(newCtx.getFlags()).isEqualTo(3); 48 assertThat(newCtx.getActivityComponent()).isEqualTo(componentName); 49 ActivityId activityId = newCtx.getActivityId(); 50 assertThat(activityId).isNotNull(); 51 assertThat(activityId.getTaskId()).isEqualTo(666); 52 assertThat(activityId.getToken()).isEqualTo(token); 53 assertThat(newCtx.getDisplayId()).isEqualTo(42); 54 assertThat(newCtx.getWindowToken()).isEqualTo(windowToken); 55 assertThat(newCtx.getExtras()).isNull(); 56 assertThat(newCtx.getLocusId()).isNull(); 57 assertThat(newCtx.getParentSessionId()).isNull(); 58 } 59 } 60