| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #include "extensions/test/extension_test_notification_observer.h" | 5 #include "extensions/test/extension_test_notification_observer.h" |
| 6 | 6 |
| 7 #include "content/public/browser/browser_context.h" | 7 #include "content/public/browser/browser_context.h" |
| 8 #include "content/public/browser/notification_details.h" | 8 #include "content/public/browser/notification_details.h" |
| 9 #include "content/public/browser/notification_registrar.h" | 9 #include "content/public/browser/notification_registrar.h" |
| 10 #include "content/public/browser/notification_service.h" | 10 #include "content/public/browser/notification_service.h" |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 void ExtensionTestNotificationObserver::Watch( | 133 void ExtensionTestNotificationObserver::Watch( |
| 134 int type, | 134 int type, |
| 135 const content::NotificationSource& source) { | 135 const content::NotificationSource& source) { |
| 136 CHECK(!observer_); | 136 CHECK(!observer_); |
| 137 observer_.reset(new content::WindowedNotificationObserver(type, source)); | 137 observer_.reset(new content::WindowedNotificationObserver(type, source)); |
| 138 registrar_.Add(this, type, source); | 138 registrar_.Add(this, type, source); |
| 139 } | 139 } |
| 140 | 140 |
| 141 void ExtensionTestNotificationObserver::Wait() { | 141 void ExtensionTestNotificationObserver::Wait() { |
| 142 observer_->Wait(); | 142 observer_->Wait(); |
| 143 // TODO(...): Find out why tests fail without it. |
| 144 // content::RunAllPendingInMessageLoop(); |
| 143 | 145 |
| 144 registrar_.RemoveAll(); | 146 registrar_.RemoveAll(); |
| 145 observer_.reset(); | 147 observer_.reset(); |
| 146 } | 148 } |
| 147 | 149 |
| 148 void ExtensionTestNotificationObserver::Observe( | 150 void ExtensionTestNotificationObserver::Observe( |
| 149 int type, | 151 int type, |
| 150 const content::NotificationSource& source, | 152 const content::NotificationSource& source, |
| 151 const content::NotificationDetails& details) { | 153 const content::NotificationDetails& details) { |
| 152 switch (type) { | 154 switch (type) { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 180 } | 182 } |
| 181 } | 183 } |
| 182 | 184 |
| 183 void ExtensionTestNotificationObserver::WaitForCondition( | 185 void ExtensionTestNotificationObserver::WaitForCondition( |
| 184 const ConditionCallback& condition, | 186 const ConditionCallback& condition, |
| 185 NotificationSet* notification_set) { | 187 NotificationSet* notification_set) { |
| 186 if (condition.Run()) | 188 if (condition.Run()) |
| 187 return; | 189 return; |
| 188 condition_ = condition; | 190 condition_ = condition; |
| 189 | 191 |
| 190 scoped_refptr<content::MessageLoopRunner> runner( | 192 base::RunLoop run_loop; |
| 191 new content::MessageLoopRunner); | 193 quit_closure_ = run_loop.QuitClosure(); |
| 192 quit_closure_ = runner->QuitClosure(); | |
| 193 | 194 |
| 194 std::unique_ptr<base::CallbackList<void()>::Subscription> subscription; | 195 std::unique_ptr<base::CallbackList<void()>::Subscription> subscription; |
| 195 if (notification_set) { | 196 if (notification_set) { |
| 196 subscription = notification_set->callback_list().Add(base::Bind( | 197 subscription = notification_set->callback_list().Add(base::Bind( |
| 197 &ExtensionTestNotificationObserver::MaybeQuit, base::Unretained(this))); | 198 &ExtensionTestNotificationObserver::MaybeQuit, base::Unretained(this))); |
| 198 } | 199 } |
| 199 runner->Run(); | 200 run_loop.Run(); |
| 200 | 201 |
| 201 condition_.Reset(); | 202 condition_.Reset(); |
| 202 quit_closure_.Reset(); | 203 quit_closure_.Reset(); |
| 203 } | 204 } |
| 204 | 205 |
| 205 void ExtensionTestNotificationObserver::MaybeQuit() { | 206 void ExtensionTestNotificationObserver::MaybeQuit() { |
| 206 if (condition_.Run()) | 207 if (condition_.Run()) |
| 207 quit_closure_.Run(); | 208 quit_closure_.Run(); |
| 208 } | 209 } |
| 209 | 210 |
| 210 } // namespace extensions | 211 } // namespace extensions |
| OLD | NEW |