diff options
author | Jinhui Wang <jinhuiw@google.com> | 2016-06-14 16:37:03 -0700 |
---|---|---|
committer | Jinhui Wang <jinhuiw@google.com> | 2016-06-21 06:57:39 -0700 |
commit | d5cdcbcea9d25bd3d0c4ccbe5fca0560338aba33 (patch) | |
tree | 1fb5e6af1312d1174fe6610ca2878b4a5ad35b25 | |
parent | 2e8c262068ccf34de556967679083d72626c7876 (diff) | |
download | AfwTestHarness-d5cdcbcea9d25bd3d0c4ccbe5fca0560338aba33.tar.gz |
Import test packages
Imported 4 test packages:
- NfcProvisioning
- NonSuwPoProvisioning
- SuwDoProvisioning
- SuwPoProvisioning
Change-Id: I170baaf684ed13c925510ef575b6ea2da6498b8a
18 files changed, 831 insertions, 0 deletions
diff --git a/tests/Android.mk b/tests/Android.mk new file mode 100644 index 0000000..41a41d0 --- /dev/null +++ b/tests/Android.mk @@ -0,0 +1,17 @@ +# +# Copyright (C) 2016 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. +# + +include $(call all-subdir-makefiles) diff --git a/tests/NfcProvisioning/Android.mk b/tests/NfcProvisioning/Android.mk new file mode 100644 index 0000000..65e6de9 --- /dev/null +++ b/tests/NfcProvisioning/Android.mk @@ -0,0 +1,33 @@ +# Copyright (C) 2016 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. + +LOCAL_PATH:= $(call my-dir) + +include $(CLEAR_VARS) + +LOCAL_PACKAGE_NAME := AfwTestNfcProvisioningTestCases + +LOCAL_MODULE_TAGS := optional + +LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS) + +LOCAL_STATIC_JAVA_LIBRARIES := ub-uiautomator AfwThCommonLib AfwThUiAutomatorLib + +LOCAL_SRC_FILES := $(call all-java-files-under, src) + +LOCAL_AFW_TEST_MODULE_CONFIG := $(LOCAL_PATH)/$(AFW_TEST_MODULE_TEST_CONFIG) + +LOCAL_SDK_VERSION := 22 + +include $(BUILD_AFW_TH_TEST_PACKAGE) diff --git a/tests/NfcProvisioning/AndroidManifest.xml b/tests/NfcProvisioning/AndroidManifest.xml new file mode 100644 index 0000000..93c1163 --- /dev/null +++ b/tests/NfcProvisioning/AndroidManifest.xml @@ -0,0 +1,30 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2016 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. +--> + +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.android.afwtest.nfcprovisioning"> + + <uses-sdk android:minSdkVersion="22"/> + + <application> + <uses-library android:name="android.test.runner" /> + </application> + + <instrumentation android:name="android.support.test.uiautomator.UiAutomatorInstrumentationTestRunner" + android:targetPackage="com.android.afwtest.nfcprovisioning" + android:label="AfW NFC Provisioning Test Package"> + </instrumentation> +</manifest> diff --git a/tests/NfcProvisioning/AndroidTest.xml b/tests/NfcProvisioning/AndroidTest.xml new file mode 100644 index 0000000..5a06ba9 --- /dev/null +++ b/tests/NfcProvisioning/AndroidTest.xml @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2016 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. +--> + +<!-- This file contains configurations used to prepare a testing device for running the + test in in AfwTestNfcProvisioningTestCases.apk. +--> +<configuration description="Test configurations for AfwTestNfcProvisioningTestCases"> + + <include name="afw-test-factory-reset"/> + + <!-- General device setup. --> + <include name="afw-test-common"/> + + <!-- Push afw-test.props --> + <include name="afw-test-push-test-suite-config"/> + + <!-- Dump testing environment info to android-cts/repository/logs/ --> + <target_preparer class="com.android.afwtest.tradefed.targetprep.AfwTestEnvDumper" > + <option name="file-name-prefix" value="AfwTestNfcProvisioningTestCases"/> + </target_preparer> +</configuration> diff --git a/tests/NfcProvisioning/src/com/android/afwtest/nfcprovisioning/NfcProvisioningTest.java b/tests/NfcProvisioning/src/com/android/afwtest/nfcprovisioning/NfcProvisioningTest.java new file mode 100644 index 0000000..c3209a6 --- /dev/null +++ b/tests/NfcProvisioning/src/com/android/afwtest/nfcprovisioning/NfcProvisioningTest.java @@ -0,0 +1,100 @@ +/* + * Copyright (C) 2016 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 com.android.afwtest.nfcprovisioning; + +import static com.android.afwtest.common.test.TestConfig.DEFAULT_TEST_CONFIG_FILE; + +import android.app.admin.DevicePolicyManager; +import android.content.Context; +import android.content.pm.PackageManager; +import android.nfc.NfcAdapter; +import android.nfc.NfcManager; +import android.support.test.uiautomator.UiAutomatorTestCase; +import android.util.Log; + +import com.android.afwtest.common.nfcprovisioning.Utils; +import com.android.afwtest.common.test.TestConfig; +import com.android.afwtest.uiautomator.provisioning.AutomationDriver; +import com.android.afwtest.uiautomator.test.AfwTestUiWatcher; + +/** + * NFC provisioning test. + */ +public class NfcProvisioningTest extends UiAutomatorTestCase { + + private static final String TAG = "afwtest.NfcProvisioningTest"; + + /** + * {@inheritDoc} + */ + @Override + public void setUp() throws Exception { + super.setUp(); + + AfwTestUiWatcher.register(getUiDevice()); + } + + /** + * {@inheritDoc} + */ + @Override + public void tearDown() throws Exception { + AfwTestUiWatcher.unregister(getUiDevice()); + + super.tearDown(); + } + + /** + * Gets application context. + * + * @return application context + */ + protected Context getContext() { + return getInstrumentation().getContext(); + } + + public void testNfcProvisioning() throws Exception { + + // Skip the test if no nfc + if (!getContext().getPackageManager().hasSystemFeature(PackageManager.FEATURE_NFC)) { + Log.w(TAG, "Device doesn't support NFC, skipping Nfc provisioning test!"); + return; + } + + // Verify if NFC is available and enabled + NfcManager nfcManager = (NfcManager) getContext().getSystemService(Context.NFC_SERVICE); + assertNotNull("Failed to get NfcManager", nfcManager); + NfcAdapter nfcAdapter = nfcManager.getDefaultAdapter(); + assertNotNull("No NFC adapter found!", nfcAdapter); + assertTrue("NFC is disabled.", nfcAdapter.isEnabled()); + + // Start provisioning + String deviceAdminPkgName = Utils.startProvisioning(getContext(), DEFAULT_TEST_CONFIG_FILE); + assertNotNull(deviceAdminPkgName); + + // Navigate the pages. + AutomationDriver driver = new AutomationDriver(getUiDevice()); + assertTrue("NFC provisioning didn't finish", + driver.runNfcProvisioning(TestConfig.getDefault())); + + DevicePolicyManager devicePolicyManager = + (DevicePolicyManager) getContext().getSystemService(Context.DEVICE_POLICY_SERVICE); + + // Verify if the device is provisioned. + assertTrue("Provisioning failed", devicePolicyManager.isDeviceOwnerApp(deviceAdminPkgName)); + } +} diff --git a/tests/NonSuwPoProvisioning/Android.mk b/tests/NonSuwPoProvisioning/Android.mk new file mode 100644 index 0000000..9077a90 --- /dev/null +++ b/tests/NonSuwPoProvisioning/Android.mk @@ -0,0 +1,33 @@ +# Copyright (C) 2016 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. + +LOCAL_PATH:= $(call my-dir) + +include $(CLEAR_VARS) + +LOCAL_PACKAGE_NAME := AfwTestNonSuwPoProvisioningTestCases + +LOCAL_MODULE_TAGS := optional + +LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS) + +LOCAL_STATIC_JAVA_LIBRARIES := ub-uiautomator AfwThCommonLib AfwThUiAutomatorLib + +LOCAL_SRC_FILES := $(call all-java-files-under, src) + +LOCAL_SDK_VERSION := 22 + +LOCAL_AFW_TEST_MODULE_CONFIG := $(LOCAL_PATH)/$(AFW_TEST_MODULE_TEST_CONFIG) + +include $(BUILD_AFW_TH_TEST_PACKAGE) diff --git a/tests/NonSuwPoProvisioning/AndroidManifest.xml b/tests/NonSuwPoProvisioning/AndroidManifest.xml new file mode 100644 index 0000000..19b8587 --- /dev/null +++ b/tests/NonSuwPoProvisioning/AndroidManifest.xml @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2016 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. +--> + +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.android.afwtest.nonsuwpoprovisioning"> + + <uses-sdk android:minSdkVersion="22"/> + + <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> + + <application> + <uses-library android:name="android.test.runner" /> + </application> + + <instrumentation android:name="android.support.test.uiautomator.UiAutomatorInstrumentationTestRunner" + android:targetPackage="com.android.afwtest.nonsuwpoprovisioning" + android:label="AfW Non-SuW PO Provisioning Test Package"> + </instrumentation> +</manifest> diff --git a/tests/NonSuwPoProvisioning/AndroidTest.xml b/tests/NonSuwPoProvisioning/AndroidTest.xml new file mode 100644 index 0000000..d0c9235 --- /dev/null +++ b/tests/NonSuwPoProvisioning/AndroidTest.xml @@ -0,0 +1,54 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2016 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. +--> + +<!-- This file contains configurations used to prepare a testing device for running the + test in in AfwTestNonSuwPoProvisioningTestCases.apk. +--> +<configuration description="Test configurations for AfwTestNonSuwPoProvisioningTestCases"> + + <!-- Disable adb root option as this test is intended to be running on production build. --> + <target_preparer class="com.android.afwtest.tradefed.targetprep.AfwTestAdbRootOptionPreparer"> + <option name="enable-root-option" value="false"/> + </target_preparer> + + <!-- General device setup --> + <include name="afw-test-common"/> + + <!-- Connect wifi --> + <include name="afw-test-wifi"/> + + <!-- Push afw-test.props --> + <include name="afw-test-push-test-suite-config"/> + + <!-- Uninstall TestDpc and reset users. --> + <include name="afw-test-uninstall-testdpc-and-reset-users"/> + + <!-- Force-stop Google Search App after the test as it often becomes not responding. --> + <target_preparer class="com.android.tradefed.targetprep.RunCommandTargetPreparer"> + <option name="teardown-command" value="am force-stop com.google.android.googlequicksearchbox"/> + </target_preparer> + + <!-- Dump testing environment info to android-cts/repository/logs/ --> + <target_preparer class="com.android.afwtest.tradefed.targetprep.AfwTestEnvDumper" > + <option name="file-name-prefix" value="AfwTestNonSuwPoProvisioningTestCases"/> + </target_preparer> + + <!-- Copy Provisioning-Stats.csv to local file --> + <target_preparer class="com.android.afwtest.tradefed.targetprep.AfwTestPullExternalFile" > + <option name="remote-file" value="Provisioning-Stats.csv"/> + <option name="local-file" value="/stats/NonSuwPoProvisioning/Provisioning-Stats.csv"/> + </target_preparer> +</configuration> diff --git a/tests/NonSuwPoProvisioning/src/com/android/afwtest/nonsuwpoprovisioning/NonSuwPoProvisioningTest.java b/tests/NonSuwPoProvisioning/src/com/android/afwtest/nonsuwpoprovisioning/NonSuwPoProvisioningTest.java new file mode 100644 index 0000000..8ed1b59 --- /dev/null +++ b/tests/NonSuwPoProvisioning/src/com/android/afwtest/nonsuwpoprovisioning/NonSuwPoProvisioningTest.java @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2016 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 com.android.afwtest.nonsuwpoprovisioning; + +import android.app.admin.DevicePolicyManager; +import android.content.Context; +import android.content.Intent; +import android.support.test.uiautomator.UiAutomatorTestCase; + +import com.android.afwtest.common.AccountManagerUtils; +import com.android.afwtest.common.test.TestConfig; +import com.android.afwtest.uiautomator.provisioning.AutomationDriver; +import com.android.afwtest.uiautomator.test.AfwTestUiWatcher; + +/** + * Test profile owner provisioning started from Settings. + */ +public class NonSuwPoProvisioningTest extends UiAutomatorTestCase { + + /** + * {@inheritDoc} + */ + @Override + public void setUp() throws Exception { + super.setUp(); + + AfwTestUiWatcher.register(getUiDevice()); + } + + /** + * {@inheritDoc} + */ + @Override + public void tearDown() throws Exception { + AfwTestUiWatcher.unregister(getUiDevice()); + + super.tearDown(); + } + + /** + * Tests non-suw profile owner provisioning flow. + */ + public void testNonSuwPoProvisioning() throws Exception { + + // Start Add Account activity. + AccountManagerUtils.startAddGoogleAccountActivity(getContext(), false); + AutomationDriver automationDriver = new AutomationDriver(getUiDevice()); + + // Navigate provisioning. + assertTrue("Non-SuW PO provisioning didn't finish", + automationDriver.runNonSuwPoProvisioning(TestConfig.getDefault())); + } + + /** + * Tests provisioning a non-existing package. + */ + public void testDisallowedProvisioning() throws Exception { + Intent startProvisioning = new Intent(DevicePolicyManager.ACTION_PROVISION_MANAGED_PROFILE); + // We're asking ManagedProvisioning to provision a non-existing package. It should not be + // allowed. + startProvisioning.putExtra( + DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME, + "package.that.does.not.exist"); + startProvisioning.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + + AutomationDriver automationDriver = new AutomationDriver(getUiDevice()); + getContext().startActivity(startProvisioning); + assertTrue("Non-SuW PO provisioning disallowed didn't finish", + automationDriver.runNonSuwPoProvisioningDisallowed(TestConfig.getDefault())); + } + + /** + * Gets application context. + * + * @return application context + */ + protected Context getContext() { + return getInstrumentation().getContext(); + } +} diff --git a/tests/SuwDoProvisioning/Android.mk b/tests/SuwDoProvisioning/Android.mk new file mode 100644 index 0000000..9d4bccb --- /dev/null +++ b/tests/SuwDoProvisioning/Android.mk @@ -0,0 +1,33 @@ +# Copyright (C) 2016 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. + +LOCAL_PATH:= $(call my-dir) + +include $(CLEAR_VARS) + +LOCAL_PACKAGE_NAME := AfwTestSuwDoProvisioningTestCases + +LOCAL_MODULE_TAGS := optional + +LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS) + +LOCAL_STATIC_JAVA_LIBRARIES := ub-uiautomator AfwThCommonLib AfwThUiAutomatorLib + +LOCAL_SRC_FILES := $(call all-java-files-under, src) + +LOCAL_SDK_VERSION := 22 + +LOCAL_AFW_TEST_MODULE_CONFIG := $(LOCAL_PATH)/$(AFW_TEST_MODULE_TEST_CONFIG) + +include $(BUILD_AFW_TH_TEST_PACKAGE) diff --git a/tests/SuwDoProvisioning/AndroidManifest.xml b/tests/SuwDoProvisioning/AndroidManifest.xml new file mode 100644 index 0000000..01f5f25 --- /dev/null +++ b/tests/SuwDoProvisioning/AndroidManifest.xml @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2016 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. +--> + +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.android.afwtest.suwdoprovisioning"> + + <uses-sdk android:minSdkVersion="22"/> + + <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> + + <application> + <uses-library android:name="android.test.runner" /> + </application> + + <instrumentation android:name="android.support.test.uiautomator.UiAutomatorInstrumentationTestRunner" + android:targetPackage="com.android.afwtest.suwdoprovisioning" + android:label="AfW SUW DO Provisioning Test Package"> + </instrumentation> +</manifest> diff --git a/tests/SuwDoProvisioning/AndroidTest.xml b/tests/SuwDoProvisioning/AndroidTest.xml new file mode 100644 index 0000000..cf940e8 --- /dev/null +++ b/tests/SuwDoProvisioning/AndroidTest.xml @@ -0,0 +1,41 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2016 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. +--> + +<!-- This file contains configurations used to prepare a testing device for running the + test in AfwTestSuwDoProvisioningTestCases.apk. +--> +<configuration description="Test configurations for AfwTestSuwDoProvisioningTestCases"> + + <!-- Factory Reset Device --> + <include name="afw-test-factory-reset"/> + + <!-- General device setup --> + <include name="afw-test-common"/> + + <!-- Encrypt Device --> + <target_preparer class="com.android.afwtest.tradefed.targetprep.AfwTestEncryptDevice"/> + + <!-- Connect wifi --> + <include name="afw-test-wifi"/> + + <!-- Push afw-test.props --> + <include name="afw-test-push-test-suite-config"/> + + <!-- Dump testing environment info to android-cts/repository/logs/ --> + <target_preparer class="com.android.afwtest.tradefed.targetprep.AfwTestEnvDumper" > + <option name="file-name-prefix" value="AfwTestSuwDoProvisioningTestCases"/> + </target_preparer> +</configuration> diff --git a/tests/SuwDoProvisioning/src/com/android/afwtest/suwdoprovisioning/SuwDoProvisioningTest.java b/tests/SuwDoProvisioning/src/com/android/afwtest/suwdoprovisioning/SuwDoProvisioningTest.java new file mode 100644 index 0000000..42bc9b7 --- /dev/null +++ b/tests/SuwDoProvisioning/src/com/android/afwtest/suwdoprovisioning/SuwDoProvisioningTest.java @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2016 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 com.android.afwtest.suwdoprovisioning; + +import static com.android.afwtest.uiautomator.Constants.TESTDPC_PKG_NAME; + +import android.app.admin.DevicePolicyManager; +import android.content.Context; +import android.support.test.uiautomator.UiAutomatorTestCase; + +import com.android.afwtest.common.AccountManagerUtils; +import com.android.afwtest.common.test.TestConfig; +import com.android.afwtest.uiautomator.provisioning.AutomationDriver; +import com.android.afwtest.uiautomator.test.AfwTestUiWatcher; + +/** + * SuW device owner provisioning test. + */ +public class SuwDoProvisioningTest extends UiAutomatorTestCase { + + /** + * {@inheritDoc} + */ + @Override + public void setUp() throws Exception { + super.setUp(); + + AfwTestUiWatcher.register(getUiDevice()); + } + + /** + * {@inheritDoc} + */ + @Override + public void tearDown() throws Exception { + AfwTestUiWatcher.unregister(getUiDevice()); + + super.tearDown(); + } + + /** + * Tests Device Owner provisioning flow. + */ + public void testDoProvisioning() throws Exception { + + AccountManagerUtils.startAddGoogleAccountActivity(getContext(), true); + + AutomationDriver runner = new AutomationDriver(getUiDevice()); + assertTrue("SuW DO provisioning didn't finish", + runner.runSuwDoProvisioning(TestConfig.getDefault())); + + DevicePolicyManager devicePolicyManager = + (DevicePolicyManager) getContext().getSystemService(Context.DEVICE_POLICY_SERVICE); + + // Verify if the device is provisioned. + assertTrue("Provisioning failed", + devicePolicyManager.isDeviceOwnerApp(TESTDPC_PKG_NAME)); + } + + /** + * Gets application context. + * + * @return application context + */ + protected Context getContext() { + return getInstrumentation().getContext(); + } +} diff --git a/tests/SuwPoProvisioning/Android.mk b/tests/SuwPoProvisioning/Android.mk new file mode 100644 index 0000000..5bd5be7 --- /dev/null +++ b/tests/SuwPoProvisioning/Android.mk @@ -0,0 +1,33 @@ +# Copyright (C) 2016 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. + +LOCAL_PATH:= $(call my-dir) + +include $(CLEAR_VARS) + +LOCAL_PACKAGE_NAME := AfwTestSuwPoProvisioningTestCases + +LOCAL_MODULE_TAGS := optional + +LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS) + +LOCAL_STATIC_JAVA_LIBRARIES := ub-uiautomator AfwThCommonLib AfwThUiAutomatorLib + +LOCAL_SRC_FILES := $(call all-java-files-under, src) + +LOCAL_SDK_VERSION := 22 + +LOCAL_AFW_TEST_MODULE_CONFIG := $(LOCAL_PATH)/$(AFW_TEST_MODULE_TEST_CONFIG) + +include $(BUILD_AFW_TH_TEST_PACKAGE) diff --git a/tests/SuwPoProvisioning/AndroidManifest.xml b/tests/SuwPoProvisioning/AndroidManifest.xml new file mode 100644 index 0000000..23edc7a --- /dev/null +++ b/tests/SuwPoProvisioning/AndroidManifest.xml @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2016 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. +--> + +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.android.afwtest.suwpoprovisioning"> + + <uses-sdk android:minSdkVersion="22"/> + + <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> + + <application> + <uses-library android:name="android.test.runner" /> + </application> + + <instrumentation android:name="android.support.test.uiautomator.UiAutomatorInstrumentationTestRunner" + android:targetPackage="com.android.afwtest.suwpoprovisioning" + android:label="AfW SUW PO Provisioning Test Package"> + </instrumentation> +</manifest> diff --git a/tests/SuwPoProvisioning/AndroidTest.xml b/tests/SuwPoProvisioning/AndroidTest.xml new file mode 100644 index 0000000..d8283cb --- /dev/null +++ b/tests/SuwPoProvisioning/AndroidTest.xml @@ -0,0 +1,52 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2016 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. +--> + +<!-- This file contains configurations used to prepare a testing device for running the + test in AfwTestSuwPoProvisioningTestCases.apk. +--> +<configuration description="Test configurations for AfwTestSuwPoProvisioningTestCases"> + + <!-- Factory Reset Device --> + <include name="afw-test-factory-reset"/> + + <!-- General device setup --> + <include name="afw-test-common"/> + + <!-- Encrypt Device --> + <target_preparer class="com.android.afwtest.tradefed.targetprep.AfwTestEncryptDevice"/> + + <!-- Connect wifi --> + <include name="afw-test-wifi"/> + + <!-- Push afw-test.props --> + <include name="afw-test-push-test-suite-config"/> + + <!-- Remove non-primary user after the test. --> + <target_preparer class="com.android.afwtest.tradefed.targetprep.AfwTestUserRemover"> + <option name="remove-users-before-test" value="false"/> + </target_preparer> + + <!-- Force-stop Google Search App after the test as it often becomes not responding. --> + <target_preparer class="com.android.tradefed.targetprep.RunCommandTargetPreparer"> + <option name="teardown-command" value="am force-stop com.google.android.googlequicksearchbox"/> + </target_preparer> + + <!-- Dump testing environment info to android-cts/repository/logs/ --> + <target_preparer class="com.android.afwtest.tradefed.targetprep.AfwTestEnvDumper" > + <option name="file-name-prefix" value="AfwTestSuwPoProvisioningTestCases"/> + </target_preparer> + +</configuration> diff --git a/tests/SuwPoProvisioning/src/com/android/afwtest/suwpoprovisioning/SuwPoProvisioningTest.java b/tests/SuwPoProvisioning/src/com/android/afwtest/suwpoprovisioning/SuwPoProvisioningTest.java new file mode 100644 index 0000000..8359aaf --- /dev/null +++ b/tests/SuwPoProvisioning/src/com/android/afwtest/suwpoprovisioning/SuwPoProvisioningTest.java @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2016 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 com.android.afwtest.suwpoprovisioning; + +import android.content.Context; +import android.support.test.uiautomator.UiAutomatorTestCase; + +import com.android.afwtest.common.AccountManagerUtils; +import com.android.afwtest.common.test.TestConfig; +import com.android.afwtest.uiautomator.provisioning.AutomationDriver; +import com.android.afwtest.uiautomator.test.AfwTestUiWatcher; + +/** + * Test Profile Owner provisioning flow from Setup Wizard. + */ +public class SuwPoProvisioningTest extends UiAutomatorTestCase { + + /** + * {@inheritDoc} + */ + @Override + public void setUp() throws Exception { + super.setUp(); + + AfwTestUiWatcher.register(getUiDevice()); + } + + /** + * {@inheritDoc} + */ + @Override + public void tearDown() throws Exception { + AfwTestUiWatcher.unregister(getUiDevice()); + + super.tearDown(); + } + + public void testPoProvisioning() throws Exception { + + AccountManagerUtils.startAddGoogleAccountActivity(getContext(), true); + + AutomationDriver runner = new AutomationDriver(getUiDevice()); + assertTrue("SuW PO provisioning didn't finish", + runner.runSuwPoProvisioning(TestConfig.getDefault())); + } + + /** + * Gets application context. + * + * @return application context + */ + protected Context getContext() { + return getInstrumentation().getContext(); + } +} diff --git a/tests/TestPlanDef.xml b/tests/TestPlanDef.xml new file mode 100644 index 0000000..d064d1f --- /dev/null +++ b/tests/TestPlanDef.xml @@ -0,0 +1,30 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2016 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. +--> +<configuration description="Test plan definitions"> + <!-- For user debug build--> + <plan name="afw-userdebug-build"> + <package name="AfwTestNfcProvisioningTestCases"/> + <package name="AfwTestSuwDoProvisioningTestCases"/> + <package name="AfwTestSuwPoProvisioningTestCases"/> + </plan> + + <!-- For user build--> + <plan name="afw-user-build"> + <package name="AfwTestNonSuwPoProvisioningTestCases"/> + </plan> + +</configuration> + |