Bug 844239: code cleanup in robocop BaseTest; r=jmaher
authorGeoff Brown <gbrown@mozilla.com>
Wed, 27 Feb 2013 08:21:23 -0700
changeset 123164 a7dec45d971d195b463bd5a629e384e3996d78b9
parent 123163 f118eb2326f7a80806d137bf760de63cb7da800e
child 123165 86811c639071fa14a0045711698a60ede7fb0bc4
push id24373
push userryanvm@gmail.com
push dateThu, 28 Feb 2013 01:36:21 +0000
treeherdermozilla-central@8cb9d6981978 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjmaher
bugs844239
milestone22.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 844239: code cleanup in robocop BaseTest; r=jmaher
mobile/android/base/tests/BaseTest.java.in
--- a/mobile/android/base/tests/BaseTest.java.in
+++ b/mobile/android/base/tests/BaseTest.java.in
@@ -82,47 +82,41 @@ abstract class BaseTest extends Activity
     protected abstract int getTestType();
 
     @Override
     protected void setUp() throws Exception {
         // Load config file from root path (setup by python script)
         String rootPath = FennecInstrumentationTestRunner.getArguments().getString("deviceroot");
         String configFile = FennecNativeDriver.getFile(rootPath + "/robotium.config");
         HashMap config = FennecNativeDriver.convertTextToTable(configFile);
-
         // Create the intent to be used with all the important arguments.
         Intent i = new Intent(Intent.ACTION_MAIN);
         mProfile = (String)config.get("profile");
         i.putExtra("args", "-no-remote -profile " + mProfile);
-
         String envString = (String)config.get("envvars");
         if (envString != "") {
             String[] envStrings = envString.split(",");
             for (int iter = 0; iter < envStrings.length; iter++) {
                 i.putExtra("env" + iter, envStrings[iter]);
             }
         }
-
         // Start the activity
         setActivityIntent(i);
         mActivity = getActivity();
-
         mLogFile = (String)config.get("logfile");
         mBaseUrl = ((String)config.get("host")).replaceAll("(/$)", "");
         mRawBaseUrl = ((String)config.get("rawhost")).replaceAll("(/$)", "");
-
         // Initialize the asserter
         if (getTestType() == TEST_TALOS) {
             mAsserter = new FennecTalosAssert();
         } else {
             mAsserter = new FennecMochitestAssert();
         }
         mAsserter.setLogFile(mLogFile);
         mAsserter.setTestName(this.getClass().getName());
-
         // Set up Robotium.solo and Driver objects
         mSolo = new Solo(getInstrumentation(), mActivity);
         mDriver = new FennecNativeDriver(mActivity, mSolo, rootPath);
         mActions = new FennecNativeActions(mActivity, mSolo, getInstrumentation(), mAsserter);
     }
 
     @Override
     protected void runTest() throws Throwable {
@@ -259,19 +253,19 @@ abstract class BaseTest extends Activity
 
     protected final String getAbsoluteRawUrl(String url) {
         return mRawBaseUrl + "/" + url.replaceAll("(^/)", "");
     }
 
     protected final boolean waitForTest(BooleanTest t, int timeout) {
         long end = SystemClock.uptimeMillis() + timeout;
         while (SystemClock.uptimeMillis() < end) {
-            if (t.test())
+            if (t.test()) {
                 return true;
-
+            }
             mSolo.sleep(100);
         }
         return false;
     }
 
     protected interface BooleanTest {
         public boolean test();
     }
@@ -287,21 +281,23 @@ abstract class BaseTest extends Activity
 
     private boolean CursorMatches(Cursor c, String[] columns, ContentValues cv) {
         for (int i = 0; i < columns.length; i++) {
             String column = columns[i];
             if (cv.containsKey(column)) {
                 mAsserter.info("Comparing", "Column values for: " + column);
                 Object value = cv.get(column);
                 if (value == null) {
-                    if (!c.isNull(i))
+                    if (!c.isNull(i)) {
                         return false;
+                    }
                 } else {
-                    if (c.isNull(i) || !value.toString().equals(c.getString(i)))
+                    if (c.isNull(i) || !value.toString().equals(c.getString(i))) {
                         return false;
+                    }
                 }
             }
         }
         return true;
     }
 
     @SuppressWarnings({"unchecked", "non-varargs"})
     public void SqliteCompare(Cursor c, ContentValues[] cvs) {
@@ -317,55 +313,55 @@ abstract class BaseTest extends Activity
                 mAsserter.is(found, true, "Password was found");
             } while(c.moveToNext());
         }
     }
 
     public boolean CursorMatches(Cursor c, ContentValues cv) {
         for (int i = 0; i < c.getColumnCount(); i++) {
             String column = c.getColumnName(i);
-             if (cv.containsKey(column)) {
+            if (cv.containsKey(column)) {
                 mAsserter.info("Comparing", "Column values for: " + column);
                 Object value = cv.get(column);
                 if (value == null) {
-                    if (!c.isNull(i))
+                    if (!c.isNull(i)) {
                         return false;
+                    }
                 } else {
-                    if (c.isNull(i) || !value.toString().equals(c.getString(i)))
+                    if (c.isNull(i) || !value.toString().equals(c.getString(i))) {
                         return false;
+                    }
                 }
             }
         }
         return true;
     }
 
     public InputStream getAsset(String filename) throws IOException {
         AssetManager assets = getInstrumentation().getContext().getAssets();
         return assets.open(filename);
     }
 
     public final void selectMenuItem(String menuItemName) {
-
-        //build the item name ready to be used
+        // build the item name ready to be used
         String itemName = "^" + menuItemName + "$";
         mActions.sendSpecialKey(Actions.SpecialKey.MENU);
-	if (mSolo.waitForText(itemName)) {
+        if (mSolo.waitForText(itemName)) {
             mSolo.clickOnText(itemName);
-	}
-	else {
-	    if (mSolo.searchText("(^More$|^Tools$)")) {
+        } else {
+            if (mSolo.searchText("(^More$|^Tools$)")) {
                 mSolo.clickOnText("(^More$|^Tools$)");
-	      }
+            }
             mSolo.waitForText(itemName);
             mSolo.clickOnText(itemName);
         }
     }
 
     public final void verifyPageTitle(String title) {
-	Element awesomebar = mDriver.findElement(getActivity(), "awesome_bar_title");
+        Element awesomebar = mDriver.findElement(getActivity(), "awesome_bar_title");
         String pageTitle = null;
         if (awesomebar != null) {
             // Wait for the title to make sure it has been displayed in case the view
             // does not update fast enough
             waitForTest(new VerifyTitle(awesomebar, title), MAX_WAIT_MS);
             pageTitle = awesomebar.getText();
         }
         mAsserter.is(pageTitle, title, "Page title is correct");
@@ -433,119 +429,106 @@ abstract class BaseTest extends Activity
     /**
      * Click on the awesome bar, click on the History tab, and return
      * the ListView for the History tab.
      */
     protected ListView getHistoryList() {
         Activity awesomeBarActivity = clickOnAwesomeBar();
         mSolo.clickOnText("History");
         mSolo.waitForText("Today|Yesterday");
-
         ArrayList<ListView> views = mSolo.getCurrentListViews();
         for (ListView view : views) {
             if (view.getTag().equals("history")) {
                 return view;
             }
         }
         return null;
     }
 
     public long addOrUpdateBookmark(String title, String url, boolean bookmarklet) {
         ContentResolver resolver = getActivity().getContentResolver();
         Uri bookmarksUri = Uri.parse("content://@ANDROID_PACKAGE_NAME@.db.browser/bookmarks");
         bookmarksUri = bookmarksUri.buildUpon().appendQueryParameter("profile", "default").build();
         long folderId = -1;
         Cursor c = null;
-
         // NOTE: this is hardcoded to toolbar/mobile and triggered from bookmarklet because the existing
         //       testcases were written this way
         String location = "toolbar";
         if (bookmarklet) {
             location = "mobile";
         }
-
         try {
             c = resolver.query(bookmarksUri,
                                new String[] { "_id" },
                                "guid = ?",
                                new String[] { location },
                                null);
-
-            if (c.moveToFirst())
+            if (c.moveToFirst()) {
                 folderId = c.getLong(c.getColumnIndexOrThrow("_id"));
+            }
         } finally {
             if (c != null) {
                 c.close();
             }
         }
-
         ContentValues values = new ContentValues();
         values.put("title", title);
         values.put("url", url);
         values.put("parent", folderId);
         long now = System.currentTimeMillis();
         values.put("modified", now);
-
         if (!bookmarklet) {
             values.put("type", 1);
             values.put("guid", url);
             values.put("position", 10);
             values.put("created", now);
         }
-
         int updated = resolver.update(bookmarksUri,
                                       values,
                                       "url = ?",
                                       new String[] { url });
         if (updated == 0) {
             Uri uri = resolver.insert(bookmarksUri, values);
             mAsserter.ok(true, "Inserted at: ", uri.toString());
             return ContentUris.parseId(uri);
         }
-
         return ContentUris.parseId(bookmarksUri);
     }
 
     public void deleteBookmark(String title) {
-
         ContentResolver resolver = getActivity().getContentResolver();
         Uri uri = Uri.parse("content://@ANDROID_PACKAGE_NAME@.db.browser/bookmarks");
         uri = uri.buildUpon().appendQueryParameter("profile", "default")
                              .appendQueryParameter("sync", "true").build();
         resolver.delete(uri, "title = ?", new String[] { title });
     }
 
     public void addTab(String url) {
         Element tabs = null;
         Element addTab = null;
-
         Activity activity = getActivity();
         tabs = mDriver.findElement(activity, "tabs");
         addTab = mDriver.findElement(activity, "add_tab");
         final int addTabId = addTab.getId();
         mAsserter.ok(tabs.click(), "checking that tabs clicked", "tabs element clicked");
-
         // wait for addTab to appear (this is usually immediate)
         boolean success = waitForTest(new BooleanTest() {
             @Override
             public boolean test() {
                 View addTabView = getActivity().findViewById(addTabId);
                 if (addTabView == null) {
                     return false;
                 }
                 return true;
             }
         }, MAX_WAIT_MS);
         mAsserter.ok(success, "waiting for add tab view", "add tab view available");
-
         mAsserter.ok(addTab.click(), "checking that add_tab clicked", "add_tab element clicked");
-
         // must pause before sending keys, until awesome bar is displayed; waiting for known text is simple
         mSolo.waitForText("History");
-
         // cannot use loadUrl(): getText fails because we are using a different urlbar
         mActions.sendKeys(url);
         hitEnterAndWait();
     }
 
     class Device {
         Build.VERSION mBuildVersion;
         public String version; // 2.x or 3.x or 4.x
@@ -565,23 +548,21 @@ abstract class BaseTest extends Activity
                 version = "2.x";
             } else {
                 if (mSDK > Build.VERSION_CODES.HONEYCOMB_MR2) {
                     version = "4.x";
                 } else {
                     version = "3.x";
                 }
             }
-
             // Determine with and height
             DisplayMetrics dm = new DisplayMetrics();
             getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
             height = dm.heightPixels;
             width = dm.widthPixels;
-
             // Determine device type
             type = "phone";
             try {
                 ClassLoader classLoader = getActivity().getClassLoader();
                 Class appsCls = classLoader.loadClass("org.mozilla.gecko.GeckoAppShell");
                 Method isTabletMethod = appsCls.getMethod("isTablet", (Class[]) null);
                 boolean isTablet = (Boolean)isTabletMethod.invoke(null);
                 if (isTablet) {