Commit d4a8bfc8 authored by Helen Yang's avatar Helen Yang Committed by Commit Bot

[ios] Remove locale overrides from bubble_util unit tests

Previously, unit tests for bubble_util overrode the ICU default
locale in order to test methods in LTR/RTL. This caused
CardStackLayoutManagerTest to fail on bots. This CL fixes the issue
by removing default locale overrides from bubble_util unit tests,
and instead adds an |isRTL| parameter to the relevant util method
to make it more testable.

Bug: 750865
Change-Id: Ia53f92c8a08636c8c56519306b9347e8b425a37f
Reviewed-on: https://chromium-review.googlesource.com/596673
Commit-Queue: Helen Yang <helenlyang@google.com>
Reviewed-by: default avatarRohit Rao (ping after 24h) <rohitrao@chromium.org>
Reviewed-by: default avatarGregory Chatzinoff <gchatz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#491134}
parent 1dfd08c8
...@@ -31,8 +31,15 @@ CGFloat OriginY(CGRect targetFrame, ...@@ -31,8 +31,15 @@ CGFloat OriginY(CGRect targetFrame,
// Calculate the maximum width of the bubble such that it stays within its // Calculate the maximum width of the bubble such that it stays within its
// bounding coordinate space. |targetFrame| is the frame the target UI element // bounding coordinate space. |targetFrame| is the frame the target UI element
// in the coordinate system in which the bubble is drawn. |alignment| is the // in the coordinate system in which the bubble is drawn. |alignment| is the
// bubble's alignment, and |boundingWidth| is the width of the coordinate space // bubble's alignment, |boundingWidth| is the width of the coordinate space
// in which the bubble is drawn. // in which the bubble is drawn, and |isRTL| is true if the language is RTL.
CGFloat MaxWidth(CGRect targetFrame,
BubbleAlignment alignment,
CGFloat boundingWidth,
bool isRTL);
// Convenience method for calculating the maximum width of the bubble. Uses the
// ICU default locale of the device to determine whether the language is RTL.
CGFloat MaxWidth(CGRect targetFrame, CGFloat MaxWidth(CGRect targetFrame,
BubbleAlignment alignment, BubbleAlignment alignment,
CGFloat boundingWidth); CGFloat boundingWidth);
......
...@@ -65,12 +65,13 @@ CGFloat OriginY(CGRect targetFrame, ...@@ -65,12 +65,13 @@ CGFloat OriginY(CGRect targetFrame,
CGFloat MaxWidth(CGRect targetFrame, CGFloat MaxWidth(CGRect targetFrame,
BubbleAlignment alignment, BubbleAlignment alignment,
CGFloat boundingWidth) { CGFloat boundingWidth,
bool isRTL) {
CGFloat anchorX = CGRectGetMidX(targetFrame); CGFloat anchorX = CGRectGetMidX(targetFrame);
CGFloat maxWidth; CGFloat maxWidth;
switch (alignment) { switch (alignment) {
case BubbleAlignmentLeading: case BubbleAlignmentLeading:
if (base::i18n::IsRTL()) { if (isRTL) {
// The bubble is aligned right, and can use space to the left of the // The bubble is aligned right, and can use space to the left of the
// anchor point and within |kBubbleAlignmentOffset| from the right. // anchor point and within |kBubbleAlignmentOffset| from the right.
maxWidth = anchorX + kBubbleAlignmentOffset; maxWidth = anchorX + kBubbleAlignmentOffset;
...@@ -86,7 +87,7 @@ CGFloat MaxWidth(CGRect targetFrame, ...@@ -86,7 +87,7 @@ CGFloat MaxWidth(CGRect targetFrame,
maxWidth = MIN(anchorX, boundingWidth - anchorX) * 2.0f; maxWidth = MIN(anchorX, boundingWidth - anchorX) * 2.0f;
break; break;
case BubbleAlignmentTrailing: case BubbleAlignmentTrailing:
if (base::i18n::IsRTL()) { if (isRTL) {
// The bubble is aligned left, and can use space to the right of the // The bubble is aligned left, and can use space to the right of the
// anchor point and within |kBubbleAlignmentOffset| from the left. // anchor point and within |kBubbleAlignmentOffset| from the left.
maxWidth = boundingWidth - anchorX + kBubbleAlignmentOffset; maxWidth = boundingWidth - anchorX + kBubbleAlignmentOffset;
...@@ -103,4 +104,11 @@ CGFloat MaxWidth(CGRect targetFrame, ...@@ -103,4 +104,11 @@ CGFloat MaxWidth(CGRect targetFrame,
return maxWidth; return maxWidth;
} }
CGFloat MaxWidth(CGRect targetFrame,
BubbleAlignment alignment,
CGFloat boundingWidth) {
bool isRTL = base::i18n::IsRTL();
return MaxWidth(targetFrame, alignment, boundingWidth, isRTL);
}
} // namespace bubble_util } // namespace bubble_util
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment