From f67172552033ad5bfc9aadea5d2729d65a666e91 Mon Sep 17 00:00:00 2001
From: "Tadashi G. Takaoka" <takaoka@google.com>
Date: Mon, 9 Jun 2014 11:13:39 +0900
Subject: [PATCH] Make keyboard theme test robust

Change-Id: I2547c8af6fa73e646f697cb4450140859d87625e
---
 .../keyboard/KeyboardThemeTests.java          | 26 +++++++++++--------
 1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/tests/src/com/android/inputmethod/keyboard/KeyboardThemeTests.java b/tests/src/com/android/inputmethod/keyboard/KeyboardThemeTests.java
index 4f4f01c766..f9d98afa2d 100644
--- a/tests/src/com/android/inputmethod/keyboard/KeyboardThemeTests.java
+++ b/tests/src/com/android/inputmethod/keyboard/KeyboardThemeTests.java
@@ -83,10 +83,14 @@ public class KeyboardThemeTests extends AndroidTestCase {
      * Test keyboard theme preference on the same platform version and the same keyboard version.
      */
 
-    private void assertKeyboardThemePreference(final int sdkVersion, final int oldThemeId,
+    private void assertKeyboardThemePreference(final int sdkVersion, final int previousThemeId,
             final int expectedThemeId) {
+        // Clear preferences before testing.
+        setKeyboardThemePreference(KeyboardTheme.KLP_KEYBOARD_THEME_KEY, THEME_ID_NULL);
+        setKeyboardThemePreference(KeyboardTheme.LXX_KEYBOARD_THEME_KEY, THEME_ID_NULL);
+        // Set the preference of the sdkVersion to previousThemeId.
         final String prefKey = KeyboardTheme.getPreferenceKey(sdkVersion);
-        setKeyboardThemePreference(prefKey, oldThemeId);
+        setKeyboardThemePreference(prefKey, previousThemeId);
         assertKeyboardTheme(sdkVersion, expectedThemeId);
     }
 
@@ -127,10 +131,10 @@ public class KeyboardThemeTests extends AndroidTestCase {
      * Test default keyboard theme based on the platform version.
      */
 
-    private void assertDefaultKeyboardTheme(final int sdkVersion, final int oldThemeId,
+    private void assertDefaultKeyboardTheme(final int sdkVersion, final int previousThemeId,
             final int expectedThemeId) {
         final String oldPrefKey = KeyboardTheme.KLP_KEYBOARD_THEME_KEY;
-        setKeyboardThemePreference(oldPrefKey, oldThemeId);
+        setKeyboardThemePreference(oldPrefKey, previousThemeId);
 
         final KeyboardTheme defaultTheme =
                 KeyboardTheme.getDefaultKeyboardTheme(mPrefs, sdkVersion);
@@ -139,7 +143,7 @@ public class KeyboardThemeTests extends AndroidTestCase {
         assertEquals(expectedThemeId, defaultTheme.mThemeId);
         if (sdkVersion <= VERSION_CODES.KITKAT) {
             // Old preference must be retained if it is valid. Otherwise it must be pruned.
-            assertEquals(isValidKeyboardThemeId(oldThemeId), mPrefs.contains(oldPrefKey));
+            assertEquals(isValidKeyboardThemeId(previousThemeId), mPrefs.contains(oldPrefKey));
             return;
         }
         // Old preference must be removed.
@@ -181,9 +185,9 @@ public class KeyboardThemeTests extends AndroidTestCase {
      * to the keyboard that supports LXX theme.
      */
 
-    private void assertUpgradeKeyboardToLxxOn(final int sdkVersion, final int oldThemeId,
+    private void assertUpgradeKeyboardToLxxOn(final int sdkVersion, final int previousThemeId,
             final int expectedThemeId) {
-        setKeyboardThemePreference(KeyboardTheme.KLP_KEYBOARD_THEME_KEY, oldThemeId);
+        setKeyboardThemePreference(KeyboardTheme.KLP_KEYBOARD_THEME_KEY, previousThemeId);
         // Clean up new keyboard theme preference to simulate "upgrade to LXX keyboard".
         setKeyboardThemePreference(KeyboardTheme.LXX_KEYBOARD_THEME_KEY, THEME_ID_NULL);
 
@@ -195,9 +199,9 @@ public class KeyboardThemeTests extends AndroidTestCase {
             // New preference must not exist.
             assertFalse(mPrefs.contains(KeyboardTheme.LXX_KEYBOARD_THEME_KEY));
             // Old preference must be retained if it is valid. Otherwise it must be pruned.
-            assertEquals(isValidKeyboardThemeId(oldThemeId),
+            assertEquals(isValidKeyboardThemeId(previousThemeId),
                     mPrefs.contains(KeyboardTheme.KLP_KEYBOARD_THEME_KEY));
-            if (isValidKeyboardThemeId(oldThemeId)) {
+            if (isValidKeyboardThemeId(previousThemeId)) {
                 // Old preference must have an expected value.
                 assertEquals(mPrefs.getString(KeyboardTheme.KLP_KEYBOARD_THEME_KEY, null),
                         Integer.toString(expectedThemeId));
@@ -247,7 +251,7 @@ public class KeyboardThemeTests extends AndroidTestCase {
      */
 
     private void assertUpgradePlatformFromTo(final int oldSdkVersion, final int newSdkVersion,
-            final int oldThemeId, final int expectedThemeId) {
+            final int previousThemeId, final int expectedThemeId) {
         if (newSdkVersion < oldSdkVersion) {
             // No need to test.
             return;
@@ -257,7 +261,7 @@ public class KeyboardThemeTests extends AndroidTestCase {
         setKeyboardThemePreference(KeyboardTheme.LXX_KEYBOARD_THEME_KEY, THEME_ID_NULL);
 
         final String oldPrefKey = KeyboardTheme.getPreferenceKey(oldSdkVersion);
-        setKeyboardThemePreference(oldPrefKey, oldThemeId);
+        setKeyboardThemePreference(oldPrefKey, previousThemeId);
 
         assertKeyboardTheme(newSdkVersion, expectedThemeId);
     }
-- 
GitLab