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/bind.h" |
10 #include "base/callback.h" | |
11 #include "base/memory/scoped_ptr.h" | |
10 #include "base/message_loop/message_pump_mac.h" | 12 #include "base/message_loop/message_pump_mac.h" |
11 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" | 13 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" |
12 #import "third_party/ocmock/gtest_support.h" | 14 #import "third_party/ocmock/gtest_support.h" |
13 #import "third_party/ocmock/OCMock/OCMock.h" | 15 #import "third_party/ocmock/OCMock/OCMock.h" |
14 | 16 |
15 class HistoryOverlayControllerTest : public CocoaTest { | 17 class HistoryOverlayControllerTest : public CocoaTest { |
16 public: | 18 public: |
17 virtual void SetUp() { | 19 virtual void SetUp() { |
18 CocoaTest::SetUp(); | 20 CocoaTest::SetUp(); |
19 | 21 |
(...skipping 26 matching lines...) Expand all Loading... | |
46 EXPECT_EQ(1u, [[content_view subviews] count]); | 48 EXPECT_EQ(1u, [[content_view subviews] count]); |
47 } | 49 } |
48 | 50 |
49 // Tests that when the controller is |-dismiss|ed, the animation runs and then | 51 // Tests that when the controller is |-dismiss|ed, the animation runs and then |
50 // is removed when the animation completes. | 52 // is removed when the animation completes. |
51 TEST_F(HistoryOverlayControllerTest, DismissClearsAnimations) { | 53 TEST_F(HistoryOverlayControllerTest, DismissClearsAnimations) { |
52 base::scoped_nsobject<HistoryOverlayController> controller( | 54 base::scoped_nsobject<HistoryOverlayController> controller( |
53 [[HistoryOverlayController alloc] initForMode:kHistoryOverlayModeBack]); | 55 [[HistoryOverlayController alloc] initForMode:kHistoryOverlayModeBack]); |
54 [controller showPanelForView:test_view()]; | 56 [controller showPanelForView:test_view()]; |
55 | 57 |
56 scoped_refptr<base::MessagePumpNSRunLoop> message_pump( | 58 scoped_ptr<base::MessagePumpNSRunLoop> message_pump( |
57 new base::MessagePumpNSRunLoop); | 59 new base::MessagePumpNSRunLoop); |
58 | 60 |
59 id mock = [OCMockObject partialMockForObject:controller]; | 61 id mock = [OCMockObject partialMockForObject:controller]; |
60 [mock setExpectationOrderMatters:YES]; | 62 [mock setExpectationOrderMatters:YES]; |
61 [[[mock expect] andForwardToRealObject] dismiss]; | 63 [[[mock expect] andForwardToRealObject] dismiss]; |
62 | 64 |
63 // Called after |-animationDidStop:finished:|. | 65 // Called after |-animationDidStop:finished:|. |
66 base::Closure quit_closure = base::Bind(&base::MessagePumpNSRunLoop::Quit, | |
67 base::Unretained(message_pump.get())); | |
64 void (^quit_loop)(NSInvocation* invocation) = ^(NSInvocation* invocation) { | 68 void (^quit_loop)(NSInvocation* invocation) = ^(NSInvocation* invocation) { |
65 message_pump->Quit(); | 69 quit_closure.Run(); |
Robert Sesek
2013/07/10 22:13:32
Why can't Quit be called directly here?
alexeypa (please no reviews)
2013/07/10 22:15:26
Because |message_pump_| is a scoped_ptr now and ca
Robert Sesek
2013/07/10 22:19:15
Ah, right. I think there's a slight preference to
alexeypa (please no reviews)
2013/07/10 22:27:23
Done.
| |
66 }; | 70 }; |
67 // Set up the mock to first forward to the real implementation and then call | 71 // Set up the mock to first forward to the real implementation and then call |
68 // the above block to quit the run loop. | 72 // the above block to quit the run loop. |
69 [[[[mock expect] andForwardToRealObject] andDo:quit_loop] | 73 [[[[mock expect] andForwardToRealObject] andDo:quit_loop] |
70 animationDidStop:[OCMArg isNotNil] finished:YES]; | 74 animationDidStop:[OCMArg isNotNil] finished:YES]; |
71 | 75 |
72 // CAAnimations must be committed within a run loop. It is not sufficient | 76 // 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 | 77 // 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 | 78 // dismiss the controller from within the run loop, which begins the |
75 // animation. | 79 // animation. |
76 CFRunLoopPerformBlock(CFRunLoopGetCurrent(), | 80 CFRunLoopPerformBlock(CFRunLoopGetCurrent(), |
77 kCFRunLoopDefaultMode, | 81 kCFRunLoopDefaultMode, |
78 ^(void) { | 82 ^(void) { |
79 [mock dismiss]; | 83 [mock dismiss]; |
80 }); | 84 }); |
81 | 85 |
82 // Run the loop, which will dismiss the overlay. | 86 // Run the loop, which will dismiss the overlay. |
83 message_pump->Run(NULL); | 87 message_pump->Run(NULL); |
84 | 88 |
85 EXPECT_OCMOCK_VERIFY(mock); | 89 EXPECT_OCMOCK_VERIFY(mock); |
86 | 90 |
87 // After the animation runs, there should be no more animations. | 91 // After the animation runs, there should be no more animations. |
88 EXPECT_FALSE([[controller view] animations]); | 92 EXPECT_FALSE([[controller view] animations]); |
89 } | 93 } |
OLD | NEW |