Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1500)

Unified Diff: content/browser/net_info_browsertest.cc

Issue 2883763002: Expose ECT to render frames, Blink and NetInfo (Closed)
Patch Set: Rebased Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/net_info_browsertest.cc
diff --git a/content/browser/net_info_browsertest.cc b/content/browser/net_info_browsertest.cc
index aea456c7e03e833085599e736c8329478c614801..22f0d79e4a3f883ab53236eaf87c4d36e2de00a0 100644
--- a/content/browser/net_info_browsertest.cc
+++ b/content/browser/net_info_browsertest.cc
@@ -19,8 +19,23 @@
#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/effective_connection_type.h"
#include "net/nqe/network_quality_estimator_test_util.h"
+namespace {
+
+// Returns the total count of samples in |histogram|.
+int GetTotalSampleCount(base::HistogramTester* tester,
+ const std::string& histogram) {
+ int count = 0;
+ std::vector<base::Bucket> buckets = tester->GetAllSamples(histogram);
+ for (const auto& bucket : buckets)
+ count += bucket.count;
+ return count;
+}
+
+} // namespace
+
namespace content {
class NetInfoBrowserTest : public content::ContentBrowserTest {
@@ -167,6 +182,47 @@ IN_PROC_BROWSER_TEST_F(NetInfoBrowserTest,
RunScriptExtractDouble("getDownlink()"));
}
+// Make sure the changes in the effective connection typeare notified to the
+// render thread.
+IN_PROC_BROWSER_TEST_F(NetInfoBrowserTest,
+ EffectiveConnectionTypeChangeNotfied) {
+ 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);
+
+ net::nqe::internal::NetworkQuality network_quality_1(
+ base::TimeDelta::FromSeconds(1), base::TimeDelta::FromSeconds(2), 300);
+ estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed(
+ network_quality_1);
+
+ EXPECT_TRUE(embedded_test_server()->Start());
+ EXPECT_TRUE(
+ NavigateToURL(shell(), embedded_test_server()->GetURL("/net_info.html")));
+
+ FetchHistogramsFromChildProcesses();
+
+ int samples =
+ GetTotalSampleCount(&histogram_tester, "NQE.RenderThreadNotified");
+ EXPECT_LT(0, samples);
+
+ // Change effective connection type so that the renderer process is notified.
+ // Changing the effective connection type from 2G to 3G is guaranteed to
+ // generate the notification to the renderers, irrespective of the current
+ // effective connection type.
+ estimator.NotifyObserversOfEffectiveConnectionType(
+ net::EFFECTIVE_CONNECTION_TYPE_2G);
+ base::RunLoop().RunUntilIdle();
+ estimator.NotifyObserversOfEffectiveConnectionType(
+ net::EFFECTIVE_CONNECTION_TYPE_3G);
+ base::RunLoop().RunUntilIdle();
+ FetchHistogramsFromChildProcesses();
+ base::RunLoop().RunUntilIdle();
+ EXPECT_GT(GetTotalSampleCount(&histogram_tester, "NQE.RenderThreadNotified"),
+ samples);
+}
+
// Make sure the changes in the network quality are notified to the render
// thread, and the changed network quality is accessible via Javascript API.
IN_PROC_BROWSER_TEST_F(NetInfoBrowserTest, NetworkQualityChangeNotified) {

Powered by Google App Engine
This is Rietveld 408576698