| Index: chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell_unittest.mm
|
| diff --git a/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell_unittest.mm b/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell_unittest.mm
|
| index e59794e17e40916d469d7f220e492a56cd8cce2c..b913e67f235114dac3332e15bd3245c233270d71 100644
|
| --- a/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell_unittest.mm
|
| +++ b/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell_unittest.mm
|
| @@ -15,6 +15,7 @@
|
| #import "chrome/browser/ui/cocoa/location_bar/selected_keyword_decoration.h"
|
| #import "chrome/browser/ui/cocoa/location_bar/star_decoration.h"
|
| #import "chrome/browser/ui/cocoa/test/cocoa_test_helper.h"
|
| +#import "chrome/browser/ui/cocoa/test/scoped_force_rtl_mac.h"
|
| #include "testing/gmock/include/gmock/gmock.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| #import "testing/gtest_mac.h"
|
| @@ -58,12 +59,12 @@ class AutocompleteTextFieldCellTest : public CocoaTest {
|
| [cell setBordered:YES];
|
|
|
| [cell clearDecorations];
|
| - mock_left_decoration_.SetVisible(false);
|
| - [cell addLeftDecoration:&mock_left_decoration_];
|
| - mock_right_decoration0_.SetVisible(false);
|
| - mock_right_decoration1_.SetVisible(false);
|
| - [cell addRightDecoration:&mock_right_decoration0_];
|
| - [cell addRightDecoration:&mock_right_decoration1_];
|
| + mock_leading_decoration_.SetVisible(false);
|
| + [cell addLeadingDecoration:&mock_leading_decoration_];
|
| + mock_trailing_decoration0_.SetVisible(false);
|
| + mock_trailing_decoration1_.SetVisible(false);
|
| + [cell addTrailingDecoration:&mock_trailing_decoration0_];
|
| + [cell addTrailingDecoration:&mock_trailing_decoration1_];
|
|
|
| [view_ setCell:cell.get()];
|
|
|
| @@ -71,9 +72,9 @@ class AutocompleteTextFieldCellTest : public CocoaTest {
|
| }
|
|
|
| NSTextField* view_;
|
| - MockDecoration mock_left_decoration_;
|
| - MockDecoration mock_right_decoration0_;
|
| - MockDecoration mock_right_decoration1_;
|
| + MockDecoration mock_leading_decoration_;
|
| + MockDecoration mock_trailing_decoration0_;
|
| + MockDecoration mock_trailing_decoration1_;
|
| };
|
|
|
| // Basic view tests (AddRemove, Display).
|
| @@ -101,7 +102,7 @@ TEST_F(AutocompleteTextFieldCellTest, DISABLED_FocusedDisplay) {
|
| SelectedKeywordDecoration selected_keyword_decoration;
|
| selected_keyword_decoration.SetVisible(true);
|
| selected_keyword_decoration.SetKeyword(base::ASCIIToUTF16("Google"), false);
|
| - [cell addLeftDecoration:&selected_keyword_decoration];
|
| + [cell addLeadingDecoration:&selected_keyword_decoration];
|
| EXPECT_NE(selected_keyword_decoration.GetWidthForSpace(kVeryWide),
|
| LocationBarDecoration::kOmittedWidth);
|
|
|
| @@ -111,7 +112,7 @@ TEST_F(AutocompleteTextFieldCellTest, DISABLED_FocusedDisplay) {
|
| LocationIconDecoration location_icon_decoration(NULL);
|
| location_icon_decoration.SetVisible(true);
|
| location_icon_decoration.SetImage([NSImage imageNamed:@"NSApplicationIcon"]);
|
| - [cell addLeftDecoration:&location_icon_decoration];
|
| + [cell addLeadingDecoration:&location_icon_decoration];
|
| EXPECT_NE(location_icon_decoration.GetWidthForSpace(kVeryWide),
|
| LocationBarDecoration::kOmittedWidth);
|
|
|
| @@ -121,27 +122,27 @@ TEST_F(AutocompleteTextFieldCellTest, DISABLED_FocusedDisplay) {
|
| security_state_bubble_decoration.SetImage(
|
| [NSImage imageNamed:@"NSApplicationIcon"]);
|
| security_state_bubble_decoration.SetLabel(@"Application");
|
| - [cell addLeftDecoration:&security_state_bubble_decoration];
|
| + [cell addLeadingDecoration:&security_state_bubble_decoration];
|
| EXPECT_NE(security_state_bubble_decoration.GetWidthForSpace(kVeryWide),
|
| LocationBarDecoration::kOmittedWidth);
|
|
|
| StarDecoration star_decoration(NULL);
|
| star_decoration.SetVisible(true);
|
| - [cell addRightDecoration:&star_decoration];
|
| + [cell addTrailingDecoration:&star_decoration];
|
| EXPECT_NE(star_decoration.GetWidthForSpace(kVeryWide),
|
| LocationBarDecoration::kOmittedWidth);
|
|
|
| KeywordHintDecoration keyword_hint_decoration;
|
| keyword_hint_decoration.SetVisible(true);
|
| keyword_hint_decoration.SetKeyword(base::ASCIIToUTF16("google"), false);
|
| - [cell addRightDecoration:&keyword_hint_decoration];
|
| + [cell addTrailingDecoration:&keyword_hint_decoration];
|
| EXPECT_NE(keyword_hint_decoration.GetWidthForSpace(kVeryWide),
|
| LocationBarDecoration::kOmittedWidth);
|
|
|
| // Make sure we're actually calling |DrawInFrame()|.
|
| StrictMock<MockDecoration> mock_decoration;
|
| mock_decoration.SetVisible(true);
|
| - [cell addLeftDecoration:&mock_decoration];
|
| + [cell addLeadingDecoration:&mock_decoration];
|
| EXPECT_CALL(mock_decoration, DrawInFrame(_, _));
|
| EXPECT_NE(mock_decoration.GetWidthForSpace(kVeryWide),
|
| LocationBarDecoration::kOmittedWidth);
|
| @@ -169,8 +170,8 @@ TEST_F(AutocompleteTextFieldCellTest, TextFrame) {
|
| EXPECT_EQ(NSMaxX(bounds), NSMaxX(textFrame));
|
| EXPECT_TRUE(NSContainsRect(cursorFrame, textFrame));
|
|
|
| - // Decoration on the left takes up space.
|
| - mock_left_decoration_.SetVisible(true);
|
| + // Leading decoration takes up space.
|
| + mock_leading_decoration_.SetVisible(true);
|
| textFrame = [cell textFrameForFrame:bounds];
|
| EXPECT_FALSE(NSIsEmptyRect(textFrame));
|
| EXPECT_TRUE(NSContainsRect(bounds, textFrame));
|
| @@ -193,34 +194,34 @@ TEST_F(AutocompleteTextFieldCellTest, DrawingRectForBounds) {
|
| // Save the starting frame for after clear.
|
| const NSRect originalDrawingRect = drawingRect;
|
|
|
| - mock_left_decoration_.SetVisible(true);
|
| + mock_leading_decoration_.SetVisible(true);
|
| textFrame = [cell textFrameForFrame:bounds];
|
| drawingRect = [cell drawingRectForBounds:bounds];
|
| EXPECT_FALSE(NSIsEmptyRect(drawingRect));
|
| EXPECT_TRUE(NSContainsRect(NSInsetRect(textFrame, 1, 1), drawingRect));
|
|
|
| - mock_right_decoration0_.SetVisible(true);
|
| + mock_trailing_decoration0_.SetVisible(true);
|
| textFrame = [cell textFrameForFrame:bounds];
|
| drawingRect = [cell drawingRectForBounds:bounds];
|
| EXPECT_FALSE(NSIsEmptyRect(drawingRect));
|
| EXPECT_TRUE(NSContainsRect(NSInsetRect(textFrame, 1, 1), drawingRect));
|
|
|
| - mock_left_decoration_.SetVisible(false);
|
| - mock_right_decoration0_.SetVisible(false);
|
| + mock_leading_decoration_.SetVisible(false);
|
| + mock_trailing_decoration0_.SetVisible(false);
|
| drawingRect = [cell drawingRectForBounds:bounds];
|
| EXPECT_FALSE(NSIsEmptyRect(drawingRect));
|
| EXPECT_NSEQ(drawingRect, originalDrawingRect);
|
| }
|
|
|
| -// Test that left decorations are at the correct edge of the cell.
|
| -TEST_F(AutocompleteTextFieldCellTest, LeftDecorationFrame) {
|
| +// Test that leading decorations are at the correct edge of the cell.
|
| +TEST_F(AutocompleteTextFieldCellTest, LeadingDecorationFrame) {
|
| AutocompleteTextFieldCell* cell =
|
| static_cast<AutocompleteTextFieldCell*>([view_ cell]);
|
| const NSRect bounds = [view_ bounds];
|
|
|
| - mock_left_decoration_.SetVisible(true);
|
| + mock_leading_decoration_.SetVisible(true);
|
| const NSRect decorationRect =
|
| - [cell frameForDecoration:&mock_left_decoration_ inFrame:bounds];
|
| + [cell frameForDecoration:&mock_leading_decoration_ inFrame:bounds];
|
| EXPECT_FALSE(NSIsEmptyRect(decorationRect));
|
| EXPECT_TRUE(NSContainsRect(bounds, decorationRect));
|
|
|
| @@ -233,24 +234,24 @@ TEST_F(AutocompleteTextFieldCellTest, LeftDecorationFrame) {
|
| EXPECT_GT(NSMinX(textFrame), NSMinX(decorationRect));
|
| }
|
|
|
| -// Test that right decorations are at the correct edge of the cell.
|
| -TEST_F(AutocompleteTextFieldCellTest, RightDecorationFrame) {
|
| +// Test that trailing decorations are at the correct edge of the cell.
|
| +TEST_F(AutocompleteTextFieldCellTest, TrailingDecorationFrame) {
|
| AutocompleteTextFieldCell* cell =
|
| static_cast<AutocompleteTextFieldCell*>([view_ cell]);
|
| const NSRect bounds = [view_ bounds];
|
|
|
| - mock_right_decoration0_.SetVisible(true);
|
| - mock_right_decoration1_.SetVisible(true);
|
| + mock_trailing_decoration0_.SetVisible(true);
|
| + mock_trailing_decoration1_.SetVisible(true);
|
|
|
| const NSRect decoration0Rect =
|
| - [cell frameForDecoration:&mock_right_decoration0_ inFrame:bounds];
|
| + [cell frameForDecoration:&mock_trailing_decoration0_ inFrame:bounds];
|
| EXPECT_FALSE(NSIsEmptyRect(decoration0Rect));
|
| EXPECT_TRUE(NSContainsRect(bounds, decoration0Rect));
|
|
|
| - // Right-side decorations are ordered from rightmost to leftmost.
|
| + // Trailing decorations are ordered from innermost to outermost.
|
| // Outer decoration (0) to right of inner decoration (1).
|
| const NSRect decoration1Rect =
|
| - [cell frameForDecoration:&mock_right_decoration1_ inFrame:bounds];
|
| + [cell frameForDecoration:&mock_trailing_decoration1_ inFrame:bounds];
|
| EXPECT_FALSE(NSIsEmptyRect(decoration1Rect));
|
| EXPECT_TRUE(NSContainsRect(bounds, decoration1Rect));
|
| EXPECT_LT(NSMinX(decoration1Rect), NSMinX(decoration0Rect));
|
| @@ -269,33 +270,89 @@ TEST_F(AutocompleteTextFieldCellTest, RightDecorationFrame) {
|
| TEST_F(AutocompleteTextFieldCellTest, UpdateToolTips) {
|
| NSString* tooltip = @"tooltip";
|
|
|
| - // Left decoration returns a tooltip, make sure it is called at
|
| + // Leading decoration returns a tooltip, make sure it is called at
|
| // least once.
|
| - mock_left_decoration_.SetVisible(true);
|
| - EXPECT_CALL(mock_left_decoration_, GetToolTip())
|
| + mock_leading_decoration_.SetVisible(true);
|
| + EXPECT_CALL(mock_leading_decoration_, GetToolTip())
|
| .WillOnce(Return(tooltip))
|
| .WillRepeatedly(Return(tooltip));
|
|
|
| // Right decoration returns no tooltip, make sure it is called at
|
| // least once.
|
| - mock_right_decoration0_.SetVisible(true);
|
| - EXPECT_CALL(mock_right_decoration0_, GetToolTip())
|
| + mock_trailing_decoration0_.SetVisible(true);
|
| + EXPECT_CALL(mock_trailing_decoration0_, GetToolTip())
|
| .WillOnce(Return((NSString*)nil))
|
| .WillRepeatedly(Return((NSString*)nil));
|
|
|
| AutocompleteTextFieldCell* cell =
|
| static_cast<AutocompleteTextFieldCell*>([view_ cell]);
|
| const NSRect bounds = [view_ bounds];
|
| - const NSRect leftDecorationRect =
|
| - [cell frameForDecoration:&mock_left_decoration_ inFrame:bounds];
|
| + const NSRect leadingDecorationRect =
|
| + [cell frameForDecoration:&mock_leading_decoration_ inFrame:bounds];
|
|
|
| - // |controlView| gets the tooltip for the left decoration.
|
| + // |controlView| gets the tooltip for the leading decoration.
|
| id controlView = [OCMockObject mockForClass:[AutocompleteTextField class]];
|
| - [[controlView expect] addToolTip:tooltip forRect:leftDecorationRect];
|
| + [[controlView expect] addToolTip:tooltip forRect:leadingDecorationRect];
|
|
|
| [cell updateMouseTrackingAndToolTipsInRect:bounds ofView:controlView];
|
|
|
| EXPECT_OCMOCK_VERIFY(controlView);
|
| }
|
|
|
| +class AutocompleteTextFieldCellTestRTL : public AutocompleteTextFieldCellTest {
|
| + private:
|
| + cocoa_l10n_util::ScopedForceRTLMac rtl_;
|
| +};
|
| +
|
| +// Test that leading decorations are at the correct edge of the cell.
|
| +TEST_F(AutocompleteTextFieldCellTestRTL, LeadingDecorationFrame) {
|
| + AutocompleteTextFieldCell* cell =
|
| + static_cast<AutocompleteTextFieldCell*>([view_ cell]);
|
| + const NSRect bounds = [view_ bounds];
|
| +
|
| + mock_leading_decoration_.SetVisible(true);
|
| + const NSRect decorationRect =
|
| + [cell frameForDecoration:&mock_leading_decoration_ inFrame:bounds];
|
| + EXPECT_FALSE(NSIsEmptyRect(decorationRect));
|
| + EXPECT_TRUE(NSContainsRect(bounds, decorationRect));
|
| + // Decoration should be right of |drawingRect|.
|
| + const NSRect drawingRect = [cell drawingRectForBounds:bounds];
|
| + EXPECT_LT(NSMinX(drawingRect), NSMinX(decorationRect));
|
| +
|
| + // Decoration should be right of |textFrame|.
|
| + const NSRect textFrame = [cell textFrameForFrame:bounds];
|
| + EXPECT_LT(NSMinX(textFrame), NSMinX(decorationRect));
|
| +}
|
| +
|
| +// Test that trailing decorations are at the correct edge of the cell.
|
| +TEST_F(AutocompleteTextFieldCellTestRTL, TrailingDecorationFrame) {
|
| + AutocompleteTextFieldCell* cell =
|
| + static_cast<AutocompleteTextFieldCell*>([view_ cell]);
|
| + const NSRect bounds = [view_ bounds];
|
| +
|
| + mock_trailing_decoration0_.SetVisible(true);
|
| + mock_trailing_decoration1_.SetVisible(true);
|
| +
|
| + const NSRect decoration0Rect =
|
| + [cell frameForDecoration:&mock_trailing_decoration0_ inFrame:bounds];
|
| + EXPECT_FALSE(NSIsEmptyRect(decoration0Rect));
|
| + EXPECT_TRUE(NSContainsRect(bounds, decoration0Rect));
|
| +
|
| + // Trailing decorations are ordered from front to back..
|
| + // Outer decoration (0) to the left of inner decoration (1).
|
| + const NSRect decoration1Rect =
|
| + [cell frameForDecoration:&mock_trailing_decoration1_ inFrame:bounds];
|
| + EXPECT_FALSE(NSIsEmptyRect(decoration1Rect));
|
| + EXPECT_TRUE(NSContainsRect(bounds, decoration1Rect));
|
| + EXPECT_GT(NSMinX(decoration1Rect), NSMinX(decoration0Rect));
|
| +
|
| + // Decoration should be left of |drawingRect|.
|
| + const NSRect drawingRect = [cell drawingRectForBounds:bounds];
|
| + EXPECT_GT(NSMinX(drawingRect), NSMinX(decoration1Rect));
|
| +
|
| + // Decoration should be left of |textFrame|.
|
| + const NSRect textFrame = [cell textFrameForFrame:bounds];
|
| + EXPECT_GT(NSMinX(textFrame), NSMinX(decoration1Rect));
|
| +}
|
| +
|
| } // namespace
|
|
|