Fixed with CPTokenField: crash if added to a window in a unit test.

This commit is contained in:
Alexander Ljungberg
2011-11-16 12:50:05 +00:00
parent e7d9b0503b
commit 07966bb7fe
2 changed files with 17 additions and 4 deletions
+5 -3
View File
@@ -184,7 +184,8 @@ var CPThemeStateAutoCompleting = @"CPThemeStateAutoCompleting",
token = [self _inputElement].value;
// Make sure the user typed an actual token to prevent the previous token from being emptied
// If the input area is empty, we want to fallback to the normal behavior, resigning first responder or select the next or previous key view
// If the input area is empty, we want to fallback to the normal behavior, resigning first
// responder or selecting the next or previous key view.
if (!token || token === @"")
{
if (DOMEvent && DOMEvent.keyCode === CPTabKeyCode)
@@ -199,7 +200,6 @@ var CPThemeStateAutoCompleting = @"CPThemeStateAutoCompleting",
return;
}
var objectValue = [self objectValue];
// Remove the uncompleted token and add the token string.
@@ -608,14 +608,16 @@ var CPThemeStateAutoCompleting = @"CPThemeStateAutoCompleting",
{
}
// ========
// = VIEW =
// ========
- (void)viewDidMoveToWindow
{
[[[self window] contentView] addSubview:_autocompleteContainer];
#if PLATFORM(DOM)
_autocompleteContainer._DOMElement.style.zIndex = 1000; // Anything else doesn't seem to work
#endif
}
- (void)removeFromSuperview
+12 -1
View File
@@ -1,5 +1,7 @@
@import <AppKit/CPTokenField.j>
[CPApplication sharedApplication];
@implementation CPTokenFieldTest : OJTestCase
{
}
@@ -17,4 +19,13 @@
[self assert:[unarchived tokenizingCharacterSet] equals:[CPCharacterSet characterSetWithCharactersInString:@","]];
}
@end
- (void)testCreate
{
var aWindow = [[CPWindow alloc] initWithContentRect:CGRectMake(0.0, 0.0, 1024.0, 768.0) styleMask:CPWindowNotSizable],
tokenField = [[CPTokenField alloc] initWithFrame:CGRectMake(10, 10, 100, 28)];
// This shouldn't crash.
[[aWindow contentView] addSubview:tokenField];
}
@end