Index: content/public/test/browser_test_utils.h |
diff --git a/content/public/test/browser_test_utils.h b/content/public/test/browser_test_utils.h |
index 3793c111e9576324556645af177e513727a7d430..8906616d8a7315a84f56f2d96c0d5bd19b2ad003 100644 |
--- a/content/public/test/browser_test_utils.h |
+++ b/content/public/test/browser_test_utils.h |
@@ -61,6 +61,7 @@ namespace content { |
class BrowserContext; |
class MessageLoopRunner; |
+class NavigationHandle; |
class RenderViewHost; |
class RenderWidgetHost; |
class WebContents; |
@@ -553,6 +554,61 @@ class InputMsgWatcher : public BrowserMessageFilter { |
DISALLOW_COPY_AND_ASSIGN(InputMsgWatcher); |
}; |
+// This class can be used to pause and resume navigations, based on a URL |
+// match. Note that it only keeps track of one navigation at a time. |
+// Navigations are paused automatically before hitting the network, and are |
+// resumed automatically if a Wait method is called for a future event. |
+// Note: This class is one time use only! After it successfully tracks a |
+// navigation it will ignore all subsequent navigations. Explicitly create |
+// mutliple of these managers if you want to pause multiple navigations. |
+class TestNavigationManager : public WebContentsObserver { |
+ public: |
+ // Monitors notifications within the given frame tree node. Use the other |
+ // constructor if the manager should monitor all frames, which is equivalent |
+ // to passing kFrameTreeNodeInvalidId for |frame_tree_node_id|. |
+ TestNavigationManager(int frame_tree_node_id, |
clamy
2016/07/26 17:09:23
nasko: is it ok to expose the FTN id in this way?
|
+ WebContents* web_contents, |
+ const GURL& url); |
+ |
+ // Monitors any frame in WebContents. |
+ TestNavigationManager(WebContents* web_contents, const GURL& url); |
+ |
+ ~TestNavigationManager() override; |
+ |
+ // Waits until the navigation request is ready to be sent to the network |
+ // stack. |
+ void WaitForWillStartRequest(); |
+ |
+ // Waits until the navigation has been finished. Will automatically resume |
+ // navigations paused before this point. |
+ void WaitForNavigationFinished(); |
+ |
+ private: |
+ // WebContentsObserver: |
+ void DidStartNavigation(NavigationHandle* handle) override; |
+ void DidFinishNavigation(NavigationHandle* handle) override; |
+ |
+ // Called when the NavigationThrottle pauses the navigation in |
+ // WillStartRequest. |
+ void OnWillStartRequest(); |
+ |
+ // Resumes the navigation. |
+ void ResumeNavigation(); |
+ |
+ // If this member is not |kFrameTreeNodeInvalidId|, notifications are filtered |
+ // so only this frame is monitored. |
+ int filtering_frame_tree_node_id_; |
+ |
+ const GURL url_; |
+ bool navigation_paused_; |
+ NavigationHandle* handle_; |
+ bool handled_navigation_; |
+ scoped_refptr<MessageLoopRunner> will_start_loop_runner_; |
+ scoped_refptr<MessageLoopRunner> did_finish_loop_runner_; |
+ |
+ base::WeakPtrFactory<TestNavigationManager> weak_factory_; |
+}; |
+ |
} // namespace content |
#endif // CONTENT_PUBLIC_TEST_BROWSER_TEST_UTILS_H_ |