Files
cappuccino/Tests/AppKit/CPScrollViewTest.j
David Richardson 1d0944c2bc CPScrollView: Show full border on bordered scroll views in Aristo3
Previously, Aristo3's 1px CSS border on scroll views was occluded on
the top and left edges by zero insets, switching to CPNoBorder left
stale border styling because CPNoBorder did not set a background, and
-setBorderType: requested only a redraw rather than a layout pass for
CSS-themed rendering.

Line and bezel insets are now 1px on all sides, every border type sets
its background (with Aristo3 returning no background for CPNoBorder),
and -setBorderType: now triggers a layout update.
2026-11-25 10:14:55 -06:00

597 lines
25 KiB
Plaintext

@import <AppKit/AppKit.j>
@import "CPNotificationCenterHelper.j"
@import "BuiltThemes.j"
@implementation CPScrollViewTest : OJTestCase
{
CPScrollerStyle globalScrollerStyle;
CPTheme previousTheme;
}
- (void)setUp
{
// This will init the global var CPApp which are used internally in the AppKit
[[CPApplication alloc] init];
globalScrollerStyle = [CPScrollView globalScrollerStyle];
previousTheme = [CPTheme defaultTheme];
}
/*
The global scroller style applies to every scroll view, including those in later
test suites, so a test that changes it must not leave it changed.
*/
- (void)tearDown
{
[CPScrollView setGlobalScrollerStyle:globalScrollerStyle];
[CPTheme setDefaultTheme:previousTheme];
}
/*!
Test that scroll views don't generate bad layouts when very small.
*/
- (void)testZeroSize
{
var scrollView = [[CPScrollView alloc] initWithFrame:CGRectMakeZero()],
documentView = [[CPView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
[scrollView setAutohidesScrollers:NO];
[scrollView setDocumentView:documentView];
[scrollView setScrollerStyle:CPScrollerStyleLegacy];
// If the layout operation leads to setKnobProportion:0/0 this will crash.
[[scrollView horizontalScroller] layoutSubviews];
[[scrollView verticalScroller] layoutSubviews];
}
- (void)testMagnification
{
var scrollView = [[CPScrollView alloc] initWithFrame:CGRectMake(0.0, 0.0, 300.0, 200.0)],
documentView = [[CPView alloc] initWithFrame:CGRectMake(0.0, 0.0, 300.0, 600.0)];
[documentView setAutoresizingMask:CPViewWidthSizable];
[scrollView setDocumentView:documentView];
[self assert:1.0 equals:[scrollView magnification]];
[scrollView setMagnification:2.0];
[self assert:2.0 equals:[scrollView magnification]];
[self assert:CGRectGetWidth([[scrollView contentView] bounds]) equals:CGRectGetWidth([documentView frame]) message:@"a document view that resizes its width takes the clip view's bounds width"];
[scrollView setMagnification:0.5];
[self assert:0.5 equals:[scrollView magnification]];
[scrollView setMagnification:10.0];
[self assert:[scrollView maxMagnification] equals:[scrollView magnification] message:@"the magnification is limited to the maximum"];
[scrollView setMagnification:1.0];
[self assert:1.0 equals:[scrollView magnification]];
[self assert:CGRectGetWidth([[scrollView contentView] frame]) equals:CGRectGetWidth([[scrollView contentView] bounds])];
}
- (void)testMagnificationArchiving
{
var scrollView = [[CPScrollView alloc] initWithFrame:CGRectMake(0.0, 0.0, 300.0, 200.0)];
[scrollView setAllowsMagnification:YES];
[scrollView setMinMagnification:0.5];
[scrollView setMaxMagnification:3.0];
var decoded = [CPKeyedUnarchiver unarchiveObjectWithData:[CPKeyedArchiver archivedDataWithRootObject:scrollView]];
[self assertTrue:[decoded allowsMagnification]];
[self assert:0.5 equals:[decoded minMagnification]];
[self assert:3.0 equals:[decoded maxMagnification]];
}
- (void)testMagnificationDecodingWithoutValidLimits
{
var scrollView = [[CPScrollView alloc] initWithFrame:CGRectMake(0.0, 0.0, 300.0, 200.0)];
// An archive made from a scroll view whose limits were never set, as nib2cib made before it
// set them, holds values that are not numbers.
scrollView._minMagnification = undefined;
scrollView._maxMagnification = undefined;
var decoded = [CPKeyedUnarchiver unarchiveObjectWithData:[CPKeyedArchiver archivedDataWithRootObject:scrollView]];
[self assert:0.25 equals:[decoded minMagnification]];
[self assert:4.0 equals:[decoded maxMagnification]];
[decoded setMagnification:0.5];
[self assert:0.5 equals:[decoded magnification]];
}
- (void)testBothScrollersVisible
{
var scrollView = [[CPScrollView alloc] initWithFrame:CGRectMake(0.0, 0.0, 100.0, 100.0)];
[scrollView setAutohidesScrollers:NO];
[scrollView setHasHorizontalScroller:YES];
[scrollView setHasVerticalScroller:YES];
var documentView = [[CPView alloc] init];
[scrollView setDocumentView:documentView];
// Test document view size smaller than scroll view size.
[documentView setFrameSize:CGSizeMake(50.0, 50.0)];
[self assert:[[scrollView horizontalScroller] isHidden] equals:NO];
[self assert:[[scrollView horizontalScroller] isEnabled] equals:NO];
[self assert:[[scrollView verticalScroller] isHidden] equals:NO];
[self assert:[[scrollView verticalScroller] isEnabled] equals:NO];
// Test document view size much larger than scroll view size.
[documentView setFrameSize:CGSizeMake(1000.0, 1000.0)];
[self assert:[[scrollView horizontalScroller] isHidden] equals:NO];
[self assert:[[scrollView horizontalScroller] isEnabled] equals:YES];
[self assert:[[scrollView verticalScroller] isHidden] equals:NO];
[self assert:[[scrollView verticalScroller] isEnabled] equals:YES];
// Test document view size much taller than scroll view size.
[documentView setFrameSize:CGSizeMake(50.0, 1000.0)];
[self assert:[[scrollView horizontalScroller] isHidden] equals:NO];
[self assert:[[scrollView horizontalScroller] isEnabled] equals:NO];
[self assert:[[scrollView verticalScroller] isHidden] equals:NO];
[self assert:[[scrollView verticalScroller] isEnabled] equals:YES];
// Test document view size much wider than scroll view size.
[documentView setFrameSize:CGSizeMake(1000.0, 50.0)];
[self assert:[[scrollView horizontalScroller] isHidden] equals:NO];
[self assert:[[scrollView horizontalScroller] isEnabled] equals:YES];
[self assert:[[scrollView verticalScroller] isHidden] equals:NO];
[self assert:[[scrollView verticalScroller] isEnabled] equals:NO];
// Test document view size equal to scroll view size.
[documentView setFrameSize:CGSizeMake(100.0, 100.0)];
[self assert:[[scrollView horizontalScroller] isHidden] equals:NO];
[self assert:[[scrollView horizontalScroller] isEnabled] equals:YES];
[self assert:[[scrollView verticalScroller] isHidden] equals:NO];
[self assert:[[scrollView verticalScroller] isEnabled] equals:YES];
// Test document view size taller than scroll view size only because of scrollers.
[documentView setFrameSize:CGSizeMake(50.0, 100.0)];
[self assert:[[scrollView horizontalScroller] isHidden] equals:NO];
[self assert:[[scrollView horizontalScroller] isEnabled] equals:NO];
[self assert:[[scrollView verticalScroller] isHidden] equals:NO];
[self assert:[[scrollView verticalScroller] isEnabled] equals:YES];
// Test document view size wider than scroll view size only because of scrollers.
[documentView setFrameSize:CGSizeMake(100.0, 50.0)];
[self assert:[[scrollView horizontalScroller] isHidden] equals:NO];
[self assert:[[scrollView horizontalScroller] isEnabled] equals:YES];
[self assert:[[scrollView verticalScroller] isHidden] equals:NO];
[self assert:[[scrollView verticalScroller] isEnabled] equals:NO];
// Test document view size exactly the right size relative to the scroll view size.
[documentView setFrameSize:CGSizeMake(100.0 - 17.0, 100.0 - 17.0)];
[self assert:[[scrollView horizontalScroller] isHidden] equals:NO];
[self assert:[[scrollView horizontalScroller] isEnabled] equals:NO];
[self assert:[[scrollView verticalScroller] isHidden] equals:NO];
[self assert:[[scrollView verticalScroller] isEnabled] equals:NO];
}
- (void)testAutoHidesScrollers
{
var scrollView = [[CPScrollView alloc] initWithFrame:CGRectMake(0.0, 0.0, 100.0, 100.0)];
[scrollView setAutohidesScrollers:YES];
[scrollView setHasHorizontalScroller:YES];
[scrollView setHasVerticalScroller:YES];
var documentView = [[CPView alloc] init];
[scrollView setDocumentView:documentView];
// Test document view size smaller than scroll view size.
[documentView setFrameSize:CGSizeMake(50.0, 50.0)];
[self assert:[[scrollView horizontalScroller] isHidden] equals:YES];
[self assert:[[scrollView horizontalScroller] isEnabled] equals:NO];
[self assert:[[scrollView verticalScroller] isHidden] equals:YES];
[self assert:[[scrollView verticalScroller] isEnabled] equals:NO];
// Test document view size much larger than scroll view size.
[documentView setFrameSize:CGSizeMake(1000.0, 1000.0)];
[self assert:[[scrollView horizontalScroller] isHidden] equals:NO];
[self assert:[[scrollView horizontalScroller] isEnabled] equals:YES];
[self assert:[[scrollView verticalScroller] isHidden] equals:NO];
[self assert:[[scrollView verticalScroller] isEnabled] equals:YES];
// Test document view size much taller than scroll view size.
[documentView setFrameSize:CGSizeMake(50.0, 1000.0)];
[self assert:[[scrollView horizontalScroller] isHidden] equals:YES];
[self assert:[[scrollView horizontalScroller] isEnabled] equals:NO];
[self assert:[[scrollView verticalScroller] isHidden] equals:NO];
[self assert:[[scrollView verticalScroller] isEnabled] equals:YES];
// Test document view size much wider than scroll view size.
[documentView setFrameSize:CGSizeMake(1000.0, 50.0)];
[self assert:[[scrollView horizontalScroller] isHidden] equals:NO];
[self assert:[[scrollView horizontalScroller] isEnabled] equals:YES];
[self assert:[[scrollView verticalScroller] isHidden] equals:YES];
[self assert:[[scrollView verticalScroller] isEnabled] equals:NO];
// Test document view size equal to scroll view size.
[documentView setFrameSize:CGSizeMake(100.0, 100.0)];
[self assert:[[scrollView horizontalScroller] isHidden] equals:YES];
[self assert:[[scrollView horizontalScroller] isEnabled] equals:NO];
[self assert:[[scrollView verticalScroller] isHidden] equals:YES];
[self assert:[[scrollView verticalScroller] isEnabled] equals:NO];
// Test document view size taller than scroll view size only because of scrollers.
[documentView setFrameSize:CGSizeMake(50.0, 100.0)];
[self assert:[[scrollView horizontalScroller] isHidden] equals:YES];
[self assert:[[scrollView horizontalScroller] isEnabled] equals:NO];
[self assert:[[scrollView verticalScroller] isHidden] equals:YES];
[self assert:[[scrollView verticalScroller] isEnabled] equals:NO];
// Test document view size wider than scroll view size only because of scrollers.
[documentView setFrameSize:CGSizeMake(100.0, 50.0)];
[self assert:[[scrollView horizontalScroller] isHidden] equals:YES];
[self assert:[[scrollView horizontalScroller] isEnabled] equals:NO];
[self assert:[[scrollView verticalScroller] isHidden] equals:YES];
[self assert:[[scrollView verticalScroller] isEnabled] equals:NO];
// Test document view size exactly the right size relative to the scroll view size.
[documentView setFrameSize:CGSizeMake(100.0 - 17.0, 100.0 - 17.0)];
[self assert:[[scrollView horizontalScroller] isHidden] equals:YES];
[self assert:[[scrollView horizontalScroller] isEnabled] equals:NO];
[self assert:[[scrollView verticalScroller] isHidden] equals:YES];
[self assert:[[scrollView verticalScroller] isEnabled] equals:NO];
}
- (void)testSetContentView
{
var scrollView = [[CPScrollView alloc] initWithFrame:CGRectMake(0.0, 0.0, 100.0, 100.0)],
documentView = [[CPView alloc] initWithFrame:CGRectMake(0.0, 0.0, 400.0, 400.0)],
replacementContentView = [[CPClipView alloc] initWithFrame:[scrollView _insetBounds]],
replacementDocumentView = [[CPView alloc] initWithFrame:CGRectMake(0.0, 0.0, 400.0, 400.0)];
[replacementContentView setDocumentView:replacementDocumentView];
// Test the obvious condition that they aren't the same
[self assert:replacementContentView notEqual:[scrollView contentView] message:@"contentView somehow equals the replacement"];
// Test the obvious condition that the document view can be get/set
[scrollView setDocumentView:documentView];
[self assert:documentView equals:[scrollView documentView] message:@"documentView is not set as expected"];
// Change the content view
[scrollView setContentView:replacementContentView];
// Test that the content view has been replaced
[self assert:replacementContentView equals:[scrollView contentView] message:@"contentView was not replaced properly"];
// and that the document view has been replaced
[self assert:replacementDocumentView equals:[scrollView documentView] message:@"documentView was not replaced properly"];
}
- (void)testScrollRectToVisible
{
var scrollView = [[CPScrollView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)],
documentView = [[CPView alloc] initWithFrame:CGRectMake(0, 0, 1000, 1000)],
textField1 = [CPTextField textFieldWithStringValue:@"Martin" placeholder:@"" width:10],
textField2 = [CPTextField textFieldWithStringValue:@"Malte" placeholder:@"" width:10],
textField2Size = CGSizeMakeCopy([textField2 bounds].size);
[scrollView setDocumentView:documentView];
[textField1 setFrameOrigin:CGPointMake(10, 10)];
[textField2 setFrameOrigin:CGPointMake(500, 500)];
[documentView addSubview:textField1];
[documentView addSubview:textField2];
var visibleRect = [documentView visibleRect],
originalVisibleSize = CGSizeMakeCopy(visibleRect.size);
// Make sure we are at the top left corner
[self assertPoint:CGPointMake(0, 0) equals:visibleRect.origin message:@"VisibleRect origin not at top left corner"];
// Make the second text field visible
var hasScrolled = [textField2 scrollRectToVisible:[textField2 bounds]];
[self assertTrue:hasScrolled];
var visibleRectOriginShouldBeAt = CGPointMake(500 - originalVisibleSize.width + textField2Size.width, 500 - originalVisibleSize.height + textField2Size.height);
visibleRect = [documentView visibleRect];
// We should now have the text field in the lower right corner
[self assertPoint:visibleRectOriginShouldBeAt equals:visibleRect.origin message:@"Second text field not at lower right corner in visible rect"];
// Make the first text field visible again
hasScrolled = [textField1 scrollRectToVisible:[textField1 bounds]];
[self assertTrue:hasScrolled];
visibleRect = [documentView visibleRect];
// We should now be back at top left corner
[self assertPoint:CGPointMake(10, 10) equals:visibleRect.origin message:@"VisibleRect origin not at top left corner again"];
// Try to scroll again and it should not scroll
hasScrolled = [textField1 scrollRectToVisible:[textField1 bounds]];
[self assertFalse:hasScrolled];
}
- (void)testScrollRectToVisibleWithLargeRect
{
var scrollView = [[CPScrollView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)],
documentView = [[CPView alloc] initWithFrame:CGRectMake(0, 0, 1000, 1000)],
view1 = [[CPView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)],
view2 = [[CPView alloc] initWithFrame:CGRectMake(500, 500, 200, 200)];
[scrollView setDocumentView:documentView];
[view1 setFrameOrigin:CGPointMake(0, 0)];
[view2 setFrameOrigin:CGPointMake(500, 500)];
[documentView addSubview:view1];
[documentView addSubview:view2];
var visibleRect = [documentView visibleRect];
// Make sure we are at the top left corner
[self assertPoint:CGPointMake(0, 0) equals:visibleRect.origin message:@"VisibleRect origin not at top left corner"];
// Make the second view visible
var hasScrolled = [view2 scrollRectToVisible:[view2 bounds]];
[self assertTrue:hasScrolled];
visibleRect = [documentView visibleRect];
// We should now have the origin of view2 in the upper left corner
[self assertPoint:CGPointMake(500, 500) equals:visibleRect.origin message:@"Origin of second view not at upper left corner in visible rect"];
// Make the first view visible again
hasScrolled = [view1 scrollRectToVisible:[view1 bounds]];
[self assertTrue:hasScrolled];
visibleRect = [documentView visibleRect];
var visibleRectOriginShouldBeAt = CGPointMake(200 - visibleRect.size.width, 200 - visibleRect.size.height);
// We should now be back almost at top left corner except that the lower right corner of the rect should be at the lower right corner of the visible rect.
[self assertPoint:visibleRectOriginShouldBeAt equals:visibleRect.origin message:@"VisibleRect origin not at top left corner again"];
// Try to scroll again and it should not scroll even as some parts are outside the visible rect
hasScrolled = [view1 scrollRectToVisible:[view1 bounds]];
[self assertFalse:hasScrolled];
}
- (void)testDocumentVisibleRect
{
var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMake(0.0, 0.0, 1024.0, 768.0)
styleMask:CPWindowNotSizable],
windowView = [theWindow contentView],
aScrollView = [[CPScrollView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)],
aDocumentView = [[CPView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
[CPScrollView setGlobalScrollerStyle:CPScrollerStyleOverlay];
[aScrollView setDocumentView:aDocumentView];
[windowView addSubview:aScrollView];
[self assertRect:CGRectMake(0, 0, 100, 100) equals:[aScrollView documentVisibleRect] message:@"documentVisibleRect is wrong in CPScrollView"];
[aDocumentView setScaleSize:CGSizeMake(0.5, 0.5)];
[self assertRect:CGRectMake(0, 0, 200, 200) equals:[aScrollView documentVisibleRect] message:@"documentVisibleRect is wrong in CPScrollView after scaling"];
[aDocumentView setScaleSize:CGSizeMake(1, 1)];
[aDocumentView scrollRectToVisible:CGRectMake(120, 120, 20, 20)];
[self assertRect:CGRectMake(40, 40, 100, 100) equals:[aScrollView documentVisibleRect] message:@"documentVisibleRect is wrong in CPScrollView"];
[aDocumentView setScaleSize:CGSizeMake(0.5, 0.5)];
[self assertRect:CGRectMake(80, 80, 200, 200) equals:[aScrollView documentVisibleRect] message:@"documentVisibleRect is wrong in CPScrollView"];
}
- (void)testSetGlobalScrollerStyle
{
// In this test, we set global scroller style to legacy, we create a scroll view, change global scroller style to overlay BEFORE placing the
// scroll view in the view hierarchy, then we insert the scroll view in the view hierarchy and it should then have overlay as scroller style.
[CPScrollView setGlobalScrollerStyle:CPScrollerStyleLegacy];
var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMake(0.0, 0.0, 1024.0, 768.0)
styleMask:CPWindowNotSizable],
windowView = [theWindow contentView],
aScrollView = [[CPScrollView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)],
aDocumentView = [[CPView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
[CPScrollView setGlobalScrollerStyle:CPScrollerStyleOverlay];
[aScrollView setDocumentView:aDocumentView];
[windowView addSubview:aScrollView];
[self assert:CPScrollerStyleOverlay equals:[aScrollView scrollerStyle] message:@"Global scroller style was not applied to this CPScrollView"];
// In this test, we have global scroller style set to overlay. We create a scroll view, set the scroller style to legacy BEFORE placing the
// scroll view in the view hierarchy, then insert it. It should have legacy as scroller style.
var anotherScrollView = [[CPScrollView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)],
anotherDocumentView = [[CPView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
[anotherScrollView setScrollerStyle:CPScrollerStyleLegacy];
[anotherScrollView setDocumentView:anotherDocumentView];
[windowView addSubview:anotherScrollView];
[self assert:CPScrollerStyleLegacy equals:[anotherScrollView scrollerStyle] message:@"Specific scroller style was overrided by global scroller style"];
}
- (void)assertPoint:(CGPoint)expected equals:(CGPoint)actual message:(CPString)message
{
[self assert:expected.x equals:actual.x message:@"X: " + message];
[self assert:expected.y equals:actual.y message:@"Y: " + message];
}
- (void)assertSize:(CGSize)expected equals:(CGSize)actual message:(CPString)message
{
[self assert:expected.width equals:actual.width message:@"Width: " + message];
[self assert:expected.height equals:actual.height message:@"Height: " + message];
}
- (void)assertRect:(CGRect)expected equals:(CGRect)actual message:(CPString)message
{
[self assertPoint:expected.origin equals:actual.origin message:message]
[self assertSize:expected.size equals:actual.size message:message]
}
- (void)testFrameSizeForContentSizeUsesScrollerStyleForBothScrollers
{
var frameSize = [CPScrollView frameSizeForContentSize:CGSizeMake(100.0, 100.0)
horizontalScrollerClass:[_CPScrollViewTestScroller class]
verticalScrollerClass:[_CPScrollViewTestScroller class]
borderType:CPNoBorder
controlSize:CPRegularControlSize
scrollerStyle:CPScrollerStyleOverlay];
[self assertSize:CGSizeMake(105.0, 105.0) equals:frameSize message:@"both scroller widths come from scrollerWidthInStyle:"];
}
- (void)testContentSizeForFrameSizeUsesScrollerStyleForBothScrollers
{
var contentSize = [CPScrollView contentSizeForFrameSize:CGSizeMake(100.0, 100.0)
horizontalScrollerClass:[_CPScrollViewTestScroller class]
verticalScrollerClass:[_CPScrollViewTestScroller class]
borderType:CPNoBorder
controlSize:CPRegularControlSize
scrollerStyle:CPScrollerStyleOverlay];
[self assertSize:CGSizeMake(95.0, 95.0) equals:contentSize message:@"both scroller widths come from scrollerWidthInStyle:"];
}
// MARK: - Borders in a CSS theme
/*
Makes the built Aristo3 theme, a CSS theme, the default theme, so that scroll views made
after it take it. The tests need the themes built first, as `npx jake build` does.
*/
- (void)useAristo3
{
var theme = BuiltThemeNamed(@"Aristo3");
[self assertNotNull:theme message:@"The built blends hold no Aristo3 theme. Build the themes first."];
[self assertTrue:[theme isCSSBased] message:@"Aristo3 is a CSS theme"];
[CPTheme setDefaultTheme:theme];
}
- (CPScrollView)scrollViewWithBorderType:(CPBorderType)aBorderType
{
var scrollView = [[CPScrollView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
[scrollView setScrollerStyle:CPScrollerStyleOverlay];
[scrollView setHasHorizontalScroller:NO];
[scrollView setHasVerticalScroller:NO];
[scrollView setBorderType:aBorderType];
[scrollView setDocumentView:[[CPView alloc] initWithFrame:CGRectMake(0, 0, 50, 50)]];
[scrollView layoutIfNeeded];
return scrollView;
}
/*
Aristo3 draws the border as a 1px CSS border, so the content must leave 1px free on every
side, or it covers the border lines there.
*/
- (void)testTheContentOfABezeledScrollViewLeavesItsBorderFreeOnEverySide
{
[self useAristo3];
var scrollView = [self scrollViewWithBorderType:CPBezelBorder];
[self assertTrue:CGRectEqualToRect([[scrollView contentView] frame], CGRectMake(1, 1, 98, 98))
message:@"content frame " + CPStringFromRect([[scrollView contentView] frame]) + " should be {{1, 1}, {98, 98}}"];
}
- (void)testTheContentOfALineBorderedScrollViewLeavesItsBorderFreeOnEverySide
{
[self useAristo3];
var scrollView = [self scrollViewWithBorderType:CPLineBorder];
[self assertTrue:CGRectEqualToRect([[scrollView contentView] frame], CGRectMake(1, 1, 98, 98))
message:@"content frame " + CPStringFromRect([[scrollView contentView] frame]) + " should be {{1, 1}, {98, 98}}"];
}
- (void)testAScrollViewWithoutABorderHasNoBackground
{
[self useAristo3];
var scrollView = [self scrollViewWithBorderType:CPNoBorder];
[self assertNull:[scrollView backgroundColor] message:@"a scroll view without a border has no background"];
}
/*
In a CSS theme the border is the background, so a scroll view whose border is removed must
lose the background too.
*/
- (void)testAScrollViewLosesItsBorderWhenTheBorderTypeChangesToNoBorder
{
[self useAristo3];
var scrollView = [self scrollViewWithBorderType:CPBezelBorder];
[self assertNotNull:[scrollView backgroundColor] message:@"precondition: a bezeled scroll view has a background"];
[scrollView setBorderType:CPNoBorder];
[scrollView layoutIfNeeded];
[self assertNull:[scrollView backgroundColor] message:@"the background of the bezel stays after the border is removed"];
}
@end
/*!
A scroller whose widths differ by style, and whose control-size width differs
from both, so a size calculation that uses the wrong method is detectable
regardless of the theme.
*/
@implementation _CPScrollViewTestScroller : CPScroller
+ (float)scrollerWidthInStyle:(CPScrollerStyle)aStyle
{
return aStyle === CPScrollerStyleOverlay ? 5.0 : 20.0;
}
+ (float)scrollerWidthForControlSize:(CPControlSize)aControlSize
{
return 99.0;
}
@end