Home | History | Annotate | Download | only in cocoa
      1 // Copyright (c) 2011 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 
      7 #include "base/memory/scoped_nsobject.h"
      8 #import "chrome/browser/ui/cocoa/animatable_view.h"
      9 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h"
     10 #import "chrome/browser/ui/cocoa/view_resizer_pong.h"
     11 #include "testing/gtest/include/gtest/gtest.h"
     12 #include "testing/platform_test.h"
     13 
     14 namespace {
     15 
     16 class AnimatableViewTest : public CocoaTest {
     17  public:
     18   AnimatableViewTest() {
     19     NSRect frame = NSMakeRect(0, 0, 100, 100);
     20     view_.reset([[AnimatableView alloc] initWithFrame:frame]);
     21     [[test_window() contentView] addSubview:view_.get()];
     22 
     23     resizeDelegate_.reset([[ViewResizerPong alloc] init]);
     24     [view_ setResizeDelegate:resizeDelegate_.get()];
     25   }
     26 
     27   scoped_nsobject<ViewResizerPong> resizeDelegate_;
     28   scoped_nsobject<AnimatableView> view_;
     29 };
     30 
     31 // Basic view tests (AddRemove, Display).
     32 TEST_VIEW(AnimatableViewTest, view_);
     33 
     34 TEST_F(AnimatableViewTest, GetAndSetHeight) {
     35   // Make sure the view's height starts out at 100.
     36   NSRect initialFrame = [view_ frame];
     37   ASSERT_EQ(100, initialFrame.size.height);
     38   EXPECT_EQ(initialFrame.size.height, [view_ height]);
     39 
     40   // Set it directly to 50 and make sure it takes effect.
     41   [resizeDelegate_ setHeight:-1];
     42   [view_ setHeight:50];
     43   EXPECT_EQ(50, [resizeDelegate_ height]);
     44 }
     45 
     46 // TODO(rohitrao): Find a way to unittest the animations and delegate messages.
     47 
     48 }  // namespace
     49