diff options
| author | Griff Hazen <griff@google.com> | 2014-07-14 23:07:22 +0000 |
|---|---|---|
| committer | Android Git Automerger <android-git-automerger@android.com> | 2014-07-14 23:07:22 +0000 |
| commit | 15d512b7b384f5650def5288daaf31fda6e2bd34 (patch) | |
| tree | 4d3ee7b01880b97405aa6e96a0b2ff91233c50d2 /tests | |
| parent | 70fb3e5463a78e491194a53febd672230338a8fc (diff) | |
| parent | fa90e0ba568e4834e481ce895c002d9d51f44fb9 (diff) | |
| download | android_frameworks_support-15d512b7b384f5650def5288daaf31fda6e2bd34.tar.gz android_frameworks_support-15d512b7b384f5650def5288daaf31fda6e2bd34.tar.bz2 android_frameworks_support-15d512b7b384f5650def5288daaf31fda6e2bd34.zip | |
am fa90e0ba: am 646064ed: Merge "Add some test for wearable extenders in support lib." into klp-modular-dev
* commit 'fa90e0ba568e4834e481ce895c002d9d51f44fb9':
Add some test for wearable extenders in support lib.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/java/android/support/v4/app/NotificationCompatWearableExtenderTest.java | 248 | ||||
| -rw-r--r-- | tests/res/drawable/action_icon.xml | 16 | ||||
| -rw-r--r-- | tests/res/drawable/action_icon2.xml | 16 | ||||
| -rw-r--r-- | tests/res/drawable/content_icon.xml | 16 | ||||
| -rw-r--r-- | tests/res/drawable/content_icon2.xml | 16 |
5 files changed, 312 insertions, 0 deletions
diff --git a/tests/java/android/support/v4/app/NotificationCompatWearableExtenderTest.java b/tests/java/android/support/v4/app/NotificationCompatWearableExtenderTest.java new file mode 100644 index 0000000000..c6fa124e08 --- /dev/null +++ b/tests/java/android/support/v4/app/NotificationCompatWearableExtenderTest.java @@ -0,0 +1,248 @@ +/* + * Copyright (C) 2014 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.support.v4.app; + +import android.app.Notification; +import android.app.PendingIntent; +import android.content.Intent; +import android.os.Bundle; +import android.support.tests.R; +import android.test.AndroidTestCase; +import android.view.Gravity; + +import java.util.Arrays; +import java.util.List; + +/** + * Tests for {@link android.support.v4.app.NotificationCompat.WearableExtender}. + */ +public class NotificationCompatWearableExtenderTest extends AndroidTestCase { + public static final int CUSTOM_CONTENT_HEIGHT_DP = 256; + + private PendingIntent mPendingIntent; + private int mCustomContentHeightPx; + + @Override + protected void setUp() throws Exception { + super.setUp(); + + mPendingIntent = PendingIntent.getActivity(getContext(), 0, new Intent(), 0); + + mCustomContentHeightPx = Math.round(getContext().getResources().getDisplayMetrics().density + * CUSTOM_CONTENT_HEIGHT_DP); + } + + public void testEmptyEquals() throws Exception { + assertExtendersEqual(new Notification.WearableExtender(), + new NotificationCompat.WearableExtender()); + } + + public void testRealReadCompatEmptyValue() throws Exception { + NotificationCompat.WearableExtender compatExtender = + new NotificationCompat.WearableExtender(); + Notification notif = new NotificationCompat.Builder(getContext()) + .extend(compatExtender) + .build(); + + assertExtendersEqual(new Notification.WearableExtender(notif), compatExtender); + assertExtendersEqual(new Notification.WearableExtender(notif), + new NotificationCompat.WearableExtender(notif)); + } + + public void testCompatReadRealEmptyValue() throws Exception { + Notification.WearableExtender realExtender = + new Notification.WearableExtender(); + Notification notif = new Notification.Builder(getContext()) + .extend(realExtender) + .build(); + + assertExtendersEqual(realExtender, new NotificationCompat.WearableExtender(notif)); + assertExtendersEqual(new Notification.WearableExtender(notif), + new NotificationCompat.WearableExtender(notif)); + } + + public void testRealReadCompatValue() throws Exception { + RemoteInput.Builder remoteInput = new RemoteInput.Builder("result_key1") + .setLabel("label") + .setChoices(new CharSequence[] {"choice 1", "choice 2"}); + remoteInput.getExtras().putString("remoteinput_string", "test"); + NotificationCompat.Action.Builder action2 = new NotificationCompat.Action.Builder( + R.drawable.action_icon, "Test title", mPendingIntent) + .addRemoteInput(remoteInput.build()) + .extend(new NotificationCompat.Action.WearableExtender() + .setAvailableOffline(false)); + // Add an arbitrary key/value. + action2.getExtras().putFloat("action_float", 10.5f); + + Notification page2 = new Notification.Builder(getContext()) + .setContentTitle("page2 title") + .extend(new Notification.WearableExtender() + .setContentIcon(R.drawable.content_icon)) + .build(); + + NotificationCompat.WearableExtender compatExtender = + new NotificationCompat.WearableExtender() + .addAction(new NotificationCompat.Action(R.drawable.action_icon2, "Action1", + mPendingIntent)) + .addAction(action2.build()) + .setContentIntentAvailableOffline(false) + .setHintHideIcon(true) + .setHintShowBackgroundOnly(true) + .setStartScrollBottom(true) + .setDisplayIntent(mPendingIntent) + .addPage(page2) + .setContentIcon(R.drawable.content_icon2) + .setContentIconGravity(Gravity.START) + .setContentAction(5 /* arbitrary content action index */) + .setCustomSizePreset(NotificationCompat.WearableExtender.SIZE_MEDIUM) + .setCustomContentHeight(mCustomContentHeightPx) + .setGravity(Gravity.TOP); + + Notification notif = new NotificationCompat.Builder(getContext()) + .extend(compatExtender).build(); + assertExtendersEqual(new Notification.WearableExtender(notif), compatExtender); + assertExtendersEqual(new Notification.WearableExtender(notif), + new NotificationCompat.WearableExtender(notif)); + } + + public void testCompatReadRealValue() throws Exception { + android.app.RemoteInput.Builder remoteInput = new android.app.RemoteInput.Builder( + "result_key1") + .setLabel("label") + .setChoices(new CharSequence[] {"choice 1", "choice 2"}); + remoteInput.getExtras().putString("remoteinput_string", "test"); + Notification.Action.Builder action2 = new Notification.Action.Builder( + R.drawable.action_icon, "Test title", mPendingIntent) + .addRemoteInput(remoteInput.build()) + .extend(new Notification.Action.WearableExtender() + .setAvailableOffline(false)); + // Add an arbitrary key/value. + action2.getExtras().putFloat("action_float", 10.5f); + + Notification page2 = new Notification.Builder(getContext()) + .setContentTitle("page2 title") + .extend(new Notification.WearableExtender() + .setContentIcon(R.drawable.content_icon)) + .build(); + + Notification.WearableExtender realExtender = + new Notification.WearableExtender() + .addAction(new Notification.Action(R.drawable.action_icon2, "Action1", + mPendingIntent)) + .addAction(action2.build()) + .setContentIntentAvailableOffline(false) + .setHintHideIcon(true) + .setHintShowBackgroundOnly(true) + .setStartScrollBottom(true) + .setDisplayIntent(mPendingIntent) + .addPage(page2) + .setContentIcon(R.drawable.content_icon2) + .setContentIconGravity(Gravity.START) + .setContentAction(5 /* arbitrary content action index */) + .setCustomSizePreset(NotificationCompat.WearableExtender.SIZE_MEDIUM) + .setCustomContentHeight(mCustomContentHeightPx) + .setGravity(Gravity.TOP); + + Notification notif = new Notification.Builder(getContext()) + .extend(realExtender).build(); + assertExtendersEqual(realExtender, new NotificationCompat.WearableExtender(notif)); + assertExtendersEqual(new Notification.WearableExtender(notif), + new NotificationCompat.WearableExtender(notif)); + } + + private void assertExtendersEqual(Notification.WearableExtender real, + NotificationCompat.WearableExtender compat) { + assertActionsEquals(real.getActions(), compat.getActions()); + assertEquals(real.getContentIntentAvailableOffline(), + compat.getContentIntentAvailableOffline()); + assertEquals(real.getHintHideIcon(), compat.getHintHideIcon()); + assertEquals(real.getHintShowBackgroundOnly(), compat.getHintShowBackgroundOnly()); + assertEquals(real.getStartScrollBottom(), compat.getStartScrollBottom()); + assertEquals(real.getDisplayIntent(), compat.getDisplayIntent()); + assertPagesEquals(real.getPages(), compat.getPages()); + assertEquals(real.getBackground(), compat.getBackground()); + assertEquals(real.getContentIcon(), compat.getContentIcon()); + assertEquals(real.getContentIconGravity(), compat.getContentIconGravity()); + assertEquals(real.getContentAction(), compat.getContentAction()); + assertEquals(real.getCustomSizePreset(), compat.getCustomSizePreset()); + assertEquals(real.getCustomContentHeight(), compat.getCustomContentHeight()); + assertEquals(real.getGravity(), compat.getGravity()); + } + + private void assertPagesEquals(List<Notification> pages1, List<Notification> pages2) { + assertEquals(pages1.size(), pages2.size()); + for (int i = 0; i < pages1.size(); i++) { + assertNotificationsEqual(pages1.get(i), pages2.get(i)); + } + } + + private void assertNotificationsEqual(Notification n1, Notification n2) { + assertEquals(n1.icon, n2.icon); + assertBundlesEqual(n1.extras, n2.extras); + assertExtendersEqual(new Notification.WearableExtender(n1), + new NotificationCompat.WearableExtender(n2)); + } + + private void assertActionsEquals(List<Notification.Action> realArray, + List<NotificationCompat.Action> compatArray) { + assertEquals(realArray.size(), compatArray.size()); + for (int i = 0; i < realArray.size(); i++) { + assertActionsEqual(realArray.get(i), compatArray.get(i)); + } + } + + private void assertActionsEqual(Notification.Action real, NotificationCompat.Action compat) { + assertEquals(real.icon, compat.icon); + assertEquals(real.title, compat.title); + assertEquals(real.actionIntent, compat.actionIntent); + assertRemoteInputsEquals(real.getRemoteInputs(), compat.getRemoteInputs()); + assertBundlesEqual(real.getExtras(), compat.getExtras()); + } + + private void assertRemoteInputsEquals(android.app.RemoteInput[] realArray, + RemoteInput[] compatArray) { + assertEquals(realArray == null, compatArray == null); + if (realArray != null) { + assertEquals(realArray.length, compatArray.length); + for (int i = 0; i < realArray.length; i++) { + assertRemoteInputsEqual(realArray[i], compatArray[i]); + } + } + } + + private void assertRemoteInputsEqual(android.app.RemoteInput real, + RemoteInput compat) { + assertEquals(real.getResultKey(), compat.getResultKey()); + assertEquals(real.getLabel(), compat.getLabel()); + assertCharSequencesEquals(real.getChoices(), compat.getChoices()); + assertEquals(real.getAllowFreeFormInput(), compat.getAllowFreeFormInput()); + assertBundlesEqual(real.getExtras(), compat.getExtras()); + } + + private void assertCharSequencesEquals(CharSequence[] array1, CharSequence[] array2) { + if (!Arrays.deepEquals(array1, array2)) { + fail("Arrays not equal: " + Arrays.toString(array1) + " != " + Arrays.toString(array2)); + } + } + + private void assertBundlesEqual(Bundle bundle1, Bundle bundle2) { + assertEquals(bundle1.size(), bundle2.size()); + for (String key : bundle1.keySet()) { + assertEquals(bundle1.get(key), bundle2.get(key)); + } + } +} diff --git a/tests/res/drawable/action_icon.xml b/tests/res/drawable/action_icon.xml new file mode 100644 index 0000000000..f38b7097b3 --- /dev/null +++ b/tests/res/drawable/action_icon.xml @@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2014 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. +--> +<shape xmlns:android="http://schemas.android.com/apk/res/android" /> diff --git a/tests/res/drawable/action_icon2.xml b/tests/res/drawable/action_icon2.xml new file mode 100644 index 0000000000..f38b7097b3 --- /dev/null +++ b/tests/res/drawable/action_icon2.xml @@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2014 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. +--> +<shape xmlns:android="http://schemas.android.com/apk/res/android" /> diff --git a/tests/res/drawable/content_icon.xml b/tests/res/drawable/content_icon.xml new file mode 100644 index 0000000000..f38b7097b3 --- /dev/null +++ b/tests/res/drawable/content_icon.xml @@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2014 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. +--> +<shape xmlns:android="http://schemas.android.com/apk/res/android" /> diff --git a/tests/res/drawable/content_icon2.xml b/tests/res/drawable/content_icon2.xml new file mode 100644 index 0000000000..f38b7097b3 --- /dev/null +++ b/tests/res/drawable/content_icon2.xml @@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2014 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. +--> +<shape xmlns:android="http://schemas.android.com/apk/res/android" /> |
