Bug 869277 - Follow-up patch to remove todo_is assertion and make the test more reliable. r=gbrown
authorAdrian Tamas <adrian.tamas@softvision.ro>
Tue, 23 Jul 2013 16:13:48 +0300
changeset 140446 1774aaaad96a25a102a86bc611e113fece8755d5
parent 140445 6364e33d76f5b456cd78377402727df544351d1d
child 140447 ab6b62fd42354a6556fb15c6f79cc6dfca52fdc7
push id25030
push userryanvm@gmail.com
push dateTue, 30 Jul 2013 17:07:39 +0000
treeherdermozilla-central@129ce98f4cb2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgbrown
bugs869277
milestone25.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 869277 - Follow-up patch to remove todo_is assertion and make the test more reliable. r=gbrown
mobile/android/base/tests/testAddSearchEngine.java.in
--- a/mobile/android/base/tests/testAddSearchEngine.java.in
+++ b/mobile/android/base/tests/testAddSearchEngine.java.in
@@ -9,19 +9,17 @@ import java.util.ArrayList;
 
 /**
  * Test adding a search engine from an input field context menu
  * 1. Get the number of existing search engines
  * 2. Load a page with a text field, open the context menu and add a search engine from the page
  * 3. Get the number of search engines after adding the new one
  */
 public class testAddSearchEngine extends PixelTest {
-
-    final int MAX_TRIES = 5;
-
+    private final int MAX_WAIT_TEST_MS = 5000;
     @Override
     protected int getTestType() {
         return TEST_MOCHITEST;
     }
 
     public void testAddSearchEngine() {
         int height,width;
         final int initialNumSearchEngines;
@@ -103,31 +101,38 @@ public class testAddSearchEngine extends
             @Override
             public boolean test() {
                 ArrayList<ListView> views;
                 int searchEngineCount = 0;
                 views = mSolo.getCurrentListViews();
                 for (ListView view : views) {
                     ListAdapter adapter = view.getAdapter();
                     if (adapter != null) {
-                        searchEngineCount = adapter.getCount();
-                        if (searchEngineCount == expectedCount) {
-                            return true;
-                        } else {
-                            mAsserter.dumpLog("Found "+searchEngineCount+" search engines");
+                        // Get only the SearchEngineRow views since getCurrentViews can also add to the ArrayList also the Top Sites entries
+                        try {
+                                ClassLoader classLoader = getActivity().getClassLoader();
+                                Class searchEngineRow = classLoader.loadClass("org.mozilla.gecko.SearchEngineRow");
+                                for (int i = 0; i < adapter.getCount(); i++ ) {
+                                    View item = view.getChildAt(i);
+                                    if (searchEngineRow.isInstance(item)) {
+                                        searchEngineCount++;
+                                    }
+                                }
+                        } catch (Exception e) {
+                             mAsserter.dumpLog("Exception in verifyDisplayedSearchEnginesCount", e);
                         }
                     } 
                 }
-                return false;
+                if (searchEngineCount == expectedCount) {
+                    return true;
+                } else {
+                    mAsserter.dumpLog("The wrong number of search engines was found. Found " + searchEngineCount + " search engines");
+                    return false;
+                }
             }
-        }, MAX_WAIT_MS);
+        }, MAX_WAIT_TEST_MS);
         
         // Close the Awesomescreen
         mActions.sendSpecialKey(Actions.SpecialKey.BACK);
         waitForText(waitText);
-        if (correctNumSearchEnginesDisplayed) {
-            mAsserter.ok(correctNumSearchEnginesDisplayed, expectedCount + " Search Engines should be displayed", "The correct number of Search Engines has been displayed");
-        } else {
-            // TODO: Investigate more why the number of displayed searchengines is not correctly determined here
-            mAsserter.todo_is(correctNumSearchEnginesDisplayed, true, "The number of Search Engines displayed is wrong");
-        }
+        mAsserter.ok(correctNumSearchEnginesDisplayed, expectedCount + " Search Engines should be displayed" , "The correct number of Search Engines has been displayed");
    }
 }