summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/cocoa/custom_frame_view_unittest.mm
blob: 4f061cdd019a7aab30444a74883eaead17f991f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#import <Cocoa/Cocoa.h>
#include <objc/runtime.h>

#include "base/mac/mac_util.h"
#include "base/mac/scoped_nsobject.h"
#import "chrome/browser/ui/cocoa/custom_frame_view.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"

class CustomFrameViewTest : public PlatformTest {
 public:
  CustomFrameViewTest() {
    NSRect frame = NSMakeRect(0, 0, 50, 50);
    // We create NSGrayFrame instead of CustomFrameView because
    // we are swizzling into NSGrayFrame. (NSThemeFrame on Mountain Lion and
    // later)
    Class customFrameClass = NSClassFromString(
        base::mac::IsOSMountainLionOrLater() ? @"NSThemeFrame"
                                             : @"NSGrayFrame");
    view_.reset([[customFrameClass alloc] initWithFrame:frame]);
  }

  base::scoped_nsobject<NSView> view_;
};

//  Test to make sure our class modifications were successful.
TEST_F(CustomFrameViewTest, SuccessfulClassModifications) {
  unsigned int count;
  BOOL foundDrawRectOriginal = NO;

  Method* methods = class_copyMethodList([view_ class], &count);
  for (unsigned int i = 0; i < count; ++i) {
    SEL selector = method_getName(methods[i]);
    if (selector == @selector(drawRectOriginal:)) {
      foundDrawRectOriginal = YES;
    }
  }
  EXPECT_TRUE(foundDrawRectOriginal);
  free(methods);
}