Bug 1458697 - Use different strategy for dealing with initial session store activity. r?gbrown
Waiting for delayed startup and then attempting to force any possibly still
pending session store write to disk by flushing the session store data didn't
turn out to be a good idea, because if the session store had already started its
own automatic write at that moment in time, we'd get back an additional
"PrivateBrowsing:Data" event that we didn't expect, thereby confusing the test.
Instead, we now wait for the first session store write after startup to occur
naturally before proceeding with the test.
MozReview-Commit-ID: Hui9YYec1Ow
--- a/mobile/android/components/SessionStore.js
+++ b/mobile/android/components/SessionStore.js
@@ -1227,16 +1227,17 @@ SessionStore.prototype = {
}
log("_writeFile() _write() returned, _pendingWrite = " + this._pendingWrite);
// We don't use a stopwatch here since the calls are async and stopwatches can only manage
// a single timer per histogram.
Services.telemetry.getHistogramById("FX_SESSION_RESTORE_WRITE_FILE_MS").add(Math.round(stopWriteMs - startWriteMs));
Services.obs.notifyObservers(null, "sessionstore-state-write-complete");
+ EventDispatcher.instance.sendRequest({type: "Session:DataWritten"});
this._sessionDataIsGood = true;
});
},
/**
* Writes the session state to a disk file, using async or sync methods
* @param aFile nsIFile used for saving the session
* @param aFileTemp nsIFile used as a temporary file in writing the data
--- a/mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/testSessionPrivateBrowsing.java
+++ b/mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/testSessionPrivateBrowsing.java
@@ -1,27 +1,29 @@
package org.mozilla.gecko.tests;
import org.mozilla.gecko.Actions;
+import org.mozilla.gecko.EventDispatcher;
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 static final String DATA_WRITTEN_EVENT = "Session:DataWritten";
private volatile TestStage mTestStage;
private boolean mWait = true;
public void testSessionPrivateBrowsing() {
- GeckoHelper.blockForDelayedStartup();
+ // Wait until the initial session store activity caused by startup has quietened down.
+ runTestCycle(TestStage.WAIT_FOR_READY);
// 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);
@@ -52,33 +54,35 @@ public class testSessionPrivateBrowsing
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);
+ getEventDispatcher().registerGeckoThreadListener(this, getExpectedEvent());
+ if (testStage != TestStage.WAIT_FOR_READY) {
+ 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");
+ final String expectedEvent = getExpectedEvent();
+ mAsserter.is(event, expectedEvent, "received " + expectedEvent + " event");
switch (mTestStage) {
case NO_CHANGE:
getAsserter().ok(message.getBoolean("noChange"),
"got expected no change event", null);
break;
case NO_PRIVATE_TABS:
@@ -89,23 +93,32 @@ public class testSessionPrivateBrowsing
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);
+ getEventDispatcher().unregisterGeckoThreadListener(this, expectedEvent);
synchronized (this) {
mWait = false;
notifyAll();
}
}
+ private String getExpectedEvent() {
+ return (mTestStage == TestStage.WAIT_FOR_READY) ? DATA_WRITTEN_EVENT : PRIVATE_TABS_EVENT;
+ }
+
+ private EventDispatcher getEventDispatcher() {
+ return (mTestStage == TestStage.WAIT_FOR_READY) ? EventDispatcher.getInstance()
+ : ((GeckoApp) getActivity()).getAppEventDispatcher();
+ }
+
private enum TestStage {
+ WAIT_FOR_READY,
SETUP,
NO_CHANGE,
NO_PRIVATE_TABS,
SOME_PRIVATE_TABS,
}
}