Cherry-pick: Don't extend delete selection from zero.

This cherry-pick applied cleanly, with the exception of a conflict
in the test.

This cherry-pick should only be landed after:
https://googleplex-android-review.git.corp.google.com/#/c/555498/


BUG:17587083

Original description:

Don't extend delete selection from zero.

The previous fix ensured that trying to delete something actually did delete something but ended up also ensuring deletion even when trying to delete nothing.  Now we don't attempt to extend the range when the requested range started at zero.

BUG=355995
Committed: https://src.chromium.org/viewvc/blink?view=rev&revision=178679

Change-Id: I504516c4a8e78bc44fcdaea2ee72c4969f148f77
diff --git a/Source/core/editing/InputMethodController.cpp b/Source/core/editing/InputMethodController.cpp
index 793b04b..5f3e5b7 100644
--- a/Source/core/editing/InputMethodController.cpp
+++ b/Source/core/editing/InputMethodController.cpp
@@ -417,6 +417,8 @@
     do {
         if (!setSelectionOffsets(PlainTextRange(std::max(static_cast<int>(selectionOffsets.start()) - before, 0), selectionOffsets.end() + after)))
             return;
+        if (before == 0)
+            break;
         ++before;
     } while (m_frame.selection().start() == m_frame.selection().end() && before <= static_cast<int>(selectionOffsets.start()));
     TypingCommand::deleteSelection(*m_frame.document());
diff --git a/Source/core/editing/InputMethodControllerTest.cpp b/Source/core/editing/InputMethodControllerTest.cpp
index 73cfd37..66167b1 100644
--- a/Source/core/editing/InputMethodControllerTest.cpp
+++ b/Source/core/editing/InputMethodControllerTest.cpp
@@ -46,6 +46,12 @@
     input->setValue("fooX");
     controller().setEditableSelectionOffsets(PlainTextRange(4, 4));
     EXPECT_STREQ("fooX", input->value().utf8().data());
+    controller().extendSelectionAndDelete(0, 0);
+    EXPECT_STREQ("fooX", input->value().utf8().data());
+
+    input->setValue("fooX");
+    controller().setEditableSelectionOffsets(PlainTextRange(4, 4));
+    EXPECT_STREQ("fooX", input->value().utf8().data());
     controller().extendSelectionAndDelete(1, 0);
     EXPECT_STREQ("foo", input->value().utf8().data());
 
@@ -66,6 +72,12 @@
     EXPECT_STREQ("foo\xE0\xB8\x81\xE0\xB9\x89", input->value().utf8().data());
     controller().extendSelectionAndDelete(1, 0);
     EXPECT_STREQ("foo", input->value().utf8().data());
+
+    input->setValue("fooX");
+    controller().setEditableSelectionOffsets(PlainTextRange(4, 4));
+    EXPECT_STREQ("fooX", input->value().utf8().data());
+    controller().extendSelectionAndDelete(0, 1);
+    EXPECT_STREQ("fooX", input->value().utf8().data());
 }
 
 } // namespace