1 // Copyright (c) 2012 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.
5 #include "net/url_request/url_request_job.h"
7 #include "net/base/request_priority.h"
8 #include "net/http/http_transaction_unittest.h"
9 #include "net/url_request/url_request_test_util.h"
10 #include "testing/gtest/include/gtest/gtest.h"
16 // This is a header that signals the end of the data.
17 const char kGzipGata
[] = "\x1f\x08b\x08\0\0\0\0\0\0\3\3\0\0\0\0\0\0\0\0";
19 void GZipServer(const HttpRequestInfo
* request
,
20 std::string
* response_status
,
21 std::string
* response_headers
,
22 std::string
* response_data
) {
23 response_data
->assign(kGzipGata
, sizeof(kGzipGata
));
26 const MockTransaction kGZip_Transaction
= {
27 "http://www.google.com/gzyp",
33 "Cache-Control: max-age=10000\n"
34 "Content-Encoding: gzip\n"
35 "Content-Length: 30\n", // Intentionally wrong.
44 const MockTransaction kRedirect_Transaction
= {
45 "http://www.google.com/redirect",
51 "Cache-Control: max-age=10000\n"
52 "Location: http://www.google.com/destination\n"
53 "Content-Length: 5\n",
64 TEST(URLRequestJob
, TransactionNotifiedWhenDone
) {
65 MockNetworkLayer network_layer
;
66 TestURLRequestContext context
;
67 context
.set_http_transaction_factory(&network_layer
);
71 GURL(kGZip_Transaction
.url
), DEFAULT_PRIORITY
, &d
, &context
);
72 AddMockTransaction(&kGZip_Transaction
);
74 req
.set_method("GET");
77 base::MessageLoop::current()->Run();
79 EXPECT_TRUE(network_layer
.done_reading_called());
81 RemoveMockTransaction(&kGZip_Transaction
);
84 TEST(URLRequestJob
, SyncTransactionNotifiedWhenDone
) {
85 MockNetworkLayer network_layer
;
86 TestURLRequestContext context
;
87 context
.set_http_transaction_factory(&network_layer
);
91 GURL(kGZip_Transaction
.url
), DEFAULT_PRIORITY
, &d
, &context
);
92 MockTransaction
transaction(kGZip_Transaction
);
93 transaction
.test_mode
= TEST_MODE_SYNC_ALL
;
94 AddMockTransaction(&transaction
);
96 req
.set_method("GET");
99 base::MessageLoop::current()->Run();
101 EXPECT_TRUE(network_layer
.done_reading_called());
103 RemoveMockTransaction(&transaction
);
106 TEST(URLRequestJob
, RedirectTransactionNotifiedWhenDone
) {
107 MockNetworkLayer network_layer
;
108 TestURLRequestContext context
;
109 context
.set_http_transaction_factory(&network_layer
);
113 GURL(kRedirect_Transaction
.url
), DEFAULT_PRIORITY
, &d
, &context
);
114 AddMockTransaction(&kRedirect_Transaction
);
116 req
.set_method("GET");
119 base::MessageLoop::current()->Run();
121 EXPECT_TRUE(network_layer
.done_reading_called());
123 RemoveMockTransaction(&kRedirect_Transaction
);