Chromium Code Reviews| 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 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 546 | 547 | 
| 547 void ReceivedAck(blink::WebInputEvent::Type ack_type, uint32_t ack_state); | 548 void ReceivedAck(blink::WebInputEvent::Type ack_type, uint32_t ack_state); | 
| 548 | 549 | 
| 549 blink::WebInputEvent::Type wait_for_type_; | 550 blink::WebInputEvent::Type wait_for_type_; | 
| 550 uint32_t ack_result_; | 551 uint32_t ack_result_; | 
| 551 base::Closure quit_; | 552 base::Closure quit_; | 
| 552 | 553 | 
| 553 DISALLOW_COPY_AND_ASSIGN(InputMsgWatcher); | 554 DISALLOW_COPY_AND_ASSIGN(InputMsgWatcher); | 
| 554 }; | 555 }; | 
| 555 | 556 | 
| 557 // This class can be used to pause and resume navigations, based on a URL | |
| 558 // match. Note that it only keeps track of one navigation at a time. | |
| 559 // Navigations are paused automatically before hitting the network, and are | |
| 560 // resumed automatically if a Wait method is called for a future event. | |
| 561 // Note: This class is one time use only! After it successfully tracks a | |
| 562 // navigation it will ignore all subsequent navigations. Explicitly create | |
| 563 // mutliple of these managers if you want to pause multiple navigations. | |
| 564 class TestNavigationManager : public WebContentsObserver { | |
| 565 public: | |
| 566 // Monitors notifications within the given frame tree node. Use the other | |
| 567 // constructor if the manager should monitor all frames, which is equivalent | |
| 568 // to passing kFrameTreeNodeInvalidId for |frame_tree_node_id|. | |
| 569 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?
 
 | |
| 570 WebContents* web_contents, | |
| 571 const GURL& url); | |
| 572 | |
| 573 // Monitors any frame in WebContents. | |
| 574 TestNavigationManager(WebContents* web_contents, const GURL& url); | |
| 575 | |
| 576 ~TestNavigationManager() override; | |
| 577 | |
| 578 // Waits until the navigation request is ready to be sent to the network | |
| 579 // stack. | |
| 580 void WaitForWillStartRequest(); | |
| 581 | |
| 582 // Waits until the navigation has been finished. Will automatically resume | |
| 583 // navigations paused before this point. | |
| 584 void WaitForNavigationFinished(); | |
| 585 | |
| 586 private: | |
| 587 // WebContentsObserver: | |
| 588 void DidStartNavigation(NavigationHandle* handle) override; | |
| 589 void DidFinishNavigation(NavigationHandle* handle) override; | |
| 590 | |
| 591 // Called when the NavigationThrottle pauses the navigation in | |
| 592 // WillStartRequest. | |
| 593 void OnWillStartRequest(); | |
| 594 | |
| 595 // Resumes the navigation. | |
| 596 void ResumeNavigation(); | |
| 597 | |
| 598 // If this member is not |kFrameTreeNodeInvalidId|, notifications are filtered | |
| 599 // so only this frame is monitored. | |
| 600 int filtering_frame_tree_node_id_; | |
| 601 | |
| 602 const GURL url_; | |
| 603 bool navigation_paused_; | |
| 604 NavigationHandle* handle_; | |
| 605 bool handled_navigation_; | |
| 606 scoped_refptr<MessageLoopRunner> will_start_loop_runner_; | |
| 607 scoped_refptr<MessageLoopRunner> did_finish_loop_runner_; | |
| 608 | |
| 609 base::WeakPtrFactory<TestNavigationManager> weak_factory_; | |
| 610 }; | |
| 611 | |
| 556 } // namespace content | 612 } // namespace content | 
| 557 | 613 | 
| 558 #endif // CONTENT_PUBLIC_TEST_BROWSER_TEST_UTILS_H_ | 614 #endif // CONTENT_PUBLIC_TEST_BROWSER_TEST_UTILS_H_ | 
| OLD | NEW |