OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 | 6 |
7 #include "base/mac/scoped_nsobject.h" | 7 #include "base/mac/scoped_nsobject.h" |
8 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" | 8 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" |
9 #import "chrome/browser/ui/cocoa/sprite_view.h" | 9 #import "chrome/browser/ui/cocoa/sprite_view.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 #include "testing/platform_test.h" | 11 #include "testing/platform_test.h" |
12 #include "ui/base/resource/resource_bundle.h" | 12 #include "ui/base/resource/resource_bundle.h" |
13 #include "ui/gfx/image/image.h" | 13 #include "ui/gfx/image/image.h" |
14 #include "ui/resources/grit/ui_resources.h" | 14 #include "ui/resources/grit/ui_resources.h" |
15 | 15 |
| 16 @interface SpriteView (ExposedForTesting) |
| 17 |
| 18 - (BOOL)isAnimating; |
| 19 |
| 20 @end |
| 21 |
| 22 @implementation SpriteView (ExposedForTesting) |
| 23 |
| 24 - (BOOL)isAnimating { |
| 25 return [imageLayer_ animationForKey:[spriteAnimation_ keyPath]] != nil; |
| 26 } |
| 27 |
| 28 @end |
| 29 |
16 namespace { | 30 namespace { |
17 | 31 |
18 class SpriteViewTest : public CocoaTest { | 32 class SpriteViewTest : public CocoaTest { |
19 public: | 33 public: |
20 SpriteViewTest() { | 34 SpriteViewTest() { |
21 image_.reset(ResourceBundle::GetSharedInstance() | 35 image_.reset(ResourceBundle::GetSharedInstance() |
22 .GetNativeImageNamed(IDR_THROBBER) | 36 .GetNativeImageNamed(IDR_THROBBER) |
23 .CopyNSImage()); | 37 .CopyNSImage()); |
24 view_.reset([[SpriteView alloc] init]); | 38 view_.reset([[SpriteView alloc] init]); |
25 [view_ setImage:image_]; | 39 [view_ setImage:image_]; |
26 [[test_window() contentView] addSubview:view_]; | 40 [[test_window() contentView] addSubview:view_]; |
27 } | 41 } |
28 | 42 |
29 base::scoped_nsobject<NSImage> image_; | 43 base::scoped_nsobject<NSImage> image_; |
30 base::scoped_nsobject<SpriteView> view_; | 44 base::scoped_nsobject<SpriteView> view_; |
31 }; | 45 }; |
32 | 46 |
33 TEST_VIEW(SpriteViewTest, view_) | 47 TEST_VIEW(SpriteViewTest, view_) |
34 | 48 |
35 TEST_F(SpriteViewTest, TestViewFrame) { | 49 TEST_F(SpriteViewTest, TestViewFrame) { |
36 NSSize imageSize = [image_ size]; | 50 NSSize imageSize = [image_ size]; |
37 NSRect frame = [view_ frame]; | 51 NSRect frame = [view_ frame]; |
38 EXPECT_EQ(0.0, frame.origin.x); | 52 EXPECT_EQ(0.0, frame.origin.x); |
39 EXPECT_EQ(0.0, frame.origin.y); | 53 EXPECT_EQ(0.0, frame.origin.y); |
40 EXPECT_EQ(imageSize.height, NSWidth(frame)); | 54 EXPECT_EQ(imageSize.height, NSWidth(frame)); |
41 EXPECT_EQ(imageSize.height, NSHeight(frame)); | 55 EXPECT_EQ(imageSize.height, NSHeight(frame)); |
42 } | 56 } |
43 | 57 |
| 58 TEST_F(SpriteViewTest, StopAnimationOnMiniaturize) { |
| 59 EXPECT_TRUE([view_ isAnimating]); |
| 60 |
| 61 [test_window() miniaturize:nil]; |
| 62 EXPECT_FALSE([view_ isAnimating]); |
| 63 |
| 64 [test_window() deminiaturize:nil]; |
| 65 EXPECT_TRUE([view_ isAnimating]); |
| 66 } |
| 67 |
| 68 TEST_F(SpriteViewTest, |
| 69 StopAnimationOnRemoveFromSuperview) { |
| 70 EXPECT_TRUE([view_ isAnimating]); |
| 71 |
| 72 [view_ removeFromSuperview]; |
| 73 EXPECT_FALSE([view_ isAnimating]); |
| 74 |
| 75 [[test_window() contentView] addSubview:view_]; |
| 76 EXPECT_TRUE([view_ isAnimating]); |
| 77 } |
| 78 |
44 } // namespace | 79 } // namespace |
OLD | NEW |