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

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

Issue 894423003: Mac: Optimize HistoryOverlayView using layer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@themed-drawing
Patch Set: Fix test Created 5 years, 10 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
« no previous file with comments | « chrome/browser/ui/cocoa/history_overlay_controller.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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>
8
9 #include "base/memory/scoped_ptr.h"
10 #include "base/message_loop/message_pump_mac.h"
11 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" 7 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h"
12 #import "third_party/ocmock/gtest_support.h"
13 #import "third_party/ocmock/OCMock/OCMock.h"
14 8
15 class HistoryOverlayControllerTest : public CocoaTest { 9 class HistoryOverlayControllerTest : public CocoaTest {
16 public: 10 public:
17 void SetUp() override { 11 void SetUp() override {
18 CocoaTest::SetUp(); 12 CocoaTest::SetUp();
19 13
20 // The overlay controller shows the panel as a subview of the given view. 14 // The overlay controller shows the panel as a subview of the given view.
21 test_view_.reset([[NSView alloc] initWithFrame:NSMakeRect(10, 10, 10, 10)]); 15 test_view_.reset([[NSView alloc] initWithFrame:NSMakeRect(10, 10, 10, 10)]);
22 16
23 // We add it to the test_window for authenticity. 17 // We add it to the test_window for authenticity.
24 [[test_window() contentView] addSubview:test_view_]; 18 [[test_window() contentView] addSubview:test_view_];
25 } 19 }
26 20
27 NSView* test_view() { 21 NSView* test_view() {
28 return test_view_; 22 return test_view_;
29 } 23 }
30 24
31 private: 25 private:
32 base::scoped_nsobject<NSView> test_view_; 26 base::scoped_nsobject<NSView> test_view_;
33 }; 27 };
34 28
35 // Tests that when the controller is |-dismiss|ed, the animation runs and then 29 // Tests that the overlay view gets added and removed at the appropriate times.
36 // is removed when the animation completes. The view should be added and
37 // removed at the appropriate times.
38 TEST_F(HistoryOverlayControllerTest, DismissClearsAnimationsAndRemovesView) { 30 TEST_F(HistoryOverlayControllerTest, DismissClearsAnimationsAndRemovesView) {
39 EXPECT_EQ(0u, [[test_view() subviews] count]); 31 EXPECT_EQ(0u, [[test_view() subviews] count]);
40 32
41 base::scoped_nsobject<HistoryOverlayController> controller( 33 base::scoped_nsobject<HistoryOverlayController> controller(
42 [[HistoryOverlayController alloc] initForMode:kHistoryOverlayModeBack]); 34 [[HistoryOverlayController alloc] initForMode:kHistoryOverlayModeBack]);
43 [controller showPanelForView:test_view()]; 35 [controller showPanelForView:test_view()];
44 EXPECT_EQ(1u, [[test_view() subviews] count]); 36 EXPECT_EQ(1u, [[test_view() subviews] count]);
45 37
46 scoped_ptr<base::MessagePumpNSRunLoop> message_pump( 38 // We expect the view to be removed from its superview immediately
47 new base::MessagePumpNSRunLoop); 39 // after dismiss, even though it may still be animating a fade out.
48 40 [controller dismiss];
49 id mock = [OCMockObject partialMockForObject:controller];
50 [mock setExpectationOrderMatters:YES];
51 [[[mock expect] andForwardToRealObject] dismiss];
52
53 // Called after |-animationDidStop:finished:|.
54 base::MessagePumpNSRunLoop* weak_message_pump = message_pump.get();
55 void (^quit_loop)(NSInvocation* invocation) = ^(NSInvocation* invocation) {
56 weak_message_pump->Quit();
57 };
58 // Set up the mock to first forward to the real implementation and then call
59 // the above block to quit the run loop.
60 [[[[mock expect] andForwardToRealObject] andDo:quit_loop]
61 animationDidStop:[OCMArg isNotNil] finished:YES];
62
63 // CAAnimations must be committed within a run loop. It is not sufficient
64 // to commit them and activate the loop after the fact. Schedule a block to
65 // dismiss the controller from within the run loop, which begins the
66 // animation.
67 CFRunLoopPerformBlock(CFRunLoopGetCurrent(),
68 kCFRunLoopDefaultMode,
69 ^(void) {
70 [mock dismiss];
71 });
72
73 // Run the loop, which will dismiss the overlay.
74 message_pump->Run(NULL);
75
76 EXPECT_OCMOCK_VERIFY(mock);
77
78 // After the animation runs, there should be no more animations.
79 EXPECT_FALSE([[controller view] animations]);
80
81 EXPECT_EQ(0u, [[test_view() subviews] count]); 41 EXPECT_EQ(0u, [[test_view() subviews] count]);
Robert Sesek 2015/02/04 20:18:22 How does this ensure that the animation is no long
Andre 2015/02/04 21:01:46 It does not. Is there a benefit from waiting for t
Robert Sesek 2015/02/04 21:21:25 Part of CocoaTest is responsible for flushing the
Andre 2015/02/04 21:32:29 Which notification do you mean? NSAnimationContext
Robert Sesek 2015/02/05 21:48:03 Sorry, I was referring to -animationDidStop:finish
82 } 42 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/history_overlay_controller.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698