blob: 8edcdfc7aac20b99895def177b61545cc274b43a [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
ryansturmfe328162016-05-11 22:28:4721class NavigationData;
clamy72c72792014-11-18 18:09:4622class NavigationURLLoaderDelegate;
23class StreamHandle;
24struct ResourceResponse;
25
26// PlzNavigate
27// Test implementation of NavigationURLLoader to simulate the network stack
28// response.
29class TestNavigationURLLoader
30 : public NavigationURLLoader,
31 public base::SupportsWeakPtr<TestNavigationURLLoader> {
32 public:
dcheng6003e0b2016-04-09 18:42:3433 TestNavigationURLLoader(std::unique_ptr<NavigationRequestInfo> request_info,
clamy72c72792014-11-18 18:09:4634 NavigationURLLoaderDelegate* delegate);
35
36 // NavigationURLLoader implementation.
37 void FollowRedirect() override;
clamy5a3c3642016-03-24 17:46:5638 void ProceedWithResponse() override;
clamy72c72792014-11-18 18:09:4639
clamy72c72792014-11-18 18:09:4640 NavigationRequestInfo* request_info() const { return request_info_.get(); }
41
carloskd6a4ef362015-03-04 10:46:1742 void SimulateServerRedirect(const GURL& redirect_url);
43
clamy0e119882015-07-31 16:12:3344 void SimulateError(int error_code);
45
clamy72c72792014-11-18 18:09:4646 void CallOnRequestRedirected(const net::RedirectInfo& redirect_info,
47 const scoped_refptr<ResourceResponse>& response);
48 void CallOnResponseStarted(const scoped_refptr<ResourceResponse>& response,
ryansturmfe328162016-05-11 22:28:4749 std::unique_ptr<StreamHandle> body,
50 std::unique_ptr<NavigationData> navigation_data);
clamy72c72792014-11-18 18:09:4651
52 int redirect_count() { return redirect_count_; }
53
clamy5a3c3642016-03-24 17:46:5654 bool response_proceeded() { return response_proceeded_; }
55
clamy72c72792014-11-18 18:09:4656 private:
dcheng6e342bf2014-12-23 00:09:3557 ~TestNavigationURLLoader() override;
clamy72c72792014-11-18 18:09:4658
dcheng6003e0b2016-04-09 18:42:3459 std::unique_ptr<NavigationRequestInfo> request_info_;
clamy72c72792014-11-18 18:09:4660 NavigationURLLoaderDelegate* delegate_;
61 int redirect_count_;
clamy5a3c3642016-03-24 17:46:5662 bool response_proceeded_;
clamy72c72792014-11-18 18:09:4663};
64
65} // namespace content
66
67#endif // CONTENT_TEST_TEST_NAVIGATION_URL_LOADER_H_