Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(79)

Side by Side Diff: net/url_request/url_request_job_unittest.cc

Issue 51953002: [Net] Add a priority parameter to URLRequest's constructor (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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/base/request_priority.h"
7 #include "net/http/http_transaction_unittest.h" 8 #include "net/http/http_transaction_unittest.h"
8 #include "net/url_request/url_request_test_util.h" 9 #include "net/url_request/url_request_test_util.h"
9 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
10 11
12 namespace net {
13
11 namespace { 14 namespace {
12 15
13 // This is a header that signals the end of the data. 16 // This is a header that signals the end of the data.
14 const char kGzipGata[] = "\x1f\x08b\x08\0\0\0\0\0\0\3\3\0\0\0\0\0\0\0\0"; 17 const char kGzipGata[] = "\x1f\x08b\x08\0\0\0\0\0\0\3\3\0\0\0\0\0\0\0\0";
15 18
16 void GZipServer(const net::HttpRequestInfo* request, 19 void GZipServer(const HttpRequestInfo* request,
17 std::string* response_status, std::string* response_headers, 20 std::string* response_status,
21 std::string* response_headers,
18 std::string* response_data) { 22 std::string* response_data) {
19 response_data->assign(kGzipGata, sizeof(kGzipGata)); 23 response_data->assign(kGzipGata, sizeof(kGzipGata));
20 } 24 }
21 25
22 const MockTransaction kGZip_Transaction = { 26 const MockTransaction kGZip_Transaction = {
23 "http://www.google.com/gzyp", 27 "http://www.google.com/gzyp",
24 "GET", 28 "GET",
25 base::Time(), 29 base::Time(),
26 "", 30 "",
27 net::LOAD_NORMAL, 31 LOAD_NORMAL,
28 "HTTP/1.1 200 OK", 32 "HTTP/1.1 200 OK",
29 "Cache-Control: max-age=10000\n" 33 "Cache-Control: max-age=10000\n"
30 "Content-Encoding: gzip\n" 34 "Content-Encoding: gzip\n"
31 "Content-Length: 30\n", // Intentionally wrong. 35 "Content-Length: 30\n", // Intentionally wrong.
32 base::Time(), 36 base::Time(),
33 "", 37 "",
34 TEST_MODE_NORMAL, 38 TEST_MODE_NORMAL,
35 &GZipServer, 39 &GZipServer,
36 0, 40 0,
37 net::OK 41 OK
38 }; 42 };
39 43
40 const MockTransaction kRedirect_Transaction = { 44 const MockTransaction kRedirect_Transaction = {
41 "http://www.google.com/redirect", 45 "http://www.google.com/redirect",
42 "GET", 46 "GET",
43 base::Time(), 47 base::Time(),
44 "", 48 "",
45 net::LOAD_NORMAL, 49 LOAD_NORMAL,
46 "HTTP/1.1 302 Found", 50 "HTTP/1.1 302 Found",
47 "Cache-Control: max-age=10000\n" 51 "Cache-Control: max-age=10000\n"
48 "Location: http://www.google.com/destination\n" 52 "Location: http://www.google.com/destination\n"
49 "Content-Length: 5\n", 53 "Content-Length: 5\n",
50 base::Time(), 54 base::Time(),
51 "hello", 55 "hello",
52 TEST_MODE_NORMAL, 56 TEST_MODE_NORMAL,
53 NULL, 57 NULL,
54 0, 58 0,
55 net::OK 59 OK
56 }; 60 };
57 61
58 } // namespace 62 } // namespace
59 63
60 TEST(URLRequestJob, TransactionNotifiedWhenDone) { 64 TEST(URLRequestJob, TransactionNotifiedWhenDone) {
61 MockNetworkLayer network_layer; 65 MockNetworkLayer network_layer;
62 net::TestURLRequestContext context; 66 TestURLRequestContext context;
63 context.set_http_transaction_factory(&network_layer); 67 context.set_http_transaction_factory(&network_layer);
64 68
65 net::TestDelegate d; 69 TestDelegate d;
66 net::TestURLRequest req(GURL(kGZip_Transaction.url), &d, &context, NULL); 70 TestURLRequest req(
71 GURL(kGZip_Transaction.url), DEFAULT_PRIORITY, &d, &context);
67 AddMockTransaction(&kGZip_Transaction); 72 AddMockTransaction(&kGZip_Transaction);
68 73
69 req.set_method("GET"); 74 req.set_method("GET");
70 req.Start(); 75 req.Start();
71 76
72 base::MessageLoop::current()->Run(); 77 base::MessageLoop::current()->Run();
73 78
74 EXPECT_TRUE(network_layer.done_reading_called()); 79 EXPECT_TRUE(network_layer.done_reading_called());
75 80
76 RemoveMockTransaction(&kGZip_Transaction); 81 RemoveMockTransaction(&kGZip_Transaction);
77 } 82 }
78 83
79 TEST(URLRequestJob, SyncTransactionNotifiedWhenDone) { 84 TEST(URLRequestJob, SyncTransactionNotifiedWhenDone) {
80 MockNetworkLayer network_layer; 85 MockNetworkLayer network_layer;
81 net::TestURLRequestContext context; 86 TestURLRequestContext context;
82 context.set_http_transaction_factory(&network_layer); 87 context.set_http_transaction_factory(&network_layer);
83 88
84 net::TestDelegate d; 89 TestDelegate d;
85 net::TestURLRequest req(GURL(kGZip_Transaction.url), &d, &context, NULL); 90 TestURLRequest req(
91 GURL(kGZip_Transaction.url), DEFAULT_PRIORITY, &d, &context);
86 MockTransaction transaction(kGZip_Transaction); 92 MockTransaction transaction(kGZip_Transaction);
87 transaction.test_mode = TEST_MODE_SYNC_ALL; 93 transaction.test_mode = TEST_MODE_SYNC_ALL;
88 AddMockTransaction(&transaction); 94 AddMockTransaction(&transaction);
89 95
90 req.set_method("GET"); 96 req.set_method("GET");
91 req.Start(); 97 req.Start();
92 98
93 base::MessageLoop::current()->Run(); 99 base::MessageLoop::current()->Run();
94 100
95 EXPECT_TRUE(network_layer.done_reading_called()); 101 EXPECT_TRUE(network_layer.done_reading_called());
96 102
97 RemoveMockTransaction(&transaction); 103 RemoveMockTransaction(&transaction);
98 } 104 }
99 105
100 TEST(URLRequestJob, RedirectTransactionNotifiedWhenDone) { 106 TEST(URLRequestJob, RedirectTransactionNotifiedWhenDone) {
101 MockNetworkLayer network_layer; 107 MockNetworkLayer network_layer;
102 net::TestURLRequestContext context; 108 TestURLRequestContext context;
103 context.set_http_transaction_factory(&network_layer); 109 context.set_http_transaction_factory(&network_layer);
104 110
105 net::TestDelegate d; 111 TestDelegate d;
106 net::TestURLRequest req(GURL(kRedirect_Transaction.url), &d, &context, NULL); 112 TestURLRequest req(
113 GURL(kRedirect_Transaction.url), DEFAULT_PRIORITY, &d, &context);
107 AddMockTransaction(&kRedirect_Transaction); 114 AddMockTransaction(&kRedirect_Transaction);
108 115
109 req.set_method("GET"); 116 req.set_method("GET");
110 req.Start(); 117 req.Start();
111 118
112 base::MessageLoop::current()->Run(); 119 base::MessageLoop::current()->Run();
113 120
114 EXPECT_TRUE(network_layer.done_reading_called()); 121 EXPECT_TRUE(network_layer.done_reading_called());
115 122
116 RemoveMockTransaction(&kRedirect_Transaction); 123 RemoveMockTransaction(&kRedirect_Transaction);
117 } 124 }
125
126 } // namespace net
OLDNEW
« no previous file with comments | « net/url_request/url_request_job_factory_impl_unittest.cc ('k') | net/url_request/url_request_test_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698