Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / sprite_view_unittest.mm
blobb0566f5c6bd58004f4749a74b9055e265019b968
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.
5 #import <Cocoa/Cocoa.h>
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 "testing/gtest/include/gtest/gtest.h"
11 #include "testing/platform_test.h"
12 #include "ui/base/resource/resource_bundle.h"
13 #include "ui/gfx/image/image.h"
14 #include "ui/resources/grit/ui_resources.h"
16 @interface SpriteView (ExposedForTesting)
18 - (BOOL)isAnimating;
20 @end
22 @implementation SpriteView (ExposedForTesting)
24 - (BOOL)isAnimating {
25   return [imageLayer_ animationForKey:[spriteAnimation_ keyPath]] != nil;
28 @end
30 namespace {
32 class SpriteViewTest : public CocoaTest {
33  public:
34   SpriteViewTest() {
35     image_.reset(ResourceBundle::GetSharedInstance()
36                      .GetNativeImageNamed(IDR_THROBBER)
37                      .CopyNSImage());
38     view_.reset([[SpriteView alloc] init]);
39     [view_ setImage:image_];
40     [[test_window() contentView] addSubview:view_];
41   }
43   base::scoped_nsobject<NSImage> image_;
44   base::scoped_nsobject<SpriteView> view_;
47 TEST_VIEW(SpriteViewTest, view_)
49 TEST_F(SpriteViewTest, TestViewFrame) {
50   NSSize imageSize = [image_ size];
51   NSRect frame = [view_ frame];
52   EXPECT_EQ(0.0, frame.origin.x);
53   EXPECT_EQ(0.0, frame.origin.y);
54   EXPECT_EQ(imageSize.height, NSWidth(frame));
55   EXPECT_EQ(imageSize.height, NSHeight(frame));
58 TEST_F(SpriteViewTest, StopAnimationOnMiniaturize) {
59   EXPECT_TRUE([view_ isAnimating]);
61   [test_window() miniaturize:nil];
62   EXPECT_FALSE([view_ isAnimating]);
64   [test_window() deminiaturize:nil];
65   EXPECT_TRUE([view_ isAnimating]);
68 TEST_F(SpriteViewTest,
69        StopAnimationOnRemoveFromSuperview) {
70   EXPECT_TRUE([view_ isAnimating]);
72   [view_ removeFromSuperview];
73   EXPECT_FALSE([view_ isAnimating]);
75   [[test_window() contentView] addSubview:view_];
76   EXPECT_TRUE([view_ isAnimating]);
79 }  // namespace