summaryrefslogtreecommitdiff
path: root/chromium/net/url_request/url_request_job_unittest.cc
blob: 354915fe12be37c8ea2c0d16d74e2e80b1e3c796 (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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// 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.

#include "net/url_request/url_request_job.h"

#include "net/http/http_transaction_unittest.h"
#include "net/url_request/url_request_test_util.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace {

// This is a header that signals the end of the data.
const char kGzipGata[] = "\x1f\x08b\x08\0\0\0\0\0\0\3\3\0\0\0\0\0\0\0\0";

void GZipServer(const net::HttpRequestInfo* request,
                std::string* response_status, std::string* response_headers,
                std::string* response_data) {
  response_data->assign(kGzipGata, sizeof(kGzipGata));
}

const MockTransaction kGZip_Transaction = {
  "http://www.google.com/gzyp",
  "GET",
  base::Time(),
  "",
  net::LOAD_NORMAL,
  "HTTP/1.1 200 OK",
  "Cache-Control: max-age=10000\n"
  "Content-Encoding: gzip\n"
  "Content-Length: 30\n",  // Intentionally wrong.
  base::Time(),
  "",
  TEST_MODE_NORMAL,
  &GZipServer,
  0,
  net::OK
};

}  // namespace

TEST(URLRequestJob, TransactionNotifiedWhenDone) {
  MockNetworkLayer network_layer;
  net::TestURLRequestContext context;
  context.set_http_transaction_factory(&network_layer);

  net::TestDelegate d;
  net::TestURLRequest req(GURL(kGZip_Transaction.url), &d, &context, NULL);
  AddMockTransaction(&kGZip_Transaction);

  req.set_method("GET");
  req.Start();

  base::MessageLoop::current()->Run();

  EXPECT_TRUE(network_layer.done_reading_called());

  RemoveMockTransaction(&kGZip_Transaction);
}

TEST(URLRequestJob, SyncTransactionNotifiedWhenDone) {
  MockNetworkLayer network_layer;
  net::TestURLRequestContext context;
  context.set_http_transaction_factory(&network_layer);

  net::TestDelegate d;
  net::TestURLRequest req(GURL(kGZip_Transaction.url), &d, &context, NULL);
  MockTransaction transaction(kGZip_Transaction);
  transaction.test_mode = TEST_MODE_SYNC_ALL;
  AddMockTransaction(&transaction);

  req.set_method("GET");
  req.Start();

  base::MessageLoop::current()->Run();

  EXPECT_TRUE(network_layer.done_reading_called());

  RemoveMockTransaction(&transaction);
}