blob: d9b9b40d8b16f1810a0b61345dedfec9518d9b17 [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"
12#include "content/public/common/content_switches.h"
13#include "content/public/common/main_function_params.h"
14#include "testing/gtest/include/gtest/gtest.h"
15
16namespace content {
17
18// Verify that a single-process browser process has at least as many threads as
19// the number of cores in its foreground pool.
20TEST(BrowserMainLoopTest, CreateThreadsInSingleProcess) {
21 {
22 base::MessageLoop message_loop;
23 base::test::ScopedCommandLine scoped_command_line;
24 scoped_command_line.GetProcessCommandLine()->AppendSwitch(
25 switches::kSingleProcess);
26 MainFunctionParams main_function_params(
27 *scoped_command_line.GetProcessCommandLine());
28 BrowserMainLoop browser_main_loop(main_function_params);
29 browser_main_loop.MainMessageLoopStart();
30 browser_main_loop.CreateThreads();
31 EXPECT_GE(base::TaskScheduler::GetInstance()
Jeffrey Hed628419b2017-08-23 18:51:5132 ->GetMaxConcurrentNonBlockedTasksWithTraitsDeprecated(
Francois Doray6d3c649692017-06-16 19:20:2533 {base::TaskPriority::USER_VISIBLE}),
Gabriel Charettef61636f2018-02-05 17:50:1634 base::SysInfo::NumberOfProcessors() - 1);
Francois Doray6d3c649692017-06-16 19:20:2535 browser_main_loop.ShutdownThreadsAndCleanUp();
36 }
Scott Graham80cb2722017-08-31 02:12:4837 for (int id = BrowserThread::UI; id < BrowserThread::ID_COUNT; ++id) {
38 BrowserThreadImpl::ResetGlobalsForTesting(
39 static_cast<BrowserThread::ID>(id));
40 }
Francois Doray6d3c649692017-06-16 19:20:2541 base::TaskScheduler::GetInstance()->JoinForTesting();
42 base::TaskScheduler::SetInstance(nullptr);
43}
44
45} // namespace content