OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ui/gfx/test/ui_cocoa_test_helper.h" | 5 #import "ui/gfx/test/ui_cocoa_test_helper.h" |
6 | 6 |
7 #include "base/debug/debugger.h" | 7 #include "base/debug/debugger.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "base/test/test_timeouts.h" | 10 #include "base/test/test_timeouts.h" |
11 | 11 |
12 namespace { | |
13 | |
14 // Some AppKit function leak intentionally, e.g. for caching purposes. | |
15 // Force those leaks here, so there can be a unique calling path, allowing | |
16 // to flag intentional leaks without having to suppress all calls to | |
17 // potentially leaky functions. | |
18 void NOINLINE ForceSystemLeaks() { | |
19 // First NSCursor push always leaks. | |
20 [[NSCursor openHandCursor] push]; | |
21 [NSCursor pop]; | |
22 } | |
23 | |
24 } // namespace. | |
25 | |
12 @implementation CocoaTestHelperWindow | 26 @implementation CocoaTestHelperWindow |
13 | 27 |
14 - (id)initWithContentRect:(NSRect)contentRect { | 28 - (id)initWithContentRect:(NSRect)contentRect { |
15 return [self initWithContentRect:contentRect | 29 return [self initWithContentRect:contentRect |
16 styleMask:NSBorderlessWindowMask | 30 styleMask:NSBorderlessWindowMask |
17 backing:NSBackingStoreBuffered | 31 backing:NSBackingStoreBuffered |
18 defer:NO]; | 32 defer:NO]; |
19 } | 33 } |
20 | 34 |
21 - (id)init { | 35 - (id)init { |
(...skipping 22 matching lines...) Expand all Loading... | |
44 | 58 |
45 - (BOOL)isKeyWindow { | 59 - (BOOL)isKeyWindow { |
46 return pretendIsKeyWindow_; | 60 return pretendIsKeyWindow_; |
47 } | 61 } |
48 | 62 |
49 @end | 63 @end |
50 | 64 |
51 namespace ui { | 65 namespace ui { |
52 | 66 |
53 CocoaTest::CocoaTest() : called_tear_down_(false), test_window_(nil) { | 67 CocoaTest::CocoaTest() : called_tear_down_(false), test_window_(nil) { |
54 Init(); | 68 Init(); |
Scott Hess - ex-Googler
2014/05/30 23:58:06
I'm looking at this and thinking "Wait, what?" I
groby-ooo-7-16
2014/05/31 00:37:04
Nope, Avi :)
This used to call BootstrapCocoa, to
| |
55 } | 69 } |
56 | 70 |
57 CocoaTest::~CocoaTest() { | 71 CocoaTest::~CocoaTest() { |
58 // Must call CocoaTest's teardown from your overrides. | 72 // Must call CocoaTest's teardown from your overrides. |
59 DCHECK(called_tear_down_); | 73 DCHECK(called_tear_down_); |
60 } | 74 } |
61 | 75 |
62 void CocoaTest::Init() { | 76 void CocoaTest::Init() { |
63 // Set the duration of AppKit-evaluated animations (such as frame changes) | 77 // Set the duration of AppKit-evaluated animations (such as frame changes) |
64 // to zero for testing purposes. That way they take effect immediately. | 78 // to zero for testing purposes. That way they take effect immediately. |
65 [[NSAnimationContext currentContext] setDuration:0.0]; | 79 [[NSAnimationContext currentContext] setDuration:0.0]; |
66 | 80 |
67 // The above does not affect window-resize time, such as for an | 81 // The above does not affect window-resize time, such as for an |
68 // attached sheet dropping in. Set that duration for the current | 82 // attached sheet dropping in. Set that duration for the current |
69 // process (this is not persisted). Empirically, the value of 0.0 | 83 // process (this is not persisted). Empirically, the value of 0.0 |
70 // is ignored. | 84 // is ignored. |
71 NSDictionary* dict = | 85 NSDictionary* dict = |
72 [NSDictionary dictionaryWithObject:@"0.01" forKey:@"NSWindowResizeTime"]; | 86 [NSDictionary dictionaryWithObject:@"0.01" forKey:@"NSWindowResizeTime"]; |
73 [[NSUserDefaults standardUserDefaults] registerDefaults:dict]; | 87 [[NSUserDefaults standardUserDefaults] registerDefaults:dict]; |
74 | 88 |
75 // Collect the list of windows that were open when the test started so | 89 // Collect the list of windows that were open when the test started so |
76 // that we don't wait for them to close in TearDown. Has to be done | 90 // that we don't wait for them to close in TearDown. Has to be done |
77 // after BootstrapCocoa is called. | 91 // after BootstrapCocoa is called. |
78 initial_windows_ = ApplicationWindows(); | 92 initial_windows_ = ApplicationWindows(); |
93 | |
94 ForceSystemLeaks(); | |
Scott Hess - ex-Googler
2014/05/30 23:58:06
Stepping back and putting on my "What would anothe
groby-ooo-7-16
2014/05/31 00:37:04
Moved to top of ctor.
| |
79 } | 95 } |
80 | 96 |
81 void CocoaTest::TearDown() { | 97 void CocoaTest::TearDown() { |
82 called_tear_down_ = true; | 98 called_tear_down_ = true; |
83 // Call close on our test_window to clean it up if one was opened. | 99 // Call close on our test_window to clean it up if one was opened. |
84 [test_window_ clearPretendKeyWindowAndFirstResponder]; | 100 [test_window_ clearPretendKeyWindowAndFirstResponder]; |
85 [test_window_ close]; | 101 [test_window_ close]; |
86 test_window_ = nil; | 102 test_window_ = nil; |
87 | 103 |
88 // Recycle the pool to clean up any stuff that was put on the | 104 // Recycle the pool to clean up any stuff that was put on the |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
191 if (base::debug::BeingDebugged()) { | 207 if (base::debug::BeingDebugged()) { |
192 [test_window_ orderFront:nil]; | 208 [test_window_ orderFront:nil]; |
193 } else { | 209 } else { |
194 [test_window_ orderBack:nil]; | 210 [test_window_ orderBack:nil]; |
195 } | 211 } |
196 } | 212 } |
197 return test_window_; | 213 return test_window_; |
198 } | 214 } |
199 | 215 |
200 } // namespace ui | 216 } // namespace ui |
OLD | NEW |