Print tab history before first goBack() draft
authorPetru Lingurar <petru.lingurar@softvision.ro>
Mon, 10 Sep 2018 19:24:06 +0300
changeset 1691721 ee3c68a16800259c89c89cd318dffcaa0e60bae9
parent 1691481 8a978f2d7cf9400302ab2d666e2ce38bd2c4c2a1
child 1691722 70a348fe3df1b64905c5aa75f53985d4322df3c7
push id297846
push userplingurar@mozilla.com
push dateMon, 10 Sep 2018 16:24:58 +0000
treeherdertry@70a348fe3df1 [default view] [failures only]
milestone64.0a1
Print tab history before first goBack()
mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/testActivityStreamPocketReferrer.java
--- a/mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/testActivityStreamPocketReferrer.java
+++ b/mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/testActivityStreamPocketReferrer.java
@@ -1,19 +1,26 @@
 /* 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;
 import android.util.Log;
 import com.robotium.solo.Condition;
+
+import org.mozilla.gecko.EventDispatcher;
 import org.mozilla.gecko.R;
+import org.mozilla.gecko.Tab;
+import org.mozilla.gecko.Tabs;
 import org.mozilla.gecko.activitystream.homepanel.topstories.PocketStoriesLoader;
+import org.mozilla.gecko.tabs.TabHistoryController;
 import org.mozilla.gecko.tests.helpers.NavigationHelper;
 import org.mozilla.gecko.tests.helpers.WaitHelper;
+import org.mozilla.gecko.util.EventCallback;
+import org.mozilla.gecko.util.GeckoBundle;
 import org.mozilla.gecko.util.StringUtils;
 
 import static org.mozilla.gecko.tests.helpers.AssertionHelper.*;
 
 /**
  * It's very important that suggestions from Pocket are opened with a Pocket URI in the referrer: this is
  * what this test is for.
  *
@@ -37,32 +44,34 @@ public class testActivityStreamPocketRef
 
     private boolean wasTabLoadReceived = false;
     private boolean tabLoadContainsPocketReferrer = false;
 
     @Override
     public void setUp() throws Exception {
         super.setUp();
 
+        mSolo.getConfig().commandLogging = true;
+
         // Override the default placeholder URL so we don't access the network during testing.
         // Note: this actually only seems to take effect after we load a page and go back to about:home.
         PocketStoriesLoader.configureForTesting(getAbsoluteHostnameUrl(mStringHelper.ROBOCOP_BLANK_PAGE_01_URL));
     }
 
     public void testActivityStreamPocketReferrer() throws Exception {
         if (!getActivity().getResources().getBoolean(R.bool.pref_activitystream_pocket_enabled_default)) {
             // I don't have time to add code to force enable Pocket suggestions so we'll just assume
             // this won't break until we re-enable Pocket by default (bug 1411657).
             Log.d(LOGTAG, "Pocket recommendations are disabled by default; returning success...");
             return;
         }
 
         blockForReadyAndLoadJS(JS_FILE);
 
-        Thread.sleep(500);
+        printTabHistory();
         NavigationHelper.goBack(); // to top sites.
 
         checkReferrerInTopStories();
         checkReferrerInTopStoriesContextMenu();
 
         checkNoReferrerInTopSites(); // relies on changes to Top Sites from previous tests.
 
         // Ideally, we'd also test that there is no referrer for highlights but it's more
@@ -142,9 +151,55 @@ public class testActivityStreamPocketRef
         Log.d(LOGTAG, "setTabLoadContainsPocketReferrer called via JS: " + wasTabLoadReceived + ", " + tabLoadContainsPocketReferrer);
         this.wasTabLoadReceived = wasTabLoadReceived;
         this.tabLoadContainsPocketReferrer = tabLoadContainsPocketReferrer;
     }
 
     public void log(final String s) {
         Log.d(LOGTAG, "jsLog: " + s);
     }
+
+    private void printTabHistory() {
+        final Tab currentTab = Tabs.getInstance().getSelectedTab();
+        final TabHistoryController.HistoryAction showAllHistory =  TabHistoryController.HistoryAction.ALL;
+
+        final GeckoBundle data = new GeckoBundle(2);
+        data.putString("action", showAllHistory.name());
+        data.putInt("tabId", currentTab.getId());
+
+        EventDispatcher.getInstance().dispatch("Session:GetHistory", data, new EventCallback() {
+            @Override
+            public void sendSuccess(final Object response) {
+                /*
+                 * The response from gecko request is of the form
+                 * {
+                 *   "historyItems" : [
+                 *     {
+                 *       "title": "google",
+                 *       "url": "google.com",
+                 *       "selected": false
+                 *     }
+                 *   ],
+                 *   toIndex = 1
+                 * }
+                 */
+
+                final GeckoBundle data = (GeckoBundle) response;
+                final GeckoBundle[] historyItems = data.getBundleArray("historyItems");
+                if (historyItems.length == 0) {
+                    Log.e(LOGTAG, "No history!");
+                    // Empty history, return without showing the popup.
+                    return;
+                }
+
+                for (GeckoBundle obj : historyItems) {
+                    Log.e(LOGTAG, "History item: " + obj);
+                }
+
+            }
+
+            @Override
+            public void sendError(final Object response) {
+                Log.e(LOGTAG, "Unexpected error when querying tab history: " + response);
+            }
+        });
+    }
 }