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