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