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

Side by Side Diff: content/public/test/browser_test_utils.h

Issue 2396493002: Improve the TestNavigationManager (Closed)
Patch Set: Improve the TestNavigationManager Created 4 years, 2 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 594 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 // mutliple instances of this class if you want to pause multiple navigations. 605 // mutliple instances of this class if you want to pause multiple navigations.
606 class TestNavigationManager : public WebContentsObserver { 606 class TestNavigationManager : public WebContentsObserver {
607 public: 607 public:
608 // Monitors any frame in WebContents. 608 // Monitors any frame in WebContents.
609 TestNavigationManager(WebContents* web_contents, const GURL& url); 609 TestNavigationManager(WebContents* web_contents, const GURL& url);
610 610
611 ~TestNavigationManager() override; 611 ~TestNavigationManager() override;
612 612
613 // Waits until the navigation request is ready to be sent to the network 613 // Waits until the navigation request is ready to be sent to the network
614 // stack. Returns false if the request was aborted before starting. 614 // stack. Returns false if the request was aborted before starting.
615 WARN_UNUSED_RESULT bool WaitForWillStartRequest(); 615 WARN_UNUSED_RESULT bool WaitForWillStartRequest();
nasko 2016/10/12 23:53:58 nit: WaitForStartRequest or WaitForRequestStart.
clamy 2016/10/13 15:51:55 Done.
616 616
617 // Waits until the navigation response has been sent received. Returns false 617 // Waits until the navigation response has been sent received. Returns false
618 // if the request was aborted before getting a response. 618 // if the request was aborted before getting a response.
619 WARN_UNUSED_RESULT bool WaitForWillProcessResponse(); 619 WARN_UNUSED_RESULT bool WaitForResponse();
620 620
621 // Waits until the navigation has been finished. Will automatically resume 621 // Waits until the navigation has been finished. Will automatically resume
622 // navigations paused before this point. 622 // navigations paused before this point.
623 void WaitForNavigationFinished(); 623 void WaitForNavigationFinished();
624 624
625 protected: 625 protected:
626 // Derived classes can override if they want to filter out navigations. This 626 // Derived classes can override if they want to filter out navigations. This
627 // is called from DidStartNavigation. 627 // is called from DidStartNavigation.
628 virtual bool ShouldMonitorNavigation(NavigationHandle* handle); 628 virtual bool ShouldMonitorNavigation(NavigationHandle* handle);
629 629
630 private: 630 private:
631 enum class NavigationState {
632 INITIAL = 0,
633 STARTED = 1,
634 RESPONSE = 2,
635 FINISHED = 3,
636 };
637
631 // WebContentsObserver: 638 // WebContentsObserver:
632 void DidStartNavigation(NavigationHandle* handle) override; 639 void DidStartNavigation(NavigationHandle* handle) override;
633 void DidFinishNavigation(NavigationHandle* handle) override; 640 void DidFinishNavigation(NavigationHandle* handle) override;
634 641
635 // Called when the NavigationThrottle pauses the navigation in 642 // Called when the NavigationThrottle pauses the navigation in
636 // WillStartRequest. 643 // WillStartRequest.
637 void OnWillStartRequest(); 644 void OnWillStartRequest();
638 645
639 // Called when the NavigationThrottle pauses the navigation in 646 // Called when the NavigationThrottle pauses the navigation in
640 // WillProcessResponse. 647 // WillProcessResponse.
641 void OnWillProcessResponse(); 648 void OnWillProcessResponse();
642 649
643 // Resumes the navigation. 650 // Waits for the desired state. Returns false if the desired state cannot be
644 void ResumeNavigation(); 651 // reached (eg the navigation finishes before reaching this state).
652 bool WaitForDesiredState();
653
654 // Called when the state of the navigation has changed. This will either stop
655 // the message loop if the state specified by the user has been reached, or
656 // resume the navigation if it hasn't been reached yet.
657 void OnNavigationStateChanged();
645 658
646 const GURL url_; 659 const GURL url_;
647 bool navigation_paused_in_will_start_;
648 bool navigation_paused_in_will_process_response_;
649 NavigationHandle* handle_; 660 NavigationHandle* handle_;
650 bool handled_navigation_; 661 bool navigation_paused_;
651 scoped_refptr<MessageLoopRunner> will_start_loop_runner_; 662 NavigationState current_state_;
652 scoped_refptr<MessageLoopRunner> will_process_response_loop_runner_; 663 NavigationState desired_state_;
653 scoped_refptr<MessageLoopRunner> did_finish_loop_runner_; 664 scoped_refptr<MessageLoopRunner> loop_runner_;
654 665
655 base::WeakPtrFactory<TestNavigationManager> weak_factory_; 666 base::WeakPtrFactory<TestNavigationManager> weak_factory_;
656 667
657 DISALLOW_COPY_AND_ASSIGN(TestNavigationManager); 668 DISALLOW_COPY_AND_ASSIGN(TestNavigationManager);
658 }; 669 };
659 670
660 } // namespace content 671 } // namespace content
661 672
662 #endif // CONTENT_PUBLIC_TEST_BROWSER_TEST_UTILS_H_ 673 #endif // CONTENT_PUBLIC_TEST_BROWSER_TEST_UTILS_H_
OLDNEW
« no previous file with comments | « content/browser/site_per_process_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