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_BROWSER_TEST_UTILS_H_ | 5 #ifndef CONTENT_PUBLIC_TEST_BROWSER_TEST_UTILS_H_ |
6 #define CONTENT_PUBLIC_TEST_BROWSER_TEST_UTILS_H_ | 6 #define CONTENT_PUBLIC_TEST_BROWSER_TEST_UTILS_H_ |
7 | 7 |
8 #include <queue> | 8 #include <queue> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 // Adds another title to watch for. | 220 // Adds another title to watch for. |
221 void AlsoWaitForTitle(const base::string16& expected_title); | 221 void AlsoWaitForTitle(const base::string16& expected_title); |
222 | 222 |
223 // Waits until the title matches either expected_title or one of the titles | 223 // Waits until the title matches either expected_title or one of the titles |
224 // added with AlsoWaitForTitle. Returns the value of the most recently | 224 // added with AlsoWaitForTitle. Returns the value of the most recently |
225 // observed matching title. | 225 // observed matching title. |
226 const base::string16& WaitAndGetTitle() WARN_UNUSED_RESULT; | 226 const base::string16& WaitAndGetTitle() WARN_UNUSED_RESULT; |
227 | 227 |
228 private: | 228 private: |
229 // Overridden WebContentsObserver methods. | 229 // Overridden WebContentsObserver methods. |
230 virtual void DidStopLoading(RenderViewHost* render_view_host) OVERRIDE; | 230 virtual void DidStopLoading(RenderViewHost* render_view_host) override; |
231 virtual void TitleWasSet(NavigationEntry* entry, bool explicit_set) OVERRIDE; | 231 virtual void TitleWasSet(NavigationEntry* entry, bool explicit_set) override; |
232 | 232 |
233 void TestTitle(); | 233 void TestTitle(); |
234 | 234 |
235 std::vector<base::string16> expected_titles_; | 235 std::vector<base::string16> expected_titles_; |
236 scoped_refptr<MessageLoopRunner> message_loop_runner_; | 236 scoped_refptr<MessageLoopRunner> message_loop_runner_; |
237 | 237 |
238 // The most recently observed expected title, if any. | 238 // The most recently observed expected title, if any. |
239 base::string16 observed_title_; | 239 base::string16 observed_title_; |
240 | 240 |
241 DISALLOW_COPY_AND_ASSIGN(TitleWatcher); | 241 DISALLOW_COPY_AND_ASSIGN(TitleWatcher); |
242 }; | 242 }; |
243 | 243 |
244 // Watches a WebContents and blocks until it is destroyed. | 244 // Watches a WebContents and blocks until it is destroyed. |
245 class WebContentsDestroyedWatcher : public WebContentsObserver { | 245 class WebContentsDestroyedWatcher : public WebContentsObserver { |
246 public: | 246 public: |
247 explicit WebContentsDestroyedWatcher(WebContents* web_contents); | 247 explicit WebContentsDestroyedWatcher(WebContents* web_contents); |
248 virtual ~WebContentsDestroyedWatcher(); | 248 virtual ~WebContentsDestroyedWatcher(); |
249 | 249 |
250 // Waits until the WebContents is destroyed. | 250 // Waits until the WebContents is destroyed. |
251 void Wait(); | 251 void Wait(); |
252 | 252 |
253 private: | 253 private: |
254 // Overridden WebContentsObserver methods. | 254 // Overridden WebContentsObserver methods. |
255 virtual void WebContentsDestroyed() OVERRIDE; | 255 virtual void WebContentsDestroyed() override; |
256 | 256 |
257 scoped_refptr<MessageLoopRunner> message_loop_runner_; | 257 scoped_refptr<MessageLoopRunner> message_loop_runner_; |
258 | 258 |
259 DISALLOW_COPY_AND_ASSIGN(WebContentsDestroyedWatcher); | 259 DISALLOW_COPY_AND_ASSIGN(WebContentsDestroyedWatcher); |
260 }; | 260 }; |
261 | 261 |
262 // Watches a RenderProcessHost and waits for specified destruction events. | 262 // Watches a RenderProcessHost and waits for specified destruction events. |
263 class RenderProcessHostWatcher : public RenderProcessHostObserver { | 263 class RenderProcessHostWatcher : public RenderProcessHostObserver { |
264 public: | 264 public: |
265 enum WatchType { | 265 enum WatchType { |
266 WATCH_FOR_PROCESS_EXIT, | 266 WATCH_FOR_PROCESS_EXIT, |
267 WATCH_FOR_HOST_DESTRUCTION | 267 WATCH_FOR_HOST_DESTRUCTION |
268 }; | 268 }; |
269 | 269 |
270 RenderProcessHostWatcher(RenderProcessHost* render_process_host, | 270 RenderProcessHostWatcher(RenderProcessHost* render_process_host, |
271 WatchType type); | 271 WatchType type); |
272 // Waits for the render process that contains the specified web contents. | 272 // Waits for the render process that contains the specified web contents. |
273 RenderProcessHostWatcher(WebContents* web_contents, WatchType type); | 273 RenderProcessHostWatcher(WebContents* web_contents, WatchType type); |
274 virtual ~RenderProcessHostWatcher(); | 274 virtual ~RenderProcessHostWatcher(); |
275 | 275 |
276 // Waits until the renderer process exits. | 276 // Waits until the renderer process exits. |
277 void Wait(); | 277 void Wait(); |
278 | 278 |
279 private: | 279 private: |
280 // Overridden RenderProcessHost::LifecycleObserver methods. | 280 // Overridden RenderProcessHost::LifecycleObserver methods. |
281 virtual void RenderProcessExited(RenderProcessHost* host, | 281 virtual void RenderProcessExited(RenderProcessHost* host, |
282 base::ProcessHandle handle, | 282 base::ProcessHandle handle, |
283 base::TerminationStatus status, | 283 base::TerminationStatus status, |
284 int exit_code) OVERRIDE; | 284 int exit_code) override; |
285 virtual void RenderProcessHostDestroyed(RenderProcessHost* host) OVERRIDE; | 285 virtual void RenderProcessHostDestroyed(RenderProcessHost* host) override; |
286 | 286 |
287 RenderProcessHost* render_process_host_; | 287 RenderProcessHost* render_process_host_; |
288 WatchType type_; | 288 WatchType type_; |
289 | 289 |
290 scoped_refptr<MessageLoopRunner> message_loop_runner_; | 290 scoped_refptr<MessageLoopRunner> message_loop_runner_; |
291 | 291 |
292 DISALLOW_COPY_AND_ASSIGN(RenderProcessHostWatcher); | 292 DISALLOW_COPY_AND_ASSIGN(RenderProcessHostWatcher); |
293 }; | 293 }; |
294 | 294 |
295 // Watches for responses from the DOMAutomationController and keeps them in a | 295 // Watches for responses from the DOMAutomationController and keeps them in a |
296 // queue. Useful for waiting for a message to be received. | 296 // queue. Useful for waiting for a message to be received. |
297 class DOMMessageQueue : public NotificationObserver { | 297 class DOMMessageQueue : public NotificationObserver { |
298 public: | 298 public: |
299 // Constructs a DOMMessageQueue and begins listening for messages from the | 299 // Constructs a DOMMessageQueue and begins listening for messages from the |
300 // DOMAutomationController. Do not construct this until the browser has | 300 // DOMAutomationController. Do not construct this until the browser has |
301 // started. | 301 // started. |
302 DOMMessageQueue(); | 302 DOMMessageQueue(); |
303 virtual ~DOMMessageQueue(); | 303 virtual ~DOMMessageQueue(); |
304 | 304 |
305 // Removes all messages in the message queue. | 305 // Removes all messages in the message queue. |
306 void ClearQueue(); | 306 void ClearQueue(); |
307 | 307 |
308 // Wait for the next message to arrive. |message| will be set to the next | 308 // Wait for the next message to arrive. |message| will be set to the next |
309 // message. Returns true on success. | 309 // message. Returns true on success. |
310 bool WaitForMessage(std::string* message) WARN_UNUSED_RESULT; | 310 bool WaitForMessage(std::string* message) WARN_UNUSED_RESULT; |
311 | 311 |
312 // Overridden NotificationObserver methods. | 312 // Overridden NotificationObserver methods. |
313 virtual void Observe(int type, | 313 virtual void Observe(int type, |
314 const NotificationSource& source, | 314 const NotificationSource& source, |
315 const NotificationDetails& details) OVERRIDE; | 315 const NotificationDetails& details) override; |
316 | 316 |
317 private: | 317 private: |
318 NotificationRegistrar registrar_; | 318 NotificationRegistrar registrar_; |
319 std::queue<std::string> message_queue_; | 319 std::queue<std::string> message_queue_; |
320 scoped_refptr<MessageLoopRunner> message_loop_runner_; | 320 scoped_refptr<MessageLoopRunner> message_loop_runner_; |
321 | 321 |
322 DISALLOW_COPY_AND_ASSIGN(DOMMessageQueue); | 322 DISALLOW_COPY_AND_ASSIGN(DOMMessageQueue); |
323 }; | 323 }; |
324 | 324 |
325 } // namespace content | 325 } // namespace content |
326 | 326 |
327 #endif // CONTENT_PUBLIC_TEST_BROWSER_TEST_UTILS_H_ | 327 #endif // CONTENT_PUBLIC_TEST_BROWSER_TEST_UTILS_H_ |
OLD | NEW |