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