| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/nqe/network_quality_observation.h" | 5 #include "net/nqe/observation_buffer.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> |
| 10 #include <utility> |
| 9 #include <vector> | 11 #include <vector> |
| 10 | 12 |
| 11 #include "base/logging.h" | 13 #include "base/logging.h" |
| 12 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/ptr_util.h" |
| 16 #include "base/test/simple_test_tick_clock.h" |
| 13 #include "base/time/time.h" | 17 #include "base/time/time.h" |
| 18 #include "net/nqe/network_quality_observation.h" |
| 14 #include "net/nqe/network_quality_observation_source.h" | 19 #include "net/nqe/network_quality_observation_source.h" |
| 15 #include "net/nqe/observation_buffer.h" | |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 21 |
| 18 namespace net { | 22 namespace net { |
| 19 | 23 |
| 20 namespace nqe { | 24 namespace nqe { |
| 21 | 25 |
| 26 namespace internal { |
| 27 |
| 22 namespace { | 28 namespace { |
| 23 | 29 |
| 30 // Verify that the buffer size is never exceeded. |
| 31 TEST(NetworkQualityObservationBufferTest, BoundedBuffer) { |
| 32 ObservationBuffer<int32_t> observation_buffer(1.0); |
| 33 const base::TimeTicks now = |
| 34 base::TimeTicks() + base::TimeDelta::FromSeconds(1); |
| 35 for (int i = 1; i <= 1000; ++i) { |
| 36 observation_buffer.AddObservation( |
| 37 Observation<int32_t>(i, now, NETWORK_QUALITY_OBSERVATION_SOURCE_TCP)); |
| 38 // The number of entries should be at most the maximum buffer size. |
| 39 EXPECT_GE(300u, observation_buffer.Size()); |
| 40 } |
| 41 } |
| 42 |
| 43 // Test disabled on OS_WIN to avoid linking errors when calling |
| 44 // SetTickClockForTesting. |
| 45 // TODO(tbansal): crbug.com/651963. Pass the clock through NQE's constructor. |
| 46 #if !defined(OS_WIN) |
| 47 // Verify that the percentiles are monotonically non-decreasing when a weight is |
| 48 // applied. |
| 49 TEST(NetworkQualityObservationBufferTest, GetPercentileWithWeights) { |
| 50 std::unique_ptr<base::SimpleTestTickClock> tick_clock( |
| 51 new base::SimpleTestTickClock()); |
| 52 base::SimpleTestTickClock* tick_clock_ptr = tick_clock.get(); |
| 53 |
| 54 ObservationBuffer<int32_t> observation_buffer(0.98); |
| 55 observation_buffer.SetTickClockForTesting(std::move(tick_clock)); |
| 56 const base::TimeTicks now = tick_clock_ptr->NowTicks(); |
| 57 for (int i = 1; i <= 100; ++i) { |
| 58 tick_clock_ptr->Advance(base::TimeDelta::FromSeconds(1)); |
| 59 observation_buffer.AddObservation(Observation<int32_t>( |
| 60 i, tick_clock_ptr->NowTicks(), NETWORK_QUALITY_OBSERVATION_SOURCE_TCP)); |
| 61 } |
| 62 EXPECT_EQ(100U, observation_buffer.Size()); |
| 63 |
| 64 int32_t result_lowest = INT32_MAX; |
| 65 int32_t result_highest = INT32_MIN; |
| 66 |
| 67 for (int i = 1; i <= 100; ++i) { |
| 68 // Verify that i'th percentile is more than i-1'th percentile. |
| 69 int32_t result_i; |
| 70 EXPECT_TRUE(observation_buffer.GetPercentile( |
| 71 now, &result_i, i, std::vector<NetworkQualityObservationSource>())); |
| 72 result_lowest = std::min(result_lowest, result_i); |
| 73 |
| 74 result_highest = std::max(result_highest, result_i); |
| 75 |
| 76 int32_t result_i_1; |
| 77 EXPECT_TRUE(observation_buffer.GetPercentile( |
| 78 now, &result_i_1, i - 1, |
| 79 std::vector<NetworkQualityObservationSource>())); |
| 80 |
| 81 EXPECT_LE(result_i_1, result_i); |
| 82 } |
| 83 EXPECT_LT(result_lowest, result_highest); |
| 84 } |
| 85 #endif |
| 86 |
| 24 // Verifies that the percentiles are correctly computed. All observations have | 87 // Verifies that the percentiles are correctly computed. All observations have |
| 25 // the same timestamp. | 88 // the same timestamp. |
| 26 TEST(NetworkQualityObservationTest, PercentileSameTimestamps) { | 89 TEST(NetworkQualityObservationBufferTest, PercentileSameTimestamps) { |
| 27 internal::ObservationBuffer<int32_t> int_buffer(0.5); | 90 ObservationBuffer<int32_t> int_buffer(0.5); |
| 28 internal::ObservationBuffer<base::TimeDelta> time_delta_buffer(0.5); | 91 ObservationBuffer<base::TimeDelta> time_delta_buffer(0.5); |
| 29 ASSERT_EQ(0u, int_buffer.Size()); | 92 ASSERT_EQ(0u, int_buffer.Size()); |
| 30 ASSERT_LT(0u, int_buffer.Capacity()); | 93 ASSERT_LT(0u, int_buffer.Capacity()); |
| 31 ASSERT_EQ(0u, time_delta_buffer.Size()); | 94 ASSERT_EQ(0u, time_delta_buffer.Size()); |
| 32 ASSERT_LT(0u, time_delta_buffer.Capacity()); | 95 ASSERT_LT(0u, time_delta_buffer.Capacity()); |
| 33 | 96 |
| 34 const base::TimeTicks now = base::TimeTicks::Now(); | 97 const base::TimeTicks now = base::TimeTicks::Now(); |
| 35 | 98 |
| 36 int32_t result; | 99 int32_t result; |
| 37 base::TimeDelta time_delta_result; | 100 base::TimeDelta time_delta_result; |
| 38 | 101 |
| 39 // Percentiles should be unavailable when no observations are available. | 102 // Percentiles should be unavailable when no observations are available. |
| 40 EXPECT_FALSE( | 103 EXPECT_FALSE( |
| 41 int_buffer.GetPercentile(base::TimeTicks(), &result, 50, | 104 int_buffer.GetPercentile(base::TimeTicks(), &result, 50, |
| 42 std::vector<NetworkQualityObservationSource>())); | 105 std::vector<NetworkQualityObservationSource>())); |
| 43 EXPECT_FALSE(time_delta_buffer.GetPercentile( | 106 EXPECT_FALSE(time_delta_buffer.GetPercentile( |
| 44 base::TimeTicks(), &time_delta_result, 50, | 107 base::TimeTicks(), &time_delta_result, 50, |
| 45 std::vector<NetworkQualityObservationSource>())); | 108 std::vector<NetworkQualityObservationSource>())); |
| 46 | 109 |
| 47 // Insert samples from {1,2,3,..., 100}. First insert odd samples, then even | 110 // Insert samples from {1,2,3,..., 100}. First insert odd samples, then even |
| 48 // samples. This helps in verifying that the order of samples does not matter. | 111 // samples. This helps in verifying that the order of samples does not matter. |
| 49 for (int i = 1; i <= 99; i += 2) { | 112 for (int i = 1; i <= 99; i += 2) { |
| 50 int_buffer.AddObservation(internal::Observation<int32_t>( | 113 int_buffer.AddObservation(Observation<int32_t>( |
| 51 i, now, NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); | 114 i, now, NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); |
| 52 time_delta_buffer.AddObservation(internal::Observation<base::TimeDelta>( | 115 time_delta_buffer.AddObservation(Observation<base::TimeDelta>( |
| 53 base::TimeDelta::FromMilliseconds(i), now, | 116 base::TimeDelta::FromMilliseconds(i), now, |
| 54 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); | 117 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); |
| 55 EXPECT_TRUE(int_buffer.GetPercentile( | 118 EXPECT_TRUE(int_buffer.GetPercentile( |
| 56 base::TimeTicks(), &result, 50, | 119 base::TimeTicks(), &result, 50, |
| 57 std::vector<NetworkQualityObservationSource>())); | 120 std::vector<NetworkQualityObservationSource>())); |
| 58 ASSERT_EQ(static_cast<size_t>(i / 2 + 1), int_buffer.Size()); | 121 ASSERT_EQ(static_cast<size_t>(i / 2 + 1), int_buffer.Size()); |
| 59 EXPECT_TRUE(time_delta_buffer.GetPercentile( | 122 EXPECT_TRUE(time_delta_buffer.GetPercentile( |
| 60 base::TimeTicks(), &time_delta_result, 50, | 123 base::TimeTicks(), &time_delta_result, 50, |
| 61 std::vector<NetworkQualityObservationSource>())); | 124 std::vector<NetworkQualityObservationSource>())); |
| 62 ASSERT_EQ(static_cast<size_t>(i / 2 + 1), time_delta_buffer.Size()); | 125 ASSERT_EQ(static_cast<size_t>(i / 2 + 1), time_delta_buffer.Size()); |
| 63 } | 126 } |
| 64 | 127 |
| 65 for (int i = 2; i <= 100; i += 2) { | 128 for (int i = 2; i <= 100; i += 2) { |
| 66 int_buffer.AddObservation(internal::Observation<int32_t>( | 129 int_buffer.AddObservation(Observation<int32_t>( |
| 67 i, now, NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); | 130 i, now, NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); |
| 68 time_delta_buffer.AddObservation(internal::Observation<base::TimeDelta>( | 131 time_delta_buffer.AddObservation(Observation<base::TimeDelta>( |
| 69 base::TimeDelta::FromMilliseconds(i), now, | 132 base::TimeDelta::FromMilliseconds(i), now, |
| 70 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); | 133 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); |
| 71 EXPECT_TRUE(int_buffer.GetPercentile( | 134 EXPECT_TRUE(int_buffer.GetPercentile( |
| 72 base::TimeTicks(), &result, 50, | 135 base::TimeTicks(), &result, 50, |
| 73 std::vector<NetworkQualityObservationSource>())); | 136 std::vector<NetworkQualityObservationSource>())); |
| 74 ASSERT_EQ(static_cast<size_t>(i / 2 + 50), int_buffer.Size()); | 137 ASSERT_EQ(static_cast<size_t>(i / 2 + 50), int_buffer.Size()); |
| 75 EXPECT_TRUE(time_delta_buffer.GetPercentile( | 138 EXPECT_TRUE(time_delta_buffer.GetPercentile( |
| 76 base::TimeTicks(), &time_delta_result, 50, | 139 base::TimeTicks(), &time_delta_result, 50, |
| 77 std::vector<NetworkQualityObservationSource>())); | 140 std::vector<NetworkQualityObservationSource>())); |
| 78 ASSERT_EQ(static_cast<size_t>(i / 2 + 50), time_delta_buffer.Size()); | 141 ASSERT_EQ(static_cast<size_t>(i / 2 + 50), time_delta_buffer.Size()); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 std::vector<NetworkQualityObservationSource>())); | 174 std::vector<NetworkQualityObservationSource>())); |
| 112 EXPECT_FALSE(time_delta_buffer.GetPercentile( | 175 EXPECT_FALSE(time_delta_buffer.GetPercentile( |
| 113 base::TimeTicks(), &time_delta_result, 50, | 176 base::TimeTicks(), &time_delta_result, 50, |
| 114 std::vector<NetworkQualityObservationSource>())); | 177 std::vector<NetworkQualityObservationSource>())); |
| 115 } | 178 } |
| 116 | 179 |
| 117 // Verifies that the percentiles are correctly computed. Observations have | 180 // Verifies that the percentiles are correctly computed. Observations have |
| 118 // different timestamps with half the observations being very old and the rest | 181 // different timestamps with half the observations being very old and the rest |
| 119 // of them being very recent. Percentiles should factor in recent observations | 182 // of them being very recent. Percentiles should factor in recent observations |
| 120 // much more heavily than older samples. | 183 // much more heavily than older samples. |
| 121 TEST(NetworkQualityObservationTest, PercentileDifferentTimestamps) { | 184 TEST(NetworkQualityObservationBufferTest, PercentileDifferentTimestamps) { |
| 122 internal::ObservationBuffer<int32_t> int_buffer(0.5); | 185 ObservationBuffer<int32_t> int_buffer(0.5); |
| 123 internal::ObservationBuffer<base::TimeDelta> time_delta_buffer(0.5); | 186 ObservationBuffer<base::TimeDelta> time_delta_buffer(0.5); |
| 124 const base::TimeTicks now = base::TimeTicks::Now(); | 187 const base::TimeTicks now = base::TimeTicks::Now(); |
| 125 const base::TimeTicks very_old = now - base::TimeDelta::FromDays(365); | 188 const base::TimeTicks very_old = now - base::TimeDelta::FromDays(365); |
| 126 | 189 |
| 127 int32_t result; | 190 int32_t result; |
| 128 base::TimeDelta time_delta_result; | 191 base::TimeDelta time_delta_result; |
| 129 | 192 |
| 130 // Network quality should be unavailable when no observations are available. | 193 // Network quality should be unavailable when no observations are available. |
| 131 EXPECT_FALSE( | 194 EXPECT_FALSE( |
| 132 int_buffer.GetPercentile(base::TimeTicks(), &result, 50, | 195 int_buffer.GetPercentile(base::TimeTicks(), &result, 50, |
| 133 std::vector<NetworkQualityObservationSource>())); | 196 std::vector<NetworkQualityObservationSource>())); |
| 134 EXPECT_FALSE(time_delta_buffer.GetPercentile( | 197 EXPECT_FALSE(time_delta_buffer.GetPercentile( |
| 135 base::TimeTicks(), &time_delta_result, 50, | 198 base::TimeTicks(), &time_delta_result, 50, |
| 136 std::vector<NetworkQualityObservationSource>())); | 199 std::vector<NetworkQualityObservationSource>())); |
| 137 | 200 |
| 138 // First 50 samples have very old timestamp. | 201 // First 50 samples have very old timestamp. |
| 139 for (int i = 1; i <= 50; ++i) { | 202 for (int i = 1; i <= 50; ++i) { |
| 140 int_buffer.AddObservation(internal::Observation<int32_t>( | 203 int_buffer.AddObservation(Observation<int32_t>( |
| 141 i, very_old, NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); | 204 i, very_old, NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); |
| 142 time_delta_buffer.AddObservation(internal::Observation<base::TimeDelta>( | 205 time_delta_buffer.AddObservation(Observation<base::TimeDelta>( |
| 143 base::TimeDelta::FromMilliseconds(i), very_old, | 206 base::TimeDelta::FromMilliseconds(i), very_old, |
| 144 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); | 207 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); |
| 145 } | 208 } |
| 146 | 209 |
| 147 // Next 50 (i.e., from 51 to 100) have recent timestamp. | 210 // Next 50 (i.e., from 51 to 100) have recent timestamp. |
| 148 for (int i = 51; i <= 100; ++i) { | 211 for (int i = 51; i <= 100; ++i) { |
| 149 int_buffer.AddObservation(internal::Observation<int32_t>( | 212 int_buffer.AddObservation(Observation<int32_t>( |
| 150 i, now, NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); | 213 i, now, NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); |
| 151 time_delta_buffer.AddObservation(internal::Observation<base::TimeDelta>( | 214 time_delta_buffer.AddObservation(Observation<base::TimeDelta>( |
| 152 base::TimeDelta::FromMilliseconds(i), now, | 215 base::TimeDelta::FromMilliseconds(i), now, |
| 153 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); | 216 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); |
| 154 } | 217 } |
| 155 | 218 |
| 156 // Older samples have very little weight. So, all percentiles are >= 51 | 219 // Older samples have very little weight. So, all percentiles are >= 51 |
| 157 // (lowest value among recent observations). | 220 // (lowest value among recent observations). |
| 158 for (int i = 1; i < 100; ++i) { | 221 for (int i = 1; i < 100; ++i) { |
| 159 // Checks if the difference between the two integers is less than 1. This is | 222 // Checks if the difference between the two integers is less than 1. This is |
| 160 // required because computed percentiles may be slightly different from | 223 // required because computed percentiles may be slightly different from |
| 161 // what is expected due to floating point computation errors and integer | 224 // what is expected due to floating point computation errors and integer |
| (...skipping 12 matching lines...) Expand all Loading... |
| 174 EXPECT_FALSE(int_buffer.GetPercentile( | 237 EXPECT_FALSE(int_buffer.GetPercentile( |
| 175 now + base::TimeDelta::FromSeconds(1), &result, 50, | 238 now + base::TimeDelta::FromSeconds(1), &result, 50, |
| 176 std::vector<NetworkQualityObservationSource>())); | 239 std::vector<NetworkQualityObservationSource>())); |
| 177 EXPECT_FALSE(time_delta_buffer.GetPercentile( | 240 EXPECT_FALSE(time_delta_buffer.GetPercentile( |
| 178 now + base::TimeDelta::FromSeconds(1), &time_delta_result, 50, | 241 now + base::TimeDelta::FromSeconds(1), &time_delta_result, 50, |
| 179 std::vector<NetworkQualityObservationSource>())); | 242 std::vector<NetworkQualityObservationSource>())); |
| 180 } | 243 } |
| 181 | 244 |
| 182 // Verifies that the percentiles are correctly computed when some of the | 245 // Verifies that the percentiles are correctly computed when some of the |
| 183 // observation sources are disallowed. All observations have the same timestamp. | 246 // observation sources are disallowed. All observations have the same timestamp. |
| 184 TEST(NetworkQualityObservationTest, DisallowedObservationSources) { | 247 TEST(NetworkQualityObservationBufferTest, DisallowedObservationSources) { |
| 185 internal::ObservationBuffer<int32_t> int_buffer(0.5); | 248 ObservationBuffer<int32_t> int_buffer(0.5); |
| 186 internal::ObservationBuffer<base::TimeDelta> time_delta_buffer(0.5); | 249 ObservationBuffer<base::TimeDelta> time_delta_buffer(0.5); |
| 187 const base::TimeTicks now = base::TimeTicks::Now(); | 250 const base::TimeTicks now = base::TimeTicks::Now(); |
| 188 | 251 |
| 189 int32_t result; | 252 int32_t result; |
| 190 base::TimeDelta time_delta_result; | 253 base::TimeDelta time_delta_result; |
| 191 | 254 |
| 192 // Network quality should be unavailable when no observations are available. | 255 // Network quality should be unavailable when no observations are available. |
| 193 EXPECT_FALSE( | 256 EXPECT_FALSE( |
| 194 int_buffer.GetPercentile(base::TimeTicks(), &result, 50, | 257 int_buffer.GetPercentile(base::TimeTicks(), &result, 50, |
| 195 std::vector<NetworkQualityObservationSource>())); | 258 std::vector<NetworkQualityObservationSource>())); |
| 196 EXPECT_FALSE(time_delta_buffer.GetPercentile( | 259 EXPECT_FALSE(time_delta_buffer.GetPercentile( |
| 197 base::TimeTicks(), &time_delta_result, 50, | 260 base::TimeTicks(), &time_delta_result, 50, |
| 198 std::vector<NetworkQualityObservationSource>())); | 261 std::vector<NetworkQualityObservationSource>())); |
| 199 | 262 |
| 200 // Insert samples from {1,2,3,..., 100}. First insert odd samples, then even | 263 // Insert samples from {1,2,3,..., 100}. First insert odd samples, then even |
| 201 // samples. This helps in verifying that the order of samples does not matter. | 264 // samples. This helps in verifying that the order of samples does not matter. |
| 202 for (int i = 1; i <= 99; i += 2) { | 265 for (int i = 1; i <= 99; i += 2) { |
| 203 int_buffer.AddObservation(internal::Observation<int32_t>( | 266 int_buffer.AddObservation(Observation<int32_t>( |
| 204 i, now, NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); | 267 i, now, NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); |
| 205 time_delta_buffer.AddObservation(internal::Observation<base::TimeDelta>( | 268 time_delta_buffer.AddObservation(Observation<base::TimeDelta>( |
| 206 base::TimeDelta::FromMilliseconds(i), now, | 269 base::TimeDelta::FromMilliseconds(i), now, |
| 207 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); | 270 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); |
| 208 } | 271 } |
| 209 | 272 |
| 210 // Add samples for TCP and QUIC observations which should not be taken into | 273 // Add samples for TCP and QUIC observations which should not be taken into |
| 211 // account when computing the percentile. | 274 // account when computing the percentile. |
| 212 for (int i = 1; i <= 99; i += 2) { | 275 for (int i = 1; i <= 99; i += 2) { |
| 213 int_buffer.AddObservation(internal::Observation<int32_t>( | 276 int_buffer.AddObservation(Observation<int32_t>( |
| 214 10000, now, NETWORK_QUALITY_OBSERVATION_SOURCE_TCP)); | 277 10000, now, NETWORK_QUALITY_OBSERVATION_SOURCE_TCP)); |
| 215 int_buffer.AddObservation(internal::Observation<int32_t>( | 278 int_buffer.AddObservation(Observation<int32_t>( |
| 216 10000, now, NETWORK_QUALITY_OBSERVATION_SOURCE_QUIC)); | 279 10000, now, NETWORK_QUALITY_OBSERVATION_SOURCE_QUIC)); |
| 217 time_delta_buffer.AddObservation(internal::Observation<base::TimeDelta>( | 280 time_delta_buffer.AddObservation(Observation<base::TimeDelta>( |
| 218 base::TimeDelta::FromMilliseconds(10000), now, | 281 base::TimeDelta::FromMilliseconds(10000), now, |
| 219 NETWORK_QUALITY_OBSERVATION_SOURCE_TCP)); | 282 NETWORK_QUALITY_OBSERVATION_SOURCE_TCP)); |
| 220 time_delta_buffer.AddObservation(internal::Observation<base::TimeDelta>( | 283 time_delta_buffer.AddObservation(Observation<base::TimeDelta>( |
| 221 base::TimeDelta::FromMilliseconds(10000), now, | 284 base::TimeDelta::FromMilliseconds(10000), now, |
| 222 NETWORK_QUALITY_OBSERVATION_SOURCE_QUIC)); | 285 NETWORK_QUALITY_OBSERVATION_SOURCE_QUIC)); |
| 223 } | 286 } |
| 224 | 287 |
| 225 for (int i = 2; i <= 100; i += 2) { | 288 for (int i = 2; i <= 100; i += 2) { |
| 226 int_buffer.AddObservation(internal::Observation<int32_t>( | 289 int_buffer.AddObservation(Observation<int32_t>( |
| 227 i, now, NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); | 290 i, now, NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); |
| 228 time_delta_buffer.AddObservation(internal::Observation<base::TimeDelta>( | 291 time_delta_buffer.AddObservation(Observation<base::TimeDelta>( |
| 229 base::TimeDelta::FromMilliseconds(i), now, | 292 base::TimeDelta::FromMilliseconds(i), now, |
| 230 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); | 293 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); |
| 231 } | 294 } |
| 232 | 295 |
| 233 std::vector<NetworkQualityObservationSource> disallowed_observation_sources; | 296 std::vector<NetworkQualityObservationSource> disallowed_observation_sources; |
| 234 disallowed_observation_sources.push_back( | 297 disallowed_observation_sources.push_back( |
| 235 NETWORK_QUALITY_OBSERVATION_SOURCE_TCP); | 298 NETWORK_QUALITY_OBSERVATION_SOURCE_TCP); |
| 236 disallowed_observation_sources.push_back( | 299 disallowed_observation_sources.push_back( |
| 237 NETWORK_QUALITY_OBSERVATION_SOURCE_QUIC); | 300 NETWORK_QUALITY_OBSERVATION_SOURCE_QUIC); |
| 238 | 301 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 262 EXPECT_TRUE(int_buffer.GetPercentile(base::TimeTicks(), &result, i, | 325 EXPECT_TRUE(int_buffer.GetPercentile(base::TimeTicks(), &result, i, |
| 263 disallowed_observation_sources)); | 326 disallowed_observation_sources)); |
| 264 EXPECT_NEAR(result, 10000, 1); | 327 EXPECT_NEAR(result, 10000, 1); |
| 265 EXPECT_TRUE( | 328 EXPECT_TRUE( |
| 266 time_delta_buffer.GetPercentile(base::TimeTicks(), &time_delta_result, | 329 time_delta_buffer.GetPercentile(base::TimeTicks(), &time_delta_result, |
| 267 i, disallowed_observation_sources)); | 330 i, disallowed_observation_sources)); |
| 268 EXPECT_NEAR(time_delta_result.InMilliseconds(), 10000, 1); | 331 EXPECT_NEAR(time_delta_result.InMilliseconds(), 10000, 1); |
| 269 } | 332 } |
| 270 } | 333 } |
| 271 | 334 |
| 272 TEST(NetworkQualityObservationTest, TestGetMedianRTTSince) { | 335 TEST(NetworkQualityObservationBufferTest, TestGetMedianRTTSince) { |
| 273 internal::ObservationBuffer<int32_t> int_buffer(0.5); | 336 ObservationBuffer<int32_t> int_buffer(0.5); |
| 274 internal::ObservationBuffer<base::TimeDelta> time_delta_buffer(0.5); | 337 ObservationBuffer<base::TimeDelta> time_delta_buffer(0.5); |
| 275 base::TimeTicks now = base::TimeTicks::Now(); | 338 base::TimeTicks now = base::TimeTicks::Now(); |
| 276 base::TimeTicks old = now - base::TimeDelta::FromMilliseconds(1); | 339 base::TimeTicks old = now - base::TimeDelta::FromMilliseconds(1); |
| 277 ASSERT_NE(old, now); | 340 ASSERT_NE(old, now); |
| 278 | 341 |
| 279 // First sample has very old timestamp. | 342 // First sample has very old timestamp. |
| 280 int_buffer.AddObservation(internal::Observation<int32_t>( | 343 int_buffer.AddObservation(Observation<int32_t>( |
| 281 1, old, NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); | 344 1, old, NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); |
| 282 time_delta_buffer.AddObservation(internal::Observation<base::TimeDelta>( | 345 time_delta_buffer.AddObservation(Observation<base::TimeDelta>( |
| 283 base::TimeDelta::FromMilliseconds(1), old, | 346 base::TimeDelta::FromMilliseconds(1), old, |
| 284 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); | 347 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); |
| 285 | 348 |
| 286 int_buffer.AddObservation(internal::Observation<int32_t>( | 349 int_buffer.AddObservation(Observation<int32_t>( |
| 287 100, now, NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); | 350 100, now, NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); |
| 288 time_delta_buffer.AddObservation(internal::Observation<base::TimeDelta>( | 351 time_delta_buffer.AddObservation(Observation<base::TimeDelta>( |
| 289 base::TimeDelta::FromMilliseconds(100), now, | 352 base::TimeDelta::FromMilliseconds(100), now, |
| 290 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); | 353 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); |
| 291 | 354 |
| 292 const struct { | 355 const struct { |
| 293 base::TimeTicks start_timestamp; | 356 base::TimeTicks start_timestamp; |
| 294 bool expect_network_quality_available; | 357 bool expect_network_quality_available; |
| 295 base::TimeDelta expected_url_request_rtt; | 358 base::TimeDelta expected_url_request_rtt; |
| 296 int32_t expected_downstream_throughput; | 359 int32_t expected_downstream_throughput; |
| 297 } tests[] = { | 360 } tests[] = { |
| 298 {now + base::TimeDelta::FromSeconds(10), false, | 361 {now + base::TimeDelta::FromSeconds(10), false, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 320 if (test.expect_network_quality_available) { | 383 if (test.expect_network_quality_available) { |
| 321 EXPECT_EQ(test.expected_url_request_rtt, url_request_rtt); | 384 EXPECT_EQ(test.expected_url_request_rtt, url_request_rtt); |
| 322 EXPECT_EQ(test.expected_downstream_throughput, | 385 EXPECT_EQ(test.expected_downstream_throughput, |
| 323 downstream_throughput_kbps); | 386 downstream_throughput_kbps); |
| 324 } | 387 } |
| 325 } | 388 } |
| 326 } | 389 } |
| 327 | 390 |
| 328 } // namespace | 391 } // namespace |
| 329 | 392 |
| 393 } // namespace internal |
| 394 |
| 330 } // namespace nqe | 395 } // namespace nqe |
| 331 | 396 |
| 332 } // namespace net | 397 } // namespace net |
| OLD | NEW |