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

Side by Side Diff: net/http/winhttp_request_throttle_unittest.cc

Issue 17635: Remove HttpTransactionWinHttp and the --winhttp command-line... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « net/http/winhttp_request_throttle.cc ('k') | net/net.xcodeproj/project.pbxproj » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2006-2008 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.
4
5 #include "base/string_util.h"
6 #include "net/http/winhttp_request_throttle.h"
7 #include "testing/gtest/include/gtest/gtest.h"
8
9 namespace {
10
11 // Converts an int i to an HINTERNET (void *) request handle.
12 HINTERNET RequestHandle(int i) {
13 return reinterpret_cast<HINTERNET>(static_cast<intptr_t>(i));
14 }
15
16 class MockRequestThrottle : public net::WinHttpRequestThrottle {
17 public:
18 MockRequestThrottle() : last_sent_request_(NULL) { }
19
20 // The request handle of the last sent request. This allows us to determine
21 // whether a submitted request was sent or queued.
22 HINTERNET last_sent_request() const { return last_sent_request_; }
23
24 protected:
25 virtual BOOL SendRequest(HINTERNET request_handle,
26 DWORD total_size,
27 DWORD_PTR context,
28 bool report_async_error) {
29 last_sent_request_ = request_handle;
30 return TRUE;
31 }
32
33 private:
34 HINTERNET last_sent_request_;
35
36 DISALLOW_EVIL_CONSTRUCTORS(MockRequestThrottle);
37 };
38
39 } // namespace
40
41 namespace net {
42
43 TEST(WinHttpRequestThrottleTest, OneServer) {
44 MockRequestThrottle throttle;
45 std::string server("http://www.foo.com");
46 HINTERNET request_handle;
47
48 // Submit 20 requests to the request throttle.
49 // Expected outcome: 6 requests should be in progress, and requests 7-20
50 // should be queued.
51 for (int i = 1; i <= 20; i++) {
52 request_handle = RequestHandle(i);
53 EXPECT_TRUE(throttle.SubmitRequest(server, request_handle, 0, 0));
54 if (i <= 6)
55 EXPECT_EQ(request_handle, throttle.last_sent_request());
56 else
57 EXPECT_EQ(RequestHandle(6), throttle.last_sent_request());
58 }
59
60 // Notify the request throttle of the completion of 10 requests.
61 // Expected outcome: 6 requests should be in progress, and requests 17-20
62 // should be queued.
63 for (int j = 0; j < 10; j++) {
64 throttle.NotifyRequestDone(server);
65 EXPECT_EQ(RequestHandle(7 + j), throttle.last_sent_request());
66 }
67
68 // Remove request 17, which is queued.
69 // Expected outcome: Requests 18-20 should remain queued.
70 request_handle = RequestHandle(17);
71 throttle.RemoveRequest(server, request_handle);
72 EXPECT_EQ(RequestHandle(16), throttle.last_sent_request());
73
74 // Remove request 16, which is in progress.
75 // Expected outcome: The request throttle should send request 18.
76 // Requests 19-20 should remained queued.
77 request_handle = RequestHandle(16);
78 throttle.RemoveRequest(server, request_handle);
79 EXPECT_EQ(RequestHandle(18), throttle.last_sent_request());
80
81 // Notify the request throttle of the completion of the remaining
82 // 8 requests.
83 for (int j = 0; j < 8; j++) {
84 throttle.NotifyRequestDone(server);
85 if (j < 2)
86 EXPECT_EQ(RequestHandle(19 + j), throttle.last_sent_request());
87 else
88 EXPECT_EQ(RequestHandle(20), throttle.last_sent_request());
89 }
90 }
91
92 // Submit requests to a large number (> 64) of servers to force the garbage
93 // collection of idle PerServerThrottles.
94 TEST(WinHttpRequestThrottleTest, GarbageCollect) {
95 MockRequestThrottle throttle;
96 for (int i = 0; i < 150; i++) {
97 std::string server("http://www.foo");
98 server.append(IntToString(i));
99 server.append(".com");
100 throttle.SubmitRequest(server, RequestHandle(1), 0, 0);
101 throttle.NotifyRequestDone(server);
102 if (i < 64)
103 EXPECT_EQ(i + 1, throttle.throttles_.size());
104 else if (i < 129)
105 EXPECT_EQ(i - 64, throttle.throttles_.size());
106 else
107 EXPECT_EQ(i - 129, throttle.throttles_.size());
108 }
109 }
110
111 } // namespace net
112
OLDNEW
« no previous file with comments | « net/http/winhttp_request_throttle.cc ('k') | net/net.xcodeproj/project.pbxproj » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698