Skip testCommaInserting if screen is off or locked.

sendKey() doesn't work if the screen is off or locked.

We could probably use a WakeLock and KeyguardLock to force the
screen to be on, but that'd require adding unnecessary permissions
to the email app. (not the test apk)

Bug 1737038

Change-Id: Ic036dc4d12770e82bc5de1133d6dd34cd8465f30
This commit is contained in:
Makoto Onuki 2010-10-18 13:47:56 -07:00
parent f8b30b776b
commit e9919377ee
2 changed files with 33 additions and 5 deletions

View File

@ -16,6 +16,9 @@
package com.android.email;
import android.app.KeyguardManager;
import android.content.Context;
import android.os.PowerManager;
import android.test.MoreAsserts;
import android.test.suitebuilder.annotation.LargeTest;
import android.util.Log;
@ -140,4 +143,20 @@ public class TestUtils extends TestCase /* It tests itself */ {
}
}, AssertionFailedError.class);
}
/**
* @return true if the screen is on and not locked; false otherwise, in which case tests that
* send key events will fail.
*/
public static boolean isScreenOnAndNotLocked(Context context) {
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
if (!pm.isScreenOn()) {
return false;
}
KeyguardManager km = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
if (km.inKeyguardRestrictedInputMode()) {
return false;
}
return true;
}
}

View File

@ -19,6 +19,7 @@ package com.android.email.activity;
import com.android.email.Email;
import com.android.email.EmailAddressValidator;
import com.android.email.R;
import com.android.email.TestUtils;
import com.android.email.mail.Address;
import com.android.email.mail.MessagingException;
import com.android.email.provider.EmailContent.Account;
@ -31,6 +32,7 @@ import android.net.Uri;
import android.test.ActivityInstrumentationTestCase2;
import android.test.UiThreadTest;
import android.test.suitebuilder.annotation.LargeTest;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.MultiAutoCompleteTextView;
@ -48,6 +50,8 @@ import android.widget.MultiAutoCompleteTextView;
public class MessageComposeTests
extends ActivityInstrumentationTestCase2<MessageCompose> {
private Context mContext;
private MultiAutoCompleteTextView mToView;
private MultiAutoCompleteTextView mCcView;
private EditText mSubjectView;
@ -119,21 +123,21 @@ public class MessageComposeTests
@Override
protected void setUp() throws Exception {
super.setUp();
Context context = getInstrumentation().getTargetContext();
mContext = getInstrumentation().getTargetContext();
// Force assignment of a default account
long accountId = Account.getDefaultAccountId(context);
long accountId = Account.getDefaultAccountId(mContext);
if (accountId == -1) {
Account account = new Account();
account.mSenderName = "Bob Sender";
account.mEmailAddress = "bob@sender.com";
account.save(context);
account.save(mContext);
accountId = account.mId;
mCreatedAccountId = accountId;
}
Account account = Account.restoreAccountWithId(context, accountId);
Account account = Account.restoreAccountWithId(mContext, accountId);
mSignature = account.getSignature();
Email.setServicesEnabled(context);
Email.setServicesEnabled(mContext);
Intent intent = new Intent(Intent.ACTION_VIEW);
setActivityIntent(intent);
@ -889,6 +893,11 @@ public class MessageComposeTests
* but we only run the full set on To:
*/
public void testCommaInserting() throws Throwable {
if (!TestUtils.isScreenOnAndNotLocked(mContext)) {
Log.w(Email.LOG_TAG, "SKIP testCommaInserting: Screen off or locked");
return;
}
// simple appending cases
checkCommaInsert("a", "", false);
checkCommaInsert("a@", "", false);