OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/histogram.h" | 6 #include "base/histogram.h" |
7 #include "googleurl/src/gurl.h" | 7 #include "googleurl/src/gurl.h" |
8 #include "net/socket_stream/socket_stream_metrics.h" | 8 #include "net/socket_stream/socket_stream_metrics.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "testing/platform_test.h" | 10 #include "testing/platform_test.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 | 35 |
36 SocketStreamMetrics unknown(GURL("unknown://www.example.com/")); | 36 SocketStreamMetrics unknown(GURL("unknown://www.example.com/")); |
37 SocketStreamMetrics ws1(GURL("ws://www.example.com/")); | 37 SocketStreamMetrics ws1(GURL("ws://www.example.com/")); |
38 SocketStreamMetrics ws2(GURL("ws://www.example.com/")); | 38 SocketStreamMetrics ws2(GURL("ws://www.example.com/")); |
39 SocketStreamMetrics wss1(GURL("wss://www.example.com/")); | 39 SocketStreamMetrics wss1(GURL("wss://www.example.com/")); |
40 SocketStreamMetrics wss2(GURL("wss://www.example.com/")); | 40 SocketStreamMetrics wss2(GURL("wss://www.example.com/")); |
41 SocketStreamMetrics wss3(GURL("wss://www.example.com/")); | 41 SocketStreamMetrics wss3(GURL("wss://www.example.com/")); |
42 | 42 |
43 ASSERT_TRUE(StatisticsRecorder::FindHistogram( | 43 ASSERT_TRUE(StatisticsRecorder::FindHistogram( |
44 "Net.SocketStream.ProtocolType", &histogram)); | 44 "Net.SocketStream.ProtocolType", &histogram)); |
45 EXPECT_EQ(kUmaTargetedHistogramFlag, histogram->flags()); | 45 EXPECT_EQ(Histogram::kUmaTargetedHistogramFlag, histogram->flags()); |
46 | 46 |
47 Histogram::SampleSet sample; | 47 Histogram::SampleSet sample; |
48 histogram->SnapshotSample(&sample); | 48 histogram->SnapshotSample(&sample); |
49 original.Resize(*histogram); // Ensure |original| size is same as |sample|. | 49 original.Resize(*histogram); // Ensure |original| size is same as |sample|. |
50 sample.Subtract(original); // Cancel the original values. | 50 sample.Subtract(original); // Cancel the original values. |
51 EXPECT_EQ(1, sample.counts(SocketStreamMetrics::PROTOCOL_UNKNOWN)); | 51 EXPECT_EQ(1, sample.counts(SocketStreamMetrics::PROTOCOL_UNKNOWN)); |
52 EXPECT_EQ(2, sample.counts(SocketStreamMetrics::PROTOCOL_WEBSOCKET)); | 52 EXPECT_EQ(2, sample.counts(SocketStreamMetrics::PROTOCOL_WEBSOCKET)); |
53 EXPECT_EQ(3, sample.counts(SocketStreamMetrics::PROTOCOL_WEBSOCKET_SECURE)); | 53 EXPECT_EQ(3, sample.counts(SocketStreamMetrics::PROTOCOL_WEBSOCKET_SECURE)); |
54 } | 54 } |
55 | 55 |
(...skipping 12 matching lines...) Expand all Loading... |
68 metrics.OnStartConnection(); | 68 metrics.OnStartConnection(); |
69 for (int i = 0; i < 2; ++i) | 69 for (int i = 0; i < 2; ++i) |
70 metrics.OnTunnelProxy(); | 70 metrics.OnTunnelProxy(); |
71 for (int i = 0; i < 3; ++i) | 71 for (int i = 0; i < 3; ++i) |
72 metrics.OnSOCKSProxy(); | 72 metrics.OnSOCKSProxy(); |
73 for (int i = 0; i < 4; ++i) | 73 for (int i = 0; i < 4; ++i) |
74 metrics.OnSSLConnection(); | 74 metrics.OnSSLConnection(); |
75 | 75 |
76 ASSERT_TRUE(StatisticsRecorder::FindHistogram( | 76 ASSERT_TRUE(StatisticsRecorder::FindHistogram( |
77 "Net.SocketStream.ConnectionType", &histogram)); | 77 "Net.SocketStream.ConnectionType", &histogram)); |
78 EXPECT_EQ(kUmaTargetedHistogramFlag, histogram->flags()); | 78 EXPECT_EQ(Histogram::kUmaTargetedHistogramFlag, histogram->flags()); |
79 | 79 |
80 Histogram::SampleSet sample; | 80 Histogram::SampleSet sample; |
81 histogram->SnapshotSample(&sample); | 81 histogram->SnapshotSample(&sample); |
82 original.Resize(*histogram); | 82 original.Resize(*histogram); |
83 sample.Subtract(original); | 83 sample.Subtract(original); |
84 EXPECT_EQ(1, sample.counts(SocketStreamMetrics::ALL_CONNECTIONS)); | 84 EXPECT_EQ(1, sample.counts(SocketStreamMetrics::ALL_CONNECTIONS)); |
85 EXPECT_EQ(2, sample.counts(SocketStreamMetrics::TUNNEL_CONNECTION)); | 85 EXPECT_EQ(2, sample.counts(SocketStreamMetrics::TUNNEL_CONNECTION)); |
86 EXPECT_EQ(3, sample.counts(SocketStreamMetrics::SOCKS_CONNECTION)); | 86 EXPECT_EQ(3, sample.counts(SocketStreamMetrics::SOCKS_CONNECTION)); |
87 EXPECT_EQ(4, sample.counts(SocketStreamMetrics::SSL_CONNECTION)); | 87 EXPECT_EQ(4, sample.counts(SocketStreamMetrics::SSL_CONNECTION)); |
88 } | 88 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 metrics.OnWrite(2); | 127 metrics.OnWrite(2); |
128 metrics.OnWrite(20); | 128 metrics.OnWrite(20); |
129 metrics.OnWrite(200); | 129 metrics.OnWrite(200); |
130 metrics.OnClose(); | 130 metrics.OnClose(); |
131 | 131 |
132 Histogram::SampleSet sample; | 132 Histogram::SampleSet sample; |
133 | 133 |
134 // ConnectionLatency. | 134 // ConnectionLatency. |
135 ASSERT_TRUE(StatisticsRecorder::FindHistogram( | 135 ASSERT_TRUE(StatisticsRecorder::FindHistogram( |
136 "Net.SocketStream.ConnectionLatency", &histogram)); | 136 "Net.SocketStream.ConnectionLatency", &histogram)); |
137 EXPECT_EQ(kUmaTargetedHistogramFlag, histogram->flags()); | 137 EXPECT_EQ(Histogram::kUmaTargetedHistogramFlag, histogram->flags()); |
138 // We don't check the contents of the histogram as it's time sensitive. | 138 // We don't check the contents of the histogram as it's time sensitive. |
139 | 139 |
140 // ConnectionEstablish. | 140 // ConnectionEstablish. |
141 ASSERT_TRUE(StatisticsRecorder::FindHistogram( | 141 ASSERT_TRUE(StatisticsRecorder::FindHistogram( |
142 "Net.SocketStream.ConnectionEstablish", &histogram)); | 142 "Net.SocketStream.ConnectionEstablish", &histogram)); |
143 EXPECT_EQ(kUmaTargetedHistogramFlag, histogram->flags()); | 143 EXPECT_EQ(Histogram::kUmaTargetedHistogramFlag, histogram->flags()); |
144 // We don't check the contents of the histogram as it's time sensitive. | 144 // We don't check the contents of the histogram as it's time sensitive. |
145 | 145 |
146 // Duration. | 146 // Duration. |
147 ASSERT_TRUE(StatisticsRecorder::FindHistogram( | 147 ASSERT_TRUE(StatisticsRecorder::FindHistogram( |
148 "Net.SocketStream.Duration", &histogram)); | 148 "Net.SocketStream.Duration", &histogram)); |
149 EXPECT_EQ(kUmaTargetedHistogramFlag, histogram->flags()); | 149 EXPECT_EQ(Histogram::kUmaTargetedHistogramFlag, histogram->flags()); |
150 // We don't check the contents of the histogram as it's time sensitive. | 150 // We don't check the contents of the histogram as it's time sensitive. |
151 | 151 |
152 // ReceivedBytes. | 152 // ReceivedBytes. |
153 ASSERT_TRUE(StatisticsRecorder::FindHistogram( | 153 ASSERT_TRUE(StatisticsRecorder::FindHistogram( |
154 "Net.SocketStream.ReceivedBytes", &histogram)); | 154 "Net.SocketStream.ReceivedBytes", &histogram)); |
155 EXPECT_EQ(kUmaTargetedHistogramFlag, histogram->flags()); | 155 EXPECT_EQ(Histogram::kUmaTargetedHistogramFlag, histogram->flags()); |
156 histogram->SnapshotSample(&sample); | 156 histogram->SnapshotSample(&sample); |
157 EXPECT_EQ(11, sample.sum() - original_received_bytes); // 11 bytes read. | 157 EXPECT_EQ(11, sample.sum() - original_received_bytes); // 11 bytes read. |
158 | 158 |
159 // ReceivedCounts. | 159 // ReceivedCounts. |
160 ASSERT_TRUE(StatisticsRecorder::FindHistogram( | 160 ASSERT_TRUE(StatisticsRecorder::FindHistogram( |
161 "Net.SocketStream.ReceivedCounts", &histogram)); | 161 "Net.SocketStream.ReceivedCounts", &histogram)); |
162 EXPECT_EQ(kUmaTargetedHistogramFlag, histogram->flags()); | 162 EXPECT_EQ(Histogram::kUmaTargetedHistogramFlag, histogram->flags()); |
163 histogram->SnapshotSample(&sample); | 163 histogram->SnapshotSample(&sample); |
164 EXPECT_EQ(2, sample.sum() - original_received_counts); // 2 read requests. | 164 EXPECT_EQ(2, sample.sum() - original_received_counts); // 2 read requests. |
165 | 165 |
166 // SentBytes. | 166 // SentBytes. |
167 ASSERT_TRUE(StatisticsRecorder::FindHistogram( | 167 ASSERT_TRUE(StatisticsRecorder::FindHistogram( |
168 "Net.SocketStream.SentBytes", &histogram)); | 168 "Net.SocketStream.SentBytes", &histogram)); |
169 EXPECT_EQ(kUmaTargetedHistogramFlag, histogram->flags()); | 169 EXPECT_EQ(Histogram::kUmaTargetedHistogramFlag, histogram->flags()); |
170 histogram->SnapshotSample(&sample); | 170 histogram->SnapshotSample(&sample); |
171 EXPECT_EQ(222, sample.sum() - original_sent_bytes); // 222 bytes sent. | 171 EXPECT_EQ(222, sample.sum() - original_sent_bytes); // 222 bytes sent. |
172 | 172 |
173 // SentCounts. | 173 // SentCounts. |
174 ASSERT_TRUE(StatisticsRecorder::FindHistogram( | 174 ASSERT_TRUE(StatisticsRecorder::FindHistogram( |
175 "Net.SocketStream.SentCounts", &histogram)); | 175 "Net.SocketStream.SentCounts", &histogram)); |
176 EXPECT_EQ(kUmaTargetedHistogramFlag, histogram->flags()); | 176 EXPECT_EQ(Histogram::kUmaTargetedHistogramFlag, histogram->flags()); |
177 histogram->SnapshotSample(&sample); | 177 histogram->SnapshotSample(&sample); |
178 EXPECT_EQ(3, sample.sum() - original_sent_counts); // 3 write requests. | 178 EXPECT_EQ(3, sample.sum() - original_sent_counts); // 3 write requests. |
179 } | 179 } |
180 | 180 |
181 } // namespace net | 181 } // namespace net |
OLD | NEW |