Bug 1168175 - Turn on screen and disable keyboard before running each test. r=gbrown
--- a/mobile/android/app/src/androidTest/AndroidManifest.xml
+++ b/mobile/android/app/src/androidTest/AndroidManifest.xml
@@ -6,16 +6,19 @@
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="${MOZ_ANDROID_MIN_SDK_VERSION}"
android:targetSdkVersion="23"/>
<!-- TODO: re-instate maxSdkVersion. -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
+ <uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
+ <uses-permission android:name="android.permission.WAKE_LOCK" />
+
<instrumentation
android:name="org.mozilla.gecko.FennecInstrumentationTestRunner"
android:targetPackage="${ANDROID_PACKAGE_NAME}" />
<application
android:label="@string/app_name">
<uses-library android:name="android.test.runner" />
--- a/mobile/android/tests/browser/robocop/AndroidManifest.xml.in
+++ b/mobile/android/tests/browser/robocop/AndroidManifest.xml.in
@@ -11,16 +11,19 @@
<uses-sdk android:minSdkVersion="@MOZ_ANDROID_MIN_SDK_VERSION@"
#ifdef MOZ_ANDROID_MAX_SDK_VERSION
android:maxSdkVersion="@MOZ_ANDROID_MAX_SDK_VERSION@"
#endif
android:targetSdkVersion="23"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
+ <uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
+ <uses-permission android:name="android.permission.WAKE_LOCK" />
+
<instrumentation
android:name="org.mozilla.gecko.FennecInstrumentationTestRunner"
android:targetPackage="@ANDROID_PACKAGE_NAME@" />
<application
android:label="@string/app_name"
android:debuggable="true">
--- a/mobile/android/tests/browser/robocop/src/org/mozilla/gecko/FennecInstrumentationTestRunner.java
+++ b/mobile/android/tests/browser/robocop/src/org/mozilla/gecko/FennecInstrumentationTestRunner.java
@@ -1,20 +1,29 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.gecko;
+import android.app.KeyguardManager;
+import android.content.Context;
import android.os.Bundle;
+import android.os.PowerManager;
import android.test.InstrumentationTestRunner;
import android.util.Log;
+import static android.os.PowerManager.ACQUIRE_CAUSES_WAKEUP;
+import static android.os.PowerManager.FULL_WAKE_LOCK;
+import static android.os.PowerManager.ON_AFTER_RELEASE;
+
public class FennecInstrumentationTestRunner extends InstrumentationTestRunner {
private static Bundle sArguments;
+ private PowerManager.WakeLock wakeLock;
+ private KeyguardManager.KeyguardLock keyguardLock;
@Override
public void onCreate(Bundle arguments) {
sArguments = arguments;
if (sArguments == null) {
Log.e("Robocop", "FennecInstrumentationTestRunner.onCreate got null bundle");
}
super.onCreate(arguments);
@@ -23,9 +32,37 @@ public class FennecInstrumentationTestRu
// unfortunately we have to make this static because test classes that don't extend
// from ActivityInstrumentationTestCase2 can't get a reference to this class.
public static Bundle getFennecArguments() {
if (sArguments == null) {
Log.e("Robocop", "FennecInstrumentationTestCase.getFennecArguments returns null bundle");
}
return sArguments;
}
+
+ @Override
+ public void onStart() {
+ final Context app = getTargetContext().getApplicationContext();
+
+ final String name = FennecInstrumentationTestRunner.class.getSimpleName();
+ // Unlock the device so that the tests can input keystrokes.
+ final KeyguardManager keyguard = (KeyguardManager) app.getSystemService(Context.KEYGUARD_SERVICE);
+ // Deprecated in favour of window flags, which aren't appropriate here.
+ keyguardLock = keyguard.newKeyguardLock(name);
+ keyguardLock.disableKeyguard();
+
+ // Wake up the screen.
+ final PowerManager power = (PowerManager) app.getSystemService(Context.POWER_SERVICE);
+ wakeLock = power.newWakeLock(FULL_WAKE_LOCK | ACQUIRE_CAUSES_WAKEUP | ON_AFTER_RELEASE, name);
+ wakeLock.acquire();
+
+ super.onStart();
+ }
+
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+
+ wakeLock.release();
+ // Deprecated in favour of window flags, which aren't appropriate here.
+ keyguardLock.reenableKeyguard();
+ }
}