OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/cocoa_test_helper.h" | 5 #import "chrome/browser/ui/cocoa/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/mac/mac_util.h" |
9 #include "base/test/test_timeouts.h" | 10 #include "base/test/test_timeouts.h" |
10 #import "chrome/browser/chrome_browser_application_mac.h" | 11 #import "chrome/browser/chrome_browser_application_mac.h" |
11 | 12 |
12 @implementation CocoaTestHelperWindow | 13 @implementation CocoaTestHelperWindow |
13 | 14 |
14 - (id)initWithContentRect:(NSRect)contentRect { | 15 - (id)initWithContentRect:(NSRect)contentRect { |
15 return [self initWithContentRect:contentRect | 16 return [self initWithContentRect:contentRect |
16 styleMask:NSBorderlessWindowMask | 17 styleMask:NSBorderlessWindowMask |
17 backing:NSBackingStoreBuffered | 18 backing:NSBackingStoreBuffered |
18 defer:NO]; | 19 defer:NO]; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 CocoaTest::~CocoaTest() { | 73 CocoaTest::~CocoaTest() { |
73 // Must call CocoaTest's teardown from your overrides. | 74 // Must call CocoaTest's teardown from your overrides. |
74 DCHECK(called_tear_down_); | 75 DCHECK(called_tear_down_); |
75 } | 76 } |
76 | 77 |
77 void CocoaTest::BootstrapCocoa() { | 78 void CocoaTest::BootstrapCocoa() { |
78 // Look in the framework bundle for resources. | 79 // Look in the framework bundle for resources. |
79 FilePath path; | 80 FilePath path; |
80 PathService::Get(base::DIR_EXE, &path); | 81 PathService::Get(base::DIR_EXE, &path); |
81 path = path.Append(chrome::kFrameworkName); | 82 path = path.Append(chrome::kFrameworkName); |
82 mac_util::SetOverrideAppBundlePath(path); | 83 base::mac::SetOverrideAppBundlePath(path); |
83 | 84 |
84 // Bootstrap Cocoa. It's very unhappy without this. | 85 // Bootstrap Cocoa. It's very unhappy without this. |
85 [CrApplication sharedApplication]; | 86 [CrApplication sharedApplication]; |
86 } | 87 } |
87 | 88 |
88 void CocoaTest::TearDown() { | 89 void CocoaTest::TearDown() { |
89 called_tear_down_ = true; | 90 called_tear_down_ = true; |
90 // Call close on our test_window to clean it up if one was opened. | 91 // Call close on our test_window to clean it up if one was opened. |
91 [test_window_ close]; | 92 [test_window_ close]; |
92 test_window_ = nil; | 93 test_window_ = nil; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 // reset if progress is made. | 125 // reset if progress is made. |
125 std::set<NSWindow*> still_left = windows_left; | 126 std::set<NSWindow*> still_left = windows_left; |
126 | 127 |
127 NSDate* start_date = [NSDate date]; | 128 NSDate* start_date = [NSDate date]; |
128 bool one_more_time = true; | 129 bool one_more_time = true; |
129 int spins = 0; | 130 int spins = 0; |
130 while (still_left.size() == windows_left.size() && | 131 while (still_left.size() == windows_left.size() && |
131 (spins < kCloseSpins || one_more_time)) { | 132 (spins < kCloseSpins || one_more_time)) { |
132 // Check the timeout before pumping events, so that we'll spin | 133 // Check the timeout before pumping events, so that we'll spin |
133 // the loop once after the timeout. | 134 // the loop once after the timeout. |
134 one_more_time = ([start_date timeIntervalSinceNow] > -kCloseTimeoutSeconds
); | 135 one_more_time = |
| 136 ([start_date timeIntervalSinceNow] > -kCloseTimeoutSeconds); |
135 | 137 |
136 // Autorelease anything thrown up by the event loop. | 138 // Autorelease anything thrown up by the event loop. |
137 { | 139 { |
138 base::mac::ScopedNSAutoreleasePool pool; | 140 base::mac::ScopedNSAutoreleasePool pool; |
139 ++spins; | 141 ++spins; |
140 NSEvent *next_event = [NSApp nextEventMatchingMask:NSAnyEventMask | 142 NSEvent *next_event = [NSApp nextEventMatchingMask:NSAnyEventMask |
141 untilDate:nil | 143 untilDate:nil |
142 inMode:NSDefaultRunLoopMode | 144 inMode:NSDefaultRunLoopMode |
143 dequeue:YES]; | 145 dequeue:YES]; |
144 [NSApp sendEvent:next_event]; | 146 [NSApp sendEvent:next_event]; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 if (!test_window_) { | 198 if (!test_window_) { |
197 test_window_ = [[CocoaTestHelperWindow alloc] init]; | 199 test_window_ = [[CocoaTestHelperWindow alloc] init]; |
198 if (base::debug::BeingDebugged()) { | 200 if (base::debug::BeingDebugged()) { |
199 [test_window_ orderFront:nil]; | 201 [test_window_ orderFront:nil]; |
200 } else { | 202 } else { |
201 [test_window_ orderBack:nil]; | 203 [test_window_ orderBack:nil]; |
202 } | 204 } |
203 } | 205 } |
204 return test_window_; | 206 return test_window_; |
205 } | 207 } |
OLD | NEW |