diff options
author | Jiun-Yang Hsu <jyhsu@google.com> | 2020-07-24 03:44:23 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2020-07-24 03:44:23 +0000 |
commit | 6df9ed2247bd60e24482e982143fa08a15fd686b (patch) | |
tree | 711d3a3fa0fc8a677eb66e8f097a0bf91d092c34 | |
parent | 1449ded6a4e79a4b3a6bd0acc4e7cdf07def84d8 (diff) | |
parent | a4b8bac1e3ceee6584b7ce50c51c74fac441dbda (diff) | |
download | platform_testing-6df9ed2247bd60e24482e982143fa08a15fd686b.tar.gz |
Merge "Add rules and fix bug in AbstractStandardAppHelper" into rvc-dev am: a4b8bac1e3
Original change: https://googleplex-android-review.googlesource.com/c/platform/platform_testing/+/12168029
Change-Id: I7b130f20c6fffe45f5bc227531c7337b138deccb
-rw-r--r-- | libraries/app-helpers/core/src/android/platform/helpers/AbstractStandardAppHelper.java | 2 | ||||
-rw-r--r-- | libraries/health/rules/src/android/platform/test/rule/DisableAutofillRule.java | 59 |
2 files changed, 60 insertions, 1 deletions
diff --git a/libraries/app-helpers/core/src/android/platform/helpers/AbstractStandardAppHelper.java b/libraries/app-helpers/core/src/android/platform/helpers/AbstractStandardAppHelper.java index 331091541..fe710b0b0 100644 --- a/libraries/app-helpers/core/src/android/platform/helpers/AbstractStandardAppHelper.java +++ b/libraries/app-helpers/core/src/android/platform/helpers/AbstractStandardAppHelper.java @@ -198,7 +198,7 @@ public abstract class AbstractStandardAppHelper implements IAppHelper { } } if (!mDevice.wait( - Until.hasObject(mLauncherStrategy.getWorkspaceSelector()), EXIT_WAIT_TIMEOUT)) { + Until.hasObject(getLauncherStrategy().getWorkspaceSelector()), EXIT_WAIT_TIMEOUT)) { throw new IllegalStateException("Failed to exit the app to launcher."); } } diff --git a/libraries/health/rules/src/android/platform/test/rule/DisableAutofillRule.java b/libraries/health/rules/src/android/platform/test/rule/DisableAutofillRule.java new file mode 100644 index 000000000..ec936d0f8 --- /dev/null +++ b/libraries/health/rules/src/android/platform/test/rule/DisableAutofillRule.java @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2020 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.platform.test.rule; + +import android.support.test.uiautomator.UiDevice; +import android.text.TextUtils; + +import androidx.test.platform.app.InstrumentationRegistry; + +import org.junit.runner.Description; + +import java.io.IOException; + +/** + * This rule sets the Android Autofill provider to none, and prevents autofill dialogs from popping + * up during the test. . + */ +public class DisableAutofillRule extends TestWatcher { + private String originalAutoFillService = "null"; + + @Override + protected void starting(Description description) { + try { + UiDevice uiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()); + String result = uiDevice.executeShellCommand("settings get secure autofill_service"); + if (!TextUtils.isEmpty(result) && !result.equals(originalAutoFillService)) { + originalAutoFillService = result; + } + uiDevice.executeShellCommand("settings put secure autofill_service null"); + } catch (IOException e) { + throw new RuntimeException("Failed to set autofill service to none"); + } + } + + @Override + protected void finished(Description description) { + try { + UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) + .executeShellCommand( + "settings put secure autofill_service " + originalAutoFillService); + } catch (IOException e) { + throw new RuntimeException("Failed to set autofill service back to original"); + } + } +} |