michael@0: package org.mozilla.gecko.tests; michael@0: michael@0: import org.mozilla.gecko.Actions; michael@0: michael@0: import com.jayway.android.robotium.solo.Condition; michael@0: michael@0: /** michael@0: * Tests session OOM save behavior. michael@0: * michael@0: * Builds a session and tests that the saved state is correct. michael@0: */ michael@0: public class testSessionOOMSave extends SessionTest { michael@0: private final static int SESSION_TIMEOUT = 25000; michael@0: michael@0: public void testSessionOOMSave() { michael@0: Actions.EventExpecter pageShowExpecter = mActions.expectGeckoEvent("Content:PageShow"); michael@0: pageShowExpecter.blockForEvent(); michael@0: pageShowExpecter.unregisterListener(); michael@0: michael@0: PageInfo home = new PageInfo("about:home"); michael@0: PageInfo page1 = new PageInfo("page1"); michael@0: PageInfo page2 = new PageInfo("page2"); michael@0: PageInfo page3 = new PageInfo("page3"); michael@0: PageInfo page4 = new PageInfo("page4"); michael@0: PageInfo page5 = new PageInfo("page5"); michael@0: PageInfo page6 = new PageInfo("page6"); michael@0: michael@0: SessionTab tab1 = new SessionTab(0, home, page1, page2); michael@0: SessionTab tab2 = new SessionTab(1, home, page3, page4); michael@0: SessionTab tab3 = new SessionTab(2, home, page5, page6); michael@0: michael@0: final Session session = new Session(1, tab1, tab2, tab3); michael@0: michael@0: // Load the tabs into the browser michael@0: loadSessionTabs(session); michael@0: michael@0: // Verify sessionstore.js written by Gecko. The session write is michael@0: // delayed for certain interactions (such as changing the selected michael@0: // tab), so the file is repeatedly read until it matches the expected michael@0: // output. Because of the delay, this part of the test takes ~9 seconds michael@0: // to pass. michael@0: VerifyJSONCondition verifyJSONCondition = new VerifyJSONCondition(session); michael@0: boolean success = waitForCondition(verifyJSONCondition, SESSION_TIMEOUT); michael@0: if (success) { michael@0: mAsserter.ok(true, "verified session JSON", null); michael@0: } else { michael@0: mAsserter.ok(false, "failed to verify session JSON", michael@0: getStackTraceString(verifyJSONCondition.getLastException())); michael@0: } michael@0: } michael@0: michael@0: private class VerifyJSONCondition implements Condition { michael@0: private AssertException mLastException; michael@0: private final NonFatalAsserter mAsserter = new NonFatalAsserter(); michael@0: private final Session mSession; michael@0: michael@0: public VerifyJSONCondition(Session session) { michael@0: mSession = session; michael@0: } michael@0: michael@0: @Override michael@0: public boolean isSatisfied() { michael@0: try { michael@0: String sessionString = readProfileFile("sessionstore.js"); michael@0: if (sessionString == null) { michael@0: mLastException = new AssertException("Could not read sessionstore.js"); michael@0: return false; michael@0: } michael@0: michael@0: verifySessionJSON(mSession, sessionString, mAsserter); michael@0: } catch (AssertException e) { michael@0: mLastException = e; michael@0: return false; michael@0: } michael@0: return true; michael@0: } michael@0: michael@0: /** michael@0: * Gets the last AssertException thrown by verifySessionJSON(). michael@0: * michael@0: * This is useful to get the stack trace if the test fails. michael@0: */ michael@0: public AssertException getLastException() { michael@0: return mLastException; michael@0: } michael@0: } michael@0: }