RingtonePickerActivityTestpublic class RingtonePickerActivityTest extends android.test.ActivityInstrumentationTestCase Tests the RingtonePickerActivity.
There is a launcher for launching the RingtonePickerActivity (RPA) since the RPA needs
to be a subactivity. We don't have a reference to the actual RPA.
This relies heavily on keypresses getting to the right widget. It depends on:
Less than NUM_RINGTONES_AND_SOME ringtones on the system
Pressing arrow-down a ton will eventually end up on the 'Cancel' button
From the 'Cancel' button, pressing arrow-left will end up on 'OK' button |
Fields Summary |
---|
private static final int | NUM_RINGTONES_AND_SOME | private com.android.frameworktest.settings.RingtonePickerActivityLauncher | mActivity | private android.app.Instrumentation | mInstrumentation |
Constructors Summary |
---|
public RingtonePickerActivityTest()
super("com.android.frameworktest", RingtonePickerActivityLauncher.class);
|
Methods Summary |
---|
private void | goTo(boolean top)
// Get to the buttons at the bottom (top == false), or the top (top == true)
for (int i = 0; i < NUM_RINGTONES_AND_SOME; i++) {
sendKeys(top ? KeyEvent.KEYCODE_DPAD_UP : KeyEvent.KEYCODE_DPAD_DOWN);
}
| protected void | setUp()
super.setUp();
mActivity = getActivity();
mInstrumentation = getInstrumentation();
assertNotNull(mActivity);
assertFalse(mActivity.resultReceived);
assertNotNull(mInstrumentation);
| public void | testCancel()
mActivity.launchRingtonePickerActivity(true, null, RingtoneManager.TYPE_ALL);
mInstrumentation.waitForIdleSync();
// Go to bottom
goTo(false);
// Select Cancel button
sendKeys(KeyEvent.KEYCODE_DPAD_CENTER);
mInstrumentation.waitForIdleSync();
assertTrue(mActivity.resultReceived);
assertNull(mActivity.result);
| public void | testDefault()
mActivity.launchRingtonePickerActivity(true, null, RingtoneManager.TYPE_ALL);
mInstrumentation.waitForIdleSync();
// Go to top
goTo(true);
// Select default ringtone
sendKeys(KeyEvent.KEYCODE_DPAD_CENTER);
// Go to bottom/cancel button
goTo(false);
// Select OK button
sendKeys(KeyEvent.KEYCODE_DPAD_LEFT, KeyEvent.KEYCODE_DPAD_CENTER);
mInstrumentation.waitForIdleSync();
assertTrue(mActivity.resultReceived);
assertNotNull(mActivity.result);
assertTrue(RingtoneManager.isDefault(mActivity.pickedUri));
| public void | testExisting()
// We need to get an existing ringtone first, so launch it, pick first,
// and keep that URI
testFirst();
Uri firstUri = mActivity.pickedUri;
mActivity.launchRingtonePickerActivity(true, firstUri, RingtoneManager.TYPE_ALL);
mInstrumentation.waitForIdleSync();
//// Hit cancel:
// Go to bottom
goTo(false);
// Select Cancel button
sendKeys(KeyEvent.KEYCODE_DPAD_CENTER);
mInstrumentation.waitForIdleSync();
assertTrue(mActivity.resultReceived);
assertEquals(mActivity.pickedUri, firstUri);
| public void | testExistingButDifferent()
// We need to get an existing ringtone first, so launch it, pick first,
// and keep that URI
testFirst();
Uri firstUri = mActivity.pickedUri;
mActivity.launchRingtonePickerActivity(true, firstUri, RingtoneManager.TYPE_ALL);
mInstrumentation.waitForIdleSync();
//// Pick second:
// Go to top
goTo(true);
// Select second (non-default) ringtone
sendKeys(KeyEvent.KEYCODE_DPAD_DOWN, KeyEvent.KEYCODE_DPAD_DOWN,
KeyEvent.KEYCODE_DPAD_CENTER);
// Go to bottom/cancel button
goTo(false);
// Select OK button
sendKeys(KeyEvent.KEYCODE_DPAD_LEFT, KeyEvent.KEYCODE_DPAD_CENTER);
mInstrumentation.waitForIdleSync();
assertTrue(mActivity.resultReceived);
assertNotNull(mActivity.result);
assertTrue(!firstUri.equals(mActivity.pickedUri));
| public void | testFirst()
mActivity.launchRingtonePickerActivity(true, null, RingtoneManager.TYPE_ALL);
mInstrumentation.waitForIdleSync();
// Go to top
goTo(true);
// Select first (non-default) ringtone
sendKeys(KeyEvent.KEYCODE_DPAD_DOWN, KeyEvent.KEYCODE_DPAD_CENTER);
// Go to bottom/cancel button
goTo(false);
// Select OK button
sendKeys(KeyEvent.KEYCODE_DPAD_LEFT, KeyEvent.KEYCODE_DPAD_CENTER);
mInstrumentation.waitForIdleSync();
assertTrue(mActivity.resultReceived);
assertNotNull(mActivity.result);
assertNotNull(mActivity.pickedUri);
assertFalse(RingtoneManager.isDefault(mActivity.pickedUri));
| public void | testNoDefault()
mActivity.launchRingtonePickerActivity(false, null, RingtoneManager.TYPE_ALL);
mInstrumentation.waitForIdleSync();
// Go to top
goTo(true);
// Select first (non-default) ringtone
sendKeys(KeyEvent.KEYCODE_DPAD_CENTER);
// Go to bottom/cancel button
goTo(false);
// Select OK button
sendKeys(KeyEvent.KEYCODE_DPAD_LEFT, KeyEvent.KEYCODE_DPAD_CENTER);
mInstrumentation.waitForIdleSync();
assertTrue(mActivity.resultReceived);
assertNotNull(mActivity.result);
assertNotNull(mActivity.pickedUri);
assertFalse(RingtoneManager.isDefault(mActivity.pickedUri));
| public void | testNotifications()
mActivity.launchRingtonePickerActivity(false, null, RingtoneManager.TYPE_NOTIFICATION);
mInstrumentation.waitForIdleSync();
// Move to top of list
goTo(true);
// Select first ringtone in list
sendKeys(KeyEvent.KEYCODE_DPAD_CENTER);
// Move all the way down (will focus 'Cancel')
goTo(false);
// Move left and click (will click 'Ok')
sendKeys(KeyEvent.KEYCODE_DPAD_LEFT, KeyEvent.KEYCODE_DPAD_CENTER);
// Wait until main thread is idle
mInstrumentation.waitForIdleSync();
assertTrue(mActivity.resultReceived);
assertNotNull(mActivity.result);
assertNotNull(mActivity.pickedUri);
// Get the path of the picked ringtone
Uri uri = mActivity.pickedUri;
Cursor c = mActivity.getContentResolver().query(uri, new String[] { "_data" },
null, null, null);
assertTrue("Query for selected ringtone URI does not have a result", c.moveToFirst());
String path = c.getString(0);
// Quick check to see if the ringtone is a notification
assertTrue("The path of the selected ringtone did not contain \"notification\"",
path.contains("notifications"));
|
|