summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaurice Lam <yukl@google.com>2015-04-07 16:57:48 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2015-04-07 16:57:48 +0000
commit5575246aae55ec053430d23b9bd515c8bb0cc51c (patch)
tree6bc095ca49be9c0e453eb116e82ba1c1589b3c38
parent589209c5b6a8636a4e88cd101eff614ba1f87f84 (diff)
parent64158e33c3ad618ed0eecef71fd20dd8e3c02568 (diff)
downloadandroid_frameworks_opt_setupwizard-5575246aae55ec053430d23b9bd515c8bb0cc51c.tar.gz
android_frameworks_opt_setupwizard-5575246aae55ec053430d23b9bd515c8bb0cc51c.tar.bz2
android_frameworks_opt_setupwizard-5575246aae55ec053430d23b9bd515c8bb0cc51c.zip
am 64158e33: [SetupWizardLib] Fix Partner class and tests
* commit '64158e33c3ad618ed0eecef71fd20dd8e3c02568': [SetupWizardLib] Fix Partner class and tests
-rw-r--r--library/main/src/com/android/setupwizardlib/util/Partner.java13
-rw-r--r--library/test/res/values/config.xml3
-rw-r--r--library/test/src/com/android/setupwizardlib/test/PartnerTest.java54
3 files changed, 61 insertions, 9 deletions
diff --git a/library/main/src/com/android/setupwizardlib/util/Partner.java b/library/main/src/com/android/setupwizardlib/util/Partner.java
index 5a81d4c..b41edf9 100644
--- a/library/main/src/com/android/setupwizardlib/util/Partner.java
+++ b/library/main/src/com/android/setupwizardlib/util/Partner.java
@@ -78,24 +78,27 @@ public class Partner {
*/
public static ResourceEntry getResourceEntry(Context context, int id) {
final Partner partner = Partner.get(context);
- if (partner == null) {
- return new ResourceEntry(context.getResources(), id);
- } else {
+ if (partner != null) {
final Resources ourResources = context.getResources();
final String name = ourResources.getResourceEntryName(id);
final String type = ourResources.getResourceTypeName(id);
final int partnerId = partner.getIdentifier(name, type);
- return new ResourceEntry(partner.mResources, partnerId);
+ if (partnerId != 0) {
+ return new ResourceEntry(partner.mResources, partnerId, true);
+ }
}
+ return new ResourceEntry(context.getResources(), id, false);
}
public static class ResourceEntry {
public Resources resources;
public int id;
+ public boolean isOverlay;
- ResourceEntry(Resources resources, int id) {
+ ResourceEntry(Resources resources, int id, boolean isOverlay) {
this.resources = resources;
this.id = id;
+ this.isOverlay = isOverlay;
}
}
diff --git a/library/test/res/values/config.xml b/library/test/res/values/config.xml
index 35425fc..d4027d0 100644
--- a/library/test/res/values/config.xml
+++ b/library/test/res/values/config.xml
@@ -17,9 +17,6 @@
<resources>
- <!-- Overlay the transition duration for testing partner overlays -->
- <integer name="suwTransitionDuration">5000</integer>
-
<item type="id" name="test_view_id" />
</resources>
diff --git a/library/test/src/com/android/setupwizardlib/test/PartnerTest.java b/library/test/src/com/android/setupwizardlib/test/PartnerTest.java
index c5d698f..3265164 100644
--- a/library/test/src/com/android/setupwizardlib/test/PartnerTest.java
+++ b/library/test/src/com/android/setupwizardlib/test/PartnerTest.java
@@ -26,14 +26,18 @@ import android.content.pm.ResolveInfo;
import android.content.res.Resources;
import android.test.InstrumentationTestCase;
import android.test.mock.MockPackageManager;
+import android.test.mock.MockResources;
import android.test.suitebuilder.annotation.SmallTest;
+import android.util.SparseArray;
import com.android.setupwizardlib.util.Partner;
import com.android.setupwizardlib.util.Partner.ResourceEntry;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
public class PartnerTest extends InstrumentationTestCase {
@@ -76,6 +80,7 @@ public class PartnerTest extends InstrumentationTestCase {
assertNull("Partner should be null", partner);
}
+ @SmallTest
public void testLoadPartnerValue() {
mTestContext.partnerList = Arrays.asList(
createResolveInfo("hocus.pocus", false),
@@ -86,8 +91,10 @@ public class PartnerTest extends InstrumentationTestCase {
Partner.getResourceEntry(mTestContext, R.integer.suwTransitionDuration);
int partnerValue = entry.resources.getInteger(entry.id);
assertEquals("Partner value should be overlaid to 5000", 5000, partnerValue);
+ assertTrue("Partner value should come from overlay", entry.isOverlay);
}
+ @SmallTest
public void testLoadDefaultValue() {
mTestContext.partnerList = Arrays.asList(
createResolveInfo("hocus.pocus", false),
@@ -98,6 +105,7 @@ public class PartnerTest extends InstrumentationTestCase {
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);
+ assertFalse("Partner value should come from fallback", entry.isOverlay);
}
private ResolveInfo createResolveInfo(String packageName, boolean isSystem) {
@@ -114,18 +122,62 @@ public class PartnerTest extends InstrumentationTestCase {
return info;
}
+ private static class TestResources extends MockResources {
+
+ private static final Map<String, Integer> TEST_RESOURCE_IDS = new HashMap<>();
+ private static final SparseArray<Object> TEST_RESOURCES = new SparseArray<>();
+
+ private static void addItem(String name, int id, Object value) {
+ TEST_RESOURCE_IDS.put(name, id);
+ TEST_RESOURCES.put(id, value);
+ }
+
+ static {
+ addItem("integer/suwTransitionDuration", 0x7f010000, 5000);
+ }
+
+ @Override
+ public int getIdentifier(String name, String defType, String defPackage) {
+ String key = defType + "/" + name;
+ if (TEST_RESOURCE_IDS.containsKey(key)) {
+ return TEST_RESOURCE_IDS.get(key);
+ }
+ return 0;
+ }
+
+ @Override
+ public int getInteger(int id) throws NotFoundException {
+ if (TEST_RESOURCES.indexOfKey(id) >= 0) {
+ return (int) TEST_RESOURCES.get(id);
+ } else {
+ throw new NotFoundException();
+ }
+ }
+
+ @Override
+ public int getColor(int id) throws NotFoundException {
+ if (TEST_RESOURCES.indexOfKey(id) >= 0) {
+ return (int) TEST_RESOURCES.get(id);
+ } else {
+ throw new NotFoundException();
+ }
+ }
+ }
+
private static class TestPackageManager extends MockPackageManager {
private Context mTestContext;
+ private Resources mTestResources;
public TestPackageManager(Context testContext) {
mTestContext = testContext;
+ mTestResources = new TestResources();
}
@Override
public Resources getResourcesForApplication(ApplicationInfo app) {
if (app != null && "com.android.setupwizardlib.test".equals(app.packageName)) {
- return mTestContext.getResources();
+ return mTestResources;
} else {
return super.getResourcesForApplication(app);
}