Index: chrome/browser/ui/cocoa/circular_activity_indicator_view_unittest.mm |
diff --git a/chrome/browser/ui/cocoa/circular_activity_indicator_view_unittest.mm b/chrome/browser/ui/cocoa/circular_activity_indicator_view_unittest.mm |
new file mode 100644 |
index 0000000000000000000000000000000000000000..ddb75590b5179ed5b4597d439f7bf8e845638964 |
--- /dev/null |
+++ b/chrome/browser/ui/cocoa/circular_activity_indicator_view_unittest.mm |
@@ -0,0 +1,111 @@ |
+// Copyright (c) 2015 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. |
+ |
+#include "chrome/browser/ui/cocoa/circular_activity_indicator_view.h" |
+ |
+#include "base/mac/bind_objc_block.h" |
+#include "base/mac/foundation_util.h" |
+#include "base/time/time.h" |
+#import "chrome/browser/ui/cocoa/cocoa_test_helper.h" |
groby-ooo-7-16
2015/03/30 23:42:07
You probably want ui/gfx/test/ui_cocoa_test_helper
shrike
2015/03/31 07:05:53
Acknowledged.
|
+#import "chrome/browser/ui/cocoa/circular_activity_indicator_view.h" |
+#include "chrome/browser/ui/cocoa/run_loop_testing.h" |
+ |
+typedef CocoaTest CircularActivityIndicatorViewTest; |
+ |
+@interface TestCircularActivityIndicatorView : CircularActivityIndicatorView |
+ |
+- (BOOL)is_animating; |
+ |
+@end |
+ |
+@implementation TestCircularActivityIndicatorView |
+ |
+- (BOOL)is_animating |
groby-ooo-7-16
2015/03/30 23:42:07
Wouldn't @property BOOL is_animating; auto-synthes
shrike
2015/03/31 07:05:53
I don't think it's declared to do so. In general t
|
+{ |
+ return is_animating_; |
+} |
+ |
+@end |
+ |
groby-ooo-7-16
2015/03/30 23:42:07
Customarily, unit tests for views have a a fixture
shrike
2015/03/31 07:05:53
Acknowledged.
|
+ |
+TEST_F(CircularActivityIndicatorViewTest, StopAnimationOnMiniaturize) { |
+ CGRect frame = NSMakeRect(0.0, 0.0, 100.0, 100.0); |
+ NSWindow* test_window = |
groby-ooo-7-16
2015/03/30 23:42:07
If you have a ui::CocoaTest, just call test_window
shrike
2015/03/31 07:05:54
Acknowledged.
|
+ [[NSWindow alloc] initWithContentRect:frame |
+ styleMask:NSClosableWindowMask | |
+ NSMiniaturizableWindowMask | |
+ NSResizableWindowMask |
+ backing:NSBackingStoreBuffered |
+ defer:NO]; |
+ frame = NSMakeRect(10.0, 10.0, 16.0, 16.0); |
+ TestCircularActivityIndicatorView* test_view = |
groby-ooo-7-16
2015/03/30 23:42:07
scoped_nsobject, please. Chromium tries to do most
shrike
2015/03/31 07:05:54
Acknowledged.
|
+ [[TestCircularActivityIndicatorView alloc] initWithFrame:frame]; |
+ |
+ EXPECT_FALSE([test_view is_animating]); |
+ |
+ [[test_window contentView] addSubview:test_view]; |
+ |
groby-ooo-7-16
2015/03/30 23:42:07
nit: I'd kill the empty spaces between changes and
shrike
2015/03/31 07:05:54
Acknowledged.
|
+ EXPECT_TRUE([test_view is_animating]); |
+ |
+ [test_window makeKeyAndOrderFront:nil]; |
+ |
+ EXPECT_TRUE([test_view is_animating]); |
+ |
+ [test_window miniaturize:nil]; |
+ |
+ EXPECT_FALSE([test_view is_animating]); |
+ |
+ [test_window deminiaturize:nil]; |
+ |
+ EXPECT_TRUE([test_view is_animating]); |
+ |
+ [test_view removeFromSuperview]; |
+ |
+ EXPECT_FALSE([test_view is_animating]); |
+ |
+ [test_view release]; |
+ [test_window orderOut:nil]; |
groby-ooo-7-16
2015/03/30 23:42:07
No need to orderOut
shrike
2015/03/31 07:05:54
Done.
|
+ [test_window release]; |
+} |
+ |
+TEST_F(CircularActivityIndicatorViewTest, StopAnimationOnHidden) { |
+ CGRect frame = NSMakeRect(0.0, 0.0, 100.0, 100.0); |
+ NSWindow* test_window = |
+ [[NSWindow alloc] initWithContentRect:frame |
+ styleMask:NSClosableWindowMask | |
+ NSMiniaturizableWindowMask | |
+ NSResizableWindowMask |
+ backing:NSBackingStoreBuffered |
+ defer:NO]; |
+ frame = NSMakeRect(10.0, 10.0, 16.0, 16.0); |
+ TestCircularActivityIndicatorView* test_view = |
+ [[TestCircularActivityIndicatorView alloc] initWithFrame:frame]; |
+ |
+ EXPECT_FALSE([test_view is_animating]); |
+ |
+ [[test_window contentView] addSubview:test_view]; |
+ |
+ EXPECT_TRUE([test_view is_animating]); |
+ |
+ [test_window makeKeyAndOrderFront:nil]; |
+ |
+ EXPECT_TRUE([test_view is_animating]); |
+ |
+ [test_view setHidden:YES]; |
+ |
+ EXPECT_FALSE([test_view is_animating]); |
+ |
+ [test_view setHidden:NO]; |
+ |
+ EXPECT_TRUE([test_view is_animating]); |
+ |
+ [test_view removeFromSuperview]; |
+ |
+ EXPECT_FALSE([test_view is_animating]); |
+ |
+ [test_view release]; |
+ [test_window orderOut:nil]; |
+ [test_window release]; |
+} |
+ |