Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 90058c3d authored by Tadashi G. Takaoka's avatar Tadashi G. Takaoka
Browse files

Add an internal state test to ImportantNoticeUtilsTests

On some 32bit-x86 testing emulators, it seems the internal state after
clear the related settings seems like a contradiction state. This CL
adds an test to check such internal state in order to investigate what
is happening on these emulators.

Bug: 17635340
Change-Id: Iba85f06c46959b1dc22e2a9213c50c9e7e30949b
parent dd052f00
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -53,7 +53,8 @@ public final class ImportantNoticeUtils {
        // This utility class is not publicly instantiable.
    }

    private static boolean isInSystemSetupWizard(final Context context) {
    @UsedForTesting
    static boolean isInSystemSetupWizard(final Context context) {
        try {
            final int userSetupComplete = Settings.Secure.getInt(
                    context.getContentResolver(), Settings_Secure_USER_SETUP_COMPLETE);
@@ -84,7 +85,8 @@ public final class ImportantNoticeUtils {
        return getLastImportantNoticeVersion(context) + 1;
    }

    private static boolean hasNewImportantNotice(final Context context) {
    @UsedForTesting
    static boolean hasNewImportantNotice(final Context context) {
        final int lastVersion = getLastImportantNoticeVersion(context);
        return getCurrentImportantNoticeVersion(context) > lastVersion;
    }
+29 −7
Original line number Diff line number Diff line
@@ -16,18 +16,18 @@

package com.android.inputmethod.latin.utils;

import static com.android.inputmethod.latin.utils.ImportantNoticeUtils.KEY_TIMESTAMP_OF_FIRST_IMPORTANT_NOTICE;
import static com.android.inputmethod.latin.utils.ImportantNoticeUtils.KEY_IMPORTANT_NOTICE_VERSION;
import static com.android.inputmethod.latin.utils.ImportantNoticeUtils.KEY_TIMESTAMP_OF_FIRST_IMPORTANT_NOTICE;

import android.content.Context;
import android.content.SharedPreferences;
import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.SmallTest;
import android.test.suitebuilder.annotation.MediumTest;
import android.text.TextUtils;

import java.util.concurrent.TimeUnit;

@SmallTest
@MediumTest
public class ImportantNoticeUtilsTests extends AndroidTestCase {
    // This should be aligned with R.integer.config_important_notice_version.
    private static final int CURRENT_IMPORTANT_NOTICE_VERSION = 1;
@@ -112,6 +112,28 @@ public class ImportantNoticeUtilsTests extends AndroidTestCase {
                ImportantNoticeUtils.getCurrentImportantNoticeVersion(getContext()));
    }

    public void testStateAfterFreshInstall() {
        mImportantNoticePreferences.clear();

        // Check internal state of {@link ImportantNoticeUtils.shouldShowImportantNotice(Context)}
        // after fresh install.
        assertEquals("Has new imortant notice after fresh install", true,
                ImportantNoticeUtils.hasNewImportantNotice(getContext()));
        assertEquals("Next important norice title after fresh install", false, TextUtils.isEmpty(
                ImportantNoticeUtils.getNextImportantNoticeTitle(getContext())));
        assertEquals("Is in system setup wizard after fresh install", false,
                ImportantNoticeUtils.isInSystemSetupWizard(getContext()));
        final long currentTimeMillis = System.currentTimeMillis();
        assertEquals("Has timeout passed after fresh install", false,
                ImportantNoticeUtils.hasTimeoutPassed(getContext(), currentTimeMillis));
        assertEquals("Timestamp of first important notice after fresh install",
                (Long)currentTimeMillis,
                mImportantNoticePreferences.getLong(KEY_TIMESTAMP_OF_FIRST_IMPORTANT_NOTICE));

        assertEquals("Current boolean before update", true,
                ImportantNoticeUtils.shouldShowImportantNotice(getContext()));
    }

    public void testUpdateVersion() {
        mImportantNoticePreferences.clear();

@@ -163,7 +185,7 @@ public class ImportantNoticeUtilsTests extends AndroidTestCase {
                ImportantNoticeUtils.getLastImportantNoticeVersion(getContext()));
        assertEquals("Next version before timeout 1", 1,
                ImportantNoticeUtils.getNextImportantNoticeVersion(getContext()));
        assertEquals("Last time before timeout 1", (Long)lastTime,
        assertEquals("Timestamp of first important notice before timeout 1", (Long)lastTime,
                mImportantNoticePreferences.getLong(KEY_TIMESTAMP_OF_FIRST_IMPORTANT_NOTICE));
        assertEquals("Current title before timeout 1", false, TextUtils.isEmpty(
                ImportantNoticeUtils.getNextImportantNoticeTitle(getContext())));
@@ -180,7 +202,7 @@ public class ImportantNoticeUtilsTests extends AndroidTestCase {
                ImportantNoticeUtils.getLastImportantNoticeVersion(getContext()));
        assertEquals("Next version before timeout 2", 1,
                ImportantNoticeUtils.getNextImportantNoticeVersion(getContext()));
        assertEquals("Last time before timeout 2", (Long)lastTime,
        assertEquals("Timestamp of first important notice before timeout 2", (Long)lastTime,
                mImportantNoticePreferences.getLong(KEY_TIMESTAMP_OF_FIRST_IMPORTANT_NOTICE));
        assertEquals("Current title before timeout 2", false, TextUtils.isEmpty(
                ImportantNoticeUtils.getNextImportantNoticeTitle(getContext())));
@@ -196,7 +218,7 @@ public class ImportantNoticeUtilsTests extends AndroidTestCase {
                ImportantNoticeUtils.getLastImportantNoticeVersion(getContext()));
        assertEquals("Next version after timeout 1", 2,
                ImportantNoticeUtils.getNextImportantNoticeVersion(getContext()));
        assertEquals("Last time aflter timeout 1", null,
        assertEquals("Timestamp of first important notice after timeout 1", null,
                mImportantNoticePreferences.getLong(KEY_TIMESTAMP_OF_FIRST_IMPORTANT_NOTICE));
        assertEquals("Current title after timeout 1", true, TextUtils.isEmpty(
                ImportantNoticeUtils.getNextImportantNoticeTitle(getContext())));
@@ -212,7 +234,7 @@ public class ImportantNoticeUtilsTests extends AndroidTestCase {
                ImportantNoticeUtils.getLastImportantNoticeVersion(getContext()));
        assertEquals("Next version after timeout 2", 2,
                ImportantNoticeUtils.getNextImportantNoticeVersion(getContext()));
        assertEquals("Last time aflter timeout 2", null,
        assertEquals("Timestamp of first important notice after timeout 2", null,
                mImportantNoticePreferences.getLong(KEY_TIMESTAMP_OF_FIRST_IMPORTANT_NOTICE));
        assertEquals("Current title after timeout 2", true, TextUtils.isEmpty(
                ImportantNoticeUtils.getNextImportantNoticeTitle(getContext())));