blob: 07cacb3d22415a6c5c7fdbf3afc3631a747b6d84 [file] [log] [blame]
clamy72c72792014-11-18 18:09:461// Copyright (c) 2014 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_H_
6#define CONTENT_TEST_TEST_NAVIGATION_URL_LOADER_H_
7
dcheng6003e0b2016-04-09 18:42:348#include <memory>
9
clamy72c72792014-11-18 18:09:4610#include "base/memory/weak_ptr.h"
11#include "content/browser/frame_host/navigation_request_info.h"
12#include "content/browser/loader/navigation_url_loader.h"
13#include "content/common/navigation_params.h"
14
15namespace net {
16struct RedirectInfo;
17}
18
19namespace content {
20
21class NavigationURLLoaderDelegate;
22class StreamHandle;
23struct ResourceResponse;
24
25// PlzNavigate
26// Test implementation of NavigationURLLoader to simulate the network stack
27// response.
28class TestNavigationURLLoader
29 : public NavigationURLLoader,
30 public base::SupportsWeakPtr<TestNavigationURLLoader> {
31 public:
dcheng6003e0b2016-04-09 18:42:3432 TestNavigationURLLoader(std::unique_ptr<NavigationRequestInfo> request_info,
clamy72c72792014-11-18 18:09:4633 NavigationURLLoaderDelegate* delegate);
34
35 // NavigationURLLoader implementation.
36 void FollowRedirect() override;
clamy5a3c3642016-03-24 17:46:5637 void ProceedWithResponse() override;
clamy72c72792014-11-18 18:09:4638
clamy72c72792014-11-18 18:09:4639 NavigationRequestInfo* request_info() const { return request_info_.get(); }
40
carloskd6a4ef362015-03-04 10:46:1741 void SimulateServerRedirect(const GURL& redirect_url);
42
clamy0e119882015-07-31 16:12:3343 void SimulateError(int error_code);
44
clamy72c72792014-11-18 18:09:4645 void CallOnRequestRedirected(const net::RedirectInfo& redirect_info,
46 const scoped_refptr<ResourceResponse>& response);
47 void CallOnResponseStarted(const scoped_refptr<ResourceResponse>& response,
dcheng6003e0b2016-04-09 18:42:3448 std::unique_ptr<StreamHandle> body);
clamy72c72792014-11-18 18:09:4649
50 int redirect_count() { return redirect_count_; }
51
clamy5a3c3642016-03-24 17:46:5652 bool response_proceeded() { return response_proceeded_; }
53
clamy72c72792014-11-18 18:09:4654 private:
dcheng6e342bf2014-12-23 00:09:3555 ~TestNavigationURLLoader() override;
clamy72c72792014-11-18 18:09:4656
dcheng6003e0b2016-04-09 18:42:3457 std::unique_ptr<NavigationRequestInfo> request_info_;
clamy72c72792014-11-18 18:09:4658 NavigationURLLoaderDelegate* delegate_;
59 int redirect_count_;
clamy5a3c3642016-03-24 17:46:5660 bool response_proceeded_;
clamy72c72792014-11-18 18:09:4661};
62
63} // namespace content
64
65#endif // CONTENT_TEST_TEST_NAVIGATION_URL_LOADER_H_