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

Unified Diff: chrome/browser/net/nqe/ui_network_quality_estimator_service_browsertest.cc

Issue 2369673004: Wire NQE Prefs to Profile (Closed)
Patch Set: ps Created 4 years, 2 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: chrome/browser/net/nqe/ui_network_quality_estimator_service_browsertest.cc
diff --git a/chrome/browser/net/nqe/ui_network_quality_estimator_service_browsertest.cc b/chrome/browser/net/nqe/ui_network_quality_estimator_service_browsertest.cc
index d3ad81a5f7afe5e7d884e32ba8cbf43bc0a2ad28..87e86fe97378aa9305b7b19c71df5587333f40b7 100644
--- a/chrome/browser/net/nqe/ui_network_quality_estimator_service_browsertest.cc
+++ b/chrome/browser/net/nqe/ui_network_quality_estimator_service_browsertest.cc
@@ -2,12 +2,18 @@
// 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/test/histogram_tester.h"
#include "chrome/browser/net/nqe/ui_network_quality_estimator_service.h"
#include "chrome/browser/net/nqe/ui_network_quality_estimator_service_factory.h"
#include "chrome/browser/net/nqe/ui_network_quality_estimator_service_test_util.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/test/base/in_process_browser_test.h"
+#include "components/variations/variations_associated_data.h"
#include "content/public/test/browser_test.h"
+#include "net/base/network_change_notifier.h"
#include "net/nqe/effective_connection_type.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -38,3 +44,79 @@ IN_PROC_BROWSER_TEST_F(UINetworkQualityEstimatorServiceBrowserTest,
EXPECT_EQ(net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G,
nqe_service->GetEffectiveConnectionType());
}
+
+// Enables persistent caching if |persistent_caching_enabled| is true.
+// Verifies that the network quality prefs are written only if the persistent
+// caching was enabled.
+void VerifyWritingPrefs(bool persistent_caching_enabled) {
+ if (persistent_caching_enabled) {
+ std::map<std::string, std::string> variation_params;
+ variation_params["persistent_caching_enabled"] = "true";
+
+ variations::AssociateVariationParams("NetworkQualityEstimator", "Enabled",
+ variation_params);
+ base::FieldTrialList::CreateFieldTrial("NetworkQualityEstimator",
+ "Enabled");
+ }
+
+ // Verifies that NQE notifying EffectiveConnectionTypeObservers causes the
+ // UINetworkQualityEstimatorService to receive an updated
+ // EffectiveConnectionType.
+ Profile* profile = ProfileManager::GetActiveUserProfile();
+
+ bool network_id_available = true;
+ if (net::NetworkChangeNotifier::GetConnectionType() ==
+ net::NetworkChangeNotifier::CONNECTION_UNKNOWN ||
+ net::NetworkChangeNotifier::GetConnectionType() ==
+ net::NetworkChangeNotifier::CONNECTION_NONE ||
+ net::NetworkChangeNotifier::GetConnectionType() ==
+ net::NetworkChangeNotifier::CONNECTION_BLUETOOTH) {
+ network_id_available = false;
+ }
+
+ UINetworkQualityEstimatorService* nqe_service =
+ UINetworkQualityEstimatorServiceFactory::GetForProfile(profile);
+ ASSERT_NE(nullptr, nqe_service);
+
+ {
+ base::HistogramTester histogram_tester;
+ nqe_test_util::OverrideEffectiveConnectionTypeAndWait(
+ net::EFFECTIVE_CONNECTION_TYPE_OFFLINE);
+
+ EXPECT_EQ(net::EFFECTIVE_CONNECTION_TYPE_OFFLINE,
+ nqe_service->GetEffectiveConnectionType());
+
+ // Prefs are written only if the network id was available, and persistent
+ // caching was enabled.
+ EXPECT_NE(network_id_available && persistent_caching_enabled,
+ histogram_tester.GetAllSamples("NQE.Prefs.WriteCount").empty());
+ }
+
+ {
+ base::HistogramTester histogram_tester;
+ nqe_test_util::OverrideEffectiveConnectionTypeAndWait(
+ net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G);
+
+ EXPECT_EQ(net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G,
+ nqe_service->GetEffectiveConnectionType());
+
+ // Prefs are written only if the network id was available, and persistent
+ // caching was enabled.
+ EXPECT_NE(network_id_available && persistent_caching_enabled,
+ histogram_tester.GetAllSamples("NQE.Prefs.WriteCount").empty());
RyanSturm 2016/10/05 20:59:42 Please test that multiple network ids can be writt
tbansal1 2016/10/11 20:49:26 Done. I was planning to add Read() in a separate C
+ }
+}
+
+// Verify that prefs are not writen when writing of the prefs is not enabled
+// via field trial.
+IN_PROC_BROWSER_TEST_F(UINetworkQualityEstimatorServiceBrowserTest,
+ WritingToPrefsDisabled) {
+ VerifyWritingPrefs(false);
+}
+
+// Verify that prefs are writen when writing of the prefs is enabled via field
+// trial.
+IN_PROC_BROWSER_TEST_F(UINetworkQualityEstimatorServiceBrowserTest,
+ WritingToPrefsEnabled) {
+ VerifyWritingPrefs(true);
+}

Powered by Google App Engine
This is Rietveld 408576698