| Index: chrome/browser/cocoa/location_bar/autocomplete_text_field_cell_unittest.mm
|
| diff --git a/chrome/browser/cocoa/location_bar/autocomplete_text_field_cell_unittest.mm b/chrome/browser/cocoa/location_bar/autocomplete_text_field_cell_unittest.mm
|
| index 6dfa50bdae1d756783dfd7da7a9bd7befe952917..5c0286dee71521bdd74ebc3d5b18bd28df9e4a4f 100644
|
| --- a/chrome/browser/cocoa/location_bar/autocomplete_text_field_cell_unittest.mm
|
| +++ b/chrome/browser/cocoa/location_bar/autocomplete_text_field_cell_unittest.mm
|
| @@ -9,6 +9,7 @@
|
| #import "chrome/browser/cocoa/cocoa_test_helper.h"
|
| #import "chrome/browser/cocoa/location_bar/autocomplete_text_field_cell.h"
|
| #import "chrome/browser/cocoa/location_bar/ev_bubble_decoration.h"
|
| +#import "chrome/browser/cocoa/location_bar/keyword_hint_decoration.h"
|
| #import "chrome/browser/cocoa/location_bar/location_bar_decoration.h"
|
| #import "chrome/browser/cocoa/location_bar/location_icon_decoration.h"
|
| #import "chrome/browser/cocoa/location_bar/selected_keyword_decoration.h"
|
| @@ -33,12 +34,8 @@ const CGFloat kNarrowWidth(5.0);
|
| class MockDecoration : public LocationBarDecoration {
|
| public:
|
| virtual CGFloat GetWidthForSpace(CGFloat width) { return 20.0; }
|
| - virtual bool IsVisible() const { return visible_; }
|
| - void SetVisible(bool visible) { visible_ = visible; }
|
|
|
| MOCK_METHOD2(DrawInFrame, void(NSRect frame, NSView* control_view));
|
| -
|
| - bool visible_;
|
| };
|
|
|
| class AutocompleteTextFieldCellTest : public CocoaTest {
|
| @@ -92,14 +89,6 @@ TEST_F(AutocompleteTextFieldCellTest, FocusedDisplay) {
|
| AutocompleteTextFieldCell* cell =
|
| static_cast<AutocompleteTextFieldCell*>([view_ cell]);
|
|
|
| - [cell setSearchHintString:@"Type to search" availableWidth:kWidth];
|
| - [view_ display];
|
| -
|
| - NSImage* image = [NSImage imageNamed:@"NSApplicationIcon"];
|
| - [cell setKeywordHintPrefix:@"prefix" image:image suffix:@"suffix"
|
| - availableWidth:kWidth];
|
| - [view_ display];
|
| -
|
| // Load available decorations and try drawing. To make sure that
|
| // they are actually drawn, check that |GetWidthForSpace()| doesn't
|
| // indicate that they should be omitted.
|
| @@ -137,6 +126,13 @@ TEST_F(AutocompleteTextFieldCellTest, FocusedDisplay) {
|
| EXPECT_NE(star_decoration.GetWidthForSpace(kVeryWide),
|
| LocationBarDecoration::kOmittedWidth);
|
|
|
| + KeywordHintDecoration keyword_hint_decoration([view_ font]);
|
| + keyword_hint_decoration.SetVisible(true);
|
| + keyword_hint_decoration.SetKeyword(std::wstring(L"google"), false);
|
| + [cell addRightDecoration:&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);
|
| @@ -150,26 +146,6 @@ TEST_F(AutocompleteTextFieldCellTest, FocusedDisplay) {
|
| [cell clearDecorations];
|
| }
|
|
|
| -TEST_F(AutocompleteTextFieldCellTest, ClearKeywordAndHint) {
|
| - AutocompleteTextFieldCell* cell =
|
| - static_cast<AutocompleteTextFieldCell*>([view_ cell]);
|
| - EXPECT_FALSE([cell hintString]);
|
| -
|
| - // Check that the search hint can be cleared.
|
| - [cell setSearchHintString:@"Type to search" availableWidth:kWidth];
|
| - EXPECT_TRUE([cell hintString]);
|
| - [cell clearHint];
|
| - EXPECT_FALSE([cell hintString]);
|
| -
|
| - // Check that the keyword hint can be cleared.
|
| - NSImage* image = [NSImage imageNamed:@"NSApplicationIcon"];
|
| - [cell setKeywordHintPrefix:@"Press " image:image suffix:@" to search Engine"
|
| - availableWidth:kWidth];
|
| - EXPECT_TRUE([cell hintString]);
|
| - [cell clearHint];
|
| - EXPECT_FALSE([cell hintString]);
|
| -}
|
| -
|
| TEST_F(AutocompleteTextFieldCellTest, TextFrame) {
|
| AutocompleteTextFieldCell* cell =
|
| static_cast<AutocompleteTextFieldCell*>([view_ cell]);
|
| @@ -188,49 +164,6 @@ TEST_F(AutocompleteTextFieldCellTest, TextFrame) {
|
| EXPECT_EQ(NSMaxX(bounds), NSMaxX(textFrame));
|
| EXPECT_TRUE(NSContainsRect(cursorFrame, textFrame));
|
|
|
| - // Small search hint leaves text frame to left.
|
| - [cell setSearchHintString:@"Search hint" availableWidth:kWidth];
|
| - textFrame = [cell textFrameForFrame:bounds];
|
| - EXPECT_FALSE(NSIsEmptyRect(textFrame));
|
| - EXPECT_TRUE(NSContainsRect(bounds, textFrame));
|
| - EXPECT_LT(NSMaxX(textFrame), NSMaxX(bounds));
|
| - EXPECT_TRUE(NSContainsRect(cursorFrame, textFrame));
|
| -
|
| - // Save search-hint's frame for future reference.
|
| - const CGFloat searchHintMaxX(NSMaxX(textFrame));
|
| -
|
| - // Keyword hint also leaves text to left. Arrange for it to be
|
| - // larger than the search hint just to make sure that things have
|
| - // changed (keyword hint overrode search hint), and that they aren't
|
| - // handled identically w/out reference to the actual button cell.
|
| - NSImage* image = [NSImage imageNamed:@"NSApplicationIcon"];
|
| - [cell setKeywordHintPrefix:@"Keyword " image:image suffix:@" hint"
|
| - availableWidth:kWidth];
|
| - textFrame = [cell textFrameForFrame:bounds];
|
| - EXPECT_FALSE(NSIsEmptyRect(textFrame));
|
| - EXPECT_TRUE(NSContainsRect(bounds, textFrame));
|
| - EXPECT_LT(NSMaxX(textFrame), NSMaxX(bounds));
|
| - EXPECT_LT(NSMaxX(textFrame), searchHintMaxX);
|
| - EXPECT_TRUE(NSContainsRect(cursorFrame, textFrame));
|
| -
|
| -
|
| - // Text frame should take everything over again on reset.
|
| - [cell clearHint];
|
| - textFrame = [cell textFrameForFrame:bounds];
|
| - EXPECT_FALSE(NSIsEmptyRect(textFrame));
|
| - EXPECT_TRUE(NSContainsRect(bounds, textFrame));
|
| - EXPECT_EQ(NSMinX(bounds), NSMinX(textFrame));
|
| - EXPECT_EQ(NSMaxX(bounds), NSMaxX(textFrame));
|
| - EXPECT_TRUE(NSContainsRect(cursorFrame, textFrame));
|
| -
|
| - // Search hint text takes precedence over the hint icon; the text frame
|
| - // should be smaller in order to accomodate the text that is wider than
|
| - // the icon.
|
| - [cell setSearchHintString:@"Search hint" availableWidth:kWidth];
|
| - NSRect textFrameWithHintText = [cell textFrameForFrame:bounds];
|
| - EXPECT_TRUE(NSContainsRect(textFrame, textFrameWithHintText));
|
| - EXPECT_LT(NSWidth(textFrameWithHintText), NSWidth(textFrame));
|
| -
|
| // Decoration on the left takes up space.
|
| mock_left_decoration_.SetVisible(true);
|
| textFrame = [cell textFrameForFrame:bounds];
|
| @@ -253,43 +186,25 @@ TEST_F(AutocompleteTextFieldCellTest, DrawingRectForBounds) {
|
| EXPECT_TRUE(NSContainsRect(textFrame, NSInsetRect(drawingRect, 1, 1)));
|
|
|
| // Save the starting frame for after clear.
|
| - const NSRect originalDrawingRect(drawingRect);
|
| -
|
| - // TODO(shess): Do we really need to test every combination?
|
| + const NSRect originalDrawingRect = drawingRect;
|
|
|
| - [cell setSearchHintString:@"Search hint" availableWidth:kWidth];
|
| - textFrame = [cell textFrameForFrame:bounds];
|
| - drawingRect = [cell drawingRectForBounds:bounds];
|
| - EXPECT_FALSE(NSIsEmptyRect(drawingRect));
|
| - EXPECT_TRUE(NSContainsRect(textFrame, NSInsetRect(drawingRect, 1, 1)));
|
| -
|
| - NSImage* image = [NSImage imageNamed:@"NSApplicationIcon"];
|
| - [cell setKeywordHintPrefix:@"Keyword " image:image suffix:@" hint"
|
| - availableWidth:kWidth];
|
| + mock_left_decoration_.SetVisible(true);
|
| textFrame = [cell textFrameForFrame:bounds];
|
| drawingRect = [cell drawingRectForBounds:bounds];
|
| EXPECT_FALSE(NSIsEmptyRect(drawingRect));
|
| EXPECT_TRUE(NSContainsRect(NSInsetRect(textFrame, 1, 1), drawingRect));
|
|
|
| - [cell clearHint];
|
| -
|
| + mock_right_decoration0_.SetVisible(true);
|
| textFrame = [cell textFrameForFrame:bounds];
|
| drawingRect = [cell drawingRectForBounds:bounds];
|
| EXPECT_FALSE(NSIsEmptyRect(drawingRect));
|
| EXPECT_TRUE(NSContainsRect(NSInsetRect(textFrame, 1, 1), drawingRect));
|
| - EXPECT_TRUE(NSEqualRects(drawingRect, originalDrawingRect));
|
|
|
| - mock_left_decoration_.SetVisible(true);
|
| - textFrame = [cell textFrameForFrame:bounds];
|
| + mock_left_decoration_.SetVisible(false);
|
| + mock_right_decoration0_.SetVisible(false);
|
| drawingRect = [cell drawingRectForBounds:bounds];
|
| EXPECT_FALSE(NSIsEmptyRect(drawingRect));
|
| - EXPECT_TRUE(NSContainsRect(NSInsetRect(textFrame, 1, 1), drawingRect));
|
| -
|
| - mock_right_decoration0_.SetVisible(true);
|
| - textFrame = [cell textFrameForFrame:bounds];
|
| - drawingRect = [cell drawingRectForBounds:bounds];
|
| - EXPECT_FALSE(NSIsEmptyRect(drawingRect));
|
| - EXPECT_TRUE(NSContainsRect(NSInsetRect(textFrame, 1, 1), drawingRect));
|
| + EXPECT_TRUE(NSEqualRects(drawingRect, originalDrawingRect));
|
| }
|
|
|
| // Test that left decorations are at the correct edge of the cell.
|
| @@ -344,48 +259,4 @@ TEST_F(AutocompleteTextFieldCellTest, RightDecorationFrame) {
|
| EXPECT_LT(NSMinX(textFrame), NSMinX(decoration1Rect));
|
| }
|
|
|
| - NSImage* image = [NSImage imageNamed:@"NSApplicationIcon"];
|
| -
|
| -// Test that the cell drops the search hint if there is no room for
|
| -// it.
|
| -TEST_F(AutocompleteTextFieldCellTest, OmitsSearchHintIfNarrow) {
|
| - AutocompleteTextFieldCell* cell =
|
| - static_cast<AutocompleteTextFieldCell*>([view_ cell]);
|
| -
|
| - NSString* const kSearchHint = @"Type to search";
|
| -
|
| - // Wide width chooses the full string.
|
| - [cell setSearchHintString:kSearchHint availableWidth:kWidth];
|
| - EXPECT_TRUE([cell hintString]);
|
| - EXPECT_TRUE([[[cell hintString] string] isEqualToString:kSearchHint]);
|
| -
|
| - // Narrow width suppresses entirely.
|
| - [cell setSearchHintString:kSearchHint availableWidth:kNarrowWidth];
|
| - EXPECT_FALSE([cell hintString]);
|
| -}
|
| -
|
| -// Test that the cell drops all but the image if there is no room for
|
| -// the entire keyword hint.
|
| -TEST_F(AutocompleteTextFieldCellTest, TrimsKeywordHintIfNarrow) {
|
| - AutocompleteTextFieldCell* cell =
|
| - static_cast<AutocompleteTextFieldCell*>([view_ cell]);
|
| - scoped_nsobject<NSImage> image(
|
| - [[NSImage alloc] initWithSize:NSMakeSize(20, 20)]);
|
| -
|
| - NSString* const kHintPrefix = @"Press ";
|
| - NSString* const kHintSuffix = @" to search Engine";
|
| -
|
| - // Wide width chooses the full string.
|
| - [cell setKeywordHintPrefix:kHintPrefix image:image suffix:kHintSuffix
|
| - availableWidth:kWidth];
|
| - EXPECT_TRUE([cell hintString]);
|
| - EXPECT_TRUE([[[cell hintString] string] hasPrefix:kHintPrefix]);
|
| - EXPECT_TRUE([[[cell hintString] string] hasSuffix:kHintSuffix]);
|
| -
|
| - // Narrow width suppresses everything but the image.
|
| - [cell setKeywordHintPrefix:kHintPrefix image:image suffix:kHintSuffix
|
| - availableWidth:kNarrowWidth];
|
| - EXPECT_EQ([[cell hintString] length], 1U);
|
| -}
|
| -
|
| } // namespace
|
|
|