Tony Mak | 751afc9 | 2019-04-02 18:23:54 +0100 | [diff] [blame^] | 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 | package android.view.textclassifier; |
| 17 | |
| 18 | import android.content.Context; |
| 19 | import android.perftests.utils.BenchmarkState; |
| 20 | import android.perftests.utils.PerfStatusReporter; |
| 21 | import android.perftests.utils.SettingsHelper; |
| 22 | import android.provider.Settings; |
| 23 | |
| 24 | import androidx.test.InstrumentationRegistry; |
| 25 | import androidx.test.filters.LargeTest; |
| 26 | |
| 27 | import org.junit.After; |
| 28 | import org.junit.Rule; |
| 29 | import org.junit.Test; |
| 30 | |
| 31 | @LargeTest |
| 32 | public class TextClassificationManagerPerfTest { |
| 33 | |
| 34 | @Rule |
| 35 | public PerfStatusReporter mPerfStatusReporter = new PerfStatusReporter(); |
| 36 | |
| 37 | @After |
| 38 | public void tearDown() { |
| 39 | SettingsHelper.delete( |
| 40 | SettingsHelper.NAMESPACE_GLOBAL, Settings.Global.TEXT_CLASSIFIER_CONSTANTS); |
| 41 | } |
| 42 | |
| 43 | @Test |
| 44 | public void testGetTextClassifier_systemTextClassifierDisabled() { |
| 45 | Context context = InstrumentationRegistry.getTargetContext(); |
| 46 | SettingsHelper.set( |
| 47 | SettingsHelper.NAMESPACE_GLOBAL, |
| 48 | Settings.Global.TEXT_CLASSIFIER_CONSTANTS, |
| 49 | "system_textclassifier_enabled=false"); |
| 50 | TextClassificationManager textClassificationManager = |
| 51 | context.getSystemService(TextClassificationManager.class); |
| 52 | BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); |
| 53 | while (state.keepRunning()) { |
| 54 | textClassificationManager.getTextClassifier(); |
| 55 | textClassificationManager.invalidate(); |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | @Test |
| 60 | public void testGetTextClassifier_systemTextClassifierEnabled() { |
| 61 | Context context = InstrumentationRegistry.getTargetContext(); |
| 62 | SettingsHelper.set( |
| 63 | SettingsHelper.NAMESPACE_GLOBAL, |
| 64 | Settings.Global.TEXT_CLASSIFIER_CONSTANTS, |
| 65 | "system_textclassifier_enabled=true"); |
| 66 | TextClassificationManager textClassificationManager = |
| 67 | context.getSystemService(TextClassificationManager.class); |
| 68 | BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); |
| 69 | while (state.keepRunning()) { |
| 70 | textClassificationManager.getTextClassifier(); |
| 71 | textClassificationManager.invalidate(); |
| 72 | } |
| 73 | } |
| 74 | } |