diff options
author | gtm.daemon <gtm.daemon@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3> | 2010-11-08 21:39:10 +0000 |
---|---|---|
committer | gtm.daemon <gtm.daemon@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3> | 2010-11-08 21:39:10 +0000 |
commit | 144526b58bb1d6866f8c427a63036c31f8e1d8a9 (patch) | |
tree | b98665ac3f36bd957783bb36741905ea3aaab0cf /AppKit/GTMWindowSheetControllerTest.m | |
parent | 2e0d716e8fe85d33f1b68e2830d2f33c79dd8289 (diff) |
[Author: avi]
Allow adding a new sheet in a sheet's closing callback in GTMWindowSheetController. GTMWindowSheetController does not completely remove a sheet until after the callback has been invoked. This causes an assert to trigger if another sheet is launched in the callback, which is inconsistent with normal Cocoa sheets. Switch the order of the two operations and add a unit test. This affects http://crbug.com/56948 . Patch by davidben@chromium.org .
R=dmaclach
DELTA=112 (106 added, 5 deleted, 1 changed)
Diffstat (limited to 'AppKit/GTMWindowSheetControllerTest.m')
-rw-r--r-- | AppKit/GTMWindowSheetControllerTest.m | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/AppKit/GTMWindowSheetControllerTest.m b/AppKit/GTMWindowSheetControllerTest.m index b2cb7b2..65ef084 100644 --- a/AppKit/GTMWindowSheetControllerTest.m +++ b/AppKit/GTMWindowSheetControllerTest.m @@ -25,12 +25,16 @@ NSTabViewDelegate> { @private GTMWindowSheetController *sheetController_; + NSWindow* window_; BOOL didAlertClose_; BOOL didSheetClose_; } - (void)alertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode context:(void *)context; +- (void)openSecondSheet:(NSAlert *)alert + returnCode:(NSInteger)returnCode + context:(void *)context; - (void)sheetDidEnd:(NSWindow *)sheet returnCode:(NSInteger)returnCode context:(void *)context; @@ -172,12 +176,105 @@ STAssertTrue(didSheetClose_, @"Sheet should have closed"); } +- (void)testOpenSheetAfterFirst { + // Set up window + window_ = + [[[NSWindow alloc] initWithContentRect:NSMakeRect(100, 100, 600, 600) + styleMask:NSTitledWindowMask + backing:NSBackingStoreBuffered + defer:NO] autorelease]; + STAssertNotNil(window_, @"Could not allocate window"); + + sheetController_ = + [[[GTMWindowSheetController alloc] initWithWindow:window_ + delegate:self] autorelease]; + + STAssertFalse([sheetController_ isSheetAttachedToView: + [window_ contentView]], + @"Sheet should not be attached to current view"); + STAssertEquals([[sheetController_ viewsWithAttachedSheets] count], + (NSUInteger)0, + @"Should have no views with sheets"); + + // Pop alert on first tab + NSAlert* alert = [[NSAlert alloc] init]; + + [alert setMessageText:@"Hell Has Broken Loose."]; + [alert setInformativeText:@"All hell has broken loose. You may want to run " + @"outside screaming and waving your arms around " + @"wildly."]; + + NSButton *alertButton = [alert addButtonWithTitle:@"OK"]; + + // Allocate a second sheet to be launched by the alert + NSPanel *sheet = + [[[NSPanel alloc] initWithContentRect:NSMakeRect(0, 0, 300, 200) + styleMask:NSTitledWindowMask + backing:NSBackingStoreBuffered + defer:NO] autorelease]; + + [sheetController_ beginSystemSheet:alert + modalForView:[window_ contentView] + withParameters:[NSArray arrayWithObjects: + [NSNull null], + self, + [NSValue valueWithPointer: + @selector(openSecondSheet:returnCode:context:)], + [NSValue valueWithPointer:sheet], + nil]]; + didAlertClose_ = NO; + didSheetClose_ = NO; + + STAssertTrue([sheetController_ isSheetAttachedToView: + [window_ contentView]], + @"Sheet should be attached to view"); + STAssertEquals([[sheetController_ viewsWithAttachedSheets] count], + (NSUInteger)1, + @"Should have one view with sheets"); + + // Close alert + [alertButton performClick:self]; + + STAssertTrue([sheetController_ isSheetAttachedToView: + [window_ contentView]], + @"Second sheet should be attached to view"); + STAssertEquals([[sheetController_ viewsWithAttachedSheets] count], + (NSUInteger)1, + @"Should have one view with sheets"); + STAssertTrue(didAlertClose_, @"Alert should have closed"); + + // Close sheet + [[NSApplication sharedApplication] endSheet:sheet returnCode:NSOKButton]; + + STAssertFalse([sheetController_ isSheetAttachedToView: + [window_ contentView]], + @"Sheet should not be attached to current view"); + STAssertEquals([[sheetController_ viewsWithAttachedSheets] count], + (NSUInteger)0, + @"Should have no views with sheets"); + STAssertTrue(didSheetClose_, @"Sheet should have closed"); +} + - (void)alertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode context:(void *)context { didAlertClose_ = YES; } +- (void)openSecondSheet:(NSAlert *)alert + returnCode:(NSInteger)returnCode + context:(void *)context { + didAlertClose_ = YES; + + NSPanel* sheet = context; + // Pop a second sheet + [sheetController_ beginSheet:sheet + modalForView:[window_ contentView] + modalDelegate:self + didEndSelector:@selector(sheetDidEnd:returnCode:context:) + contextInfo:nil]; +} + - (void)sheetDidEnd:(NSWindow *)sheet returnCode:(NSInteger)returnCode context:(void *)context { |