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/autocomplete_text_field_cell.h" | 9 #import "chrome/browser/cocoa/autocomplete_text_field_cell.h" |
10 #import "chrome/browser/cocoa/cocoa_test_helper.h" | 10 #import "chrome/browser/cocoa/cocoa_test_helper.h" |
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 EXPECT_LE(NSMaxX(iconRect1), NSMinX(iconRect0)); | 428 EXPECT_LE(NSMaxX(iconRect1), NSMinX(iconRect0)); |
429 EXPECT_LE(NSMaxX(labelRect), NSMinX(iconRect0)); | 429 EXPECT_LE(NSMaxX(labelRect), NSMinX(iconRect0)); |
430 } | 430 } |
431 | 431 |
432 // Test that the cell correctly chooses the partial keyword if there's | 432 // Test that the cell correctly chooses the partial keyword if there's |
433 // not enough room. | 433 // not enough room. |
434 TEST_F(AutocompleteTextFieldCellTest, UsesPartialKeywordIfNarrow) { | 434 TEST_F(AutocompleteTextFieldCellTest, UsesPartialKeywordIfNarrow) { |
435 AutocompleteTextFieldCell* cell = | 435 AutocompleteTextFieldCell* cell = |
436 static_cast<AutocompleteTextFieldCell*>([view_ cell]); | 436 static_cast<AutocompleteTextFieldCell*>([view_ cell]); |
437 | 437 |
438 const NSString* kFullString = @"Search Engine:"; | 438 NSString* const kFullString = @"Search Engine:"; |
439 const NSString* kPartialString = @"Search Eng:"; | 439 NSString* const kPartialString = @"Search Eng:"; |
440 | 440 |
441 // Wide width chooses the full string, including an image on the | 441 // Wide width chooses the full string, including an image on the |
442 // left. | 442 // left. |
443 [cell setKeywordString:kFullString | 443 [cell setKeywordString:kFullString |
444 partialString:kPartialString | 444 partialString:kPartialString |
445 availableWidth:kWidth]; | 445 availableWidth:kWidth]; |
446 EXPECT_TRUE([cell keywordString]); | 446 EXPECT_TRUE([cell keywordString]); |
447 EXPECT_TRUE([[[cell keywordString] string] hasSuffix:kFullString]); | 447 EXPECT_TRUE([[[cell keywordString] string] hasSuffix:kFullString]); |
448 EXPECT_TRUE([[cell keywordString] containsAttachments]); | 448 EXPECT_TRUE([[cell keywordString] containsAttachments]); |
449 | 449 |
(...skipping 20 matching lines...) Expand all Loading... |
470 EXPECT_TRUE([cell keywordString]); | 470 EXPECT_TRUE([cell keywordString]); |
471 EXPECT_TRUE([[[cell keywordString] string] isEqualToString:kFullString]); | 471 EXPECT_TRUE([[[cell keywordString] string] isEqualToString:kFullString]); |
472 } | 472 } |
473 | 473 |
474 // Test that the cell drops the search hint if there is no room for | 474 // Test that the cell drops the search hint if there is no room for |
475 // it. | 475 // it. |
476 TEST_F(AutocompleteTextFieldCellTest, OmitsSearchHintIfNarrow) { | 476 TEST_F(AutocompleteTextFieldCellTest, OmitsSearchHintIfNarrow) { |
477 AutocompleteTextFieldCell* cell = | 477 AutocompleteTextFieldCell* cell = |
478 static_cast<AutocompleteTextFieldCell*>([view_ cell]); | 478 static_cast<AutocompleteTextFieldCell*>([view_ cell]); |
479 | 479 |
480 const NSString* kSearchHint = @"Type to search"; | 480 NSString* const kSearchHint = @"Type to search"; |
481 | 481 |
482 // Wide width chooses the full string. | 482 // Wide width chooses the full string. |
483 [cell setSearchHintString:kSearchHint availableWidth:kWidth]; | 483 [cell setSearchHintString:kSearchHint availableWidth:kWidth]; |
484 EXPECT_TRUE([cell hintString]); | 484 EXPECT_TRUE([cell hintString]); |
485 EXPECT_TRUE([[[cell hintString] string] isEqualToString:kSearchHint]); | 485 EXPECT_TRUE([[[cell hintString] string] isEqualToString:kSearchHint]); |
486 | 486 |
487 // Narrow width suppresses entirely. | 487 // Narrow width suppresses entirely. |
488 [cell setSearchHintString:kSearchHint availableWidth:kNarrowWidth]; | 488 [cell setSearchHintString:kSearchHint availableWidth:kNarrowWidth]; |
489 EXPECT_FALSE([cell hintString]); | 489 EXPECT_FALSE([cell hintString]); |
490 } | 490 } |
491 | 491 |
492 // Test that the cell drops all but the image if there is no room for | 492 // Test that the cell drops all but the image if there is no room for |
493 // the entire keyword hint. | 493 // the entire keyword hint. |
494 TEST_F(AutocompleteTextFieldCellTest, TrimsKeywordHintIfNarrow) { | 494 TEST_F(AutocompleteTextFieldCellTest, TrimsKeywordHintIfNarrow) { |
495 AutocompleteTextFieldCell* cell = | 495 AutocompleteTextFieldCell* cell = |
496 static_cast<AutocompleteTextFieldCell*>([view_ cell]); | 496 static_cast<AutocompleteTextFieldCell*>([view_ cell]); |
497 scoped_nsobject<NSImage> image( | 497 scoped_nsobject<NSImage> image( |
498 [[NSImage alloc] initWithSize:NSMakeSize(20, 20)]); | 498 [[NSImage alloc] initWithSize:NSMakeSize(20, 20)]); |
499 | 499 |
500 const NSString* kHintPrefix = @"Press "; | 500 NSString* const kHintPrefix = @"Press "; |
501 const NSString* kHintSuffix = @" to search Engine"; | 501 NSString* const kHintSuffix = @" to search Engine"; |
502 | 502 |
503 // Wide width chooses the full string. | 503 // Wide width chooses the full string. |
504 [cell setKeywordHintPrefix:kHintPrefix image:image suffix:kHintSuffix | 504 [cell setKeywordHintPrefix:kHintPrefix image:image suffix:kHintSuffix |
505 availableWidth:kWidth]; | 505 availableWidth:kWidth]; |
506 EXPECT_TRUE([cell hintString]); | 506 EXPECT_TRUE([cell hintString]); |
507 EXPECT_TRUE([[[cell hintString] string] hasPrefix:kHintPrefix]); | 507 EXPECT_TRUE([[[cell hintString] string] hasPrefix:kHintPrefix]); |
508 EXPECT_TRUE([[[cell hintString] string] hasSuffix:kHintSuffix]); | 508 EXPECT_TRUE([[[cell hintString] string] hasSuffix:kHintSuffix]); |
509 | 509 |
510 // Narrow width suppresses everything but the image. | 510 // Narrow width suppresses everything but the image. |
511 [cell setKeywordHintPrefix:kHintPrefix image:image suffix:kHintSuffix | 511 [cell setKeywordHintPrefix:kHintPrefix image:image suffix:kHintSuffix |
512 availableWidth:kNarrowWidth]; | 512 availableWidth:kNarrowWidth]; |
513 EXPECT_EQ([[cell hintString] length], 1U); | 513 EXPECT_EQ([[cell hintString] length], 1U); |
514 } | 514 } |
515 | 515 |
516 } // namespace | 516 } // namespace |
OLD | NEW |