Bug 770456 - Robocop: be more careful when accessing child view in testHistoryTab; r=jmaher
authorGeoff Brown <gbrown@mozilla.com>
Fri, 24 Aug 2012 19:03:05 -0600
changeset 105397 010b43686a5fb14887b56289d8635582eb49c9fb
parent 105396 dc3f29a730b10ace9129d2605c7a40822ee8121f
child 105398 89e186d2a1716b5609fb939394853d23558b4b01
push id55
push usershu@rfrn.org
push dateThu, 30 Aug 2012 01:33:09 +0000
reviewersjmaher
bugs770456
milestone17.0a1
Bug 770456 - Robocop: be more careful when accessing child view in testHistoryTab; r=jmaher
mobile/android/base/tests/testHistoryTab.java.in
--- a/mobile/android/base/tests/testHistoryTab.java.in
+++ b/mobile/android/base/tests/testHistoryTab.java.in
@@ -29,16 +29,17 @@ import java.io.File;
 
 public class testHistoryTab extends PixelTest {
     private static final String ABOUT_HOME_URL = "about:home";
     private static final String OPEN_NEW_TAB = "Open in New Tab";
     private static final int WAIT_FOR_CHILD_TIMEOUT = 2000;
     private String[] bookmarks = new String[] {
         "http://mochi.test:8888/tests/robocop/robocop_blank_01.html"
     };
+    private View mFirstChild;
 
     @Override
     protected int getTestType() {
         return TEST_MOCHITEST;
     }
 
     public void testHistoryTab() {
         mActions.expectGeckoEvent("Gecko:Ready").blockForEvent();
@@ -125,75 +126,86 @@ public class testHistoryTab extends Pixe
         mActions.sendSpecialKey(Actions.SpecialKey.BACK);
         mSolo.waitForText(url);
 
         View child = list.getChildAt(0);
         mSolo.clickLongOnView(child);
         mAsserter.is(false, mSolo.waitForText("Open in New Tab"), "Header rows should not show a context menu");
 
         // wait for the history list to be populated
-        waitForTest(new BooleanTest() {
+        mFirstChild = null;
+        boolean success = waitForTest(new BooleanTest() {
             public boolean test() {
-                if (list.getChildAt(1) == null) {
+                mFirstChild = list.getChildAt(1);
+                if (mFirstChild == null) {
                     return false;
                 }
-                View firstChild = list.getChildAt(1);
-                if (firstChild instanceof android.view.ViewGroup) {
-                    ViewGroup group = (ViewGroup)firstChild;
+                if (mFirstChild instanceof android.view.ViewGroup) {
+                    ViewGroup group = (ViewGroup)mFirstChild;
                     if (group.getChildCount() < 1) {
                         return false;
                     }
                     for (int i = 0; i < group.getChildCount(); i++) {
                         View grandChild = group.getChildAt(i);
                         if (grandChild instanceof android.widget.TextView) {
                             mAsserter.ok(true, "found TextView:", ((android.widget.TextView)grandChild).getText().toString());
                         }
                     }
+                } else {
+                    mAsserter.dumpLog("first child not a ViewGroup: "+mFirstChild);
+                    return false;
                 }
                 return true;
             }
         }, WAIT_FOR_CHILD_TIMEOUT);
-        child = list.getChildAt(1);
-
-        mSolo.clickLongOnView(child);
+        if (success == true && mFirstChild != null) {
+            mAsserter.dumpLog("clickLongOnView: "+mFirstChild);
+            mSolo.clickLongOnView(mFirstChild);
 
-        // TODO: Test clicking these does the right thing
-        mAsserter.ok(mSolo.waitForText("Open in New Tab"), "Context menu has New Tab option", "Open in New Tab");
-        mAsserter.ok(mSolo.searchText("Share", true), "Context menu has Share option", "Share");
-        mAsserter.ok(mSolo.searchText("Remove", true), "Context menu has Remove option", "Remove");
-        mAsserter.ok(mSolo.searchText("Add to Home Screen", true), "Context menu has Add to Home Screen option", "Add to Home Screen");
+            // TODO: Test clicking these does the right thing
+            mAsserter.ok(mSolo.waitForText("Open in New Tab"), "Context menu has New Tab option", "Open in New Tab");
+            mAsserter.ok(mSolo.searchText("Share", true), "Context menu has Share option", "Share");
+            mAsserter.ok(mSolo.searchText("Remove", true), "Context menu has Remove option", "Remove");
+            mAsserter.ok(mSolo.searchText("Add to Home Screen", true), "Context menu has Add to Home Screen option", "Add to Home Screen");
 
-        mActions.sendSpecialKey(Actions.SpecialKey.BACK);
+            mActions.sendSpecialKey(Actions.SpecialKey.BACK);
+        } else {
+            mAsserter.ok(false, "waiting for history item", "history item available");
+        }
         mActions.sendSpecialKey(Actions.SpecialKey.BACK);
     }
 
     private void testClick(String url) {
         list = getHistoryList();
         // clear VKB
         mActions.sendSpecialKey(Actions.SpecialKey.BACK);
         mSolo.waitForText(url);
 
         View child = list.getChildAt(0);
         mSolo.clickOnView(child);
         // nothing should happen
 
         Actions.EventExpecter contentEventExpecter = mActions.expectGeckoEvent("DOMContentLoaded");
-        waitForTest(new BooleanTest() {
+        mFirstChild = null;
+        boolean success = waitForTest(new BooleanTest() {
             public boolean test() {
-                if (list.getChildAt(1) == null) {
+                mFirstChild = list.getChildAt(1);
+                if (mFirstChild == null) {
                     return false;
                 }
                 return true;
             }
         }, WAIT_FOR_CHILD_TIMEOUT);
-        child = list.getChildAt(1);
-
-        mSolo.clickOnView(child);
-        contentEventExpecter.blockForEvent();
-        verifyUrl(url);
+        if (success == true && mFirstChild != null) {
+            mSolo.clickOnView(mFirstChild);
+            contentEventExpecter.blockForEvent();
+            verifyUrl(url);
+        } else {
+            mAsserter.ok(false, "waiting for history item", "history item available");
+        }
     }
 
     private ListView getHistoryList() {
         Activity awesomeBarActivity = clickOnAwesomeBar();
         mSolo.clickOnText("History");
 
         TabHost tabHost = (TabHost)mSolo.getView(TabHost.class, 0);
         return (ListView)tabHost.getCurrentView();