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

Side by Side Diff: chrome/browser/io_thread_unittest.cc

Issue 2850003002: Add flag to override Effective Connection Type (Closed)
Patch Set: ryansturm nits 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stddef.h> 5 #include <stddef.h>
6 6
7 #include <map>
8 #include <string>
9
7 #include "base/at_exit.h" 10 #include "base/at_exit.h"
8 #include "base/command_line.h" 11 #include "base/command_line.h"
9 #include "base/macros.h" 12 #include "base/macros.h"
10 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
11 #include "base/metrics/field_trial.h" 14 #include "base/metrics/field_trial.h"
12 #include "base/run_loop.h" 15 #include "base/run_loop.h"
13 #include "base/test/mock_entropy_provider.h" 16 #include "base/test/mock_entropy_provider.h"
14 #include "build/build_config.h" 17 #include "build/build_config.h"
15 #include "chrome/browser/io_thread.h" 18 #include "chrome/browser/io_thread.h"
16 #include "chrome/common/chrome_switches.h" 19 #include "chrome/common/chrome_switches.h"
17 #include "chrome/common/pref_names.h" 20 #include "chrome/common/pref_names.h"
18 #include "components/policy/core/common/mock_policy_service.h" 21 #include "components/policy/core/common/mock_policy_service.h"
19 #include "components/prefs/pref_registry_simple.h" 22 #include "components/prefs/pref_registry_simple.h"
20 #include "components/prefs/pref_service.h" 23 #include "components/prefs/pref_service.h"
21 #include "components/prefs/testing_pref_service.h" 24 #include "components/prefs/testing_pref_service.h"
22 #include "components/proxy_config/pref_proxy_config_tracker_impl.h" 25 #include "components/proxy_config/pref_proxy_config_tracker_impl.h"
23 #include "components/proxy_config/proxy_config_pref_names.h" 26 #include "components/proxy_config/proxy_config_pref_names.h"
24 #include "components/variations/variations_associated_data.h" 27 #include "components/variations/variations_associated_data.h"
25 #include "content/public/browser/browser_thread.h" 28 #include "content/public/browser/browser_thread.h"
26 #include "content/public/test/test_browser_thread_bundle.h" 29 #include "content/public/test/test_browser_thread_bundle.h"
27 #include "extensions/features/features.h" 30 #include "extensions/features/features.h"
28 #include "net/cert_net/nss_ocsp.h" 31 #include "net/cert_net/nss_ocsp.h"
29 #include "net/http/http_auth_preferences.h" 32 #include "net/http/http_auth_preferences.h"
30 #include "net/http/http_auth_scheme.h" 33 #include "net/http/http_auth_scheme.h"
31 #include "net/http/http_network_session.h" 34 #include "net/http/http_network_session.h"
35 #include "net/nqe/effective_connection_type.h"
36 #include "net/nqe/network_quality_estimator.h"
32 #include "net/quic/chromium/quic_stream_factory.h" 37 #include "net/quic/chromium/quic_stream_factory.h"
33 #include "net/quic/core/quic_tag.h" 38 #include "net/quic/core/quic_tag.h"
34 #include "net/quic/core/quic_versions.h" 39 #include "net/quic/core/quic_versions.h"
35 #include "testing/gmock/include/gmock/gmock.h" 40 #include "testing/gmock/include/gmock/gmock.h"
36 #include "testing/gtest/include/gtest/gtest.h" 41 #include "testing/gtest/include/gtest/gtest.h"
37 42
38 #if BUILDFLAG(ENABLE_EXTENSIONS) 43 #if BUILDFLAG(ENABLE_EXTENSIONS)
39 #include "chrome/browser/extensions/event_router_forwarder.h" 44 #include "chrome/browser/extensions/event_router_forwarder.h"
40 #endif 45 #endif
41 46
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 EXPECT_EQ(expected, http_auth_preferences->NegotiateDisableCnameLookup()); 80 EXPECT_EQ(expected, http_auth_preferences->NegotiateDisableCnameLookup());
76 } 81 }
77 82
78 void CheckNegotiateEnablePort(bool expected) { 83 void CheckNegotiateEnablePort(bool expected) {
79 auto* http_auth_preferences = 84 auto* http_auth_preferences =
80 IOThreadPeer::GetAuthPreferences(io_thread_.get()); 85 IOThreadPeer::GetAuthPreferences(io_thread_.get());
81 ASSERT_NE(nullptr, http_auth_preferences); 86 ASSERT_NE(nullptr, http_auth_preferences);
82 EXPECT_EQ(expected, http_auth_preferences->NegotiateEnablePort()); 87 EXPECT_EQ(expected, http_auth_preferences->NegotiateEnablePort());
83 } 88 }
84 89
90 void CheckEffectiveConnectionType(net::EffectiveConnectionType expected) {
91 ASSERT_EQ(expected,
92 io_thread_->globals()
93 ->network_quality_estimator->GetEffectiveConnectionType());
94 }
95
85 #if defined(OS_ANDROID) 96 #if defined(OS_ANDROID)
86 void CheckAuthAndroidNegoitateAccountType(std::string expected) { 97 void CheckAuthAndroidNegoitateAccountType(std::string expected) {
87 auto* http_auth_preferences = 98 auto* http_auth_preferences =
88 IOThreadPeer::GetAuthPreferences(io_thread_.get()); 99 IOThreadPeer::GetAuthPreferences(io_thread_.get());
89 ASSERT_NE(nullptr, http_auth_preferences); 100 ASSERT_NE(nullptr, http_auth_preferences);
90 EXPECT_EQ(expected, 101 EXPECT_EQ(expected,
91 http_auth_preferences->AuthAndroidNegotiateAccountType()); 102 http_auth_preferences->AuthAndroidNegotiateAccountType());
92 } 103 }
93 #endif 104 #endif
94 105
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 RunOnIOThreadBlocking(base::Bind( 252 RunOnIOThreadBlocking(base::Bind(
242 &IOThreadTestWithIOThreadObject::CheckAuthAndroidNegoitateAccountType, 253 &IOThreadTestWithIOThreadObject::CheckAuthAndroidNegoitateAccountType,
243 base::Unretained(this), "acc1")); 254 base::Unretained(this), "acc1"));
244 pref_service()->SetString(prefs::kAuthAndroidNegotiateAccountType, "acc2"); 255 pref_service()->SetString(prefs::kAuthAndroidNegotiateAccountType, "acc2");
245 RunOnIOThreadBlocking(base::Bind( 256 RunOnIOThreadBlocking(base::Bind(
246 &IOThreadTestWithIOThreadObject::CheckAuthAndroidNegoitateAccountType, 257 &IOThreadTestWithIOThreadObject::CheckAuthAndroidNegoitateAccountType,
247 base::Unretained(this), "acc2")); 258 base::Unretained(this), "acc2"));
248 } 259 }
249 #endif 260 #endif
250 261
262 TEST_F(IOThreadTestWithIOThreadObject, ForceECTFromCommandLine) {
263 base::CommandLine::Init(0, nullptr);
264 ASSERT_TRUE(base::CommandLine::InitializedForCurrentProcess());
265 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
266 "--force-effective-connection-type", "Slow-2G");
267
268 RunOnIOThreadBlocking(base::Bind(
269 &IOThreadTestWithIOThreadObject::CheckEffectiveConnectionType,
270 base::Unretained(this), net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G));
271 }
272
273 TEST_F(IOThreadTestWithIOThreadObject, ForceECTUsingFieldTrial) {
274 base::CommandLine::Init(0, nullptr);
275 ASSERT_TRUE(base::CommandLine::InitializedForCurrentProcess());
276
277 variations::testing::ClearAllVariationParams();
278 std::map<std::string, std::string> variation_params;
279 variation_params["force_effective_connection_type"] = "2G";
280 ASSERT_TRUE(variations::AssociateVariationParams(
281 "NetworkQualityEstimator", "Enabled", variation_params));
282
283 base::FieldTrialList field_trial_list(nullptr);
284 base::FieldTrialList::CreateFieldTrial("NetworkQualityEstimator", "Enabled");
285
286 RunOnIOThreadBlocking(
287 base::Bind(&IOThreadTestWithIOThreadObject::CheckEffectiveConnectionType,
288 base::Unretained(this), net::EFFECTIVE_CONNECTION_TYPE_2G));
289 }
290
291 TEST_F(IOThreadTestWithIOThreadObject, ECTFromCommandLineOverridesFieldTrial) {
292 base::CommandLine::Init(0, nullptr);
293 ASSERT_TRUE(base::CommandLine::InitializedForCurrentProcess());
294 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
295 "--force-effective-connection-type", "Slow-2G");
296
297 variations::testing::ClearAllVariationParams();
298 std::map<std::string, std::string> variation_params;
299 variation_params["force_effective_connection_type"] = "2G";
300 ASSERT_TRUE(variations::AssociateVariationParams(
301 "NetworkQualityEstimator", "Enabled", variation_params));
302
303 base::FieldTrialList field_trial_list(nullptr);
304 base::FieldTrialList::CreateFieldTrial("NetworkQualityEstimator", "Enabled");
305
306 RunOnIOThreadBlocking(base::Bind(
307 &IOThreadTestWithIOThreadObject::CheckEffectiveConnectionType,
308 base::Unretained(this), net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G));
309 }
310
251 class ConfigureParamsFromFieldTrialsAndCommandLineTest 311 class ConfigureParamsFromFieldTrialsAndCommandLineTest
252 : public ::testing::Test { 312 : public ::testing::Test {
253 public: 313 public:
254 ConfigureParamsFromFieldTrialsAndCommandLineTest() 314 ConfigureParamsFromFieldTrialsAndCommandLineTest()
255 : command_line_(base::CommandLine::NO_PROGRAM), 315 : command_line_(base::CommandLine::NO_PROGRAM),
256 is_quic_allowed_by_policy_(true) {} 316 is_quic_allowed_by_policy_(true) {}
257 317
258 protected: 318 protected:
259 void ConfigureParamsFromFieldTrialsAndCommandLine() { 319 void ConfigureParamsFromFieldTrialsAndCommandLine() {
260 IOThreadPeer::ConfigureParamsFromFieldTrialsAndCommandLine( 320 IOThreadPeer::ConfigureParamsFromFieldTrialsAndCommandLine(
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 command_line_.AppendSwitchASCII("testing-fixed-http-port", "42"); 476 command_line_.AppendSwitchASCII("testing-fixed-http-port", "42");
417 command_line_.AppendSwitchASCII("testing-fixed-https-port", "137"); 477 command_line_.AppendSwitchASCII("testing-fixed-https-port", "137");
418 478
419 ConfigureParamsFromFieldTrialsAndCommandLine(); 479 ConfigureParamsFromFieldTrialsAndCommandLine();
420 480
421 EXPECT_EQ(42u, params_.testing_fixed_http_port); 481 EXPECT_EQ(42u, params_.testing_fixed_http_port);
422 EXPECT_EQ(137u, params_.testing_fixed_https_port); 482 EXPECT_EQ(137u, params_.testing_fixed_https_port);
423 } 483 }
424 484
425 } // namespace test 485 } // namespace test
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698