Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | package org.mozilla.gecko.tests; |
michael@0 | 2 | |
michael@0 | 3 | import org.mozilla.gecko.Actions; |
michael@0 | 4 | |
michael@0 | 5 | import com.jayway.android.robotium.solo.Condition; |
michael@0 | 6 | |
michael@0 | 7 | /** |
michael@0 | 8 | * Tests session OOM save behavior. |
michael@0 | 9 | * |
michael@0 | 10 | * Builds a session and tests that the saved state is correct. |
michael@0 | 11 | */ |
michael@0 | 12 | public class testSessionOOMSave extends SessionTest { |
michael@0 | 13 | private final static int SESSION_TIMEOUT = 25000; |
michael@0 | 14 | |
michael@0 | 15 | public void testSessionOOMSave() { |
michael@0 | 16 | Actions.EventExpecter pageShowExpecter = mActions.expectGeckoEvent("Content:PageShow"); |
michael@0 | 17 | pageShowExpecter.blockForEvent(); |
michael@0 | 18 | pageShowExpecter.unregisterListener(); |
michael@0 | 19 | |
michael@0 | 20 | PageInfo home = new PageInfo("about:home"); |
michael@0 | 21 | PageInfo page1 = new PageInfo("page1"); |
michael@0 | 22 | PageInfo page2 = new PageInfo("page2"); |
michael@0 | 23 | PageInfo page3 = new PageInfo("page3"); |
michael@0 | 24 | PageInfo page4 = new PageInfo("page4"); |
michael@0 | 25 | PageInfo page5 = new PageInfo("page5"); |
michael@0 | 26 | PageInfo page6 = new PageInfo("page6"); |
michael@0 | 27 | |
michael@0 | 28 | SessionTab tab1 = new SessionTab(0, home, page1, page2); |
michael@0 | 29 | SessionTab tab2 = new SessionTab(1, home, page3, page4); |
michael@0 | 30 | SessionTab tab3 = new SessionTab(2, home, page5, page6); |
michael@0 | 31 | |
michael@0 | 32 | final Session session = new Session(1, tab1, tab2, tab3); |
michael@0 | 33 | |
michael@0 | 34 | // Load the tabs into the browser |
michael@0 | 35 | loadSessionTabs(session); |
michael@0 | 36 | |
michael@0 | 37 | // Verify sessionstore.js written by Gecko. The session write is |
michael@0 | 38 | // delayed for certain interactions (such as changing the selected |
michael@0 | 39 | // tab), so the file is repeatedly read until it matches the expected |
michael@0 | 40 | // output. Because of the delay, this part of the test takes ~9 seconds |
michael@0 | 41 | // to pass. |
michael@0 | 42 | VerifyJSONCondition verifyJSONCondition = new VerifyJSONCondition(session); |
michael@0 | 43 | boolean success = waitForCondition(verifyJSONCondition, SESSION_TIMEOUT); |
michael@0 | 44 | if (success) { |
michael@0 | 45 | mAsserter.ok(true, "verified session JSON", null); |
michael@0 | 46 | } else { |
michael@0 | 47 | mAsserter.ok(false, "failed to verify session JSON", |
michael@0 | 48 | getStackTraceString(verifyJSONCondition.getLastException())); |
michael@0 | 49 | } |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | private class VerifyJSONCondition implements Condition { |
michael@0 | 53 | private AssertException mLastException; |
michael@0 | 54 | private final NonFatalAsserter mAsserter = new NonFatalAsserter(); |
michael@0 | 55 | private final Session mSession; |
michael@0 | 56 | |
michael@0 | 57 | public VerifyJSONCondition(Session session) { |
michael@0 | 58 | mSession = session; |
michael@0 | 59 | } |
michael@0 | 60 | |
michael@0 | 61 | @Override |
michael@0 | 62 | public boolean isSatisfied() { |
michael@0 | 63 | try { |
michael@0 | 64 | String sessionString = readProfileFile("sessionstore.js"); |
michael@0 | 65 | if (sessionString == null) { |
michael@0 | 66 | mLastException = new AssertException("Could not read sessionstore.js"); |
michael@0 | 67 | return false; |
michael@0 | 68 | } |
michael@0 | 69 | |
michael@0 | 70 | verifySessionJSON(mSession, sessionString, mAsserter); |
michael@0 | 71 | } catch (AssertException e) { |
michael@0 | 72 | mLastException = e; |
michael@0 | 73 | return false; |
michael@0 | 74 | } |
michael@0 | 75 | return true; |
michael@0 | 76 | } |
michael@0 | 77 | |
michael@0 | 78 | /** |
michael@0 | 79 | * Gets the last AssertException thrown by verifySessionJSON(). |
michael@0 | 80 | * |
michael@0 | 81 | * This is useful to get the stack trace if the test fails. |
michael@0 | 82 | */ |
michael@0 | 83 | public AssertException getLastException() { |
michael@0 | 84 | return mLastException; |
michael@0 | 85 | } |
michael@0 | 86 | } |
michael@0 | 87 | } |