Bug 946656 - Correct regex that determines a loading page in WaitHelper. r=margaret
authorMichael Comella <michael.l.comella@gmail.com>
Thu, 19 Dec 2013 19:49:02 -0800
changeset 161259 fc7c74d38d03bdbfb49023c783717636b0e30f67
parent 161258 70befb4cf2f47672974f63fd6a5d80ab4f1a5f23
child 161386 0a48358f0aefcbcb68ada66a227a6f99bd532b19
push id4103
push usermichael.l.comella@gmail.com
push dateFri, 20 Dec 2013 03:49:03 +0000
treeherderfx-team@fc7c74d38d03 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmargaret
bugs946656
milestone29.0a1
Bug 946656 - Correct regex that determines a loading page in WaitHelper. r=margaret
mobile/android/base/tests/helpers/WaitHelper.java
--- a/mobile/android/base/tests/helpers/WaitHelper.java
+++ b/mobile/android/base/tests/helpers/WaitHelper.java
@@ -10,16 +10,18 @@ import org.mozilla.gecko.Actions;
 import org.mozilla.gecko.Actions.EventExpecter;
 import org.mozilla.gecko.tests.components.ToolbarComponent;
 import org.mozilla.gecko.tests.UITestContext;
 import org.mozilla.gecko.tests.UITestContext.ComponentType;
 
 import com.jayway.android.robotium.solo.Condition;
 import com.jayway.android.robotium.solo.Solo;
 
+import java.util.regex.Pattern;
+
 /**
  * Provides functionality related to waiting on certain events to happen.
  */
 public final class WaitHelper {
     // TODO: Make public for when Solo.waitForCondition is used directly (i.e. do not want
     // assertion from waitFor)?
     private static final int DEFAULT_MAX_WAIT_MS = 5000;
     private static final int PAGE_LOAD_WAIT_MS = 10000;
@@ -126,17 +128,17 @@ public final class WaitHelper {
         public boolean hasStateChanged();
     }
 
     private static class ToolbarTitleTextChangeVerifier implements ChangeVerifier {
         private static final String LOGTAG =
                 ToolbarTitleTextChangeVerifier.class.getSimpleName() + ": ";
 
         // A regex that matches the page title that shows up while the page is loading.
-        private static final String LOADING_REGEX = "^[A-Za-z]{3,9}://";
+        private static final Pattern LOADING_PREFIX = Pattern.compile("[A-Za-z]{3,9}://");
 
         private CharSequence mOldTitleText;
 
         @Override
         public String getLogTag() {
             return LOGTAG;
         }
 
@@ -152,17 +154,17 @@ public final class WaitHelper {
             // TODO: Robocop sleeps .5 sec between calls. Cache title view?
             final CharSequence title = sToolbar.getPotentiallyInconsistentTitle();
 
             // TODO: Handle the case where the URL is shown instead of page title by preference.
             // HACK: We want to wait until the title changes to the state a tester may assert
             // (e.g. the page title). However, the title is set to the URL before the title is
             // loaded from the server and set as the final page title; we ignore the
             // intermediate URL loading state here.
-            final boolean isLoading = title.toString().matches(LOADING_REGEX);
+            final boolean isLoading = LOADING_PREFIX.matcher(title).lookingAt();
             final boolean hasStateChanged = !isLoading && !mOldTitleText.equals(title);
 
             if (hasStateChanged) {
                 sContext.dumpLog(LOGTAG + "state changed to title, \"" + title + "\".");
             }
             return hasStateChanged;
         }
     }