1 // Copyright 2016 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "base/at_exit.h" 6 #include "base/command_line.h" 7 #include "base/i18n/icu_util.h" 8 #include "base/logging.h" 9 #include "base/test/scoped_run_loop_timeout.h" 10 #include "base/test/task_environment.h" 11 #include "base/test/test_timeouts.h" 12 13 namespace { 14 15 // Set up globals that a number of network tests use. 16 // 17 // Note that in general static initializers are not allowed, however this is 18 // just being used by test code. 19 struct InitGlobals { InitGlobals__anon91994a5a0111::InitGlobals20 InitGlobals() { 21 base::CommandLine::Init(0, nullptr); 22 23 // |test| instances uses TaskEnvironment, which needs TestTimeouts. 24 TestTimeouts::Initialize(); 25 26 task_environment = std::make_unique<base::test::TaskEnvironment>( 27 base::test::TaskEnvironment::MainThreadType::IO); 28 29 increased_timeout_ = std::make_unique<base::test::ScopedRunLoopTimeout>( 30 FROM_HERE, TestTimeouts::action_max_timeout()); 31 32 // Set up ICU. ICU is used internally by GURL, which is used throughout the 33 // //net code. Initializing ICU is important to prevent fuzztests from 34 // asserting when handling non-ASCII urls. 35 CHECK(base::i18n::InitializeICU()); 36 37 // Disable noisy logging as per "libFuzzer in Chrome" documentation: 38 // testing/libfuzzer/getting_started.md#Disable-noisy-error-message-logging. 39 logging::SetMinLogLevel(logging::LOG_FATAL); 40 } 41 42 // A number of tests use async code which depends on there being a 43 // TaskEnvironment. Setting one up here allows tests to reuse the 44 // TaskEnvironment between runs. 45 std::unique_ptr<base::test::TaskEnvironment> task_environment; 46 47 // Fuzzing tests often need to Run() for longer than action_timeout(). 48 std::unique_ptr<base::test::ScopedRunLoopTimeout> increased_timeout_; 49 50 base::AtExitManager at_exit_manager; 51 }; 52 53 InitGlobals* init_globals = new InitGlobals(); 54 55 } // namespace 56