Bug 1068489 - Robocop: Provide error message where device screen may be sleeping, r=nalexander
authorMark Capella <markcapella@twcny.rr.com>
Tue, 30 Sep 2014 18:52:48 -0400
changeset 208110 aa1bad45519230187138b08a4fe1ced4bf757a49
parent 208109 e1afb3399612da4a9f99e013083f1132cafd88c2
child 208111 0204f2429e77707883f544ac32dff52023b185c1
push id27576
push usercbook@mozilla.com
push dateWed, 01 Oct 2014 13:00:38 +0000
treeherderautoland@1a550125928f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnalexander
bugs1068489
milestone35.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1068489 - Robocop: Provide error message where device screen may be sleeping, r=nalexander
mobile/android/base/tests/BaseRobocopTest.java
mobile/android/base/tests/BaseTest.java
mobile/android/base/tests/UITest.java
--- a/mobile/android/base/tests/BaseRobocopTest.java
+++ b/mobile/android/base/tests/BaseRobocopTest.java
@@ -10,16 +10,18 @@ import org.mozilla.gecko.Assert;
 import org.mozilla.gecko.FennecInstrumentationTestRunner;
 import org.mozilla.gecko.FennecMochitestAssert;
 import org.mozilla.gecko.FennecNativeDriver;
 import org.mozilla.gecko.FennecTalosAssert;
 
 import org.mozilla.gecko.AppConstants;
 
 import android.app.Activity;
+import android.content.Context;
+import android.os.PowerManager;
 import android.test.ActivityInstrumentationTestCase2;
 import android.util.Log;
 
 @SuppressWarnings("unchecked")
 public abstract class BaseRobocopTest extends ActivityInstrumentationTestCase2<Activity> {
     public enum Type {
         MOCHITEST,
         TALOS
@@ -102,9 +104,18 @@ public abstract class BaseRobocopTest ex
         if (getTestType() == Type.TALOS) {
             mAsserter = new FennecTalosAssert();
         } else {
             mAsserter = new FennecMochitestAssert();
         }
         mAsserter.setLogFile(mLogFile);
         mAsserter.setTestName(getClass().getName());
     }
+
+    /**
+     * Ensure that the screen on the test device is powered on during tests.
+     */
+    public void throwIfScreenNotOn() {
+        final PowerManager pm = (PowerManager) getActivity().getSystemService(Context.POWER_SERVICE);
+        mAsserter.ok(pm.isScreenOn(),
+            "Robocop tests need the test device screen to be powered on.", "");
+    }
 }
--- a/mobile/android/base/tests/BaseTest.java
+++ b/mobile/android/base/tests/BaseTest.java
@@ -116,16 +116,19 @@ abstract class BaseTest extends BaseRobo
         setActivityIntent(i);
         mActivity = getActivity();
         // Set up Robotium.solo and Driver objects
         mSolo = new Solo(getInstrumentation(), mActivity);
         mDriver = new FennecNativeDriver(mActivity, mSolo, mRootPath);
         mActions = new FennecNativeActions(mActivity, mSolo, getInstrumentation(), mAsserter);
         mDevice = new Device();
         mDatabaseHelper = new DatabaseHelper(mActivity, mAsserter);
+
+        // Ensure Robocop tests are run with Display powered on.
+        throwIfScreenNotOn();
     }
 
     protected void initializeProfile() {
         final GeckoProfile profile;
         if (mProfile.startsWith("/")) {
             profile = GeckoProfile.get(getActivity(), "default", mProfile);
         } else {
             profile = GeckoProfile.get(getActivity(), mProfile);
--- a/mobile/android/base/tests/UITest.java
+++ b/mobile/android/base/tests/UITest.java
@@ -69,16 +69,19 @@ abstract class UITest extends BaseRoboco
         mActions = new FennecNativeActions(activity, mSolo, getInstrumentation(), mAsserter);
 
         mBaseHostnameUrl = mConfig.get("host").replaceAll("(/$)", "");
         mBaseIpUrl = mConfig.get("rawhost").replaceAll("(/$)", "");
 
         // Helpers depend on components so initialize them first.
         initComponents();
         initHelpers();
+
+        // Ensure Robocop tests are run with Display powered on.
+        throwIfScreenNotOn();
     }
 
     @Override
     public void tearDown() throws Exception {
         try {
             mAsserter.endTest();
             // request a force quit of the browser and wait for it to take effect
             GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Robocop:Quit", null));