blob: 61ec07ae36be81214fe1d3edc9e20a209e71ffe1 [file] [log] [blame]
Francois Doray6d3c649692017-06-16 19:20:251// Copyright 2017 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 "content/browser/browser_main_loop.h"
6
7#include "base/command_line.h"
8#include "base/message_loop/message_loop.h"
9#include "base/sys_info.h"
10#include "base/task_scheduler/task_scheduler.h"
11#include "base/test/scoped_command_line.h"
Gabriel Charette790754c2018-03-16 21:32:5912#include "content/public/browser/browser_thread.h"
Francois Doray6d3c649692017-06-16 19:20:2513#include "content/public/common/content_switches.h"
14#include "content/public/common/main_function_params.h"
15#include "testing/gtest/include/gtest/gtest.h"
16
17namespace content {
18
19// Verify that a single-process browser process has at least as many threads as
20// the number of cores in its foreground pool.
21TEST(BrowserMainLoopTest, CreateThreadsInSingleProcess) {
22 {
23 base::MessageLoop message_loop;
24 base::test::ScopedCommandLine scoped_command_line;
25 scoped_command_line.GetProcessCommandLine()->AppendSwitch(
26 switches::kSingleProcess);
27 MainFunctionParams main_function_params(
28 *scoped_command_line.GetProcessCommandLine());
29 BrowserMainLoop browser_main_loop(main_function_params);
30 browser_main_loop.MainMessageLoopStart();
Xi Han066637cf2018-02-16 16:41:4731 browser_main_loop.InitializeIOThreadForTesting();
Francois Doray6d3c649692017-06-16 19:20:2532 browser_main_loop.CreateThreads();
33 EXPECT_GE(base::TaskScheduler::GetInstance()
Jeffrey Hed628419b2017-08-23 18:51:5134 ->GetMaxConcurrentNonBlockedTasksWithTraitsDeprecated(
Francois Doray6d3c649692017-06-16 19:20:2535 {base::TaskPriority::USER_VISIBLE}),
Gabriel Charettef61636f2018-02-05 17:50:1636 base::SysInfo::NumberOfProcessors() - 1);
Francois Doray6d3c649692017-06-16 19:20:2537 browser_main_loop.ShutdownThreadsAndCleanUp();
38 }
Scott Graham80cb2722017-08-31 02:12:4839 for (int id = BrowserThread::UI; id < BrowserThread::ID_COUNT; ++id) {
40 BrowserThreadImpl::ResetGlobalsForTesting(
41 static_cast<BrowserThread::ID>(id));
42 }
Francois Doray6d3c649692017-06-16 19:20:2543 base::TaskScheduler::GetInstance()->JoinForTesting();
44 base::TaskScheduler::SetInstance(nullptr);
45}
46
47} // namespace content