From dfbe2bfe089b301819039e9b3a7d2c307e6beac7 Mon Sep 17 00:00:00 2001
From: Jean Chalard <jchalard@google.com>
Date: Wed, 18 Dec 2013 16:53:54 +0900
Subject: [PATCH] Add some info to test crashes to help diagnose flakiness

Bug: 11142685
Change-Id: Ic3a5d452f6c325248ac4e1bfa37774c58586f359
---
 java/src/com/android/inputmethod/latin/LatinIME.java  | 11 +++--------
 .../latin/InputLogicTestsLanguageWithoutSpaces.java   |  3 ++-
 .../inputmethod/latin/InputLogicTestsNonEnglish.java  |  3 ++-
 .../android/inputmethod/latin/PunctuationTests.java   |  9 +++++++--
 4 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 67b5702771..4b38c88714 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -3253,8 +3253,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
 
     // TODO: can this be removed somehow without breaking the tests?
     @UsedForTesting
-    /* package for test */ String getFirstSuggestedWord() {
-        return mSuggestedWords.size() > 0 ? mSuggestedWords.getWord(0) : null;
+    /* package for test */ SuggestedWords getSuggestedWords() {
+        // You may not use this method for anything else than debug
+        return DEBUG ? mSuggestedWords : null;
     }
 
     // DO NOT USE THIS for any other purpose than testing. This is information private to LatinIME.
@@ -3263,12 +3264,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
         return mSuggest.isCurrentlyWaitingForMainDictionary();
     }
 
-    // DO NOT USE THIS for any other purpose than testing. This is information private to LatinIME.
-    @UsedForTesting
-    /* package for test */ boolean hasMainDictionary() {
-        return mSuggest.hasMainDictionary();
-    }
-
     // DO NOT USE THIS for any other purpose than testing. This can break the keyboard badly.
     @UsedForTesting
     /* package for test */ void replaceMainDictionaryForTest(final Locale locale) {
diff --git a/tests/src/com/android/inputmethod/latin/InputLogicTestsLanguageWithoutSpaces.java b/tests/src/com/android/inputmethod/latin/InputLogicTestsLanguageWithoutSpaces.java
index 0f0ebafb99..89021b4e57 100644
--- a/tests/src/com/android/inputmethod/latin/InputLogicTestsLanguageWithoutSpaces.java
+++ b/tests/src/com/android/inputmethod/latin/InputLogicTestsLanguageWithoutSpaces.java
@@ -99,7 +99,8 @@ public class InputLogicTestsLanguageWithoutSpaces extends InputTestsBase {
         assertEquals("predictions in lang without spaces", "Barack",
                 mEditText.getText().toString());
         // Test the first prediction is displayed
+        final SuggestedWords suggestedWords = mLatinIME.getSuggestedWords();
         assertEquals("predictions in lang without spaces", "Obama",
-                mLatinIME.getFirstSuggestedWord());
+                suggestedWords.size() > 0 ? suggestedWords.getWord(0) : null);
     }
 }
diff --git a/tests/src/com/android/inputmethod/latin/InputLogicTestsNonEnglish.java b/tests/src/com/android/inputmethod/latin/InputLogicTestsNonEnglish.java
index 2d736e3388..a474c6a8d7 100644
--- a/tests/src/com/android/inputmethod/latin/InputLogicTestsNonEnglish.java
+++ b/tests/src/com/android/inputmethod/latin/InputLogicTestsNonEnglish.java
@@ -84,8 +84,9 @@ public class InputLogicTestsNonEnglish extends InputTestsBase {
             type(WORD_TO_TYPE);
             sleep(DELAY_TO_WAIT_FOR_UNDERLINE);
             runMessages();
+            final SuggestedWords suggestedWords = mLatinIME.getSuggestedWords();
             assertEquals("type word then type space yields predictions for French",
-                    EXPECTED_RESULT, mLatinIME.getFirstSuggestedWord());
+                    EXPECTED_RESULT, suggestedWords.size() > 0 ? suggestedWords.getWord(0) : null);
         } finally {
             setBooleanPreference(NEXT_WORD_PREDICTION_OPTION, previousNextWordPredictionOption,
                     defaultNextWordPredictionOption);
diff --git a/tests/src/com/android/inputmethod/latin/PunctuationTests.java b/tests/src/com/android/inputmethod/latin/PunctuationTests.java
index 84ff6b3075..d5c06e223b 100644
--- a/tests/src/com/android/inputmethod/latin/PunctuationTests.java
+++ b/tests/src/com/android/inputmethod/latin/PunctuationTests.java
@@ -16,6 +16,7 @@
 
 package com.android.inputmethod.latin;
 
+import android.provider.Settings.Secure;
 import android.test.suitebuilder.annotation.LargeTest;
 
 import com.android.inputmethod.latin.R;
@@ -153,7 +154,9 @@ public class PunctuationTests extends InputTestsBase {
         final String WORD_TO_TYPE = "you'f ";
         final String EXPECTED_RESULT = "you'd ";
         type(WORD_TO_TYPE);
-        assertEquals("auto-correction with single quote inside",
+        assertEquals("auto-correction with single quote inside. ID = "
+                + Secure.getString(getContext().getContentResolver(), Secure.ANDROID_ID)
+                + " ; Suggestions = " + mLatinIME.getSuggestedWords(),
                 EXPECTED_RESULT, mEditText.getText().toString());
     }
 
@@ -161,7 +164,9 @@ public class PunctuationTests extends InputTestsBase {
         final String WORD_TO_TYPE = "'tgis' ";
         final String EXPECTED_RESULT = "'this' ";
         type(WORD_TO_TYPE);
-        assertEquals("auto-correction with single quotes around",
+        assertEquals("auto-correction with single quotes around. ID = "
+                + Secure.getString(getContext().getContentResolver(), Secure.ANDROID_ID)
+                + " ; Suggestions = " + mLatinIME.getSuggestedWords(),
                 EXPECTED_RESULT, mEditText.getText().toString());
     }
 }
-- 
GitLab