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.autofillservice.cts.augmented; 17 18 import static android.autofillservice.cts.Helper.allowOverlays; 19 import static android.autofillservice.cts.Helper.disallowOverlays; 20 21 import android.autofillservice.cts.AbstractAutoFillActivity; 22 import android.autofillservice.cts.AutoFillServiceTestCase; 23 import android.autofillservice.cts.augmented.CtsAugmentedAutofillService.AugmentedReplier; 24 import android.content.AutofillOptions; 25 import android.view.autofill.AutofillManager; 26 27 import org.junit.AfterClass; 28 import org.junit.Before; 29 import org.junit.BeforeClass; 30 31 ///// 32 ///// NOTE: changes in this class should also be applied to 33 ///// AugmentedAutofillManualActivityLaunchTestCase, which is exactly the same as this except 34 ///// by which class it extends. 35 36 // Must be public because of the @ClassRule 37 public abstract class AugmentedAutofillAutoActivityLaunchTestCase 38 <A extends AbstractAutoFillActivity> extends AutoFillServiceTestCase.AutoActivityLaunch<A> { 39 40 protected static AugmentedReplier sAugmentedReplier; 41 protected AugmentedUiBot mAugmentedUiBot; 42 43 private CtsAugmentedAutofillService.ServiceWatcher mServiceWatcher; 44 45 @BeforeClass allowAugmentedAutofill()46 public static void allowAugmentedAutofill() { 47 sContext.getApplicationContext() 48 .setAutofillOptions(AutofillOptions.forWhitelistingItself()); 49 allowOverlays(); 50 } 51 52 @AfterClass resetAllowAugmentedAutofill()53 public static void resetAllowAugmentedAutofill() { 54 sContext.getApplicationContext().setAutofillOptions(null); 55 disallowOverlays(); 56 } 57 58 @Before setFixtures()59 public void setFixtures() { 60 mServiceWatcher = null; 61 sAugmentedReplier = CtsAugmentedAutofillService.getAugmentedReplier(); 62 sAugmentedReplier.reset(); 63 CtsAugmentedAutofillService.resetStaticState(); 64 mAugmentedUiBot = new AugmentedUiBot(mUiBot); 65 mSafeCleanerRule 66 .run(() -> sAugmentedReplier.assertNoUnhandledFillRequests()) 67 .run(() -> { 68 AugmentedHelper.resetAugmentedService(); 69 if (mServiceWatcher != null) { 70 mServiceWatcher.waitOnDisconnected(); 71 } 72 }) 73 .add(() -> { return sAugmentedReplier.getExceptions(); }); 74 } 75 76 @Override getNumberRetries()77 protected int getNumberRetries() { 78 return 0; // A.K.A. "Optimistic Thinking" 79 } 80 81 @Override getSmartSuggestionMode()82 protected int getSmartSuggestionMode() { 83 return AutofillManager.FLAG_SMART_SUGGESTION_SYSTEM; 84 } 85 enableAugmentedService()86 protected CtsAugmentedAutofillService enableAugmentedService() throws InterruptedException { 87 if (mServiceWatcher != null) { 88 throw new IllegalStateException("There Can Be Only One!"); 89 } 90 91 mServiceWatcher = CtsAugmentedAutofillService.setServiceWatcher(); 92 AugmentedHelper.setAugmentedService(CtsAugmentedAutofillService.SERVICE_NAME); 93 94 CtsAugmentedAutofillService service = mServiceWatcher.waitOnConnected(); 95 service.waitUntilConnected(); 96 return service; 97 } 98 } 99