| 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 fc06bc412d9b1754feb9b238236e7915303ec859..84c3e9bde0261f3f5849fb155693ab2d639d13f4 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
|
| @@ -14,6 +14,7 @@
|
| #import "chrome/browser/ui/cocoa/location_bar/location_bar_decoration.h"
|
| #import "chrome/browser/ui/cocoa/location_bar/location_icon_decoration.h"
|
| #import "chrome/browser/ui/cocoa/location_bar/selected_keyword_decoration.h"
|
| +#import "chrome/browser/ui/cocoa/location_bar/separator_decoration.h"
|
| #import "chrome/browser/ui/cocoa/location_bar/star_decoration.h"
|
| #include "grit/theme_resources.h"
|
| #include "testing/gmock/include/gmock/gmock.h"
|
| @@ -38,10 +39,22 @@ const CGFloat kNarrowWidth(5.0);
|
|
|
| class MockDecoration : public LocationBarDecoration {
|
| public:
|
| + MockDecoration() : LocationBarDecoration(),
|
| + should_auto_collapse_(false) {
|
| + }
|
| +
|
| virtual CGFloat GetWidthForSpace(CGFloat width) { return 20.0; }
|
| + virtual bool ShouldAutoCollapse() const OVERRIDE {
|
| + return should_auto_collapse_;
|
| + }
|
| +
|
| + void set_should_auto_collapse(bool value) { should_auto_collapse_ = value; }
|
|
|
| MOCK_METHOD2(DrawInFrame, void(NSRect frame, NSView* control_view));
|
| MOCK_METHOD0(GetToolTip, NSString*());
|
| +
|
| + private:
|
| + bool should_auto_collapse_;
|
| };
|
|
|
| class AutocompleteTextFieldCellTest : public CocoaTest {
|
| @@ -299,4 +312,62 @@ TEST_F(AutocompleteTextFieldCellTest, UpdateToolTips) {
|
| EXPECT_OCMOCK_VERIFY(controlView);
|
| }
|
|
|
| +TEST_F(AutocompleteTextFieldCellTest, HideUnneededSeparators) {
|
| + AutocompleteTextFieldCell* cell =
|
| + static_cast<AutocompleteTextFieldCell*>([view_ cell]);
|
| + const NSRect bounds = [view_ bounds];
|
| +
|
| + SeparatorDecoration separator;
|
| + [cell clearDecorations];
|
| + [cell addRightDecoration:&mock_right_decoration0_];
|
| + [cell addRightDecoration:&separator];
|
| + [cell addRightDecoration:&mock_right_decoration1_];
|
| + separator.SetVisible(true);
|
| +
|
| + // Verify that a separator between two decorations is visible.
|
| + mock_right_decoration0_.SetVisible(true);
|
| + mock_right_decoration1_.SetVisible(true);
|
| + NSRect rect = [cell frameForDecoration:&separator inFrame:bounds];
|
| + EXPECT_LT(0, NSWidth(rect));
|
| +
|
| + // Verify that a separator with no visible decorations on the right is hidden.
|
| + mock_right_decoration0_.SetVisible(false);
|
| + mock_right_decoration1_.SetVisible(true);
|
| + rect = [cell frameForDecoration:&separator inFrame:bounds];
|
| + EXPECT_EQ(0, NSWidth(rect));
|
| +
|
| + // Verify that a separator with no visible decorations on the left is hidden.
|
| + mock_right_decoration0_.SetVisible(true);
|
| + mock_right_decoration1_.SetVisible(false);
|
| + rect = [cell frameForDecoration:&separator inFrame:bounds];
|
| + EXPECT_EQ(0, NSWidth(rect));
|
| +}
|
| +
|
| +TEST_F(AutocompleteTextFieldCellTest, AutoCollapse) {
|
| + AutocompleteTextFieldCell* cell =
|
| + static_cast<AutocompleteTextFieldCell*>([view_ cell]);
|
| + const NSRect bounds = [view_ bounds];
|
| + // Force the string to overlap decorations.
|
| + [cell setStringValue:@"WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW"];
|
| +
|
| + // Verify that the decoration is visible without auto collapse.
|
| + mock_right_decoration0_.SetVisible(true);
|
| + mock_right_decoration0_.set_should_auto_collapse(false);
|
| + NSRect rect = [cell frameForDecoration:&mock_right_decoration0_
|
| + inFrame:bounds];
|
| + EXPECT_LT(0, NSWidth(rect));
|
| +
|
| + // Verify that the decoration is hidden with auto collapse.
|
| + mock_right_decoration0_.set_should_auto_collapse(true);
|
| + rect = [cell frameForDecoration:&mock_right_decoration0_
|
| + inFrame:bounds];
|
| + EXPECT_EQ(0, NSWidth(rect));
|
| +
|
| + // Verify that the decoration is visible with auto collapse and short string.
|
| + [cell setStringValue:@"WWW"];
|
| + rect = [cell frameForDecoration:&mock_right_decoration0_
|
| + inFrame:bounds];
|
| + EXPECT_LT(0, NSWidth(rect));
|
| +}
|
| +
|
| } // namespace
|
|
|