From f2541223466265a3d1d9811d09bf4e240e65e764 Mon Sep 17 00:00:00 2001 From: Aparajita Fishman Date: Thu, 10 Mar 2011 12:26:23 -0500 Subject: [PATCH] Added CPView -hasThemeAttribute and tests --- AppKit/CPView.j | 5 +++++ Tests/AppKit/CPButtonTest.j | 15 +++++++++++++++ Tests/AppKit/CPViewTest.j | 25 ++++++++++++++++++++----- 3 files changed, 40 insertions(+), 5 deletions(-) diff --git a/AppKit/CPView.j b/AppKit/CPView.j index afd79c850..74b800e34 100644 --- a/AppKit/CPView.j +++ b/AppKit/CPView.j @@ -2498,6 +2498,11 @@ setBoundsOrigin: return [_themeAttributes[aName] valueForState:_themeState]; } +- (BOOL)hasThemeAttribute:(CPString)aName +{ + return (_themeAttributes && _themeAttributes[aName] !== undefined); +} + - (CPView)createEphemeralSubviewNamed:(CPString)aViewName { return nil; diff --git a/Tests/AppKit/CPButtonTest.j b/Tests/AppKit/CPButtonTest.j index 8acf049df..3b2d1d4b2 100644 --- a/Tests/AppKit/CPButtonTest.j +++ b/Tests/AppKit/CPButtonTest.j @@ -132,4 +132,19 @@ [self assert:CPMixedState equals:[button state] message:@"Mixed state is allowed, state should be CPMixedState"]; } +- (void)testThemeAttributes +{ + var attributes = [CPButton themeAttributes]; + + if (attributes) + { + var keys = [attributes allKeys], + firstKey = [keys objectAtIndex:0]; + + [self assertTrue:[button hasThemeAttribute:[firstKey]] message:[button className] + " should have the theme attribute \"" + firstKey + "\""]; + } + + [self assertFalse:[button hasThemeAttribute:@"foobar"] message:[button className] + " should not have theme attribute \"" + firstKey + "\""]; +} + @end diff --git a/Tests/AppKit/CPViewTest.j b/Tests/AppKit/CPViewTest.j index 2f5c01566..01aa80af2 100644 --- a/Tests/AppKit/CPViewTest.j +++ b/Tests/AppKit/CPViewTest.j @@ -23,18 +23,18 @@ /* During the layout process for the view, _CPImageAndTextView.j throws a ReferenceError with the following: - + "hasDOMImageElement" is not defined - - The referenced variable is #if PLATFORM(DOM) excluded in all other - instances. While not isolated to the behaviour of a CPView alone, the + + The referenced variable is #if PLATFORM(DOM) excluded in all other + instances. While not isolated to the behaviour of a CPView alone, the following test ensures that pending actions in the _CPDisplayServer can be flushed without touching unimplemented portions of the test platform (e.g. the DOM). There are times where we want to confirm that some setting requiring relayout (e.g. string truncation based on available space), the following test should help ensure those types of tests are safe to carry out with ojunit. - + Demonstrates issue #562. */ - (void)testCanFlushPendingLayoutWork @@ -58,4 +58,19 @@ [self assertTrue:[view hasThemeState:CPThemeStateHighlighted] message:@"The view should be CPThemeStateHighlighted"]; } +- (void)testThemeAttributes +{ + var attributes = [CPView themeAttributes]; + + if (attributes) + { + var keys = [attributes allKeys], + firstKey = [keys objectAtIndex:0]; + + [self assertTrue:[view hasThemeAttribute:[firstKey]] message:[view className] + " should have the theme attribute \"" + firstKey + "\""]; + } + + [self assertFalse:[view hasThemeAttribute:@"foobar"] message:[view className] + " should not have theme attribute \"" + firstKey + "\""]; +} + @end