OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/url_request/url_request_job.h" | 5 #include "net/url_request/url_request_job.h" |
6 | 6 |
7 #include "net/http/http_transaction_unittest.h" | 7 #include "net/http/http_transaction_unittest.h" |
8 #include "net/url_request/url_request_test_util.h" | 8 #include "net/url_request/url_request_test_util.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
(...skipping 21 matching lines...) Expand all Loading... |
32 base::Time(), | 32 base::Time(), |
33 "", | 33 "", |
34 TEST_MODE_NORMAL, | 34 TEST_MODE_NORMAL, |
35 &GZipServer, | 35 &GZipServer, |
36 0 | 36 0 |
37 }; | 37 }; |
38 | 38 |
39 } // namespace | 39 } // namespace |
40 | 40 |
41 TEST(URLRequestJob, TransactionNotifiedWhenDone) { | 41 TEST(URLRequestJob, TransactionNotifiedWhenDone) { |
| 42 MockNetworkLayer network_layer; |
| 43 TestURLRequestContext context; |
| 44 context.set_http_transaction_factory(&network_layer); |
| 45 |
42 TestDelegate d; | 46 TestDelegate d; |
43 TestURLRequest req(GURL(kGZip_Transaction.url), &d); | 47 TestURLRequest req(GURL(kGZip_Transaction.url), &d); |
44 MockNetworkLayer network_layer; | |
45 | |
46 AddMockTransaction(&kGZip_Transaction); | 48 AddMockTransaction(&kGZip_Transaction); |
47 | 49 |
48 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); | 50 req.set_context(&context); |
49 context->set_http_transaction_factory(&network_layer); | |
50 req.set_context(context); | |
51 req.set_method("GET"); | 51 req.set_method("GET"); |
52 req.Start(); | 52 req.Start(); |
53 | 53 |
54 MessageLoop::current()->Run(); | 54 MessageLoop::current()->Run(); |
55 | 55 |
56 EXPECT_TRUE(network_layer.done_reading_called()); | 56 EXPECT_TRUE(network_layer.done_reading_called()); |
57 | 57 |
58 RemoveMockTransaction(&kGZip_Transaction); | 58 RemoveMockTransaction(&kGZip_Transaction); |
59 } | 59 } |
60 | 60 |
61 TEST(URLRequestJob, SyncTransactionNotifiedWhenDone) { | 61 TEST(URLRequestJob, SyncTransactionNotifiedWhenDone) { |
| 62 MockNetworkLayer network_layer; |
| 63 TestURLRequestContext context; |
| 64 context.set_http_transaction_factory(&network_layer); |
| 65 |
62 TestDelegate d; | 66 TestDelegate d; |
63 TestURLRequest req(GURL(kGZip_Transaction.url), &d); | 67 TestURLRequest req(GURL(kGZip_Transaction.url), &d); |
64 MockNetworkLayer network_layer; | |
65 | |
66 MockTransaction transaction(kGZip_Transaction); | 68 MockTransaction transaction(kGZip_Transaction); |
67 transaction.test_mode = TEST_MODE_SYNC_ALL; | 69 transaction.test_mode = TEST_MODE_SYNC_ALL; |
68 AddMockTransaction(&transaction); | 70 AddMockTransaction(&transaction); |
69 | 71 |
70 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); | 72 req.set_context(&context); |
71 context->set_http_transaction_factory(&network_layer); | |
72 req.set_context(context); | |
73 req.set_method("GET"); | 73 req.set_method("GET"); |
74 req.Start(); | 74 req.Start(); |
75 | 75 |
76 MessageLoop::current()->Run(); | 76 MessageLoop::current()->Run(); |
77 | 77 |
78 EXPECT_TRUE(network_layer.done_reading_called()); | 78 EXPECT_TRUE(network_layer.done_reading_called()); |
79 | 79 |
80 RemoveMockTransaction(&transaction); | 80 RemoveMockTransaction(&transaction); |
81 } | 81 } |
OLD | NEW |