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/ref_counted.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" |
11 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" | 11 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" |
12 #import "third_party/ocmock/gtest_support.h" | 12 #import "third_party/ocmock/gtest_support.h" |
13 #import "third_party/ocmock/OCMock/OCMock.h" | 13 #import "third_party/ocmock/OCMock/OCMock.h" |
14 | 14 |
15 class HistoryOverlayControllerTest : public CocoaTest { | 15 class HistoryOverlayControllerTest : public CocoaTest { |
16 public: | 16 public: |
17 virtual void SetUp() { | 17 virtual void SetUp() { |
18 CocoaTest::SetUp(); | 18 CocoaTest::SetUp(); |
19 | 19 |
(...skipping 26 matching lines...) Expand all Loading... |
46 EXPECT_EQ(1u, [[content_view subviews] count]); | 46 EXPECT_EQ(1u, [[content_view subviews] count]); |
47 } | 47 } |
48 | 48 |
49 // Tests that when the controller is |-dismiss|ed, the animation runs and then | 49 // Tests that when the controller is |-dismiss|ed, the animation runs and then |
50 // is removed when the animation completes. | 50 // is removed when the animation completes. |
51 TEST_F(HistoryOverlayControllerTest, DismissClearsAnimations) { | 51 TEST_F(HistoryOverlayControllerTest, DismissClearsAnimations) { |
52 base::scoped_nsobject<HistoryOverlayController> controller( | 52 base::scoped_nsobject<HistoryOverlayController> controller( |
53 [[HistoryOverlayController alloc] initForMode:kHistoryOverlayModeBack]); | 53 [[HistoryOverlayController alloc] initForMode:kHistoryOverlayModeBack]); |
54 [controller showPanelForView:test_view()]; | 54 [controller showPanelForView:test_view()]; |
55 | 55 |
56 scoped_refptr<base::MessagePumpNSRunLoop> message_pump( | 56 scoped_ptr<base::MessagePumpNSRunLoop> message_pump( |
57 new base::MessagePumpNSRunLoop); | 57 new base::MessagePumpNSRunLoop); |
58 | 58 |
59 id mock = [OCMockObject partialMockForObject:controller]; | 59 id mock = [OCMockObject partialMockForObject:controller]; |
60 [mock setExpectationOrderMatters:YES]; | 60 [mock setExpectationOrderMatters:YES]; |
61 [[[mock expect] andForwardToRealObject] dismiss]; | 61 [[[mock expect] andForwardToRealObject] dismiss]; |
62 | 62 |
63 // Called after |-animationDidStop:finished:|. | 63 // Called after |-animationDidStop:finished:|. |
| 64 base::MessagePumpNSRunLoop* weak_message_pump = message_pump.get(); |
64 void (^quit_loop)(NSInvocation* invocation) = ^(NSInvocation* invocation) { | 65 void (^quit_loop)(NSInvocation* invocation) = ^(NSInvocation* invocation) { |
65 message_pump->Quit(); | 66 weak_message_pump->Quit(); |
66 }; | 67 }; |
67 // Set up the mock to first forward to the real implementation and then call | 68 // Set up the mock to first forward to the real implementation and then call |
68 // the above block to quit the run loop. | 69 // the above block to quit the run loop. |
69 [[[[mock expect] andForwardToRealObject] andDo:quit_loop] | 70 [[[[mock expect] andForwardToRealObject] andDo:quit_loop] |
70 animationDidStop:[OCMArg isNotNil] finished:YES]; | 71 animationDidStop:[OCMArg isNotNil] finished:YES]; |
71 | 72 |
72 // CAAnimations must be committed within a run loop. It is not sufficient | 73 // CAAnimations must be committed within a run loop. It is not sufficient |
73 // to commit them and activate the loop after the fact. Schedule a block to | 74 // to commit them and activate the loop after the fact. Schedule a block to |
74 // dismiss the controller from within the run loop, which begins the | 75 // dismiss the controller from within the run loop, which begins the |
75 // animation. | 76 // animation. |
76 CFRunLoopPerformBlock(CFRunLoopGetCurrent(), | 77 CFRunLoopPerformBlock(CFRunLoopGetCurrent(), |
77 kCFRunLoopDefaultMode, | 78 kCFRunLoopDefaultMode, |
78 ^(void) { | 79 ^(void) { |
79 [mock dismiss]; | 80 [mock dismiss]; |
80 }); | 81 }); |
81 | 82 |
82 // Run the loop, which will dismiss the overlay. | 83 // Run the loop, which will dismiss the overlay. |
83 message_pump->Run(NULL); | 84 message_pump->Run(NULL); |
84 | 85 |
85 EXPECT_OCMOCK_VERIFY(mock); | 86 EXPECT_OCMOCK_VERIFY(mock); |
86 | 87 |
87 // After the animation runs, there should be no more animations. | 88 // After the animation runs, there should be no more animations. |
88 EXPECT_FALSE([[controller view] animations]); | 89 EXPECT_FALSE([[controller view] animations]); |
89 } | 90 } |
OLD | NEW |