Merge "Make InputLogicTest more robust"
diff --git a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
index 7d61569..bd114eb 100644
--- a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
+++ b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
@@ -973,7 +973,13 @@
                 } else {
                     final int codePointBeforeCursor = mConnection.getCodePointBeforeCursor();
                     if (codePointBeforeCursor == Constants.NOT_A_CODE) {
-                        // Nothing to delete before the cursor.
+                        // HACK for backward compatibility with broken apps that haven't realized
+                        // yet that hardware keyboards are not the only way of inputting text.
+                        // Nothing to delete before the cursor. We should not do anything, but many
+                        // broken apps expect something to happen in this case so that they can
+                        // catch it and have their broken interface react. If you need the keyboard
+                        // to do this, you're doing it wrong -- please fix your app.
+                        mConnection.deleteSurroundingText(1, 0);
                         return;
                     }
                     final int lengthToDelete =
diff --git a/tests/src/com/android/inputmethod/latin/BlueUnderlineTests.java b/tests/src/com/android/inputmethod/latin/BlueUnderlineTests.java
index 82bf0d4..6e894de 100644
--- a/tests/src/com/android/inputmethod/latin/BlueUnderlineTests.java
+++ b/tests/src/com/android/inputmethod/latin/BlueUnderlineTests.java
@@ -50,8 +50,7 @@
         final SpanGetter spanBefore = new SpanGetter(mEditText.getText(), SuggestionSpan.class);
         assertEquals("extend blue underline, span start", EXPECTED_SPAN_START, spanBefore.mStart);
         assertEquals("extend blue underline, span end", EXPECTED_SPAN_END, spanBefore.mEnd);
-        assertEquals("extend blue underline, span color", true,
-                spanBefore.isAutoCorrectionIndicator());
+        assertTrue("extend blue underline, span color", spanBefore.isAutoCorrectionIndicator());
         sleep(DELAY_TO_WAIT_FOR_UNDERLINE);
         runMessages();
         // Now we have been able to re-evaluate the word, there shouldn't be an auto-correction span
@@ -80,8 +79,8 @@
         sleep(DELAY_TO_WAIT_FOR_UNDERLINE);
         runMessages();
         final SpanGetter suggestionSpan = new SpanGetter(mEditText.getText(), SuggestionSpan.class);
-        assertFalse("show no blue underline after backspace, span start should be -1",
-                suggestionSpan.isAutoCorrectionIndicator());
+        assertFalse("show no blue underline after backspace, span should not be the auto-"
+                + "correction indicator", suggestionSpan.isAutoCorrectionIndicator());
         final SpanGetter underlineSpan = new SpanGetter(mEditText.getText(), UnderlineSpan.class);
         assertEquals("should be composing, so should have an underline span",
                 EXPECTED_UNDERLINE_SPAN_START, underlineSpan.mStart);
@@ -107,7 +106,8 @@
         sleep(DELAY_TO_WAIT_FOR_UNDERLINE);
         runMessages();
         final SpanGetter span = new SpanGetter(mEditText.getText(), SuggestionSpan.class);
-        assertNull("blue underline removed when cursor is moved", span.mSpan);
+        assertFalse("blue underline removed when cursor is moved",
+                span.isAutoCorrectionIndicator());
     }
 
     public void testComposingStopsOnSpace() {