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

Side by Side Diff: net/http/http_transaction_unittest.h

Issue 12701011: [Net] Propagate priority changes from URLRequest to HttpTransaction (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix use-after-free bug Created 7 years, 9 months 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
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 #ifndef NET_HTTP_HTTP_TRANSACTION_UNITTEST_H_ 5 #ifndef NET_HTTP_HTTP_TRANSACTION_UNITTEST_H_
6 #define NET_HTTP_HTTP_TRANSACTION_UNITTEST_H_ 6 #define NET_HTTP_HTTP_TRANSACTION_UNITTEST_H_
7 7
8 #include "net/http/http_transaction.h" 8 #include "net/http/http_transaction.h"
9 9
10 #include <string> 10 #include <string>
11 11
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "base/compiler_specific.h" 13 #include "base/compiler_specific.h"
14 #include "base/memory/scoped_ptr.h"
14 #include "base/string16.h" 15 #include "base/string16.h"
15 #include "net/base/io_buffer.h" 16 #include "net/base/io_buffer.h"
16 #include "net/base/load_flags.h" 17 #include "net/base/load_flags.h"
17 #include "net/base/net_errors.h" 18 #include "net/base/net_errors.h"
18 #include "net/base/request_priority.h" 19 #include "net/base/request_priority.h"
19 #include "net/base/test_completion_callback.h" 20 #include "net/base/test_completion_callback.h"
20 #include "net/disk_cache/disk_cache.h" 21 #include "net/disk_cache/disk_cache.h"
21 #include "net/http/http_cache.h" 22 #include "net/http/http_cache.h"
22 #include "net/http/http_request_info.h" 23 #include "net/http/http_request_info.h"
23 #include "net/http/http_response_headers.h" 24 #include "net/http/http_response_headers.h"
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 186
186 virtual const net::HttpResponseInfo* GetResponseInfo() const OVERRIDE; 187 virtual const net::HttpResponseInfo* GetResponseInfo() const OVERRIDE;
187 188
188 virtual net::LoadState GetLoadState() const OVERRIDE; 189 virtual net::LoadState GetLoadState() const OVERRIDE;
189 190
190 virtual net::UploadProgress GetUploadProgress() const OVERRIDE; 191 virtual net::UploadProgress GetUploadProgress() const OVERRIDE;
191 192
192 virtual bool GetLoadTimingInfo( 193 virtual bool GetLoadTimingInfo(
193 net::LoadTimingInfo* load_timing_info) const OVERRIDE; 194 net::LoadTimingInfo* load_timing_info) const OVERRIDE;
194 195
196 virtual void SetPriority(net::RequestPriority priority) OVERRIDE;
197
198 net::RequestPriority priority() const { return priority_; }
199
195 private: 200 private:
196 void CallbackLater(const net::CompletionCallback& callback, int result); 201 void CallbackLater(const net::CompletionCallback& callback, int result);
197 void RunCallback(const net::CompletionCallback& callback, int result); 202 void RunCallback(const net::CompletionCallback& callback, int result);
198 203
199 base::WeakPtrFactory<MockNetworkTransaction> weak_factory_; 204 base::WeakPtrFactory<MockNetworkTransaction> weak_factory_;
200 net::HttpResponseInfo response_; 205 net::HttpResponseInfo response_;
201 std::string data_; 206 std::string data_;
202 int data_cursor_; 207 int data_cursor_;
203 int test_mode_; 208 int test_mode_;
209 net::RequestPriority priority_;
204 base::WeakPtr<MockNetworkLayer> transaction_factory_; 210 base::WeakPtr<MockNetworkLayer> transaction_factory_;
205 }; 211 };
206 212
207 class MockNetworkLayer : public net::HttpTransactionFactory, 213 class MockNetworkLayer : public net::HttpTransactionFactory,
208 public base::SupportsWeakPtr<MockNetworkLayer> { 214 public base::SupportsWeakPtr<MockNetworkLayer> {
209 public: 215 public:
210 MockNetworkLayer(); 216 MockNetworkLayer();
211 virtual ~MockNetworkLayer(); 217 virtual ~MockNetworkLayer();
212 218
213 int transaction_count() const { return transaction_count_; } 219 int transaction_count() const { return transaction_count_; }
214 bool done_reading_called() const { return done_reading_called_; } 220 bool done_reading_called() const { return done_reading_called_; }
215 void TransactionDoneReading(); 221 void TransactionDoneReading();
216 222
223 // Returns the last transaction created by CreateTransaction, or
224 // NULL if one has not been created yet.
mmenke 2013/03/21 15:39:23 Think it's worth noting that this owns a reference
akalin 2013/03/21 23:43:48 Turns out the DelegatingTransaction approach doesn
225 MockNetworkTransaction* last_transaction() {
226 return last_transaction_.get();
227 }
228
229 // Makes last_transaction() return NULL until the next transaction
230 // is created.
231 void ClearLastTransaction() {
232 last_transaction_.reset();
233 }
234
217 // net::HttpTransactionFactory: 235 // net::HttpTransactionFactory:
218 virtual int CreateTransaction( 236 virtual int CreateTransaction(
219 net::RequestPriority priority, 237 net::RequestPriority priority,
220 scoped_ptr<net::HttpTransaction>* trans, 238 scoped_ptr<net::HttpTransaction>* trans,
221 net::HttpTransactionDelegate* delegate) OVERRIDE; 239 net::HttpTransactionDelegate* delegate) OVERRIDE;
222 virtual net::HttpCache* GetCache() OVERRIDE; 240 virtual net::HttpCache* GetCache() OVERRIDE;
223 virtual net::HttpNetworkSession* GetSession() OVERRIDE; 241 virtual net::HttpNetworkSession* GetSession() OVERRIDE;
224 242
225 private: 243 private:
226 int transaction_count_; 244 int transaction_count_;
227 bool done_reading_called_; 245 bool done_reading_called_;
246 scoped_ptr<MockNetworkTransaction> last_transaction_;
228 }; 247 };
229 248
230 //----------------------------------------------------------------------------- 249 //-----------------------------------------------------------------------------
231 // helpers 250 // helpers
232 251
233 // read the transaction completely 252 // read the transaction completely
234 int ReadTransaction(net::HttpTransaction* trans, std::string* result); 253 int ReadTransaction(net::HttpTransaction* trans, std::string* result);
235 254
236 #endif // NET_HTTP_HTTP_TRANSACTION_UNITTEST_H_ 255 #endif // NET_HTTP_HTTP_TRANSACTION_UNITTEST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698