summaryrefslogtreecommitdiffstats
path: root/content/test/net/url_request_abort_on_end_job.h
blob: e1045a28779df7db20ef3e3b0bca8122c941fe19 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// This class simulates what wininet does when a dns lookup fails.

#ifndef CONTENT_TEST_NET_URL_REQUEST_ABORT_ON_END_JOB_H_
#define CONTENT_TEST_NET_URL_REQUEST_ABORT_ON_END_JOB_H_

#include <string>

#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/memory/weak_ptr.h"
#include "net/url_request/url_request_job.h"

// This url request simulates a network error which occurs immediately after
// receiving the very first data.

class URLRequestAbortOnEndJob : public net::URLRequestJob {
 public:
  static const char k400AbortOnEndUrl[];

  // net::URLRequestJob
  virtual void Start() OVERRIDE;
  virtual bool GetMimeType(std::string* mime_type) const OVERRIDE;
  virtual void GetResponseInfo(net::HttpResponseInfo* info) OVERRIDE;
  virtual bool ReadRawData(net::IOBuffer* buf,
                           int buf_size,
                           int* bytes_read) OVERRIDE;

  static net::URLRequestJob* Factory(net::URLRequest* request,
                                     net::NetworkDelegate* network_delegate,
                                     const std::string& scheme);

  static void AddUrlHandler();

 private:
  URLRequestAbortOnEndJob(net::URLRequest* request,
                          net::NetworkDelegate* network_delegate);
  virtual ~URLRequestAbortOnEndJob();

  void GetResponseInfoConst(net::HttpResponseInfo* info) const;
  void StartAsync();

  bool sent_data_;

  base::WeakPtrFactory<URLRequestAbortOnEndJob> weak_factory_;

  DISALLOW_COPY_AND_ASSIGN(URLRequestAbortOnEndJob);
};

#endif  // CONTENT_TEST_NET_URL_REQUEST_ABORT_ON_END_JOB_H_