| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import <Cocoa/Cocoa.h> | 5 #import <Cocoa/Cocoa.h> |
| 6 #include <objc/runtime.h> | 6 #include <objc/runtime.h> |
| 7 | 7 |
| 8 #include "base/mac/mac_util.h" | 8 #include "base/mac/mac_util.h" |
| 9 #include "base/memory/scoped_nsobject.h" | 9 #include "base/mac/scoped_nsobject.h" |
| 10 #import "chrome/browser/ui/cocoa/custom_frame_view.h" | 10 #import "chrome/browser/ui/cocoa/custom_frame_view.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "testing/platform_test.h" | 12 #include "testing/platform_test.h" |
| 13 | 13 |
| 14 class CustomFrameViewTest : public PlatformTest { | 14 class CustomFrameViewTest : public PlatformTest { |
| 15 public: | 15 public: |
| 16 CustomFrameViewTest() { | 16 CustomFrameViewTest() { |
| 17 NSRect frame = NSMakeRect(0, 0, 50, 50); | 17 NSRect frame = NSMakeRect(0, 0, 50, 50); |
| 18 // We create NSGrayFrame instead of CustomFrameView because | 18 // We create NSGrayFrame instead of CustomFrameView because |
| 19 // we are swizzling into NSGrayFrame. (NSThemeFrame on Mountain Lion and | 19 // we are swizzling into NSGrayFrame. (NSThemeFrame on Mountain Lion and |
| 20 // later) | 20 // later) |
| 21 Class customFrameClass = NSClassFromString( | 21 Class customFrameClass = NSClassFromString( |
| 22 base::mac::IsOSMountainLionOrLater() ? @"NSThemeFrame" | 22 base::mac::IsOSMountainLionOrLater() ? @"NSThemeFrame" |
| 23 : @"NSGrayFrame"); | 23 : @"NSGrayFrame"); |
| 24 view_.reset([[customFrameClass alloc] initWithFrame:frame]); | 24 view_.reset([[customFrameClass alloc] initWithFrame:frame]); |
| 25 } | 25 } |
| 26 | 26 |
| 27 scoped_nsobject<NSView> view_; | 27 base::scoped_nsobject<NSView> view_; |
| 28 }; | 28 }; |
| 29 | 29 |
| 30 // Test to make sure our class modifications were successful. | 30 // Test to make sure our class modifications were successful. |
| 31 TEST_F(CustomFrameViewTest, SuccessfulClassModifications) { | 31 TEST_F(CustomFrameViewTest, SuccessfulClassModifications) { |
| 32 unsigned int count; | 32 unsigned int count; |
| 33 BOOL foundDrawRectOriginal = NO; | 33 BOOL foundDrawRectOriginal = NO; |
| 34 | 34 |
| 35 Method* methods = class_copyMethodList([view_ class], &count); | 35 Method* methods = class_copyMethodList([view_ class], &count); |
| 36 for (unsigned int i = 0; i < count; ++i) { | 36 for (unsigned int i = 0; i < count; ++i) { |
| 37 SEL selector = method_getName(methods[i]); | 37 SEL selector = method_getName(methods[i]); |
| 38 if (selector == @selector(drawRectOriginal:)) { | 38 if (selector == @selector(drawRectOriginal:)) { |
| 39 foundDrawRectOriginal = YES; | 39 foundDrawRectOriginal = YES; |
| 40 } | 40 } |
| 41 } | 41 } |
| 42 EXPECT_TRUE(foundDrawRectOriginal); | 42 EXPECT_TRUE(foundDrawRectOriginal); |
| 43 free(methods); | 43 free(methods); |
| 44 } | 44 } |
| OLD | NEW |