Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(266)

Unified Diff: content/public/test/browser_test_utils.h

Issue 2132603002: [page_load_metrics] Add a NavigationThrottle for richer abort metrics (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Attach the throttle first so it gets all notifications before any DEFERs Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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_

Powered by Google App Engine
This is Rietveld 408576698