Commit 2595aa00 authored by twellington's avatar twellington Committed by Commit bot

Add tests for DocumentModeAssassin#isOptedOutOfDocumentMode()

BUG=646146

Review-Url: https://codereview.chromium.org/2337143004
Cr-Commit-Position: refs/heads/master@{#418954}
parent 5e840a17
...@@ -106,16 +106,16 @@ public class DocumentModeAssassin { ...@@ -106,16 +106,16 @@ public class DocumentModeAssassin {
private static final int TAB_MODEL_INDEX = 0; private static final int TAB_MODEL_INDEX = 0;
/** SharedPreference values to determine whether user had document mode turned on. */ /** SharedPreference values to determine whether user had document mode turned on. */
private static final String OPT_OUT_STATE = "opt_out_state"; static final String OPT_OUT_STATE = "opt_out_state";
private static final int OPT_IN_TO_DOCUMENT_MODE = 0; private static final int OPT_IN_TO_DOCUMENT_MODE = 0;
private static final int OPT_OUT_STATE_UNSET = -1; private static final int OPT_OUT_STATE_UNSET = -1;
private static final int OPTED_OUT_OF_DOCUMENT_MODE = 2; static final int OPTED_OUT_OF_DOCUMENT_MODE = 2;
/** /**
* Preference that denotes that Chrome has attempted to migrate from tabbed mode to document * Preference that denotes that Chrome has attempted to migrate from tabbed mode to document
* mode. Indicates that the user may be in document mode. * mode. Indicates that the user may be in document mode.
*/ */
public static final String MIGRATION_ON_UPGRADE_ATTEMPTED = "migration_on_upgrade_attempted"; static final String MIGRATION_ON_UPGRADE_ATTEMPTED = "migration_on_upgrade_attempted";
/** Creates and holds the Singleton. */ /** Creates and holds the Singleton. */
private static class LazyHolder { private static class LazyHolder {
......
...@@ -612,6 +612,45 @@ public class DocumentModeAssassinTest extends NativeLibraryTestBase { ...@@ -612,6 +612,45 @@ public class DocumentModeAssassinTest extends NativeLibraryTestBase {
assertFalse(prefs.contains(keyToBeDeleted)); assertFalse(prefs.contains(keyToBeDeleted));
} }
@SmallTest
public void testIsOptedOutOfDocumentModeMigration() throws Exception {
TabPersistentStore.setBaseStateDirectoryForTests(mTabbedModeDirectory.getBaseDirectory());
SharedPreferences.Editor sharedPreferencesEditor =
ContextUtils.getAppSharedPreferences().edit();
// If no preferences for document mode are set, the user is not in document mode.
sharedPreferencesEditor.remove(DocumentModeAssassin.MIGRATION_ON_UPGRADE_ATTEMPTED);
sharedPreferencesEditor.remove(DocumentModeAssassin.OPT_OUT_STATE);
sharedPreferencesEditor.apply();
assertTrue(DocumentModeAssassin.isOptedOutOfDocumentMode());
// If the preference for opting out of document mode is set, the user is not in document
// mode.
sharedPreferencesEditor.remove(DocumentModeAssassin.MIGRATION_ON_UPGRADE_ATTEMPTED);
sharedPreferencesEditor.putInt(DocumentModeAssassin.OPT_OUT_STATE,
DocumentModeAssassin.OPTED_OUT_OF_DOCUMENT_MODE);
sharedPreferencesEditor.apply();
assertTrue(DocumentModeAssassin.isOptedOutOfDocumentMode());
// If the user has been migrated into document mode and no preference has been set for
// OPT_OUT_STATE, the user should still be in document mode.
sharedPreferencesEditor.putBoolean(DocumentModeAssassin.MIGRATION_ON_UPGRADE_ATTEMPTED,
true);
sharedPreferencesEditor.remove(DocumentModeAssassin.OPT_OUT_STATE);
sharedPreferencesEditor.apply();
assertFalse(DocumentModeAssassin.isOptedOutOfDocumentMode());
// If the user has been migrated into document mode and no preference has been set for
// OPT_OUT_STATE, but a "new" tabbed mode metadata file exists, migration has already been
// attempted or incorrectly skipped. The user is not in document mode.
sharedPreferencesEditor.putBoolean(DocumentModeAssassin.MIGRATION_ON_UPGRADE_ATTEMPTED,
true);
sharedPreferencesEditor.remove(DocumentModeAssassin.OPT_OUT_STATE);
sharedPreferencesEditor.apply();
mTabbedModeDirectory.writeTabModelFiles(TestTabModelDirectory.TAB_MODEL_METADATA_V5, false);
assertTrue(DocumentModeAssassin.isOptedOutOfDocumentMode());
}
/** Creates a DocumentModeAssassin with all of its calls pointing at our mocked classes. /** Creates a DocumentModeAssassin with all of its calls pointing at our mocked classes.
* @param isMigrationNecessary TODO(dfalcantara):*/ * @param isMigrationNecessary TODO(dfalcantara):*/
private DocumentModeAssassinForTesting createAssassinForTesting( private DocumentModeAssassinForTesting createAssassinForTesting(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment