Bug 1437382 - Part 5 - Test that flushing pending session store data sends the expected messages to Java. r?jchen
We attempt to get the session store into a known state as far as is possible
from Java and then test various situations to check that the expected
"PrivateBrowsing:Data" message is received in each case.
MozReview-Commit-ID: 8RkCQjAPXTT
--- a/mobile/android/base/java/org/mozilla/gecko/Tabs.java
+++ b/mobile/android/base/java/org/mozilla/gecko/Tabs.java
@@ -1091,16 +1091,17 @@ public class Tabs implements BundleEvent
@RobocopTarget
public Tab addTab() {
return addTab(Tabs.LOADURL_NONE);
}
/**
* Opens a new tab and loads a page according to the user's preferences (by default about:home).
*/
+ @RobocopTarget
public Tab addPrivateTab() {
return addTab(Tabs.LOADURL_PRIVATE);
}
/**
* Opens a new tab and loads a page according to the user's preferences (by default about:home).
*
* @param flags additional flags used when opening the tab
--- a/mobile/android/tests/browser/robocop/robocop.ini
+++ b/mobile/android/tests/browser/robocop/robocop.ini
@@ -73,16 +73,17 @@ disabled=see bug 757475
skip-if = android_version == "18"
[src/org/mozilla/gecko/tests/testSearchHistoryProvider.java]
[src/org/mozilla/gecko/tests/testSearchSuggestions.java]
# disabled on 4.3, bug 1145867
skip-if = android_version == "18"
[src/org/mozilla/gecko/tests/testSessionFilePreservation.java]
[src/org/mozilla/gecko/tests/testSessionOOMSave.java]
[src/org/mozilla/gecko/tests/testSessionOOMRestore.java]
+[src/org/mozilla/gecko/tests/testSessionPrivateBrowsing.java]
[src/org/mozilla/gecko/tests/testSettingsPages.java]
[src/org/mozilla/gecko/tests/testShareLink.java]
disabled=see bug 915897
[src/org/mozilla/gecko/tests/testThumbnails.java]
disabled=see bug 813107
[src/org/mozilla/gecko/tests/testViewPageSource.java]
[src/org/mozilla/gecko/tests/testVkbOverlap.java]
disabled=see bug 907274
--- a/mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/components/AppMenuComponent.java
+++ b/mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/components/AppMenuComponent.java
@@ -35,16 +35,17 @@ import com.robotium.solo.Solo;
* A class representing any interactions that take place on the app menu.
*/
public class AppMenuComponent extends BaseComponent {
private static final int MAX_WAITTIME_FOR_MENU_UPDATE_IN_MS = 7500;
public enum MenuItem {
FORWARD(R.string.forward),
NEW_TAB(R.string.new_tab),
+ NEW_PRIVATE_TAB(R.string.new_private_tab),
PAGE(R.string.page),
RELOAD(R.string.reload);
private final int resourceID;
private String stringResource;
MenuItem(final int resourceID) {
this.resourceID = resourceID;
new file mode 100644
--- /dev/null
+++ b/mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/testSessionPrivateBrowsing.java
@@ -0,0 +1,111 @@
+package org.mozilla.gecko.tests;
+
+import org.mozilla.gecko.Actions;
+import org.mozilla.gecko.GeckoApp;
+import org.mozilla.gecko.Tabs;
+import org.mozilla.gecko.tests.helpers.GeckoHelper;
+import org.mozilla.gecko.util.BundleEventListener;
+import org.mozilla.gecko.util.EventCallback;
+import org.mozilla.gecko.util.GeckoBundle;
+
+public class testSessionPrivateBrowsing extends UITest implements BundleEventListener {
+ private static final String PRIVATE_TABS_EVENT = "PrivateBrowsing:Data";
+ private static final String FLUSH_TABS_EVENT = "Session:FlushTabs";
+
+ private volatile TestStage mTestStage;
+ private boolean mWait = true;
+
+ public void testSessionPrivateBrowsing() {
+ GeckoHelper.blockForDelayedStartup();
+
+ // Attempt to get the session store into a known idle state by flushing any possibly
+ // still pending writes.
+ runTestCycle(TestStage.SETUP);
+
+ // Flushing with no pending writes should yield a "no change" message.
+ runTestCycle(TestStage.NO_CHANGE);
+
+ // Flushing with a pending write, but no private tabs open, should yield "null" private
+ // tab data.
+ openNewTab(false);
+ runTestCycle(TestStage.NO_PRIVATE_TABS);
+
+ // After opening a private tab, the private tabs session string we receive shouldn't be
+ // emtpy anymore.
+ openNewTab(true);
+ runTestCycle(TestStage.SOME_PRIVATE_TABS);
+ }
+
+ private void openNewTab(final boolean privateTab) {
+ // WaitHelper#waitForPageLoad does some additional checks which we don't require, so in
+ // order to speed things up (see below), we do our own custom waiting to make sure the
+ // new tab has been opened in Gecko as well.
+ Actions.EventExpecter pageLoad =
+ getActions().expectGlobalEvent(Actions.EventType.UI, "Content:DOMTitleChanged");
+ // We only have a limited window of time in which we can manually flush the pending session
+ // store writes before they are written out automatically. Opening new tabs the Robocop way
+ // by actually clicking the corresponding menu item is currently rather slow, so we bypass
+ // this and open them directly.
+ if (privateTab) {
+ Tabs.getInstance().addPrivateTab();
+ } else {
+ Tabs.getInstance().addTab();
+ }
+ pageLoad.blockForEvent();
+ pageLoad.unregisterListener();
+ }
+
+ private void runTestCycle(final TestStage testStage) {
+ mTestStage = testStage;
+ ((GeckoApp) getActivity()).getAppEventDispatcher()
+ .registerGeckoThreadListener(this, PRIVATE_TABS_EVENT);
+ getActions().sendGlobalEvent(FLUSH_TABS_EVENT, null);
+ synchronized (this) {
+ while (mWait) {
+ try {
+ wait();
+ } catch (InterruptedException e) { }
+ }
+ mWait = true;
+ }
+ }
+
+
+ @Override
+ public void handleMessage(String event, GeckoBundle message, EventCallback callback) {
+ mAsserter.is(event, PRIVATE_TABS_EVENT, "received " + PRIVATE_TABS_EVENT + " event");
+
+ switch (mTestStage) {
+ case NO_CHANGE:
+ getAsserter().ok(message.getBoolean("noChange"),
+ "got expected no change event", null);
+ break;
+
+ case NO_PRIVATE_TABS:
+ getAsserter().ok(!message.containsKey("noChange"),
+ "didn't get no change event", null);
+ getAsserter().ok(message.getString("session") == null,
+ "got empty private tabs data",null);
+ break;
+
+ case SOME_PRIVATE_TABS:
+ getAsserter().ok(message.getString("session") != null,
+ "got some private tabs data",null);
+ break;
+ }
+
+ ((GeckoApp) getActivity()).getAppEventDispatcher()
+ .unregisterGeckoThreadListener(this, PRIVATE_TABS_EVENT);
+ synchronized (this) {
+ mWait = false;
+ notifyAll();
+ }
+ }
+
+ private enum TestStage {
+ SETUP,
+ NO_CHANGE,
+ NO_PRIVATE_TABS,
+ SOME_PRIVATE_TABS,
+ }
+}