Bug 716937 - Robocop: make testBookmark more reliable; r=jmaher
authorGeoff Brown <gbrown@mozilla.com>
Wed, 18 Jan 2012 13:44:47 -0500
changeset 86027 6553d699ca34e64dbec22d26c8ae0e7e655d6893
parent 86026 acbca13be1cb99dddc347835dab0fc0b92466061
child 86028 e30e16f95cb08c0a28ff7731de249f882a250f27
push id805
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 18:17:35 +0000
treeherdermozilla-aurora@6fb3bf232436 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjmaher
bugs716937
milestone12.0a1
Bug 716937 - Robocop: make testBookmark more reliable; r=jmaher
mobile/android/base/tests/BaseTest.java.in
mobile/android/base/tests/testBookmark.java.in
--- a/mobile/android/base/tests/BaseTest.java.in
+++ b/mobile/android/base/tests/BaseTest.java.in
@@ -11,17 +11,17 @@ import android.content.Intent;
 import java.util.HashMap;
 
 abstract class BaseTest extends ActivityInstrumentationTestCase2<Activity> {
     private static final String TARGET_PACKAGE_ID = "org.mozilla.gecko";
     private static final String LAUNCH_ACTIVITY_FULL_CLASSNAME="@ANDROID_PACKAGE_NAME@.App";
 
     private static Class<Activity> mLauncherActivityClass;
     private Activity mActivity;
-    private Solo mSolo;
+    protected Solo mSolo;
     protected Driver mDriver;
     protected Assert mAsserter;
     protected Actions mActions;
 
     static {
         try {
             mLauncherActivityClass = (Class<Activity>)Class.forName(LAUNCH_ACTIVITY_FULL_CLASSNAME);
         } catch (ClassNotFoundException e) {
@@ -94,16 +94,22 @@ abstract class BaseTest extends Activity
 
     protected final void hitEnterAndWait() {
         Actions.EventExpecter contentEventExpecter = mActions.expectGeckoEvent("DOMContentLoaded");
         mActions.sendSpecialKey(Actions.SpecialKey.ENTER);
         // wait for screen to load
         contentEventExpecter.blockForEvent();
     }
 
+    protected final void waitForLoad() {
+        Actions.EventExpecter contentEventExpecter = mActions.expectGeckoEvent("DOMContentLoaded");
+        // wait for screen to load
+        contentEventExpecter.blockForEvent();
+    }
+
     protected final void loadUrl(String url) {
         enterUrl(url);
         hitEnterAndWait();
     }
 
     protected final void verifyUrl(String url) {
         Activity awesomeBarActivity = clickOnAwesomeBar();
         Element urlbar = mDriver.findElement(awesomeBarActivity, "awesomebar_text");
--- a/mobile/android/base/tests/testBookmark.java.in
+++ b/mobile/android/base/tests/testBookmark.java.in
@@ -1,31 +1,32 @@
 #filter substitution
 package @ANDROID_PACKAGE_NAME@.tests;
 
 import @ANDROID_PACKAGE_NAME@.*;
+import android.widget.TextView;
+import java.util.ArrayList;
 
 public class testBookmark extends BaseTest {
     private static final String URL = "http://mochi.test:8888/tests/robocop/robocop_blank_02.html";
 
     public void testBookmark() {
         enterUrl(URL);
 
-        //Click the top item in the list.
+        //Click the top item in the awesome list.
         mActions.sendSpecialKey(Actions.SpecialKey.DOWN);
         hitEnterAndWait();
 
-        //Click the Top item in the history list.
+        //Click the top item in the history list.
         clickOnAwesomeBar();
         mActions.sendSpecialKey(Actions.SpecialKey.RIGHT);
         mActions.sendSpecialKey(Actions.SpecialKey.RIGHT);
-        getInstrumentation().waitForIdleSync();
-        mActions.sendSpecialKey(Actions.SpecialKey.DOWN);
-        mActions.sendSpecialKey(Actions.SpecialKey.DOWN);
+        ArrayList<TextView> l = null;
+        while (l == null || l.size() < 1) {
+            // first item in the history list is a heading ("Today");
+            // click on the next one
+            l = mSolo.clickInList(2);
+        }
+        waitForLoad();
 
-        hitEnterAndWait();
-
-        getInstrumentation().waitForIdleSync();
-        //Unfortunately, the item isn't constant so can't be tested.
-        //awesomebar.click();
-        //asserter.is(url, urlbar.getText(),"Shouldn't this be the last url in the history?");
+        //Order of history items isn't constant so URL can't be tested.
     }
 }