| 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..0fe881ca756f3ae0fad7861eaec0bf0661c64498
|
| --- /dev/null
|
| +++ b/chrome/browser/net/nqe/ui_network_quality_estimator_service_test_util.cc
|
| @@ -0,0 +1,51 @@
|
| +// 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 {
|
| +
|
| +// Reports |type| to all of NetworkQualityEstimator's
|
| +// EffectiveConnectionTypeObservers.
|
| +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->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(
|
| + 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
|
|
|