OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/ui/cocoa/history_overlay_controller.h" | 5 #import "chrome/browser/ui/cocoa/history_overlay_controller.h" |
6 | 6 |
7 #import <QuartzCore/QuartzCore.h> | 7 #import <QuartzCore/QuartzCore.h> |
8 | 8 |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/message_loop/message_pump_mac.h" | 10 #include "base/message_loop/message_pump_mac.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 } | 24 } |
25 | 25 |
26 NSView* test_view() { | 26 NSView* test_view() { |
27 return test_view_; | 27 return test_view_; |
28 } | 28 } |
29 | 29 |
30 private: | 30 private: |
31 base::scoped_nsobject<NSView> test_view_; | 31 base::scoped_nsobject<NSView> test_view_; |
32 }; | 32 }; |
33 | 33 |
34 // Tests that the controller's view gets removed from the hierarchy when the | 34 // Tests that when the controller is |-dismiss|ed, the animation runs and then |
35 // controller is deallocated. | 35 // is removed when the animation completes. The view should be added and |
36 TEST_F(HistoryOverlayControllerTest, RemovedViewWhenDeallocated) { | 36 // removed at the appropriate times. |
| 37 TEST_F(HistoryOverlayControllerTest, DismissClearsAnimationsAndRemovesView) { |
37 NSView* content_view = [test_window() contentView]; | 38 NSView* content_view = [test_window() contentView]; |
38 EXPECT_EQ(1u, [[content_view subviews] count]); | 39 EXPECT_EQ(1u, [[content_view subviews] count]); |
39 | 40 |
40 base::scoped_nsobject<HistoryOverlayController> controller( | 41 base::scoped_nsobject<HistoryOverlayController> controller( |
41 [[HistoryOverlayController alloc] initForMode:kHistoryOverlayModeBack]); | 42 [[HistoryOverlayController alloc] initForMode:kHistoryOverlayModeBack]); |
42 [controller showPanelForView:test_view()]; | 43 [controller showPanelForView:test_view()]; |
43 EXPECT_EQ(2u, [[content_view subviews] count]); | 44 EXPECT_EQ(2u, [[content_view subviews] count]); |
44 | 45 |
45 controller.reset(); | |
46 EXPECT_EQ(1u, [[content_view subviews] count]); | |
47 } | |
48 | |
49 // Tests that when the controller is |-dismiss|ed, the animation runs and then | |
50 // is removed when the animation completes. | |
51 TEST_F(HistoryOverlayControllerTest, DismissClearsAnimations) { | |
52 base::scoped_nsobject<HistoryOverlayController> controller( | |
53 [[HistoryOverlayController alloc] initForMode:kHistoryOverlayModeBack]); | |
54 [controller showPanelForView:test_view()]; | |
55 | |
56 scoped_ptr<base::MessagePumpNSRunLoop> message_pump( | 46 scoped_ptr<base::MessagePumpNSRunLoop> message_pump( |
57 new base::MessagePumpNSRunLoop); | 47 new base::MessagePumpNSRunLoop); |
58 | 48 |
59 id mock = [OCMockObject partialMockForObject:controller]; | 49 id mock = [OCMockObject partialMockForObject:controller]; |
60 [mock setExpectationOrderMatters:YES]; | 50 [mock setExpectationOrderMatters:YES]; |
61 [[[mock expect] andForwardToRealObject] dismiss]; | 51 [[[mock expect] andForwardToRealObject] dismiss]; |
62 | 52 |
63 // Called after |-animationDidStop:finished:|. | 53 // Called after |-animationDidStop:finished:|. |
64 base::MessagePumpNSRunLoop* weak_message_pump = message_pump.get(); | 54 base::MessagePumpNSRunLoop* weak_message_pump = message_pump.get(); |
65 void (^quit_loop)(NSInvocation* invocation) = ^(NSInvocation* invocation) { | 55 void (^quit_loop)(NSInvocation* invocation) = ^(NSInvocation* invocation) { |
(...skipping 14 matching lines...) Expand all Loading... |
80 [mock dismiss]; | 70 [mock dismiss]; |
81 }); | 71 }); |
82 | 72 |
83 // Run the loop, which will dismiss the overlay. | 73 // Run the loop, which will dismiss the overlay. |
84 message_pump->Run(NULL); | 74 message_pump->Run(NULL); |
85 | 75 |
86 EXPECT_OCMOCK_VERIFY(mock); | 76 EXPECT_OCMOCK_VERIFY(mock); |
87 | 77 |
88 // After the animation runs, there should be no more animations. | 78 // After the animation runs, there should be no more animations. |
89 EXPECT_FALSE([[controller view] animations]); | 79 EXPECT_FALSE([[controller view] animations]); |
| 80 |
| 81 EXPECT_EQ(1u, [[content_view subviews] count]); |
90 } | 82 } |
OLD | NEW |