Files
cappuccino/Tests/AppKit/DropInCompatibilityTest.j
T
David Richardson d55a620223 AppKit: Move platform window decoration from application state into theme variants
Remove incomplete host-platform OS behaviour API and its platform-specific conditionals. Derive window buttons, title, and title bar layout from window view's own theme, and select platform variants through a private function.

* CPApplication.j: Remove setOSBehavior:, OSBehavior, shouldMimicWindows and the simulatesWindows accessors, with the Info.plist keys and user default they read; set the default theme through _CPThemeVariant.

* CPApplication_Constants.j: Remove the OS behaviour constants, dictionary and notification.

* CPCompatibility.j: Add _CPBrowserOperatingSystem, returning the detected host operating system.

* CPTheme.j: Remove CPThemeStateWindowsPlatform; add _CPThemeVariant, returning the base theme.

* CPWindow.j: Remove the _close call to the window view.

* _CPStandardWindowView.j:
  - Remove the OS behaviour observer, _close and _osBehaviorDidChange:.
  - Place the buttons and title from theme values on every layout, with fixed defaults where a theme supplies none.
  - Read title bar and sheet values from the window view's theme instead of the default theme.

* _CPTitleableWindowView.j: Read title-margin at layout time instead of caching it.
2026-11-08 13:51:36 -06:00

102 lines
3.6 KiB
Plaintext

/*
* DropInCompatibilityTest.j
* AppKit
*
* Created by David Richardson on 31/10/2026.
* Copyright David Richardson 2026.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@import <AppKit/AppKit.j>
function DropInWindowButton(aStyleMask, aName)
{
var aWindow = [[CPWindow alloc] initWithContentRect:CGRectMake(0.0, 0.0, 400.0, 400.0) styleMask:aStyleMask],
windowView = [aWindow _windowView];
return windowView[aName];
}
/*
Defaults that existing applications rely on. An application that updates its
frameworks must keep these without any change of its own.
*/
@implementation DropInCompatibilityTest : OJTestCase
- (void)setUp
{
// This will init the global var CPApp which are used internally in the AppKit
[[CPApplication alloc] init];
}
- (void)testDefaultThemeNameIsAristo2WithoutInfoPlistKey
{
[self assertNull:[[CPBundle mainBundle] objectForInfoDictionaryKey:@"CPDefaultTheme"]];
[self assert:@"Aristo2" equals:[CPApplication defaultThemeName]];
}
/*
Window buttons follow Apple's guidelines under every theme, as a deliberate change
to the drop-in contract: a standard titled window shows close, minimize and zoom,
and enables each only when its style mask allows it. Until 2026-11, a window showed
only the buttons its style mask allowed.
*/
- (void)testStandardTitledWindowShowsCloseMinimizeAndZoom
{
[CPTitledWindowMask,
CPTitledWindowMask | CPClosableWindowMask,
CPTitledWindowMask | CPClosableWindowMask | CPResizableWindowMask,
CPTitledWindowMask | CPClosableWindowMask | CPMiniaturizableWindowMask | CPResizableWindowMask].forEach(function(aStyleMask)
{
[@"_closeButton", @"_minimizeButton", @"_zoomButton"].forEach(function(aName)
{
[self assertNotNull:DropInWindowButton(aStyleMask, aName) message:aName + ", style mask " + aStyleMask];
});
});
}
- (void)testCloseButtonIsEnabledOnlyForAClosableWindow
{
[self assertTrue:[DropInWindowButton(CPTitledWindowMask | CPClosableWindowMask, @"_closeButton") isEnabled]];
[self assertFalse:[DropInWindowButton(CPTitledWindowMask, @"_closeButton") isEnabled]];
}
- (void)testMinimizeButtonIsNeverEnabled
{
[self assertFalse:[DropInWindowButton(CPTitledWindowMask | CPClosableWindowMask | CPMiniaturizableWindowMask, @"_minimizeButton") isEnabled]];
}
- (void)testPopUpButtonKeepsTheDefaultButtonBezelStyle
{
var frame = CGRectMake(0.0, 0.0, 100.0, 24.0),
popUpButton = [[CPPopUpButton alloc] initWithFrame:frame pullsDown:NO],
button = [[CPButton alloc] initWithFrame:frame];
[self assert:[button bezelStyle] equals:[popUpButton bezelStyle]];
}
- (void)testTableViewGridColorHasAClassDefault
{
[self assertFalse:[[[CPTableView themeAttributes] objectForKey:@"grid-color"] isEqual:[CPNull null]]];
}
- (void)testTableViewAlternatingRowColorsHaveAClassDefault
{
[self assertFalse:[[[CPTableView themeAttributes] objectForKey:@"alternating-row-colors"] isEqual:[CPNull null]]];
}
@end