blob: cf80aeee2caa804ec8ef6977845c3cdb78ab14e4 [file] [log] [blame]
clamy9fb38cd2016-04-11 12:57:481// Copyright 2016 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CONTENT_TEST_TEST_NAVIGATION_URL_LOADER_DELEGATE_H_
6#define CONTENT_TEST_TEST_NAVIGATION_URL_LOADER_DELEGATE_H_
7
dcheng18ec0b542016-04-26 19:28:538#include <memory>
9
clamy9fb38cd2016-04-11 12:57:4810#include "base/macros.h"
11#include "base/memory/ref_counted.h"
clamy9fb38cd2016-04-11 12:57:4812#include "base/time/time.h"
13#include "content/browser/loader/navigation_url_loader_delegate.h"
14#include "net/url_request/redirect_info.h"
15
16namespace base {
17class RunLoop;
18}
19
20namespace content {
21
22class StreamHandle;
23struct ResourceResponse;
24
25// PlzNavigate
26// Test implementation of NavigationURLLoaderDelegate to monitor navigation
27// progress in the network stack.
28class TestNavigationURLLoaderDelegate : public NavigationURLLoaderDelegate {
29 public:
30 TestNavigationURLLoaderDelegate();
31 ~TestNavigationURLLoaderDelegate() override;
32
33 const net::RedirectInfo& redirect_info() const { return redirect_info_; }
34 ResourceResponse* redirect_response() const {
35 return redirect_response_.get();
36 }
37 ResourceResponse* response() const { return response_.get(); }
38 StreamHandle* body() const { return body_.get(); }
39 int net_error() const { return net_error_; }
40 int on_request_handled_counter() const { return on_request_handled_counter_; }
41
42 // Waits for various navigation events.
43 // Note: if the event already happened, the functions will hang.
44 // TODO(clamy): Make the functions not hang if they are called after the
45 // event happened.
46 void WaitForRequestRedirected();
47 void WaitForResponseStarted();
48 void WaitForRequestFailed();
49 void WaitForRequestStarted();
50
51 void ReleaseBody();
52
53 // NavigationURLLoaderDelegate implementation.
54 void OnRequestRedirected(
55 const net::RedirectInfo& redirect_info,
56 const scoped_refptr<ResourceResponse>& response) override;
ryansturmfe328162016-05-11 22:28:4757 void OnResponseStarted(
58 const scoped_refptr<ResourceResponse>& response,
59 std::unique_ptr<StreamHandle> body,
jamb981f482016-08-30 05:55:0260 const SSLStatus& ssl_status,
ryansturmfe328162016-05-11 22:28:4761 std::unique_ptr<NavigationData> navigation_data) override;
clamy9fb38cd2016-04-11 12:57:4862 void OnRequestFailed(bool in_cache, int net_error) override;
63 void OnRequestStarted(base::TimeTicks timestamp) override;
clamy9fb38cd2016-04-11 12:57:4864
65 private:
66 net::RedirectInfo redirect_info_;
67 scoped_refptr<ResourceResponse> redirect_response_;
68 scoped_refptr<ResourceResponse> response_;
dcheng18ec0b542016-04-26 19:28:5369 std::unique_ptr<StreamHandle> body_;
clamy9fb38cd2016-04-11 12:57:4870 int net_error_;
71 int on_request_handled_counter_;
72
dcheng18ec0b542016-04-26 19:28:5373 std::unique_ptr<base::RunLoop> request_redirected_;
74 std::unique_ptr<base::RunLoop> response_started_;
75 std::unique_ptr<base::RunLoop> request_failed_;
76 std::unique_ptr<base::RunLoop> request_started_;
clamy9fb38cd2016-04-11 12:57:4877
78 DISALLOW_COPY_AND_ASSIGN(TestNavigationURLLoaderDelegate);
79};
80
81} // namespace content
82
83#endif // CONTENT_TEST_TEST_NAVIGATION_URL_LOADER_DELEGATE_H