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/ref_counted.h" |
10 #include "base/message_loop/message_pump_mac.h" | 10 #include "base/message_loop/message_pump_mac.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 // view, so create the given view. | 21 // view, so create the given view. |
22 test_view_.reset([[NSView alloc] initWithFrame:NSMakeRect(10, 10, 10, 10)]); | 22 test_view_.reset([[NSView alloc] initWithFrame:NSMakeRect(10, 10, 10, 10)]); |
23 [[test_window() contentView] addSubview:test_view_]; | 23 [[test_window() contentView] addSubview:test_view_]; |
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 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 the controller's view gets removed from the hierarchy when the |
35 // controller is deallocated. | 35 // controller is deallocated. |
36 TEST_F(HistoryOverlayControllerTest, RemovedViewWhenDeallocated) { | 36 TEST_F(HistoryOverlayControllerTest, RemovedViewWhenDeallocated) { |
37 NSView* content_view = [test_window() contentView]; | 37 NSView* content_view = [test_window() contentView]; |
38 EXPECT_EQ(1u, [[content_view subviews] count]); | 38 EXPECT_EQ(1u, [[content_view subviews] count]); |
39 | 39 |
40 scoped_nsobject<HistoryOverlayController> controller( | 40 base::scoped_nsobject<HistoryOverlayController> controller( |
41 [[HistoryOverlayController alloc] initForMode:kHistoryOverlayModeBack]); | 41 [[HistoryOverlayController alloc] initForMode:kHistoryOverlayModeBack]); |
42 [controller showPanelForView:test_view()]; | 42 [controller showPanelForView:test_view()]; |
43 EXPECT_EQ(2u, [[content_view subviews] count]); | 43 EXPECT_EQ(2u, [[content_view subviews] count]); |
44 | 44 |
45 controller.reset(); | 45 controller.reset(); |
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 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_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 |
(...skipping 17 matching lines...) Expand all Loading... |
80 }); | 80 }); |
81 | 81 |
82 // Run the loop, which will dismiss the overlay. | 82 // Run the loop, which will dismiss the overlay. |
83 message_pump->Run(NULL); | 83 message_pump->Run(NULL); |
84 | 84 |
85 EXPECT_OCMOCK_VERIFY(mock); | 85 EXPECT_OCMOCK_VERIFY(mock); |
86 | 86 |
87 // After the animation runs, there should be no more animations. | 87 // After the animation runs, there should be no more animations. |
88 EXPECT_FALSE([[controller view] animations]); | 88 EXPECT_FALSE([[controller view] animations]); |
89 } | 89 } |
OLD | NEW |