Bug 1476635 - Robocop instrumented tests will check if Tab can go back before trying it; r?sdaswani draft
authorPetru Lingurar <petru.lingurar@softvision.ro>
Wed, 05 Sep 2018 10:26:20 +0300
changeset 1686742 e7199375391e0271a3e403accf541f27fbf347d7
parent 1686526 bb0febbdbb250756bbaab3ebf525874fdaa0e170
child 1686743 42ff35fb2746744a93c82c5b170e2a834fe786f2
child 1687443 8b32ab4d7c16660aef17928804290927af5d45ac
push id296486
push userplingurar@mozilla.com
push dateWed, 05 Sep 2018 07:29:15 +0000
treeherdertry@42ff35fb2746 [default view] [failures only]
reviewerssdaswani
bugs1476635
milestone64.0a1
Bug 1476635 - Robocop instrumented tests will check if Tab can go back before trying it; r?sdaswani
mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/helpers/NavigationHelper.java
--- a/mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/helpers/NavigationHelper.java
+++ b/mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/helpers/NavigationHelper.java
@@ -1,28 +1,35 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko.tests.helpers;
 
 import static org.mozilla.gecko.tests.helpers.AssertionHelper.fAssertNotNull;
 
+import org.mozilla.gecko.Tab;
+import org.mozilla.gecko.Tabs;
 import org.mozilla.gecko.tests.UITestContext;
 import org.mozilla.gecko.tests.UITestContext.ComponentType;
 import org.mozilla.gecko.tests.components.AppMenuComponent;
 import org.mozilla.gecko.tests.components.ToolbarComponent;
+import org.mozilla.gecko.util.StringUtils;
 
+import com.leanplum.internal.Log;
 import com.robotium.solo.Solo;
 
 /**
  * Provides helper functionality for navigating around the Firefox UI. These functions will often
  * combine actions taken on multiple components to perform larger interactions.
  */
 final public class NavigationHelper {
+    private static final String LOGTAG =
+            StringUtils.safeSubstring(NavigationHelper.class.getSimpleName(), 0, 23);
+
     private static UITestContext sContext;
     private static Solo sSolo;
 
     private static AppMenuComponent sAppMenu;
     private static ToolbarComponent sToolbar;
 
     protected static void init(final UITestContext context) {
         sContext = context;
@@ -51,16 +58,22 @@ final public class NavigationHelper {
                 url.startsWith("intent:") || url.startsWith("view-source:")) {
             return url;
         }
 
         return sContext.getAbsoluteHostnameUrl(url);
     }
 
     public static void goBack() {
+        final Tab currentTab = Tabs.getInstance().getSelectedTab();
+        if (currentTab != null && !currentTab.canDoBack()) {
+            Log.d(LOGTAG, "Current Tab can't go back");
+            return;
+        }
+
         if (DeviceHelper.isTablet()) {
             sToolbar.pressBackButton(); // Waits for page load & asserts isNotEditing.
             return;
         }
 
         sToolbar.assertIsNotEditing();
         WaitHelper.waitForPageLoad(new Runnable() {
             @Override