Bug 785577 - Robocop: improve wait before testing menus; r=jmaher
authorGeoff Brown <gbrown@mozilla.com>
Tue, 25 Sep 2012 10:56:34 -0600
changeset 108147 051d7855b93f05a6a5b94367d699ae529e8548c0
parent 108146 293dee8a857a56ea4650835ac067e91787694373
child 108148 7cd024506a0c2083c891da6a1b70d803cdb09edc
push id82
push usershu@rfrn.org
push dateFri, 05 Oct 2012 13:20:22 +0000
reviewersjmaher
bugs785577
milestone18.0a1
Bug 785577 - Robocop: improve wait before testing menus; r=jmaher
mobile/android/base/tests/testWebContentContextMenu.java.in
--- a/mobile/android/base/tests/testWebContentContextMenu.java.in
+++ b/mobile/android/base/tests/testWebContentContextMenu.java.in
@@ -1,16 +1,20 @@
 #filter substitution
 package @ANDROID_PACKAGE_NAME@.tests;
 
 import @ANDROID_PACKAGE_NAME@.*;
 import android.app.Activity;
 import android.util.DisplayMetrics;
 
-public class testWebContentContextMenu extends BaseTest {
+/* Test the context menu on web content: Long click on a link,
+ * verify that the context menu is shown and verify that some
+ * of the menu actions work.
+ */
+public class testWebContentContextMenu extends PixelTest {
     @Override
     protected int getTestType() {
         return TEST_MOCHITEST;
     }
 
     public void testWebContentContextMenu() {
         mActions.expectGeckoEvent("Gecko:Ready").blockForEvent();
 
@@ -18,56 +22,57 @@ public class testWebContentContextMenu e
         getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
 
         // The link has a 60px height, so let's try to hit the middle
         float top = mDriver.getGeckoTop() + 30 * dm.density;
         float left = mDriver.getGeckoLeft() + mDriver.getGeckoWidth() / 2;
 
         // Load the test page and check for 'Open Link'
         String url = getAbsoluteUrl("/robocop/robocop_big_link.html");
-        loadUrl(url);
+        loadAndPaint(url);
 
+        mAsserter.dumpLog("long-clicking at "+left+", "+top);
         mSolo.clickLongOnScreen(left, top);
 
-        mAsserter.ok(mSolo.waitForText("Open"), "looking for context menu action", "found 'Open Link'");
+        mAsserter.ok(mSolo.waitForText("^Open Link in New Tab$"), "looking for context menu action", "found 'Open Link in New Tab'");
 
         Actions.EventExpecter tabEventExpecter = mActions.expectGeckoEvent("Tab:Added");
         Actions.EventExpecter contentEventExpecter = mActions.expectGeckoEvent("DOMContentLoaded");
-        mSolo.clickOnText("Open");
+        mSolo.clickOnText("Open Link");
 
         // Wait for the new tab and page to load
         tabEventExpecter.blockForEvent();
         contentEventExpecter.blockForEvent();
 
         // See tab count
         Element tabCount = mDriver.findElement(getActivity(), "tabs_count");
         String tabCountText = null;
         if (tabCount != null) {
             tabCountText = tabCount.getText();
         }
         mAsserter.is(tabCountText, "2", "Number of tabs has increased");
 
         // Load the test page again and test for 'Share Link' and 'Bookmark Link'
-        loadUrl(url);
+        loadAndPaint(url);
 
         mSolo.clickLongOnScreen(left, top);
 
-        mAsserter.ok(mSolo.waitForText("Share"), "looking for context menu action", "found 'Share Link'");        
-        mAsserter.ok(mSolo.waitForText("Bookmark"), "looking for context menu action", "found 'Bookmark Link'");
+        mAsserter.ok(mSolo.waitForText("^Share Link$"), "looking for context menu action", "found 'Share Link'");        
+        mAsserter.ok(mSolo.waitForText("^Bookmark Link$"), "looking for context menu action", "found 'Bookmark Link'");
         mSolo.clickOnText("Bookmark");
         mAsserter.is(mSolo.waitForText("Bookmark added"), true, "Bookmark added verified");
 
         // This waitForIdleSync improves reliability of the following loadUrl.
         // TODO: understand why!
         getInstrumentation().waitForIdleSync();
 
         // We know that the link test page points to robocop_blank_01.html, so lets
         // load it and see if the page is bookmarked
         url = getAbsoluteUrl("/robocop/robocop_blank_01.html");
-        loadUrl(url);
+        loadAndPaint(url);
 
         // Pause briefly, to ensure that the bookmark addition, above, updates database tables and
         // completes before checking that the bookmark exists.
         // TODO: Find a better way to wait for completion of bookmark operations.
         try { Thread.sleep(2000); } catch(Exception e) {}
 
         mActions.sendSpecialKey(Actions.SpecialKey.MENU);
         mSolo.waitForText("Bookmark");
@@ -80,17 +85,17 @@ public class testWebContentContextMenu e
         mAsserter.is(mSolo.waitForText("Bookmark removed"), true, "Bookmark removal verified");
 
         // This waitForIdleSync improves reliability of the following loadUrl.
         // TODO: understand why!
         getInstrumentation().waitForIdleSync();
 
         // Load the mailto test page again and test for allowed menu actions
         url = getAbsoluteUrl("/robocop/robocop_big_mailto.html");
-        loadUrl(url);
+        loadAndPaint(url);
 
         mSolo.clickLongOnScreen(left, top);
 
-        mAsserter.ok(mSolo.waitForText("Share"), "looking for context menu action", "found 'Share Link'");        
-        mAsserter.ok(!mSolo.waitForText("Open", 0, 1000, false), "looking for context menu action", "did not find 'Open Link'");        
-        mAsserter.ok(!mSolo.waitForText("Bookmark", 0, 1000, false), "looking for context menu action", "did not find 'Bookmark Link'");
+        mAsserter.ok(mSolo.waitForText("Share"), "looking for context menu action", "found 'Share'");        
+        mAsserter.ok(!mSolo.waitForText("^Open Link in New Tab$", 0, 1000, false), "looking for context menu action", "did not find 'Open Link in New Tab'");        
+        mAsserter.ok(!mSolo.waitForText("^Bookmark Link$", 0, 1000, false), "looking for context menu action", "did not find 'Bookmark Link'");
     }
 }