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

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: rebase on #408334 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 493 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 // Puts text/rtf |rtf| on the clipboard. 568 // Puts text/rtf |rtf| on the clipboard.
568 void SetRtf(const std::string& rtf); 569 void SetRtf(const std::string& rtf);
569 570
570 // Puts plain text |text| on the clipboard. 571 // Puts plain text |text| on the clipboard.
571 void SetText(const std::string& text); 572 void SetText(const std::string& text);
572 573
573 private: 574 private:
574 DISALLOW_COPY_AND_ASSIGN(BrowserTestClipboardScope); 575 DISALLOW_COPY_AND_ASSIGN(BrowserTestClipboardScope);
575 }; 576 };
576 577
578 // This class can be used to pause and resume navigations, based on a URL
579 // match. Note that it only keeps track of one navigation at a time.
580 // Navigations are paused automatically before hitting the network, and are
581 // resumed automatically if a Wait method is called for a future event.
582 // Note: This class is one time use only! After it successfully tracks a
583 // navigation it will ignore all subsequent navigations. Explicitly create
584 // mutliple of these managers if you want to pause multiple navigations.
nasko 2016/08/01 15:29:23 nit: "multiple instances of this class if you ..."
Charlie Harrison 2016/08/01 17:42:19 Done.
585 class TestNavigationManager : public WebContentsObserver {
586 public:
587 // Monitors notifications within the given frame tree node. Use the other
nasko 2016/08/01 15:29:23 FrameTreeNode is mostly internal concept to conten
Charlie Harrison 2016/08/01 17:42:19 So, Camille wanted this functionality as a prereq
nasko 2016/08/01 23:38:11 We don't have anyone outside of content/ using thi
Charlie Harrison 2016/08/02 13:09:15 Fair point. I've removed the method and added a s
588 // constructor if the manager should monitor all frames, which is equivalent
589 // to passing kFrameTreeNodeInvalidId for |frame_tree_node_id|.
590 TestNavigationManager(int frame_tree_node_id,
591 WebContents* web_contents,
592 const GURL& url);
593
594 // Monitors any frame in WebContents.
595 TestNavigationManager(WebContents* web_contents, const GURL& url);
596
597 ~TestNavigationManager() override;
598
599 // Waits until the navigation request is ready to be sent to the network
600 // stack. Returns false if the request was aborted before starting.
601 WARN_UNUSED_RESULT bool WaitForWillStartRequest();
602
603 // Waits until the navigation has been finished. Will automatically resume
604 // navigations paused before this point.
605 void WaitForNavigationFinished();
606
607 private:
608 // WebContentsObserver:
609 void DidStartNavigation(NavigationHandle* handle) override;
610 void DidFinishNavigation(NavigationHandle* handle) override;
611
612 // Called when the NavigationThrottle pauses the navigation in
613 // WillStartRequest.
614 void OnWillStartRequest();
615
616 // Resumes the navigation.
617 void ResumeNavigation();
618
619 // If this member is not |kFrameTreeNodeInvalidId|, notifications are filtered
620 // so only this frame is monitored.
621 int filtering_frame_tree_node_id_;
622
623 const GURL url_;
624 bool navigation_paused_;
625 NavigationHandle* handle_;
626 bool handled_navigation_;
627 scoped_refptr<MessageLoopRunner> will_start_loop_runner_;
628 scoped_refptr<MessageLoopRunner> did_finish_loop_runner_;
629
630 base::WeakPtrFactory<TestNavigationManager> weak_factory_;
631 };
632
577 } // namespace content 633 } // namespace content
578 634
579 #endif // CONTENT_PUBLIC_TEST_BROWSER_TEST_UTILS_H_ 635 #endif // CONTENT_PUBLIC_TEST_BROWSER_TEST_UTILS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698