diff options
author | Tsu Chiang Chuang <tsu@google.com> | 2011-06-22 11:33:16 -0700 |
---|---|---|
committer | Tsu Chiang Chuang <tsu@google.com> | 2011-06-24 16:19:37 -0700 |
commit | a760e55783ee30b0f3494e113a1c37003c9d1770 (patch) | |
tree | 0ffb695665407894a01fbd5d460c66ac3f4fb9ea /core/tests | |
parent | 8969d9924c662ab4cdacc342bbdc33756db730be (diff) | |
download | frameworks_base-a760e55783ee30b0f3494e113a1c37003c9d1770.zip frameworks_base-a760e55783ee30b0f3494e113a1c37003c9d1770.tar.gz frameworks_base-a760e55783ee30b0f3494e113a1c37003c9d1770.tar.bz2 |
adding notification stress tests.
Change-Id: Ideaae33843685fcbec4c4f38bf9c2ced97c9bf86
Diffstat (limited to 'core/tests')
-rw-r--r-- | core/tests/notificationtests/Android.mk | 16 | ||||
-rw-r--r-- | core/tests/notificationtests/AndroidManifest.xml | 29 | ||||
-rw-r--r-- | core/tests/notificationtests/src/android/app/NotificationStressTest.java | 92 |
3 files changed, 137 insertions, 0 deletions
diff --git a/core/tests/notificationtests/Android.mk b/core/tests/notificationtests/Android.mk new file mode 100644 index 0000000..be2e6bf --- /dev/null +++ b/core/tests/notificationtests/Android.mk @@ -0,0 +1,16 @@ +LOCAL_PATH:= $(call my-dir) +include $(CLEAR_VARS) + +# We only want this apk build for tests. +LOCAL_MODULE_TAGS := tests + +# Include all test java files. +LOCAL_SRC_FILES := \ + $(call all-java-files-under, src) + +LOCAL_JAVA_LIBRARIES := android.test.runner +LOCAL_PACKAGE_NAME := NotificationStressTests + +include $(BUILD_PACKAGE) + +include $(call all-makefiles-under,$(LOCAL_PATH)) diff --git a/core/tests/notificationtests/AndroidManifest.xml b/core/tests/notificationtests/AndroidManifest.xml new file mode 100644 index 0000000..51e530a --- /dev/null +++ b/core/tests/notificationtests/AndroidManifest.xml @@ -0,0 +1,29 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2011 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.notification.tests" > + + <application > + <uses-library android:name="android.test.runner" /> + </application> + + <instrumentation + android:name="android.test.InstrumentationTestRunner" + android:targetPackage="com.android.notification.tests" + android:label="Notification Stress Tests" /> + +</manifest> diff --git a/core/tests/notificationtests/src/android/app/NotificationStressTest.java b/core/tests/notificationtests/src/android/app/NotificationStressTest.java new file mode 100644 index 0000000..52ea1c4 --- /dev/null +++ b/core/tests/notificationtests/src/android/app/NotificationStressTest.java @@ -0,0 +1,92 @@ +/* + * Copyright (C) 2011 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.app; + + +import android.content.Context; +import android.content.Intent; +import android.net.Uri; +import android.os.SystemClock; +import android.test.InstrumentationTestCase; +import android.test.RepetitiveTest; +import android.test.TimedTest; + +import java.util.Random; + +/** + * Test which spams notification manager with a large number of notifications, for both stress and + * performance testing. + */ +public class NotificationStressTest extends InstrumentationTestCase { + + private static final int NUM_ITERATIONS = 200; + private static final int[] ICONS = new int[] { + android.R.drawable.stat_notify_call_mute, + android.R.drawable.stat_notify_chat, + android.R.drawable.stat_notify_error, + android.R.drawable.stat_notify_missed_call, + android.R.drawable.stat_notify_more, + android.R.drawable.stat_notify_sdcard, + android.R.drawable.stat_notify_sdcard_prepare, + android.R.drawable.stat_notify_sdcard_usb, + android.R.drawable.stat_notify_sync, + android.R.drawable.stat_notify_sync_noanim, + android.R.drawable.stat_notify_voicemail, + }; + + private final Random mRandom = new Random(); + private Context mContext; + private NotificationManager mNotificationManager; + private int notifyId = 0; + + @Override + protected void setUp() throws Exception { + super.setUp(); + mContext = getInstrumentation().getContext(); + mNotificationManager = (NotificationManager) mContext.getSystemService( + Context.NOTIFICATION_SERVICE); + } + + @Override + protected void tearDown() throws Exception { + super.tearDown(); + mNotificationManager.cancelAll(); + } + + @RepetitiveTest(numIterations=NUM_ITERATIONS) + public void testNotificationStress() { + // Cancel one of every five notifications to vary load on notification manager + if (notifyId % 5 == 4) { + mNotificationManager.cancel(notifyId - 4); + } + sendNotification(notifyId++, "testNotificationStressNotify"); + } + + private void sendNotification(int id, CharSequence text) { + // Create "typical" notification with random icon + Notification notification = new Notification(ICONS[mRandom.nextInt(ICONS.length)], text, + System.currentTimeMillis()); + // Fill in arbitrary content + Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com")); + PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, intent, 0); + CharSequence title = text + " " + id; + CharSequence subtitle = String.valueOf(System.currentTimeMillis()); + notification.setLatestEventInfo(mContext, title, subtitle, pendingIntent); + mNotificationManager.notify(id, notification); + SystemClock.sleep(10); + } +} |