Bug 715443 - [2/2] More robotium cleanup. r=jmaher
authorKartikaya Gupta <kgupta@mozilla.com>
Thu, 05 Jan 2012 10:20:22 -0500
changeset 85115 e4c773d0f228232e8a022746285f1aa52636bdd0
parent 85114 262123f588e0061d2ec720f55e2117a0743d11aa
child 85116 4f11bea71a4a50465fc6b05e02def70a163dca04
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
bugs715443
milestone12.0a1
Bug 715443 - [2/2] More robotium cleanup. r=jmaher - Extract utility functions into BaseTest so that there's a bunch of duplicated code everywhere - Use long instead of Long in testPan to avoid object creation
mobile/android/base/tests/BaseTest.java.in
mobile/android/base/tests/testAwesomebar.java.in
mobile/android/base/tests/testBookmark.java.in
mobile/android/base/tests/testLoad.java.in
mobile/android/base/tests/testPan.java.in
--- a/mobile/android/base/tests/BaseTest.java.in
+++ b/mobile/android/base/tests/BaseTest.java.in
@@ -61,9 +61,36 @@ abstract class BaseTest extends Activity
         try {
             mSolo.finalize();
         } catch (Throwable e) {
             e.printStackTrace();
         }
         getActivity().finish();
         super.tearDown();
     }
+
+    protected final void enterUrl(String url) {
+        mActions.waitForGeckoEvent("Gecko:Ready");
+        Element awesomebar = mDriver.findElement("awesome_bar");
+        awesomebar.click();
+        getInstrumentation().waitForIdleSync();
+
+        Element urlbar = mDriver.findElement("awesomebar_text");
+        mActions.sendKeys(url);
+        mAsserter.is(urlbar.getText(), url, "Awesomebar URL typed properly");
+    }
+
+    protected final void loadUrl(String url) {
+        enterUrl(url);
+
+        mActions.sendSpecialKey(Actions.SpecialKey.ENTER);
+        // wait for screen to load
+        mActions.waitForGeckoEvent("DOMContentLoaded");
+    }
+
+    protected final void verifyUrl(String url) {
+        Element awesomebar = mDriver.findElement("awesome_bar");
+        Element urlbar = mDriver.findElement("awesomebar_text");
+        awesomebar.click();
+        getInstrumentation().waitForIdleSync();
+        mAsserter.is(urlbar.getText(), url, "Awesomebar URL stayed the same");
+    }
 }
--- a/mobile/android/base/tests/testAwesomebar.java.in
+++ b/mobile/android/base/tests/testAwesomebar.java.in
@@ -1,40 +1,28 @@
 #filter substitution
 package @ANDROID_PACKAGE_NAME@.tests;
 
 import @ANDROID_PACKAGE_NAME@.*;
 
 public class testAwesomebar extends BaseTest {
-    public void testAwesomebar() {
-        String url = "http://mochi.test:8888/tests/robocop/robocop_blank_01.html";
-        mActions.waitForGeckoEvent("Gecko:Ready");
-        Element awesomebar = mDriver.findElement("awesome_bar");
-        awesomebar.click();
+    private static final String URL = "http://mochi.test:8888/tests/robocop/robocop_blank_01.html";
 
-        Element urlbar = mDriver.findElement("awesomebar_text");
-        getInstrumentation().waitForIdleSync();
-        mActions.sendKeys(url);
-        mAsserter.is(urlbar.getText(), url, "Awesomebar URL Typed Properly");
+    public void testAwesomebar() {
+        loadUrl(URL);
 
-        mActions.sendSpecialKey(Actions.SpecialKey.ENTER);
-        // wait for screen to load
-        mActions.waitForGeckoEvent("DOMContentLoaded");
         mDriver.setupScrollHandling();
-
         // Calculate where we should be dragging.
         int midX = mDriver.getGeckoLeft() + mDriver.getGeckoWidth()/2;
         int midY = mDriver.getGeckoTop() + mDriver.getGeckoHeight()/2;
         int endY = mDriver.getGeckoTop() + mDriver.getGeckoHeight()/10;
         for (int i = 0; i < 10; i++) {
             mActions.drag(midX, midX, midY, endY);
             try {
                 Thread.sleep(200);
             } catch (InterruptedException e) {
                 e.printStackTrace();
             }
         }
-        // Click the awesomebar again
-        awesomebar.click();
-        getInstrumentation().waitForIdleSync();
-        mAsserter.is(urlbar.getText(), url, "Awesomebar URL stayed the same");
+
+        verifyUrl(URL);
     }
 }
--- a/mobile/android/base/tests/testBookmark.java.in
+++ b/mobile/android/base/tests/testBookmark.java.in
@@ -1,44 +1,34 @@
 #filter substitution
 package @ANDROID_PACKAGE_NAME@.tests;
 
 import @ANDROID_PACKAGE_NAME@.*;
 
 public class testBookmark extends BaseTest {
-    public void testBookmark() {
-        // TODO: find a better way to not hardcode this url
-        String url = "http://mochi.test:8888/tests/robocop/robocop_blank_02.html";
+    private static final String URL = "http://mochi.test:8888/tests/robocop/robocop_blank_02.html";
 
-        mActions.waitForGeckoEvent("Gecko:Ready");
-        Element awesomebar = mDriver.findElement("awesome_bar");
-        awesomebar.click();
-
-        Element urlbar = mDriver.findElement("awesomebar_text");
-        getInstrumentation().waitForIdleSync();
-        mActions.sendKeys(url);
-        mAsserter.is(urlbar.getText(), url, "Awesomebar url typed properly");
+    public void testBookmark() {
+        enterUrl(URL);
 
         //Click the top item in the list.
         mActions.sendSpecialKey(Actions.SpecialKey.DOWN);
         mActions.sendSpecialKey(Actions.SpecialKey.ENTER);
         mActions.waitForGeckoEvent("DOMContentLoaded");
 
-        getInstrumentation().waitForIdleSync();
-        awesomebar.click();
-        mAsserter.is(urlbar.getText(), url, "Awesomebar URL still on");
+        verifyUrl(URL);
 
         //Click the Top item in the history list.
         getInstrumentation().waitForIdleSync();
         mActions.sendSpecialKey(Actions.SpecialKey.RIGHT);
         mActions.sendSpecialKey(Actions.SpecialKey.RIGHT);
         getInstrumentation().waitForIdleSync();
         mActions.sendSpecialKey(Actions.SpecialKey.DOWN);
         mActions.sendSpecialKey(Actions.SpecialKey.DOWN);
         mActions.sendSpecialKey(Actions.SpecialKey.ENTER);
         mActions.waitForGeckoEvent("DOMContentLoaded");
 
         getInstrumentation().waitForIdleSync();
-        awesomebar.click();
         //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?");
     }
 }
--- a/mobile/android/base/tests/testLoad.java.in
+++ b/mobile/android/base/tests/testLoad.java.in
@@ -1,30 +1,13 @@
 #filter substitution
 package @ANDROID_PACKAGE_NAME@.tests;
 
 import @ANDROID_PACKAGE_NAME@.*;
 
 public class testLoad extends BaseTest {
-    public void testLoad() {
-        // TODO: find a better way to not hardcode this url
-        String url = "http://mochi.test:8888/tests/robocop/robocop_blank_03.html";
-
-        mActions.waitForGeckoEvent("Gecko:Ready");
-        Element awesomebar = mDriver.findElement("awesome_bar");
-        awesomebar.click();
+    private static final String URL = "http://mochi.test:8888/tests/robocop/robocop_blank_03.html";
 
-        Element urlbar = mDriver.findElement("awesomebar_text");
-        getInstrumentation().waitForIdleSync();
-        mActions.sendKeys(url);
-        getInstrumentation().waitForIdleSync();
-        mAsserter.is(urlbar.getText(), url, "Awesomebar URL Correct");
-
-        // Select top item in the list.
-        mActions.sendSpecialKey(Actions.SpecialKey.DOWN);
-        mActions.sendSpecialKey(Actions.SpecialKey.ENTER);
-        mActions.waitForGeckoEvent("DOMContentLoaded");
-
-        awesomebar.click();
-        getInstrumentation().waitForIdleSync();
-        mAsserter.is(urlbar.getText(), url, "Awesomebar URL is still correct");
+    public void testLoad() {
+        loadUrl(URL);
+        verifyUrl(URL);
     }
 }
--- a/mobile/android/base/tests/testPan.java.in
+++ b/mobile/android/base/tests/testPan.java.in
@@ -1,28 +1,19 @@
 #filter substitution
 package @ANDROID_PACKAGE_NAME@.tests;
 
 import @ANDROID_PACKAGE_NAME@.*;
 
 public class testPan extends BaseTest {
-    public void testPan() {
-        // TODO: find a better way to not hardcode this url
-        String url = "http://mochi.test:8888/startup_test/fenncmark/wikipedia.html";
-        mActions.waitForGeckoEvent("Gecko:Ready");
-        Element awesomebar = mDriver.findElement("awesome_bar");
-        awesomebar.click();
+    private static final String URL = "http://mochi.test:8888/startup_test/fenncmark/wikipedia.html";
 
-        Element urlbar = mDriver.findElement("awesomebar_text");
-        getInstrumentation().waitForIdleSync();
-        mActions.sendKeys(url);
-        mAsserter.is(url, urlbar.getText(),"Asserting Awesomebar typing works");
+    public void testPan() {
+        loadUrl(URL);
 
-        mActions.sendSpecialKey(Actions.SpecialKey.ENTER);
-        mActions.waitForGeckoEvent("DOMContentLoaded");
         mDriver.setupScrollHandling();
 
         // Setup scrolling coordinates.
         int midX = mDriver.getGeckoLeft() + mDriver.getGeckoWidth()/2;
         int midY = mDriver.getGeckoTop() + mDriver.getGeckoHeight()/2;
         int endY = mDriver.getGeckoTop() + mDriver.getGeckoHeight()/10;
 
         mDriver.startFrameRecording();
@@ -37,12 +28,12 @@ public class testPan extends BaseTest {
                 e.printStackTrace();
             }
             i++;
         } while (i < 1000 && mDriver.getScrollHeight() + 2 * mDriver.getHeight() < mDriver.getPageHeight());
         // asserter.ok(i < 1000, "Less than 1000", "Should take less than 1000 drags to get to bottom of the page.");
 
         int frames = mDriver.stopFrameRecording();
         mDriver.dumpLog("__start_report" + Integer.toString(frames) + "__end_report");
-        Long msecs = System.currentTimeMillis();
-        mDriver.dumpLog("__startTimestamp" + msecs.toString() + "__endTimestamp");
+        long msecs = System.currentTimeMillis();
+        mDriver.dumpLog("__startTimestamp" + msecs + "__endTimestamp");
     }	
 }