| 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/cocoa/cocoa_test_helper.h" | 5 #import "chrome/browser/cocoa/cocoa_test_helper.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/test/test_timeouts.h" | 8 #include "base/test/test_timeouts.h" |
| 9 #import "chrome/browser/chrome_browser_application_mac.h" | 9 #import "chrome/browser/chrome_browser_application_mac.h" |
| 10 | 10 |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 bool one_more_time = true; | 117 bool one_more_time = true; |
| 118 int spins = 0; | 118 int spins = 0; |
| 119 while (still_left.size() == windows_left.size() && | 119 while (still_left.size() == windows_left.size() && |
| 120 (spins < kCloseSpins || one_more_time)) { | 120 (spins < kCloseSpins || one_more_time)) { |
| 121 // Check the timeout before pumping events, so that we'll spin | 121 // Check the timeout before pumping events, so that we'll spin |
| 122 // the loop once after the timeout. | 122 // the loop once after the timeout. |
| 123 one_more_time = ([start_date timeIntervalSinceNow] > -kCloseTimeoutSeconds
); | 123 one_more_time = ([start_date timeIntervalSinceNow] > -kCloseTimeoutSeconds
); |
| 124 | 124 |
| 125 // Autorelease anything thrown up by the event loop. | 125 // Autorelease anything thrown up by the event loop. |
| 126 { | 126 { |
| 127 base::ScopedNSAutoreleasePool pool; | 127 base::mac::ScopedNSAutoreleasePool pool; |
| 128 ++spins; | 128 ++spins; |
| 129 NSEvent *next_event = [NSApp nextEventMatchingMask:NSAnyEventMask | 129 NSEvent *next_event = [NSApp nextEventMatchingMask:NSAnyEventMask |
| 130 untilDate:nil | 130 untilDate:nil |
| 131 inMode:NSDefaultRunLoopMode | 131 inMode:NSDefaultRunLoopMode |
| 132 dequeue:YES]; | 132 dequeue:YES]; |
| 133 [NSApp sendEvent:next_event]; | 133 [NSApp sendEvent:next_event]; |
| 134 [NSApp updateWindows]; | 134 [NSApp updateWindows]; |
| 135 } | 135 } |
| 136 | 136 |
| 137 // Refresh the outstanding windows. | 137 // Refresh the outstanding windows. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 157 } | 157 } |
| 158 PlatformTest::TearDown(); | 158 PlatformTest::TearDown(); |
| 159 } | 159 } |
| 160 | 160 |
| 161 std::set<NSWindow*> CocoaTest::ApplicationWindows() { | 161 std::set<NSWindow*> CocoaTest::ApplicationWindows() { |
| 162 // This must NOT retain the windows it is returning. | 162 // This must NOT retain the windows it is returning. |
| 163 std::set<NSWindow*> windows; | 163 std::set<NSWindow*> windows; |
| 164 | 164 |
| 165 // Must create a pool here because [NSApp windows] has created an array | 165 // Must create a pool here because [NSApp windows] has created an array |
| 166 // with retains on all the windows in it. | 166 // with retains on all the windows in it. |
| 167 base::ScopedNSAutoreleasePool pool; | 167 base::mac::ScopedNSAutoreleasePool pool; |
| 168 NSArray *appWindows = [NSApp windows]; | 168 NSArray *appWindows = [NSApp windows]; |
| 169 for (NSWindow *window in appWindows) { | 169 for (NSWindow *window in appWindows) { |
| 170 windows.insert(window); | 170 windows.insert(window); |
| 171 } | 171 } |
| 172 return windows; | 172 return windows; |
| 173 } | 173 } |
| 174 | 174 |
| 175 std::set<NSWindow*> CocoaTest::WindowsLeft() { | 175 std::set<NSWindow*> CocoaTest::WindowsLeft() { |
| 176 const std::set<NSWindow*> windows(ApplicationWindows()); | 176 const std::set<NSWindow*> windows(ApplicationWindows()); |
| 177 std::set<NSWindow*> windows_left; | 177 std::set<NSWindow*> windows_left; |
| 178 std::set_difference(windows.begin(), windows.end(), | 178 std::set_difference(windows.begin(), windows.end(), |
| 179 initial_windows_.begin(), initial_windows_.end(), | 179 initial_windows_.begin(), initial_windows_.end(), |
| 180 std::inserter(windows_left, windows_left.begin())); | 180 std::inserter(windows_left, windows_left.begin())); |
| 181 return windows_left; | 181 return windows_left; |
| 182 } | 182 } |
| 183 | 183 |
| 184 CocoaTestHelperWindow* CocoaTest::test_window() { | 184 CocoaTestHelperWindow* CocoaTest::test_window() { |
| 185 if (!test_window_) { | 185 if (!test_window_) { |
| 186 test_window_ = [[CocoaTestHelperWindow alloc] init]; | 186 test_window_ = [[CocoaTestHelperWindow alloc] init]; |
| 187 if (DebugUtil::BeingDebugged()) { | 187 if (DebugUtil::BeingDebugged()) { |
| 188 [test_window_ orderFront:nil]; | 188 [test_window_ orderFront:nil]; |
| 189 } else { | 189 } else { |
| 190 [test_window_ orderBack:nil]; | 190 [test_window_ orderBack:nil]; |
| 191 } | 191 } |
| 192 } | 192 } |
| 193 return test_window_; | 193 return test_window_; |
| 194 } | 194 } |
| OLD | NEW |