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