| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/base/test/windowed_nsnotification_observer.h" | 5 #import "ui/base/test/windowed_nsnotification_observer.h" |
| 6 | 6 |
| 7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
| 8 | 8 |
| 9 #include "base/location.h" |
| 9 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| 11 #include "base/single_thread_task_runner.h" |
| 10 #include "base/test/test_timeouts.h" | 12 #include "base/test/test_timeouts.h" |
| 13 #include "base/threading/thread_task_runner_handle.h" |
| 11 | 14 |
| 12 @interface WindowedNSNotificationObserver () | 15 @interface WindowedNSNotificationObserver () |
| 13 - (void)onNotification:(NSNotification*)notification; | 16 - (void)onNotification:(NSNotification*)notification; |
| 14 @end | 17 @end |
| 15 | 18 |
| 16 @implementation WindowedNSNotificationObserver | 19 @implementation WindowedNSNotificationObserver |
| 17 | 20 |
| 18 @synthesize notificationCount = notificationCount_; | 21 @synthesize notificationCount = notificationCount_; |
| 19 | 22 |
| 20 - (id)initForNotification:(NSString*)name { | 23 - (id)initForNotification:(NSString*)name { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 | 65 |
| 63 ++notificationCount_; | 66 ++notificationCount_; |
| 64 if (runLoop_) | 67 if (runLoop_) |
| 65 runLoop_->Quit(); | 68 runLoop_->Quit(); |
| 66 } | 69 } |
| 67 | 70 |
| 68 - (BOOL)waitForCount:(int)minimumCount { | 71 - (BOOL)waitForCount:(int)minimumCount { |
| 69 while (notificationCount_ < minimumCount) { | 72 while (notificationCount_ < minimumCount) { |
| 70 const int oldCount = notificationCount_; | 73 const int oldCount = notificationCount_; |
| 71 base::RunLoop runLoop; | 74 base::RunLoop runLoop; |
| 72 base::MessageLoop::current()->task_runner()->PostDelayedTask( | 75 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 73 FROM_HERE, runLoop.QuitClosure(), TestTimeouts::action_timeout()); | 76 FROM_HERE, runLoop.QuitClosure(), TestTimeouts::action_timeout()); |
| 74 runLoop_ = &runLoop; | 77 runLoop_ = &runLoop; |
| 75 runLoop.Run(); | 78 runLoop.Run(); |
| 76 runLoop_ = nullptr; | 79 runLoop_ = nullptr; |
| 77 | 80 |
| 78 // If there was no new notification, it must have been a timeout. | 81 // If there was no new notification, it must have been a timeout. |
| 79 if (notificationCount_ == oldCount) | 82 if (notificationCount_ == oldCount) |
| 80 break; | 83 break; |
| 81 } | 84 } |
| 82 return notificationCount_ >= minimumCount; | 85 return notificationCount_ >= minimumCount; |
| 83 } | 86 } |
| 84 | 87 |
| 85 - (BOOL)wait { | 88 - (BOOL)wait { |
| 86 return [self waitForCount:1]; | 89 return [self waitForCount:1]; |
| 87 } | 90 } |
| 88 | 91 |
| 89 @end | 92 @end |
| OLD | NEW |