| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef CONTENT_PUBLIC_TEST_TEST_UTILS_H_ | 5 #ifndef CONTENT_PUBLIC_TEST_TEST_UTILS_H_ |
| 6 #define CONTENT_PUBLIC_TEST_TEST_UTILS_H_ | 6 #define CONTENT_PUBLIC_TEST_TEST_UTILS_H_ |
| 7 | 7 |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 | 141 |
| 142 // Set up to wait for a complex condition. The condition is met when | 142 // Set up to wait for a complex condition. The condition is met when |
| 143 // |callback| returns |true|. The callback is invoked whenever a notification | 143 // |callback| returns |true|. The callback is invoked whenever a notification |
| 144 // of |notification_type| from any source is received. | 144 // of |notification_type| from any source is received. |
| 145 WindowedNotificationObserver(int notification_type, | 145 WindowedNotificationObserver(int notification_type, |
| 146 const ConditionTestCallback& callback); | 146 const ConditionTestCallback& callback); |
| 147 WindowedNotificationObserver( | 147 WindowedNotificationObserver( |
| 148 int notification_type, | 148 int notification_type, |
| 149 const ConditionTestCallbackWithoutSourceAndDetails& callback); | 149 const ConditionTestCallbackWithoutSourceAndDetails& callback); |
| 150 | 150 |
| 151 virtual ~WindowedNotificationObserver(); | 151 ~WindowedNotificationObserver() override; |
| 152 | 152 |
| 153 // Adds an additional notification type to wait for. The condition will be met | 153 // Adds an additional notification type to wait for. The condition will be met |
| 154 // if any of the registered notification types from their respective sources | 154 // if any of the registered notification types from their respective sources |
| 155 // is received. | 155 // is received. |
| 156 void AddNotificationType(int notification_type, | 156 void AddNotificationType(int notification_type, |
| 157 const NotificationSource& source); | 157 const NotificationSource& source); |
| 158 | 158 |
| 159 // Wait until the specified condition is met. If the condition is already met | 159 // Wait until the specified condition is met. If the condition is already met |
| 160 // (that is, the expected notification has already been received or the | 160 // (that is, the expected notification has already been received or the |
| 161 // given callback returns |true| already), Wait() returns immediately. | 161 // given callback returns |true| already), Wait() returns immediately. |
| 162 void Wait(); | 162 void Wait(); |
| 163 | 163 |
| 164 // Returns NotificationService::AllSources() if we haven't observed a | 164 // Returns NotificationService::AllSources() if we haven't observed a |
| 165 // notification yet. | 165 // notification yet. |
| 166 const NotificationSource& source() const { | 166 const NotificationSource& source() const { |
| 167 return source_; | 167 return source_; |
| 168 } | 168 } |
| 169 | 169 |
| 170 const NotificationDetails& details() const { | 170 const NotificationDetails& details() const { |
| 171 return details_; | 171 return details_; |
| 172 } | 172 } |
| 173 | 173 |
| 174 // NotificationObserver: | 174 // NotificationObserver: |
| 175 virtual void Observe(int type, | 175 void Observe(int type, |
| 176 const NotificationSource& source, | 176 const NotificationSource& source, |
| 177 const NotificationDetails& details) override; | 177 const NotificationDetails& details) override; |
| 178 | 178 |
| 179 private: | 179 private: |
| 180 bool seen_; | 180 bool seen_; |
| 181 bool running_; | 181 bool running_; |
| 182 NotificationRegistrar registrar_; | 182 NotificationRegistrar registrar_; |
| 183 | 183 |
| 184 ConditionTestCallback callback_; | 184 ConditionTestCallback callback_; |
| 185 | 185 |
| 186 NotificationSource source_; | 186 NotificationSource source_; |
| 187 NotificationDetails details_; | 187 NotificationDetails details_; |
| 188 scoped_refptr<MessageLoopRunner> message_loop_runner_; | 188 scoped_refptr<MessageLoopRunner> message_loop_runner_; |
| 189 | 189 |
| 190 DISALLOW_COPY_AND_ASSIGN(WindowedNotificationObserver); | 190 DISALLOW_COPY_AND_ASSIGN(WindowedNotificationObserver); |
| 191 }; | 191 }; |
| 192 | 192 |
| 193 // Unit tests can use code which runs in the utility process by having it run on | 193 // Unit tests can use code which runs in the utility process by having it run on |
| 194 // an in-process utility thread. This eliminates having two code paths in | 194 // an in-process utility thread. This eliminates having two code paths in |
| 195 // production code to deal with unit tests, and also helps with the binary | 195 // production code to deal with unit tests, and also helps with the binary |
| 196 // separation on Windows since chrome.dll doesn't need to call into Blink code | 196 // separation on Windows since chrome.dll doesn't need to call into Blink code |
| 197 // for some utility code to handle the single process case. | 197 // for some utility code to handle the single process case. |
| 198 // Include this class as a member variable in your test harness if you take | 198 // Include this class as a member variable in your test harness if you take |
| 199 // advantage of this functionality to ensure that the in-process utility thread | 199 // advantage of this functionality to ensure that the in-process utility thread |
| 200 // is torn down correctly. See http://crbug.com/316919 for more information. | 200 // is torn down correctly. See http://crbug.com/316919 for more information. |
| 201 // Note: this class should be declared after the TestBrowserThreadBundle and | 201 // Note: this class should be declared after the TestBrowserThreadBundle and |
| 202 // ShadowingAtExitManager (if it exists) as it will need to be run before they | 202 // ShadowingAtExitManager (if it exists) as it will need to be run before they |
| 203 // are torn down. | 203 // are torn down. |
| 204 class InProcessUtilityThreadHelper : public BrowserChildProcessObserver { | 204 class InProcessUtilityThreadHelper : public BrowserChildProcessObserver { |
| 205 public: | 205 public: |
| 206 InProcessUtilityThreadHelper(); | 206 InProcessUtilityThreadHelper(); |
| 207 virtual ~InProcessUtilityThreadHelper(); | 207 ~InProcessUtilityThreadHelper() override; |
| 208 | 208 |
| 209 private: | 209 private: |
| 210 virtual void BrowserChildProcessHostConnected( | 210 void BrowserChildProcessHostConnected(const ChildProcessData& data) override; |
| 211 const ChildProcessData& data) override; | 211 void BrowserChildProcessHostDisconnected( |
| 212 virtual void BrowserChildProcessHostDisconnected( | |
| 213 const ChildProcessData& data) override; | 212 const ChildProcessData& data) override; |
| 214 | 213 |
| 215 int child_thread_count_; | 214 int child_thread_count_; |
| 216 scoped_refptr<MessageLoopRunner> runner_; | 215 scoped_refptr<MessageLoopRunner> runner_; |
| 217 | 216 |
| 218 DISALLOW_COPY_AND_ASSIGN(InProcessUtilityThreadHelper); | 217 DISALLOW_COPY_AND_ASSIGN(InProcessUtilityThreadHelper); |
| 219 }; | 218 }; |
| 220 | 219 |
| 221 } // namespace content | 220 } // namespace content |
| 222 | 221 |
| 223 #endif // CONTENT_PUBLIC_TEST_TEST_UTILS_H_ | 222 #endif // CONTENT_PUBLIC_TEST_TEST_UTILS_H_ |
| OLD | NEW |