1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_unittest_helper.h" 6 7 @interface NSArray (BookmarkBarUnitTestHelper) 8 9 // A helper function for scanning an array of buttons looking for the 10 // button with the given |title|. 11 - (BookmarkButton*)buttonWithTitleEqualTo:(NSString*)title; 12 13 @end 14 15 16 @implementation NSArray (BookmarkBarUnitTestHelper) 17 18 - (BookmarkButton*)buttonWithTitleEqualTo:(NSString*)title { 19 for (BookmarkButton* button in self) { 20 if ([[button title] isEqualToString:title]) 21 return button; 22 } 23 return nil; 24 } 25 26 @end 27 28 @implementation BookmarkBarController (BookmarkBarUnitTestHelper) 29 30 - (BookmarkButton*)buttonWithTitleEqualTo:(NSString*)title { 31 return [[self buttons] buttonWithTitleEqualTo:title]; 32 } 33 34 @end 35 36 @implementation BookmarkBarFolderController(BookmarkBarUnitTestHelper) 37 38 - (BookmarkButton*)buttonWithTitleEqualTo:(NSString*)title { 39 return [[self buttons] buttonWithTitleEqualTo:title]; 40 } 41 42 @end 43 44 @implementation BookmarkButton(BookmarkBarUnitTestHelper) 45 46 - (NSPoint)center { 47 NSRect frame = [self frame]; 48 NSPoint center = NSMakePoint(NSMidX(frame), NSMidY(frame)); 49 center = [[self superview] convertPoint:center toView:nil]; 50 return center; 51 } 52 53 - (NSPoint)top { 54 NSRect frame = [self frame]; 55 NSPoint top = NSMakePoint(NSMidX(frame), NSMaxY(frame)); 56 top = [[self superview] convertPoint:top toView:nil]; 57 return top; 58 } 59 60 - (NSPoint)bottom { 61 NSRect frame = [self frame]; 62 NSPoint bottom = NSMakePoint(NSMidX(frame), NSMinY(frame)); 63 bottom = [[self superview] convertPoint:bottom toView:nil]; 64 return bottom; 65 } 66 67 - (NSPoint)left { 68 NSRect frame = [self frame]; 69 NSPoint left = NSMakePoint(NSMinX(frame), NSMidY(frame)); 70 left = [[self superview] convertPoint:left toView:nil]; 71 return left; 72 } 73 74 - (NSPoint)right { 75 NSRect frame = [self frame]; 76 NSPoint right = NSMakePoint(NSMaxX(frame), NSMidY(frame)); 77 right = [[self superview] convertPoint:right toView:nil]; 78 return right; 79 } 80 81 @end 82