| 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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 | 143 |
| 144 // TODO(https://crbug.com/695073): Find out why tests fail without it. | |
| 145 content::RunAllPendingInMessageLoop(); | |
| 146 | |
| 147 registrar_.RemoveAll(); | 144 registrar_.RemoveAll(); |
| 148 observer_.reset(); | 145 observer_.reset(); |
| 149 } | 146 } |
| 150 | 147 |
| 151 void ExtensionTestNotificationObserver::Observe( | 148 void ExtensionTestNotificationObserver::Observe( |
| 152 int type, | 149 int type, |
| 153 const content::NotificationSource& source, | 150 const content::NotificationSource& source, |
| 154 const content::NotificationDetails& details) { | 151 const content::NotificationDetails& details) { |
| 155 switch (type) { | 152 switch (type) { |
| 156 case NOTIFICATION_EXTENSION_LOADED_DEPRECATED: | 153 case NOTIFICATION_EXTENSION_LOADED_DEPRECATED: |
| (...skipping 26 matching lines...) Expand all Loading... |
| 183 } | 180 } |
| 184 } | 181 } |
| 185 | 182 |
| 186 void ExtensionTestNotificationObserver::WaitForCondition( | 183 void ExtensionTestNotificationObserver::WaitForCondition( |
| 187 const ConditionCallback& condition, | 184 const ConditionCallback& condition, |
| 188 NotificationSet* notification_set) { | 185 NotificationSet* notification_set) { |
| 189 if (condition.Run()) | 186 if (condition.Run()) |
| 190 return; | 187 return; |
| 191 condition_ = condition; | 188 condition_ = condition; |
| 192 | 189 |
| 193 base::RunLoop run_loop; | 190 scoped_refptr<content::MessageLoopRunner> runner( |
| 194 quit_closure_ = run_loop.QuitClosure(); | 191 new content::MessageLoopRunner); |
| 192 quit_closure_ = runner->QuitClosure(); |
| 195 | 193 |
| 196 std::unique_ptr<base::CallbackList<void()>::Subscription> subscription; | 194 std::unique_ptr<base::CallbackList<void()>::Subscription> subscription; |
| 197 if (notification_set) { | 195 if (notification_set) { |
| 198 subscription = notification_set->callback_list().Add(base::Bind( | 196 subscription = notification_set->callback_list().Add(base::Bind( |
| 199 &ExtensionTestNotificationObserver::MaybeQuit, base::Unretained(this))); | 197 &ExtensionTestNotificationObserver::MaybeQuit, base::Unretained(this))); |
| 200 } | 198 } |
| 201 run_loop.Run(); | 199 runner->Run(); |
| 202 | 200 |
| 203 condition_.Reset(); | 201 condition_.Reset(); |
| 204 quit_closure_.Reset(); | 202 quit_closure_.Reset(); |
| 205 } | 203 } |
| 206 | 204 |
| 207 void ExtensionTestNotificationObserver::MaybeQuit() { | 205 void ExtensionTestNotificationObserver::MaybeQuit() { |
| 208 if (condition_.Run()) | 206 if (condition_.Run()) |
| 209 quit_closure_.Run(); | 207 quit_closure_.Run(); |
| 210 } | 208 } |
| 211 | 209 |
| 212 } // namespace extensions | 210 } // namespace extensions |
| OLD | NEW |