1 // Copyright 2014 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/mac/scoped_nsobject.h" 8 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" 9 #import "chrome/browser/ui/cocoa/sprite_view.h" 10 #include "grit/ui_resources.h" 11 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/platform_test.h" 13 #include "ui/base/resource/resource_bundle.h" 14 #include "ui/gfx/image/image.h" 15 16 namespace { 17 18 class SpriteViewTest : public CocoaTest { 19 public: 20 SpriteViewTest() { 21 image_.reset(ResourceBundle::GetSharedInstance() 22 .GetNativeImageNamed(IDR_THROBBER) 23 .ToNSImage()); 24 view_.reset([[SpriteView alloc] init]); 25 [view_ setImage:image_]; 26 [[test_window() contentView] addSubview:view_]; 27 } 28 29 base::scoped_nsobject<NSImage> image_; 30 base::scoped_nsobject<SpriteView> view_; 31 }; 32 33 TEST_VIEW(SpriteViewTest, view_) 34 35 TEST_F(SpriteViewTest, TestViewFrame) { 36 NSSize imageSize = [image_ size]; 37 NSRect frame = [view_ frame]; 38 EXPECT_EQ(0.0, frame.origin.x); 39 EXPECT_EQ(0.0, frame.origin.y); 40 EXPECT_EQ(imageSize.height, NSWidth(frame)); 41 EXPECT_EQ(imageSize.height, NSHeight(frame)); 42 } 43 44 } // namespace 45