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

Side by Side 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: nasko@ nits Created 4 years, 4 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 unified diff | Download patch
OLDNEW
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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 // browser_tests. 54 // browser_tests.
55 // TO BE CLEAR: any function here must work against both binaries. If it only 55 // TO BE CLEAR: any function here must work against both binaries. If it only
56 // works with browser_tests, it should be in chrome\test\base\ui_test_utils.h. 56 // works with browser_tests, it should be in chrome\test\base\ui_test_utils.h.
57 // If it only works with content_browsertests, it should be in 57 // If it only works with content_browsertests, it should be in
58 // content\test\content_browser_test_utils.h. 58 // content\test\content_browser_test_utils.h.
59 59
60 namespace content { 60 namespace content {
61 61
62 class BrowserContext; 62 class BrowserContext;
63 class MessageLoopRunner; 63 class MessageLoopRunner;
64 class NavigationHandle;
64 class RenderViewHost; 65 class RenderViewHost;
65 class RenderWidgetHost; 66 class RenderWidgetHost;
66 class WebContents; 67 class WebContents;
67 68
68 // Navigate a frame with ID |iframe_id| to |url|, blocking until the navigation 69 // Navigate a frame with ID |iframe_id| to |url|, blocking until the navigation
69 // finishes. Uses a renderer-initiated navigation from script code in the 70 // finishes. Uses a renderer-initiated navigation from script code in the
70 // main frame. 71 // main frame.
71 bool NavigateIframeToURL(WebContents* web_contents, 72 bool NavigateIframeToURL(WebContents* web_contents,
72 std::string iframe_id, 73 std::string iframe_id,
73 const GURL& url); 74 const GURL& url);
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 586
586 void Wait(); 587 void Wait();
587 588
588 private: 589 private:
589 // FrameTreeNode::Observer 590 // FrameTreeNode::Observer
590 std::unique_ptr<FrameTreeNodeObserverImpl> impl_; 591 std::unique_ptr<FrameTreeNodeObserverImpl> impl_;
591 592
592 DISALLOW_COPY_AND_ASSIGN(FrameFocusedObserver); 593 DISALLOW_COPY_AND_ASSIGN(FrameFocusedObserver);
593 }; 594 };
594 595
596 // This class can be used to pause and resume navigations, based on a URL
597 // match. Note that it only keeps track of one navigation at a time.
598 // Navigations are paused automatically before hitting the network, and are
599 // resumed automatically if a Wait method is called for a future event.
600 // Note: This class is one time use only! After it successfully tracks a
601 // navigation it will ignore all subsequent navigations. Explicitly create
602 // mutliple instances of this class if you want to pause multiple navigations.
603 class TestNavigationManager : public WebContentsObserver {
604 public:
605 // Monitors any frame in WebContents.
606 TestNavigationManager(WebContents* web_contents, const GURL& url);
607
608 ~TestNavigationManager() override;
609
610 // Waits until the navigation request is ready to be sent to the network
611 // stack. Returns false if the request was aborted before starting.
612 WARN_UNUSED_RESULT bool WaitForWillStartRequest();
613
614 // Waits until the navigation has been finished. Will automatically resume
615 // navigations paused before this point.
616 void WaitForNavigationFinished();
617
618 protected:
619 // Derived classes can override if they want to filter out navigations. This
620 // is called from DidStartNavigation.
621 virtual bool ShouldMonitorNavigation(NavigationHandle* handle);
622
623 private:
624 // WebContentsObserver:
625 void DidStartNavigation(NavigationHandle* handle) override;
626 void DidFinishNavigation(NavigationHandle* handle) override;
627
628 // Called when the NavigationThrottle pauses the navigation in
629 // WillStartRequest.
630 void OnWillStartRequest();
631
632 // Resumes the navigation.
633 void ResumeNavigation();
634
635 const GURL url_;
636 bool navigation_paused_;
637 NavigationHandle* handle_;
638 bool handled_navigation_;
639 scoped_refptr<MessageLoopRunner> will_start_loop_runner_;
640 scoped_refptr<MessageLoopRunner> did_finish_loop_runner_;
641
642 base::WeakPtrFactory<TestNavigationManager> weak_factory_;
643
644 DISALLOW_COPY_AND_ASSIGN(TestNavigationManager);
645 };
646
595 } // namespace content 647 } // namespace content
596 648
597 #endif // CONTENT_PUBLIC_TEST_BROWSER_TEST_UTILS_H_ 649 #endif // CONTENT_PUBLIC_TEST_BROWSER_TEST_UTILS_H_
OLDNEW
« no previous file with comments | « content/browser/web_contents/web_contents_impl_browsertest.cc ('k') | content/public/test/browser_test_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698