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 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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. |
| 585 class TestNavigationManager : public WebContentsObserver { |
| 586 public: |
| 587 // Monitors notifications within the given frame tree node. Use the other |
| 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_ |
OLD | NEW |