| Index: content/browser/net_info_browsertest.cc
|
| diff --git a/content/browser/net_info_browsertest.cc b/content/browser/net_info_browsertest.cc
|
| index 135ac36037517d3752ffb39f2d6df92059f6e029..aea456c7e03e833085599e736c8329478c614801 100644
|
| --- a/content/browser/net_info_browsertest.cc
|
| +++ b/content/browser/net_info_browsertest.cc
|
| @@ -2,6 +2,9 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| +#include <map>
|
| +#include <string>
|
| +
|
| #include "base/command_line.h"
|
| #include "base/run_loop.h"
|
| #include "base/strings/string_number_conversions.h"
|
| @@ -15,6 +18,7 @@
|
| #include "content/shell/browser/shell.h"
|
| #include "net/base/network_change_notifier.h"
|
| #include "net/base/network_change_notifier_factory.h"
|
| +#include "net/log/test_net_log.h"
|
| #include "net/nqe/network_quality_estimator_test_util.h"
|
|
|
| namespace content {
|
| @@ -144,21 +148,152 @@ IN_PROC_BROWSER_TEST_F(NetInfoBrowserTest, TwoRenderViewsInOneProcess) {
|
| EXPECT_FALSE(RunScriptExtractBool("getOnLine()"));
|
| }
|
|
|
| +// Verify that when the network quality notifications are not sent, the
|
| +// Javascript API returns invalid estimate.
|
| +IN_PROC_BROWSER_TEST_F(NetInfoBrowserTest,
|
| + NetworkQualityEstimatorNotInitialized) {
|
| + base::HistogramTester histogram_tester;
|
| + net::TestNetworkQualityEstimator estimator(
|
| + nullptr, std::map<std::string, std::string>(), false, false, true, true,
|
| + base::MakeUnique<net::BoundTestNetLog>());
|
| + NetworkQualityObserverImpl impl(&estimator);
|
| +
|
| + EXPECT_TRUE(embedded_test_server()->Start());
|
| + EXPECT_TRUE(
|
| + NavigateToURL(shell(), embedded_test_server()->GetURL("/net_info.html")));
|
| +
|
| + EXPECT_EQ(0, RunScriptExtractDouble("getRtt()"));
|
| + EXPECT_EQ(std::numeric_limits<double>::infinity(),
|
| + RunScriptExtractDouble("getDownlink()"));
|
| +}
|
| +
|
| // Make sure the changes in the network quality are notified to the render
|
| -// thread.
|
| +// thread, and the changed network quality is accessible via Javascript API.
|
| IN_PROC_BROWSER_TEST_F(NetInfoBrowserTest, NetworkQualityChangeNotified) {
|
| base::HistogramTester histogram_tester;
|
| - net::TestNetworkQualityEstimator estimator;
|
| + net::TestNetworkQualityEstimator estimator(
|
| + nullptr, std::map<std::string, std::string>(), false, false, true, true,
|
| + base::MakeUnique<net::BoundTestNetLog>());
|
| NetworkQualityObserverImpl impl(&estimator);
|
| +
|
| + net::nqe::internal::NetworkQuality network_quality_1(
|
| + base::TimeDelta::FromSeconds(1), base::TimeDelta::FromSeconds(2), 300);
|
| estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed(
|
| - net::nqe::internal::NetworkQuality(base::TimeDelta::FromSeconds(1),
|
| - base::TimeDelta::FromSeconds(2), 3));
|
| + network_quality_1);
|
|
|
| - NavigateToURL(shell(), content::GetTestUrl("", "net_info.html"));
|
| + EXPECT_TRUE(embedded_test_server()->Start());
|
| + EXPECT_TRUE(
|
| + NavigateToURL(shell(), embedded_test_server()->GetURL("/net_info.html")));
|
|
|
| FetchHistogramsFromChildProcesses();
|
| EXPECT_FALSE(
|
| histogram_tester.GetAllSamples("NQE.RenderThreadNotified").empty());
|
| +
|
| + EXPECT_EQ(network_quality_1.transport_rtt().InMilliseconds(),
|
| + RunScriptExtractDouble("getRtt()"));
|
| + EXPECT_EQ(
|
| + static_cast<double>(network_quality_1.downstream_throughput_kbps()) /
|
| + 1000,
|
| + RunScriptExtractDouble("getDownlink()"));
|
| +
|
| + // Verify that the network quality change is accessible via Javascript API.
|
| + net::nqe::internal::NetworkQuality network_quality_2(
|
| + base::TimeDelta::FromSeconds(10), base::TimeDelta::FromSeconds(20), 3000);
|
| + estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed(
|
| + network_quality_2);
|
| + base::RunLoop().RunUntilIdle();
|
| + EXPECT_EQ(network_quality_2.transport_rtt().InMilliseconds(),
|
| + RunScriptExtractDouble("getRtt()"));
|
| + EXPECT_EQ(
|
| + static_cast<double>(network_quality_2.downstream_throughput_kbps()) /
|
| + 1000,
|
| + RunScriptExtractDouble("getDownlink()"));
|
| +}
|
| +
|
| +// Make sure the changes in the network quality are rounded to the nearest
|
| +// 25 milliseconds or 25 kbps.
|
| +IN_PROC_BROWSER_TEST_F(NetInfoBrowserTest, NetworkQualityChangeRounded) {
|
| + base::HistogramTester histogram_tester;
|
| + net::TestNetworkQualityEstimator estimator(
|
| + std::unique_ptr<net::ExternalEstimateProvider>(),
|
| + std::map<std::string, std::string>(), false, false, true, true,
|
| + base::MakeUnique<net::BoundTestNetLog>());
|
| + NetworkQualityObserverImpl impl(&estimator);
|
| +
|
| + // Verify that the network quality is rounded properly.
|
| + net::nqe::internal::NetworkQuality network_quality_1(
|
| + base::TimeDelta::FromMilliseconds(123),
|
| + base::TimeDelta::FromMilliseconds(212), 303);
|
| + estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed(
|
| + network_quality_1);
|
| +
|
| + EXPECT_TRUE(embedded_test_server()->Start());
|
| + EXPECT_TRUE(
|
| + NavigateToURL(shell(), embedded_test_server()->GetURL("/net_info.html")));
|
| + EXPECT_EQ(200, RunScriptExtractDouble("getRtt()"));
|
| + EXPECT_EQ(0.300, RunScriptExtractDouble("getDownlink()"));
|
| +
|
| + net::nqe::internal::NetworkQuality network_quality_2(
|
| + base::TimeDelta::FromMilliseconds(123),
|
| + base::TimeDelta::FromMilliseconds(1217), 1317);
|
| + estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed(
|
| + network_quality_2);
|
| + base::RunLoop().RunUntilIdle();
|
| + EXPECT_EQ(1225, RunScriptExtractDouble("getRtt()"));
|
| + EXPECT_EQ(1.325, RunScriptExtractDouble("getDownlink()"));
|
| +
|
| + net::nqe::internal::NetworkQuality network_quality_3(
|
| + base::TimeDelta::FromMilliseconds(12),
|
| + base::TimeDelta::FromMilliseconds(12), 12);
|
| + estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed(
|
| + network_quality_3);
|
| + base::RunLoop().RunUntilIdle();
|
| + EXPECT_EQ(0, RunScriptExtractDouble("getRtt()"));
|
| + EXPECT_EQ(0, RunScriptExtractDouble("getDownlink()"));
|
| +}
|
| +
|
| +// Make sure the minor changes (<10%) in the network quality are not notified.
|
| +IN_PROC_BROWSER_TEST_F(NetInfoBrowserTest, NetworkQualityChangeNotNotified) {
|
| + base::HistogramTester histogram_tester;
|
| + net::TestNetworkQualityEstimator estimator(
|
| + nullptr, std::map<std::string, std::string>(), false, false, true, true,
|
| + base::MakeUnique<net::BoundTestNetLog>());
|
| + NetworkQualityObserverImpl impl(&estimator);
|
| +
|
| + // Verify that the network quality is rounded properly.
|
| + net::nqe::internal::NetworkQuality network_quality_1(
|
| + base::TimeDelta::FromMilliseconds(1123),
|
| + base::TimeDelta::FromMilliseconds(1212), 1303);
|
| + estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed(
|
| + network_quality_1);
|
| +
|
| + EXPECT_TRUE(embedded_test_server()->Start());
|
| + EXPECT_TRUE(
|
| + NavigateToURL(shell(), embedded_test_server()->GetURL("/net_info.html")));
|
| + EXPECT_EQ(1200, RunScriptExtractDouble("getRtt()"));
|
| + EXPECT_EQ(1.300, RunScriptExtractDouble("getDownlink()"));
|
| +
|
| + // All the 3 metrics change by less than 10%. So, the observers are not
|
| + // notified.
|
| + net::nqe::internal::NetworkQuality network_quality_2(
|
| + base::TimeDelta::FromMilliseconds(1223),
|
| + base::TimeDelta::FromMilliseconds(1312), 1403);
|
| + estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed(
|
| + network_quality_2);
|
| + base::RunLoop().RunUntilIdle();
|
| + EXPECT_EQ(1200, RunScriptExtractDouble("getRtt()"));
|
| + EXPECT_EQ(1.300, RunScriptExtractDouble("getDownlink()"));
|
| +
|
| + // Transport RTT has changed by more than 10% from the last notified value of
|
| + // |network_quality_1|. The observers should be notified.
|
| + net::nqe::internal::NetworkQuality network_quality_3(
|
| + base::TimeDelta::FromMilliseconds(1223),
|
| + base::TimeDelta::FromMilliseconds(2312), 1403);
|
| + estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed(
|
| + network_quality_3);
|
| + base::RunLoop().RunUntilIdle();
|
| + EXPECT_EQ(2300, RunScriptExtractDouble("getRtt()"));
|
| + EXPECT_EQ(1.400, RunScriptExtractDouble("getDownlink()"));
|
| }
|
|
|
| } // namespace content
|
|
|