OLD | NEW |
1 // Copyright (c) 2009 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/metrics/histogram.h" | 6 #include "base/metrics/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" |
11 | 11 |
12 using base::Histogram; | 12 using base::Histogram; |
13 using base::StatisticsRecorder; | 13 using base::StatisticsRecorder; |
14 | 14 |
15 namespace net { | 15 namespace net { |
16 | 16 |
17 TEST(SocketStreamMetricsTest, Initialize) { | 17 TEST(SocketStreamMetricsTest, Initialize) { |
18 if (!StatisticsRecorder::IsActive()) { | 18 if (!StatisticsRecorder::IsActive()) { |
19 // Create the recorder if not yet started, as SocketStreamMetrics | 19 // Create the recorder if not yet started, as SocketStreamMetrics |
20 // relys on the StatisticsRecorder to be present. This is useful when | 20 // relys on the StatisticsRecorder to be present. This is useful when |
21 // tests are run with --gtest_filter='SocketStreamMetricsTest*'. | 21 // tests are run with --gtest_filter='SocketStreamMetricsTest*'. |
22 static StatisticsRecorder *recorder = NULL; | 22 static StatisticsRecorder *recorder = NULL; |
23 recorder = new StatisticsRecorder; | 23 recorder = new StatisticsRecorder; |
24 } | 24 } |
25 } | 25 } |
26 | 26 |
27 TEST(SocketStreamMetricsTest, ProtocolType) { | 27 TEST(SocketStreamMetricsTest, ProtocolType) { |
28 scoped_refptr<Histogram> histogram; | 28 Histogram* histogram; |
29 | 29 |
30 // First we'll preserve the original values. We need to do this | 30 // First we'll preserve the original values. We need to do this |
31 // as histograms can get affected by other tests. In particular, | 31 // as histograms can get affected by other tests. In particular, |
32 // SocketStreamTest and WebSocketTest can affect the histograms. | 32 // SocketStreamTest and WebSocketTest can affect the histograms. |
33 Histogram::SampleSet original; | 33 Histogram::SampleSet original; |
34 if (StatisticsRecorder::FindHistogram( | 34 if (StatisticsRecorder::FindHistogram( |
35 "Net.SocketStream.ProtocolType", &histogram)) { | 35 "Net.SocketStream.ProtocolType", &histogram)) { |
36 histogram->SnapshotSample(&original); | 36 histogram->SnapshotSample(&original); |
37 } | 37 } |
38 | 38 |
(...skipping 11 matching lines...) Expand all Loading... |
50 Histogram::SampleSet sample; | 50 Histogram::SampleSet sample; |
51 histogram->SnapshotSample(&sample); | 51 histogram->SnapshotSample(&sample); |
52 original.Resize(*histogram); // Ensure |original| size is same as |sample|. | 52 original.Resize(*histogram); // Ensure |original| size is same as |sample|. |
53 sample.Subtract(original); // Cancel the original values. | 53 sample.Subtract(original); // Cancel the original values. |
54 EXPECT_EQ(1, sample.counts(SocketStreamMetrics::PROTOCOL_UNKNOWN)); | 54 EXPECT_EQ(1, sample.counts(SocketStreamMetrics::PROTOCOL_UNKNOWN)); |
55 EXPECT_EQ(2, sample.counts(SocketStreamMetrics::PROTOCOL_WEBSOCKET)); | 55 EXPECT_EQ(2, sample.counts(SocketStreamMetrics::PROTOCOL_WEBSOCKET)); |
56 EXPECT_EQ(3, sample.counts(SocketStreamMetrics::PROTOCOL_WEBSOCKET_SECURE)); | 56 EXPECT_EQ(3, sample.counts(SocketStreamMetrics::PROTOCOL_WEBSOCKET_SECURE)); |
57 } | 57 } |
58 | 58 |
59 TEST(SocketStreamMetricsTest, ConnectionType) { | 59 TEST(SocketStreamMetricsTest, ConnectionType) { |
60 scoped_refptr<Histogram> histogram; | 60 Histogram* histogram; |
61 | 61 |
62 // First we'll preserve the original values. | 62 // First we'll preserve the original values. |
63 Histogram::SampleSet original; | 63 Histogram::SampleSet original; |
64 if (StatisticsRecorder::FindHistogram( | 64 if (StatisticsRecorder::FindHistogram( |
65 "Net.SocketStream.ConnectionType", &histogram)) { | 65 "Net.SocketStream.ConnectionType", &histogram)) { |
66 histogram->SnapshotSample(&original); | 66 histogram->SnapshotSample(&original); |
67 } | 67 } |
68 | 68 |
69 SocketStreamMetrics metrics(GURL("ws://www.example.com/")); | 69 SocketStreamMetrics metrics(GURL("ws://www.example.com/")); |
70 for (int i = 0; i < 1; ++i) | 70 for (int i = 0; i < 1; ++i) |
(...skipping 13 matching lines...) Expand all Loading... |
84 histogram->SnapshotSample(&sample); | 84 histogram->SnapshotSample(&sample); |
85 original.Resize(*histogram); | 85 original.Resize(*histogram); |
86 sample.Subtract(original); | 86 sample.Subtract(original); |
87 EXPECT_EQ(1, sample.counts(SocketStreamMetrics::ALL_CONNECTIONS)); | 87 EXPECT_EQ(1, sample.counts(SocketStreamMetrics::ALL_CONNECTIONS)); |
88 EXPECT_EQ(2, sample.counts(SocketStreamMetrics::TUNNEL_CONNECTION)); | 88 EXPECT_EQ(2, sample.counts(SocketStreamMetrics::TUNNEL_CONNECTION)); |
89 EXPECT_EQ(3, sample.counts(SocketStreamMetrics::SOCKS_CONNECTION)); | 89 EXPECT_EQ(3, sample.counts(SocketStreamMetrics::SOCKS_CONNECTION)); |
90 EXPECT_EQ(4, sample.counts(SocketStreamMetrics::SSL_CONNECTION)); | 90 EXPECT_EQ(4, sample.counts(SocketStreamMetrics::SSL_CONNECTION)); |
91 } | 91 } |
92 | 92 |
93 TEST(SocketStreamMetricsTest, OtherNumbers) { | 93 TEST(SocketStreamMetricsTest, OtherNumbers) { |
94 scoped_refptr<Histogram> histogram; | 94 Histogram* histogram; |
95 | 95 |
96 // First we'll preserve the original values. | 96 // First we'll preserve the original values. |
97 int64 original_received_bytes = 0; | 97 int64 original_received_bytes = 0; |
98 int64 original_received_counts = 0; | 98 int64 original_received_counts = 0; |
99 int64 original_sent_bytes = 0; | 99 int64 original_sent_bytes = 0; |
100 int64 original_sent_counts = 0; | 100 int64 original_sent_counts = 0; |
101 | 101 |
102 Histogram::SampleSet original; | 102 Histogram::SampleSet original; |
103 if (StatisticsRecorder::FindHistogram( | 103 if (StatisticsRecorder::FindHistogram( |
104 "Net.SocketStream.ReceivedBytes", &histogram)) { | 104 "Net.SocketStream.ReceivedBytes", &histogram)) { |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 | 175 |
176 // SentCounts. | 176 // SentCounts. |
177 ASSERT_TRUE(StatisticsRecorder::FindHistogram( | 177 ASSERT_TRUE(StatisticsRecorder::FindHistogram( |
178 "Net.SocketStream.SentCounts", &histogram)); | 178 "Net.SocketStream.SentCounts", &histogram)); |
179 EXPECT_EQ(Histogram::kUmaTargetedHistogramFlag, histogram->flags()); | 179 EXPECT_EQ(Histogram::kUmaTargetedHistogramFlag, histogram->flags()); |
180 histogram->SnapshotSample(&sample); | 180 histogram->SnapshotSample(&sample); |
181 EXPECT_EQ(3, sample.sum() - original_sent_counts); // 3 write requests. | 181 EXPECT_EQ(3, sample.sum() - original_sent_counts); // 3 write requests. |
182 } | 182 } |
183 | 183 |
184 } // namespace net | 184 } // namespace net |
OLD | NEW |