Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Side by Side Diff: chrome/browser/ui/cocoa/history_overlay_controller_unittest.mm

Issue 17567007: Made MessagePump a non-thread safe class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698