OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_estimator.h" | 5 #include "net/nqe/network_quality_estimator.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <limits> | 10 #include <limits> |
(...skipping 1985 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1996 size_t notification_received_; | 1996 size_t notification_received_; |
1997 DISALLOW_COPY_AND_ASSIGN(TestNetworkQualitiesCacheObserver); | 1997 DISALLOW_COPY_AND_ASSIGN(TestNetworkQualitiesCacheObserver); |
1998 }; | 1998 }; |
1999 | 1999 |
2000 TEST(NetworkQualityEstimatorTest, CacheObserver) { | 2000 TEST(NetworkQualityEstimatorTest, CacheObserver) { |
2001 TestNetworkQualitiesCacheObserver observer; | 2001 TestNetworkQualitiesCacheObserver observer; |
2002 std::map<std::string, std::string> variation_params; | 2002 std::map<std::string, std::string> variation_params; |
2003 TestNetworkQualityEstimator estimator(variation_params); | 2003 TestNetworkQualityEstimator estimator(variation_params); |
2004 | 2004 |
2005 // Add |observer| as a persistent caching observer. | 2005 // Add |observer| as a persistent caching observer. |
2006 estimator.NetworkQualityStoreForTesting()->AddNetworkQualitiesCacheObserver( | 2006 estimator.AddNetworkQualitiesCacheObserver(&observer); |
2007 &observer); | |
2008 | 2007 |
2009 estimator.set_recent_effective_connection_type(EFFECTIVE_CONNECTION_TYPE_3G); | 2008 estimator.set_recent_effective_connection_type(EFFECTIVE_CONNECTION_TYPE_3G); |
2010 estimator.SimulateNetworkChange( | 2009 estimator.SimulateNetworkChange( |
2011 NetworkChangeNotifier::ConnectionType::CONNECTION_UNKNOWN, "test3g"); | 2010 NetworkChangeNotifier::ConnectionType::CONNECTION_UNKNOWN, "test3g"); |
2012 estimator.RunOneRequest(); | 2011 estimator.RunOneRequest(); |
2013 EXPECT_EQ(1u, observer.get_notification_received_and_reset()); | 2012 EXPECT_EQ(1u, observer.get_notification_received_and_reset()); |
2014 EXPECT_EQ("test3g", observer.network_id().id); | 2013 EXPECT_EQ("test3g", observer.network_id().id); |
2015 | 2014 |
2016 estimator.set_recent_effective_connection_type(EFFECTIVE_CONNECTION_TYPE_2G); | 2015 estimator.set_recent_effective_connection_type(EFFECTIVE_CONNECTION_TYPE_2G); |
2017 estimator.SimulateNetworkChange( | 2016 estimator.SimulateNetworkChange( |
(...skipping 12 matching lines...) Expand all Loading... |
2030 estimator.RunOneRequest(); | 2029 estimator.RunOneRequest(); |
2031 estimator.RunOneRequest(); | 2030 estimator.RunOneRequest(); |
2032 estimator.RunOneRequest(); | 2031 estimator.RunOneRequest(); |
2033 EXPECT_EQ(1u, observer.get_notification_received_and_reset()); | 2032 EXPECT_EQ(1u, observer.get_notification_received_and_reset()); |
2034 | 2033 |
2035 estimator.set_recent_effective_connection_type(EFFECTIVE_CONNECTION_TYPE_2G); | 2034 estimator.set_recent_effective_connection_type(EFFECTIVE_CONNECTION_TYPE_2G); |
2036 estimator.RunOneRequest(); | 2035 estimator.RunOneRequest(); |
2037 EXPECT_EQ(1u, observer.get_notification_received_and_reset()); | 2036 EXPECT_EQ(1u, observer.get_notification_received_and_reset()); |
2038 | 2037 |
2039 // Remove |observer|, and it should not receive any notifications. | 2038 // Remove |observer|, and it should not receive any notifications. |
2040 estimator.NetworkQualityStoreForTesting() | 2039 estimator.RemoveNetworkQualitiesCacheObserver(&observer); |
2041 ->RemoveNetworkQualitiesCacheObserver(&observer); | |
2042 estimator.set_recent_effective_connection_type(EFFECTIVE_CONNECTION_TYPE_3G); | 2040 estimator.set_recent_effective_connection_type(EFFECTIVE_CONNECTION_TYPE_3G); |
2043 estimator.SimulateNetworkChange( | 2041 estimator.SimulateNetworkChange( |
2044 NetworkChangeNotifier::ConnectionType::CONNECTION_2G, "test2g"); | 2042 NetworkChangeNotifier::ConnectionType::CONNECTION_2G, "test2g"); |
2045 EXPECT_EQ(0u, observer.get_notification_received_and_reset()); | 2043 EXPECT_EQ(0u, observer.get_notification_received_and_reset()); |
2046 estimator.RunOneRequest(); | 2044 estimator.RunOneRequest(); |
2047 EXPECT_EQ(0u, observer.get_notification_received_and_reset()); | 2045 EXPECT_EQ(0u, observer.get_notification_received_and_reset()); |
2048 } | 2046 } |
2049 | 2047 |
2050 // Tests that the value of the effective connection type can be forced through | 2048 // Tests that the value of the effective connection type can be forced through |
2051 // field trial parameters. | 2049 // field trial parameters. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2084 if (expected_count == 1) { | 2082 if (expected_count == 1) { |
2085 EffectiveConnectionType last_notified_type = | 2083 EffectiveConnectionType last_notified_type = |
2086 observer.effective_connection_types().at( | 2084 observer.effective_connection_types().at( |
2087 observer.effective_connection_types().size() - 1); | 2085 observer.effective_connection_types().size() - 1); |
2088 EXPECT_EQ(i, last_notified_type); | 2086 EXPECT_EQ(i, last_notified_type); |
2089 } | 2087 } |
2090 } | 2088 } |
2091 } | 2089 } |
2092 | 2090 |
2093 } // namespace net | 2091 } // namespace net |
OLD | NEW |