summaryrefslogtreecommitdiffstats
path: root/library/test
diff options
context:
space:
mode:
authorMaurice Lam <yukl@google.com>2015-03-11 10:39:25 -0700
committerMaurice Lam <yukl@google.com>2015-03-12 15:08:59 -0700
commitd617ee5e12914b052682ee6f1bdf3ece28392f54 (patch)
tree2d680d15f79cf0e4d3aee682913a67b1afe9a98d /library/test
parent9fdfbb26521f8a0032a426ad4f5da49111c8ee2a (diff)
downloadandroid_frameworks_opt_setupwizard-d617ee5e12914b052682ee6f1bdf3ece28392f54.tar.gz
android_frameworks_opt_setupwizard-d617ee5e12914b052682ee6f1bdf3ece28392f54.tar.bz2
android_frameworks_opt_setupwizard-d617ee5e12914b052682ee6f1bdf3ece28392f54.zip
[SetupWizardLib] Implement Partner
Implement Partner.java which helps to get resolve resources from an overlay package provided by Partners. Bug: 19680333 Change-Id: I11d3826398741fb48fb6cf40b1d66b18c42ea085
Diffstat (limited to 'library/test')
-rw-r--r--library/test/res/values/config.xml23
-rw-r--r--library/test/src/com/android/setupwizardlib/test/PartnerTest.java157
2 files changed, 180 insertions, 0 deletions
diff --git a/library/test/res/values/config.xml b/library/test/res/values/config.xml
new file mode 100644
index 0000000..bda4f54
--- /dev/null
+++ b/library/test/res/values/config.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2015 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.
+-->
+
+<resources>
+
+ <!-- Overlay the transition duration for testing partner overlays -->
+ <integer name="suwTransitionDuration">5000</integer>
+
+</resources>
diff --git a/library/test/src/com/android/setupwizardlib/test/PartnerTest.java b/library/test/src/com/android/setupwizardlib/test/PartnerTest.java
new file mode 100644
index 0000000..c5d698f
--- /dev/null
+++ b/library/test/src/com/android/setupwizardlib/test/PartnerTest.java
@@ -0,0 +1,157 @@
+/*
+ * Copyright (C) 2015 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.setupwizardlib.test;
+
+import android.content.Context;
+import android.content.ContextWrapper;
+import android.content.Intent;
+import android.content.pm.ActivityInfo;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+import android.content.res.Resources;
+import android.test.InstrumentationTestCase;
+import android.test.mock.MockPackageManager;
+import android.test.suitebuilder.annotation.SmallTest;
+
+import com.android.setupwizardlib.util.Partner;
+import com.android.setupwizardlib.util.Partner.ResourceEntry;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+public class PartnerTest extends InstrumentationTestCase {
+
+ private TestContext mTestContext;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ mTestContext = new TestContext(getInstrumentation().getTargetContext());
+ Partner.resetForTesting();
+ }
+
+ @SmallTest
+ public void testLoadPartner() {
+ mTestContext.partnerList = Arrays.asList(
+ createResolveInfo("hocus.pocus", false),
+ createResolveInfo("com.android.setupwizardlib.test", true)
+ );
+
+ Partner partner = Partner.get(mTestContext);
+ assertNotNull("Partner should not be null", partner);
+ }
+
+ @SmallTest
+ public void testLoadNoPartner() {
+ mTestContext.partnerList = new ArrayList<>();
+
+ Partner partner = Partner.get(mTestContext);
+ assertNull("Partner should be null", partner);
+ }
+
+ @SmallTest
+ public void testLoadNonSystemPartner() {
+ mTestContext.partnerList = Arrays.asList(
+ createResolveInfo("hocus.pocus", false),
+ createResolveInfo("com.android.setupwizardlib.test", false)
+ );
+
+ Partner partner = Partner.get(mTestContext);
+ assertNull("Partner should be null", partner);
+ }
+
+ public void testLoadPartnerValue() {
+ mTestContext.partnerList = Arrays.asList(
+ createResolveInfo("hocus.pocus", false),
+ createResolveInfo("com.android.setupwizardlib.test", true)
+ );
+
+ ResourceEntry entry =
+ Partner.getResourceEntry(mTestContext, R.integer.suwTransitionDuration);
+ int partnerValue = entry.resources.getInteger(entry.id);
+ assertEquals("Partner value should be overlaid to 5000", 5000, partnerValue);
+ }
+
+ public void testLoadDefaultValue() {
+ mTestContext.partnerList = Arrays.asList(
+ createResolveInfo("hocus.pocus", false),
+ createResolveInfo("com.android.setupwizardlib.test", true)
+ );
+
+ ResourceEntry entry =
+ Partner.getResourceEntry(mTestContext, R.color.suw_navbar_text_dark);
+ int partnerValue = entry.resources.getColor(entry.id);
+ assertEquals("Partner value should default to 0xdeffffff", 0xdeffffff, partnerValue);
+ }
+
+ private ResolveInfo createResolveInfo(String packageName, boolean isSystem) {
+ ResolveInfo info = new ResolveInfo();
+ info.resolvePackageName = packageName;
+ ActivityInfo activityInfo = new ActivityInfo();
+ ApplicationInfo appInfo = new ApplicationInfo();
+ appInfo.flags = isSystem ? ApplicationInfo.FLAG_SYSTEM : 0;
+ appInfo.packageName = packageName;
+ activityInfo.applicationInfo = appInfo;
+ activityInfo.packageName = packageName;
+ activityInfo.name = packageName;
+ info.activityInfo = activityInfo;
+ return info;
+ }
+
+ private static class TestPackageManager extends MockPackageManager {
+
+ private Context mTestContext;
+
+ public TestPackageManager(Context testContext) {
+ mTestContext = testContext;
+ }
+
+ @Override
+ public Resources getResourcesForApplication(ApplicationInfo app) {
+ if (app != null && "com.android.setupwizardlib.test".equals(app.packageName)) {
+ return mTestContext.getResources();
+ } else {
+ return super.getResourcesForApplication(app);
+ }
+ }
+
+ @Override
+ public List<ResolveInfo> queryBroadcastReceivers(Intent intent, int flags) {
+ if ("com.android.setupwizard.action.PARTNER_CUSTOMIZATION".equals(intent.getAction())) {
+ return ((TestContext) mTestContext).partnerList;
+ } else {
+ return super.queryBroadcastReceivers(intent, flags);
+ }
+ }
+ }
+
+ private static class TestContext extends ContextWrapper {
+
+ public List<ResolveInfo> partnerList;
+
+ public TestContext(Context context) {
+ super(context);
+ }
+
+ @Override
+ public PackageManager getPackageManager() {
+ return new TestPackageManager(this);
+ }
+ }
+}