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