Fix MoveEndpointByUnit (TextUnit_Format) degenerate range creation

ITextRangeProvider::MoveEndpointByUnit for TextUnit_Format will not
create a degenerate range in certain cases when at the beginning or end
of a document.

The reason is that CreatePositionAtFormatBoundary() uses
CreateNextTextAnchorPosition()/CreatePreviousTextAnchorPosition()
to traverse to the next anchor boundary. This can pose a problem in
the case where the range start and end span the same anchor.

For example: Text
             ^   ^
         start   end
When the above case is at the beginning of the document, and you
try to create a degenerate range by moving end to the start,
CreatePositionAtFormatBoundary() will call
CreatePreviousTextAnchorPosition(). This will return a null position
because there is no previous text anchor. This causes
CreatePositionAtFormatBoundary() to think that end is at the
beginning of the document, and as a result will leave end where it is.
However, end is still at the end of the first anchor and not at the
beginning of the document.

This change fixes the above issue by checking the text offset to see if
the position is truly at the beginning/end of the document, or if there
is actually more text to traverse.

Unit tests added.

Bug: 961351
Change-Id: Ib6ac2b279408aaf90edf9e8f3bbd2a34bf7c2f8e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1604407
Commit-Queue: Alison Maher <almaher@microsoft.com>
Reviewed-by: Kurt Catti-Schmidt <kschmi@microsoft.com>
Reviewed-by: Nektarios Paisios <nektar@chromium.org>
Cr-Commit-Position: refs/heads/master@{#661508}
3 files changed