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
3 // found in the LICENSE file.
5 #include "chrome/browser/android/net/external_estimate_provider_android.h"
9 #include "base/time/time.h"
10 #include "net/base/network_quality_estimator.h"
11 #include "testing/gtest/include/gtest/gtest.h"
15 // Tests if the |ExternalEstimateProviderAndroid| APIs return false without the
16 // downstream implementation.
17 TEST(ExternalEstimateProviderAndroidTest
, BasicsTest
) {
18 chrome::android::ExternalEstimateProviderAndroid external_estimate_provider
;
21 EXPECT_FALSE(external_estimate_provider
.GetRTT(&rtt
));
24 EXPECT_FALSE(external_estimate_provider
.GetDownstreamThroughputKbps(&kbps
));
25 EXPECT_FALSE(external_estimate_provider
.GetUpstreamThroughputKbps(&kbps
));
27 base::TimeDelta time_since_last_update
;
28 EXPECT_FALSE(external_estimate_provider
.GetTimeSinceLastUpdate(
29 &time_since_last_update
));
32 class TestNetworkQualityEstimator
: public net::NetworkQualityEstimator
{
34 TestNetworkQualityEstimator(
35 scoped_ptr
<chrome::android::ExternalEstimateProviderAndroid
>
36 external_estimate_provider
,
37 const std::map
<std::string
, std::string
>& variation_params
)
38 : NetworkQualityEstimator(external_estimate_provider
.Pass(),
42 ~TestNetworkQualityEstimator() override
{}
44 void OnUpdatedEstimateAvailable() override
{ notified_
= true; }
46 bool IsNotified() const { return notified_
; }
52 class TestExternalEstimateProviderAndroid
53 : public chrome::android::ExternalEstimateProviderAndroid
{
55 TestExternalEstimateProviderAndroid()
56 : chrome::android::ExternalEstimateProviderAndroid() {}
57 ~TestExternalEstimateProviderAndroid() override
{}
58 using ExternalEstimateProviderAndroid::NotifyUpdatedEstimateAvailable
;
61 // Tests if the |ExternalEstimateProviderAndroid| notifies
62 // |NetworkQualityEstimator|.
63 TEST(ExternalEstimateProviderAndroidTest
, DelegateTest
) {
64 scoped_ptr
<TestExternalEstimateProviderAndroid
> external_estimate_provider
;
65 external_estimate_provider
.reset(new TestExternalEstimateProviderAndroid());
67 TestExternalEstimateProviderAndroid
* ptr
= external_estimate_provider
.get();
68 std::map
<std::string
, std::string
> variation_params
;
69 TestNetworkQualityEstimator
network_quality_estimator(
70 external_estimate_provider
.Pass(), variation_params
);
71 ptr
->NotifyUpdatedEstimateAvailable();
72 DCHECK(network_quality_estimator
.IsNotified());