| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import <Cocoa/Cocoa.h> | 5 #import <Cocoa/Cocoa.h> |
| 6 | 6 |
| 7 #include "app/resource_bundle.h" | 7 #include "app/resource_bundle.h" |
| 8 #include "base/scoped_nsobject.h" | 8 #include "base/scoped_nsobject.h" |
| 9 #import "chrome/browser/cocoa/cocoa_test_helper.h" | 9 #import "chrome/browser/cocoa/cocoa_test_helper.h" |
| 10 #import "chrome/browser/cocoa/location_bar/autocomplete_text_field_cell.h" | 10 #import "chrome/browser/cocoa/location_bar/autocomplete_text_field_cell.h" |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 NSImage* image = [NSImage imageNamed:@"NSApplicationIcon"]; | 216 NSImage* image = [NSImage imageNamed:@"NSApplicationIcon"]; |
| 217 [cell setKeywordHintPrefix:@"Keyword " image:image suffix:@" hint" | 217 [cell setKeywordHintPrefix:@"Keyword " image:image suffix:@" hint" |
| 218 availableWidth:kWidth]; | 218 availableWidth:kWidth]; |
| 219 textFrame = [cell textFrameForFrame:bounds]; | 219 textFrame = [cell textFrameForFrame:bounds]; |
| 220 EXPECT_FALSE(NSIsEmptyRect(textFrame)); | 220 EXPECT_FALSE(NSIsEmptyRect(textFrame)); |
| 221 EXPECT_TRUE(NSContainsRect(bounds, textFrame)); | 221 EXPECT_TRUE(NSContainsRect(bounds, textFrame)); |
| 222 EXPECT_LT(NSMaxX(textFrame), NSMaxX(bounds)); | 222 EXPECT_LT(NSMaxX(textFrame), NSMaxX(bounds)); |
| 223 EXPECT_LT(NSMaxX(textFrame), searchHintMaxX); | 223 EXPECT_LT(NSMaxX(textFrame), searchHintMaxX); |
| 224 EXPECT_TRUE(NSContainsRect(cursorFrame, textFrame)); | 224 EXPECT_TRUE(NSContainsRect(cursorFrame, textFrame)); |
| 225 | 225 |
| 226 |
| 226 // Text frame should take everything over again on reset. | 227 // Text frame should take everything over again on reset. |
| 227 [cell clearHint]; | 228 [cell clearHint]; |
| 228 textFrame = [cell textFrameForFrame:bounds]; | 229 textFrame = [cell textFrameForFrame:bounds]; |
| 229 EXPECT_FALSE(NSIsEmptyRect(textFrame)); | 230 EXPECT_FALSE(NSIsEmptyRect(textFrame)); |
| 230 EXPECT_TRUE(NSContainsRect(bounds, textFrame)); | 231 EXPECT_TRUE(NSContainsRect(bounds, textFrame)); |
| 231 EXPECT_EQ(NSMinX(bounds), NSMinX(textFrame)); | 232 EXPECT_EQ(NSMinX(bounds), NSMinX(textFrame)); |
| 232 EXPECT_EQ(NSMaxX(bounds), NSMaxX(textFrame)); | 233 EXPECT_EQ(NSMaxX(bounds), NSMaxX(textFrame)); |
| 233 EXPECT_TRUE(NSContainsRect(cursorFrame, textFrame)); | 234 EXPECT_TRUE(NSContainsRect(cursorFrame, textFrame)); |
| 234 | 235 |
| 235 // Search hint text takes precedence over the hint icon; the text frame | 236 // Search hint text takes precedence over the hint icon; the text frame |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 | 275 |
| 275 NSImage* image = [NSImage imageNamed:@"NSApplicationIcon"]; | 276 NSImage* image = [NSImage imageNamed:@"NSApplicationIcon"]; |
| 276 [cell setKeywordHintPrefix:@"Keyword " image:image suffix:@" hint" | 277 [cell setKeywordHintPrefix:@"Keyword " image:image suffix:@" hint" |
| 277 availableWidth:kWidth]; | 278 availableWidth:kWidth]; |
| 278 textFrame = [cell textFrameForFrame:bounds]; | 279 textFrame = [cell textFrameForFrame:bounds]; |
| 279 drawingRect = [cell drawingRectForBounds:bounds]; | 280 drawingRect = [cell drawingRectForBounds:bounds]; |
| 280 EXPECT_FALSE(NSIsEmptyRect(drawingRect)); | 281 EXPECT_FALSE(NSIsEmptyRect(drawingRect)); |
| 281 EXPECT_TRUE(NSContainsRect(NSInsetRect(textFrame, 1, 1), drawingRect)); | 282 EXPECT_TRUE(NSContainsRect(NSInsetRect(textFrame, 1, 1), drawingRect)); |
| 282 | 283 |
| 283 [cell clearHint]; | 284 [cell clearHint]; |
| 285 |
| 284 textFrame = [cell textFrameForFrame:bounds]; | 286 textFrame = [cell textFrameForFrame:bounds]; |
| 285 drawingRect = [cell drawingRectForBounds:bounds]; | 287 drawingRect = [cell drawingRectForBounds:bounds]; |
| 286 EXPECT_FALSE(NSIsEmptyRect(drawingRect)); | 288 EXPECT_FALSE(NSIsEmptyRect(drawingRect)); |
| 287 EXPECT_TRUE(NSContainsRect(NSInsetRect(textFrame, 1, 1), drawingRect)); | 289 EXPECT_TRUE(NSContainsRect(NSInsetRect(textFrame, 1, 1), drawingRect)); |
| 288 EXPECT_TRUE(NSEqualRects(drawingRect, originalDrawingRect)); | 290 EXPECT_TRUE(NSEqualRects(drawingRect, originalDrawingRect)); |
| 289 | 291 |
| 290 mock_left_decoration_.SetVisible(true); | 292 mock_left_decoration_.SetVisible(true); |
| 291 textFrame = [cell textFrameForFrame:bounds]; | 293 textFrame = [cell textFrameForFrame:bounds]; |
| 292 drawingRect = [cell drawingRectForBounds:bounds]; | 294 drawingRect = [cell drawingRectForBounds:bounds]; |
| 293 EXPECT_FALSE(NSIsEmptyRect(drawingRect)); | 295 EXPECT_FALSE(NSIsEmptyRect(drawingRect)); |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 EXPECT_TRUE(NSContainsRect(bounds, iconRect1)); | 402 EXPECT_TRUE(NSContainsRect(bounds, iconRect1)); |
| 401 EXPECT_FALSE(NSIsEmptyRect(labelRect)); | 403 EXPECT_FALSE(NSIsEmptyRect(labelRect)); |
| 402 EXPECT_TRUE(NSContainsRect(bounds, labelRect)); | 404 EXPECT_TRUE(NSContainsRect(bounds, labelRect)); |
| 403 | 405 |
| 404 EXPECT_LE(NSMaxX(drawingRect), NSMinX(iconRect1)); | 406 EXPECT_LE(NSMaxX(drawingRect), NSMinX(iconRect1)); |
| 405 EXPECT_LE(NSMaxX(textFrame), NSMinX(iconRect1)); | 407 EXPECT_LE(NSMaxX(textFrame), NSMinX(iconRect1)); |
| 406 EXPECT_LE(NSMaxX(iconRect1), NSMinX(iconRect0)); | 408 EXPECT_LE(NSMaxX(iconRect1), NSMinX(iconRect0)); |
| 407 EXPECT_LE(NSMaxX(labelRect), NSMinX(iconRect0)); | 409 EXPECT_LE(NSMaxX(labelRect), NSMinX(iconRect0)); |
| 408 } | 410 } |
| 409 | 411 |
| 412 NSImage* image = [NSImage imageNamed:@"NSApplicationIcon"]; |
| 413 |
| 410 // Test that the cell drops the search hint if there is no room for | 414 // Test that the cell drops the search hint if there is no room for |
| 411 // it. | 415 // it. |
| 412 TEST_F(AutocompleteTextFieldCellTest, OmitsSearchHintIfNarrow) { | 416 TEST_F(AutocompleteTextFieldCellTest, OmitsSearchHintIfNarrow) { |
| 413 AutocompleteTextFieldCell* cell = | 417 AutocompleteTextFieldCell* cell = |
| 414 static_cast<AutocompleteTextFieldCell*>([view_ cell]); | 418 static_cast<AutocompleteTextFieldCell*>([view_ cell]); |
| 415 | 419 |
| 416 NSString* const kSearchHint = @"Type to search"; | 420 NSString* const kSearchHint = @"Type to search"; |
| 417 | 421 |
| 418 // Wide width chooses the full string. | 422 // Wide width chooses the full string. |
| 419 [cell setSearchHintString:kSearchHint availableWidth:kWidth]; | 423 [cell setSearchHintString:kSearchHint availableWidth:kWidth]; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 443 EXPECT_TRUE([[[cell hintString] string] hasPrefix:kHintPrefix]); | 447 EXPECT_TRUE([[[cell hintString] string] hasPrefix:kHintPrefix]); |
| 444 EXPECT_TRUE([[[cell hintString] string] hasSuffix:kHintSuffix]); | 448 EXPECT_TRUE([[[cell hintString] string] hasSuffix:kHintSuffix]); |
| 445 | 449 |
| 446 // Narrow width suppresses everything but the image. | 450 // Narrow width suppresses everything but the image. |
| 447 [cell setKeywordHintPrefix:kHintPrefix image:image suffix:kHintSuffix | 451 [cell setKeywordHintPrefix:kHintPrefix image:image suffix:kHintSuffix |
| 448 availableWidth:kNarrowWidth]; | 452 availableWidth:kNarrowWidth]; |
| 449 EXPECT_EQ([[cell hintString] length], 1U); | 453 EXPECT_EQ([[cell hintString] length], 1U); |
| 450 } | 454 } |
| 451 | 455 |
| 452 } // namespace | 456 } // namespace |
| OLD | NEW |