From fb696efd169db17e8169d0d0cfd1caf0728c0722 Mon Sep 17 00:00:00 2001 From: "gtm.daemon" Date: Fri, 18 Mar 2011 21:00:21 +0000 Subject: [Author: sail] Currently GTMFadeTruncatingTextFieldCell only supports truncating the tail of a string. It should also allow the head of a string to be truncated. I'd like to use this in Chromium. See http://crbug.com/69304 R=thomasvl APPROVED=thomasvl DELTA=238 (197 added, 17 deleted, 24 changed) --- AppKit/GTMFadeTruncatingTextFieldCellTest.m | 36 ++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'AppKit/GTMFadeTruncatingTextFieldCellTest.m') diff --git a/AppKit/GTMFadeTruncatingTextFieldCellTest.m b/AppKit/GTMFadeTruncatingTextFieldCellTest.m index a42e22e..a1bf937 100644 --- a/AppKit/GTMFadeTruncatingTextFieldCellTest.m +++ b/AppKit/GTMFadeTruncatingTextFieldCellTest.m @@ -28,7 +28,7 @@ @implementation GTMFadeTruncatingTextFieldCellTest -- (void)testFadeCell { +- (void)testFadeCellRight { NSTextField *field = [[[NSTextField alloc] initWithFrame: NSMakeRect(0, 0, 100, 16)] autorelease]; [field setCell:[[[GTMFadeTruncatingTextFieldCell alloc] initTextCell:@""] @@ -38,6 +38,7 @@ GTMAssertObjectImageEqualToImageNamed(field, @"GTMFadeTruncatingTextFieldCellTest1", nil); + [field setStringValue:@"A short string"]; GTMAssertObjectImageEqualToImageNamed(field, @"GTMFadeTruncatingTextFieldCellTest2", @@ -60,6 +61,39 @@ nil); } +- (void)testFadeCellLeftAndRight { + NSTextField *field = [[[NSTextField alloc] initWithFrame: + NSMakeRect(0, 0, 100, 16)] autorelease]; + GTMFadeTruncatingTextFieldCell *cell = + [[[GTMFadeTruncatingTextFieldCell alloc] initTextCell:@""] autorelease]; + [cell setTruncateMode:GTMFadeTruncatingHeadAndTail]; + [cell setDesiredCharactersToTruncateFromHead:5]; + [field setCell:cell]; + + [field setStringValue:@"Fade on both left and right AAAA"]; + GTMAssertObjectImageEqualToImageNamed(field, + @"GTMFadeTruncatingTextFieldCellTest5", + nil); + + [field setStringValue:@"Fade on left only AA"]; + GTMAssertObjectImageEqualToImageNamed(field, + @"GTMFadeTruncatingTextFieldCellTest6", + nil); + + [field setStringValue:@"A short string"]; + GTMAssertObjectImageEqualToImageNamed(field, + @"GTMFadeTruncatingTextFieldCellTest2", + nil); + + // Test the case where the number of characters to truncate from head is not + // specified. This should cause the string to be drawn centered. + [cell setDesiredCharactersToTruncateFromHead:0]; + [field setStringValue:@"Fade on both left and right AAAA"]; + GTMAssertObjectImageEqualToImageNamed(field, + @"GTMFadeTruncatingTextFieldCellTest7", + nil); +} + @end #endif // MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 -- cgit v1.2.3