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/ref_counted.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_ptr<base::MessagePumpNSRunLoop> message_pump( | 56 scoped_refptr<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(); | |
65 void (^quit_loop)(NSInvocation* invocation) = ^(NSInvocation* invocation) { | 64 void (^quit_loop)(NSInvocation* invocation) = ^(NSInvocation* invocation) { |
66 weak_message_pump->Quit(); | 65 message_pump->Quit(); |
67 }; | 66 }; |
68 // Set up the mock to first forward to the real implementation and then call | 67 // Set up the mock to first forward to the real implementation and then call |
69 // the above block to quit the run loop. | 68 // the above block to quit the run loop. |
70 [[[[mock expect] andForwardToRealObject] andDo:quit_loop] | 69 [[[[mock expect] andForwardToRealObject] andDo:quit_loop] |
71 animationDidStop:[OCMArg isNotNil] finished:YES]; | 70 animationDidStop:[OCMArg isNotNil] finished:YES]; |
72 | 71 |
73 // CAAnimations must be committed within a run loop. It is not sufficient | 72 // CAAnimations must be committed within a run loop. It is not sufficient |
74 // to commit them and activate the loop after the fact. Schedule a block to | 73 // to commit them and activate the loop after the fact. Schedule a block to |
75 // dismiss the controller from within the run loop, which begins the | 74 // dismiss the controller from within the run loop, which begins the |
76 // animation. | 75 // animation. |
77 CFRunLoopPerformBlock(CFRunLoopGetCurrent(), | 76 CFRunLoopPerformBlock(CFRunLoopGetCurrent(), |
78 kCFRunLoopDefaultMode, | 77 kCFRunLoopDefaultMode, |
79 ^(void) { | 78 ^(void) { |
80 [mock dismiss]; | 79 [mock dismiss]; |
81 }); | 80 }); |
82 | 81 |
83 // Run the loop, which will dismiss the overlay. | 82 // Run the loop, which will dismiss the overlay. |
84 message_pump->Run(NULL); | 83 message_pump->Run(NULL); |
85 | 84 |
86 EXPECT_OCMOCK_VERIFY(mock); | 85 EXPECT_OCMOCK_VERIFY(mock); |
87 | 86 |
88 // After the animation runs, there should be no more animations. | 87 // After the animation runs, there should be no more animations. |
89 EXPECT_FALSE([[controller view] animations]); | 88 EXPECT_FALSE([[controller view] animations]); |
90 } | 89 } |
OLD | NEW |