| 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 Loading... |
| 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 |
| 606 // Monitors any frame in WebContents. |
| 607 TestNavigationManager(WebContents* web_contents, const GURL& url); |
| 608 |
| 609 ~TestNavigationManager() override; |
| 610 |
| 611 // Waits until the navigation request is ready to be sent to the network |
| 612 // stack. Returns false if the request was aborted before starting. |
| 613 WARN_UNUSED_RESULT bool WaitForWillStartRequest(); |
| 614 |
| 615 // Waits until the navigation has been finished. Will automatically resume |
| 616 // navigations paused before this point. |
| 617 void WaitForNavigationFinished(); |
| 618 |
| 619 protected: |
| 620 // Derived classes can override if they want to filter out navigations. This |
| 621 // is called from DidStartNavigation. |
| 622 virtual bool ShouldMonitorNavigation(NavigationHandle* handle); |
| 623 |
| 624 private: |
| 625 // WebContentsObserver: |
| 626 void DidStartNavigation(NavigationHandle* handle) override; |
| 627 void DidFinishNavigation(NavigationHandle* handle) override; |
| 628 |
| 629 // Called when the NavigationThrottle pauses the navigation in |
| 630 // WillStartRequest. |
| 631 void OnWillStartRequest(); |
| 632 |
| 633 // Resumes the navigation. |
| 634 void ResumeNavigation(); |
| 635 |
| 636 const GURL url_; |
| 637 bool navigation_paused_; |
| 638 NavigationHandle* handle_; |
| 639 bool handled_navigation_; |
| 640 scoped_refptr<MessageLoopRunner> will_start_loop_runner_; |
| 641 scoped_refptr<MessageLoopRunner> did_finish_loop_runner_; |
| 642 |
| 643 base::WeakPtrFactory<TestNavigationManager> weak_factory_; |
| 644 |
| 645 DISALLOW_COPY_AND_ASSIGN(TestNavigationManager); |
| 646 }; |
| 647 |
| 595 } // namespace content | 648 } // namespace content |
| 596 | 649 |
| 597 #endif // CONTENT_PUBLIC_TEST_BROWSER_TEST_UTILS_H_ | 650 #endif // CONTENT_PUBLIC_TEST_BROWSER_TEST_UTILS_H_ |
| OLD | NEW |