Index: chrome/browser/net/nqe/ui_network_quality_estimator_service_test_util.cc |
diff --git a/chrome/browser/net/nqe/ui_network_quality_estimator_service_test_util.cc b/chrome/browser/net/nqe/ui_network_quality_estimator_service_test_util.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..431dab0586d064f413079deeffcf649255c816ff |
--- /dev/null |
+++ b/chrome/browser/net/nqe/ui_network_quality_estimator_service_test_util.cc |
@@ -0,0 +1,52 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/net/nqe/ui_network_quality_estimator_service_test_util.h" |
+ |
+#include "base/bind.h" |
+#include "base/run_loop.h" |
+#include "chrome/browser/browser_process.h" |
+#include "chrome/browser/io_thread.h" |
+#include "content/public/browser/browser_thread.h" |
+ |
+namespace chrome_browser_net { |
+ |
+namespace test_util { |
+ |
+namespace { |
+ |
+// Prevents NQE from reporting EffectiveConnectionType to observers, and reports |
+// |type| to all observers, including the UINetworkQualityEstimatorService. |
+void OverrideEffectiveConnectionTypeOnIO( |
+ net::NetworkQualityEstimator::EffectiveConnectionType type, |
+ IOThread* io_thread) { |
+ if (!io_thread->globals()->network_quality_estimator) |
+ return; |
+ net::NetworkQualityEstimator* network_quality_estimator = |
+ io_thread->globals()->network_quality_estimator.get(); |
+ if (!network_quality_estimator) |
+ return; |
+ network_quality_estimator->StopReportingEffectiveConnectionTypeForTesting(); |
+ network_quality_estimator->ReportEffectiveConnectionTypeForTesting(type); |
+} |
+ |
+} // namespace |
+ |
+void OverrideEffectiveConnectionTypeAndWait( |
+ net::NetworkQualityEstimator::EffectiveConnectionType type) { |
+ // Block |run_loop| until OverrideEffectiveConnectionTypeOnIO has completed. |
+ // Any UI tasks posted by calling OverrideEffectiveConnectionTypeOnIO will |
+ // complete before the reply unblocks |run_loop|. |
+ base::RunLoop run_loop; |
+ content::BrowserThread::PostTaskAndReply( |
tbansal1
2016/07/20 03:32:35
#include base/task_runner.h for PostTaskAndReply.
RyanSturm
2016/07/20 16:36:46
This is a different PostTaskAndReply in browser_th
tbansal1
2016/07/20 17:14:18
Acknowledged.
|
+ content::BrowserThread::IO, FROM_HERE, |
+ base::Bind(&OverrideEffectiveConnectionTypeOnIO, type, |
+ g_browser_process->io_thread()), |
+ run_loop.QuitClosure()); |
+ run_loop.Run(); |
+} |
+ |
+} // namespace test_util |
+ |
+} // namespace chrome_browser_net |