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

Unified Diff: content/test/content_browser_test_utils_internal.cc

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: nasko@ nits 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/test/content_browser_test_utils_internal.h ('k') | content/test/test_web_contents.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/test/content_browser_test_utils_internal.cc
diff --git a/content/test/content_browser_test_utils_internal.cc b/content/test/content_browser_test_utils_internal.cc
index fa20dfc138390a7622f2e75ca3edac040ab91bdc..447796106abf5d7ffab460651332c8e6515ea767 100644
--- a/content/test/content_browser_test_utils_internal.cc
+++ b/content/test/content_browser_test_utils_internal.cc
@@ -24,10 +24,10 @@
#include "content/browser/frame_host/render_widget_host_view_child_frame.h"
#include "content/browser/renderer_host/delegated_frame_host.h"
#include "content/browser/renderer_host/render_widget_host_view_base.h"
+#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/resource_dispatcher_host.h"
#include "content/public/browser/resource_throttle.h"
-#include "content/public/browser/web_contents.h"
#include "content/public/common/file_chooser_file_info.h"
#include "content/public/common/file_chooser_params.h"
#include "content/public/test/browser_test_utils.h"
@@ -39,30 +39,6 @@
namespace content {
-namespace {
-
-// Helper class used by the TestNavigationManager to pause navigations.
-class TestNavigationManagerThrottle : public NavigationThrottle {
- public:
- TestNavigationManagerThrottle(NavigationHandle* handle,
- base::Closure on_will_start_request_closure)
- : NavigationThrottle(handle),
- on_will_start_request_closure_(on_will_start_request_closure) {}
- ~TestNavigationManagerThrottle() override {}
-
- private:
- // NavigationThrottle implementation.
- NavigationThrottle::ThrottleCheckResult WillStartRequest() override {
- BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
- on_will_start_request_closure_);
- return NavigationThrottle::DEFER;
- }
-
- base::Closure on_will_start_request_closure_;
-};
-
-} // namespace
-
void NavigateFrameToURL(FrameTreeNode* node, const GURL& url) {
TestFrameNavigationObserver observer(node);
NavigationController::LoadURLParams params(url);
@@ -367,89 +343,6 @@ void NavigationStallDelegate::RequestBeginning(
throttles->push_back(new HttpRequestStallThrottle);
}
-TestNavigationManager::TestNavigationManager(
- int filtering_frame_tree_node_id,
- WebContents* web_contents,
- const GURL& url)
- : WebContentsObserver(web_contents),
- filtering_frame_tree_node_id_(filtering_frame_tree_node_id),
- url_(url),
- navigation_paused_(false),
- handle_(nullptr),
- weak_factory_(this) {}
-
-TestNavigationManager::TestNavigationManager(WebContents* web_contents,
- const GURL& url)
- : TestNavigationManager(FrameTreeNode::kFrameTreeNodeInvalidId,
- web_contents,
- url) {}
-
-TestNavigationManager::~TestNavigationManager() {
- ResumeNavigation();
-}
-
-void TestNavigationManager::WaitForWillStartRequest() {
- DCHECK(!did_finish_loop_runner_);
- if (navigation_paused_)
- return;
- will_start_loop_runner_ = new MessageLoopRunner();
- will_start_loop_runner_->Run();
- will_start_loop_runner_ = nullptr;
-}
-
-void TestNavigationManager::WaitForNavigationFinished() {
- DCHECK(!will_start_loop_runner_);
- // Ensure the navigation is resumed if the manager paused it previously.
- if (navigation_paused_)
- ResumeNavigation();
- did_finish_loop_runner_ = new MessageLoopRunner();
- did_finish_loop_runner_->Run();
- did_finish_loop_runner_ = nullptr;
-}
-
-void TestNavigationManager::DidStartNavigation(NavigationHandle* handle) {
- if (handle_ || handle->GetURL() != url_)
- return;
-
- if (filtering_frame_tree_node_id_ != FrameTreeNode::kFrameTreeNodeInvalidId &&
- handle->GetFrameTreeNodeId() != filtering_frame_tree_node_id_) {
- return;
- }
-
- handle_ = handle;
- std::unique_ptr<NavigationThrottle> throttle(
- new TestNavigationManagerThrottle(
- handle_, base::Bind(&TestNavigationManager::OnWillStartRequest,
- weak_factory_.GetWeakPtr())));
- handle_->RegisterThrottleForTesting(std::move(throttle));
-}
-
-void TestNavigationManager::DidFinishNavigation(NavigationHandle* handle) {
- if (handle != handle_)
- return;
- handle_ = nullptr;
- navigation_paused_ = false;
- if (did_finish_loop_runner_)
- did_finish_loop_runner_->Quit();
-}
-
-void TestNavigationManager::OnWillStartRequest() {
- navigation_paused_ = true;
- if (will_start_loop_runner_)
- will_start_loop_runner_->Quit();
-
- // If waiting for the navigation to finish, resume the navigation.
- if (did_finish_loop_runner_)
- ResumeNavigation();
-}
-
-void TestNavigationManager::ResumeNavigation() {
- if (!navigation_paused_ || !handle_)
- return;
- navigation_paused_ = false;
- handle_->Resume();
-}
-
FileChooserDelegate::FileChooserDelegate(const base::FilePath& file)
: file_(file), file_chosen_(false) {}
@@ -465,4 +358,17 @@ void FileChooserDelegate::RunFileChooser(RenderFrameHost* render_frame_host,
file_chosen_ = true;
}
+FrameTestNavigationManager::FrameTestNavigationManager(
+ int filtering_frame_tree_node_id,
+ WebContents* web_contents,
+ const GURL& url)
+ : TestNavigationManager(web_contents, url),
+ filtering_frame_tree_node_id_(filtering_frame_tree_node_id) {}
+
+bool FrameTestNavigationManager::ShouldMonitorNavigation(
+ NavigationHandle* handle) {
+ return TestNavigationManager::ShouldMonitorNavigation(handle) &&
+ handle->GetFrameTreeNodeId() == filtering_frame_tree_node_id_;
+}
+
} // namespace content
« no previous file with comments | « content/test/content_browser_test_utils_internal.h ('k') | content/test/test_web_contents.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698