• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.textclassifier.common.statsd;
18 
19 import static com.google.common.truth.Truth.assertThat;
20 
21 import android.view.textclassifier.SelectionEvent;
22 import android.view.textclassifier.TextClassificationContext;
23 import android.view.textclassifier.TextClassificationManager;
24 import android.view.textclassifier.TextClassifier;
25 import androidx.test.core.app.ApplicationProvider;
26 import androidx.test.ext.junit.runners.AndroidJUnit4;
27 import androidx.test.filters.SmallTest;
28 import com.android.textclassifier.common.logging.TextClassificationSessionId;
29 import org.junit.Test;
30 import org.junit.runner.RunWith;
31 
32 @SmallTest
33 @RunWith(AndroidJUnit4.class)
34 public class TextClassificationSessionIdConverterTest {
35 
36   @Test
testTextSelectionEvent_minimal()37   public void testTextSelectionEvent_minimal() {
38     TextClassificationManager textClassificationManager =
39         ApplicationProvider.getApplicationContext()
40             .getSystemService(TextClassificationManager.class);
41     textClassificationManager.setTextClassifier(TextClassifier.NO_OP);
42     TextClassifier textClassifier =
43         textClassificationManager.createTextClassificationSession(
44             new TextClassificationContext.Builder("com.pkg", TextClassifier.WIDGET_TYPE_TEXTVIEW)
45                 .build());
46     SelectionEvent startedEvent =
47         SelectionEvent.createSelectionStartedEvent(SelectionEvent.INVOCATION_LINK, /* start= */ 10);
48 
49     textClassifier.onSelectionEvent(startedEvent);
50     android.view.textclassifier.TextClassificationSessionId platformSessionId =
51         startedEvent.getSessionId();
52     TextClassificationSessionId textClassificationSessionId =
53         TextClassificationSessionIdConverter.fromPlatform(platformSessionId);
54 
55     assertThat(textClassificationSessionId).isNotNull();
56     assertThat(textClassificationSessionId.getValue()).isEqualTo(platformSessionId.getValue());
57   }
58 }
59