mobile/android/base/tests/testSessionOOMRestore.java

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mobile/android/base/tests/testSessionOOMRestore.java	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,54 @@
     1.4 +package org.mozilla.gecko.tests;
     1.5 +
     1.6 +import android.content.Context;
     1.7 +import android.content.Intent;
     1.8 +import android.content.SharedPreferences;
     1.9 +import android.os.Bundle;
    1.10 +
    1.11 +/**
    1.12 + * Tests session OOM restore behavior.
    1.13 + *
    1.14 + * Loads a session and tests that it is restored correctly.
    1.15 + */
    1.16 +public class testSessionOOMRestore extends SessionTest {
    1.17 +    private Session mSession;
    1.18 +    private static final String PREFS_NAME = "GeckoApp";
    1.19 +    private static final String PREFS_ALLOW_STATE_BUNDLE = "allowStateBundle";
    1.20 +
    1.21 +    @Override
    1.22 +    public void setActivityIntent(Intent intent) {
    1.23 +        PageInfo home = new PageInfo("about:home");
    1.24 +        PageInfo page1 = new PageInfo("page1");
    1.25 +        PageInfo page2 = new PageInfo("page2");
    1.26 +        PageInfo page3 = new PageInfo("page3");
    1.27 +        PageInfo page4 = new PageInfo("page4");
    1.28 +        PageInfo page5 = new PageInfo("page5");
    1.29 +        PageInfo page6 = new PageInfo("page6");
    1.30 +
    1.31 +        SessionTab tab1 = new SessionTab(0, home, page1, page2);
    1.32 +        SessionTab tab2 = new SessionTab(1, home, page3, page4);
    1.33 +        SessionTab tab3 = new SessionTab(2, home, page5, page6);
    1.34 +
    1.35 +        mSession = new Session(1, tab1, tab2, tab3);
    1.36 +
    1.37 +        String sessionString = buildSessionJSON(mSession);
    1.38 +        writeProfileFile("sessionstore.js", sessionString);
    1.39 +
    1.40 +        // This feature is pref-protected to prevent other apps from injecting
    1.41 +        // a state bundle, so enable it here.
    1.42 +        SharedPreferences prefs = getInstrumentation().getTargetContext()
    1.43 +                .getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
    1.44 +        prefs.edit().putBoolean(PREFS_ALLOW_STATE_BUNDLE, true).commit();
    1.45 +
    1.46 +        Bundle bundle = new Bundle();
    1.47 +        bundle.putString("privateSession", null);
    1.48 +        intent.putExtra("stateBundle", bundle);
    1.49 +
    1.50 +        super.setActivityIntent(intent);
    1.51 +    }
    1.52 +
    1.53 +    public void testSessionOOMRestore() throws Exception {
    1.54 +        blockForGeckoReady();
    1.55 +        verifySessionTabs(mSession);
    1.56 +    }
    1.57 +}

mercurial