blob: b5d345fc2d0f487d0d0b55adf8250b263d2825a6 [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"
Gabriel Charette44db1422018-08-06 11:19:3310#include "base/task/task_scheduler/task_scheduler.h"
Francois Doray6d3c649692017-06-16 19:20:2511#include "base/test/scoped_command_line.h"
Gabriel Charette8eb4dff2018-03-27 14:22:5412#include "content/browser/browser_thread_impl.h"
Alex Clarke7dc412d2018-09-14 10:02:3113#include "content/browser/scheduler/browser_task_executor.h"
Xi Han8012e462018-10-05 19:52:3014#include "content/browser/startup_helper.h"
Gabriel Charette790754c2018-03-16 21:32:5915#include "content/public/browser/browser_thread.h"
Francois Doray6d3c649692017-06-16 19:20:2516#include "content/public/common/content_switches.h"
17#include "content/public/common/main_function_params.h"
18#include "testing/gtest/include/gtest/gtest.h"
19
20namespace content {
21
22// Verify that a single-process browser process has at least as many threads as
23// the number of cores in its foreground pool.
24TEST(BrowserMainLoopTest, CreateThreadsInSingleProcess) {
25 {
Francois Doray6d3c649692017-06-16 19:20:2526 base::test::ScopedCommandLine scoped_command_line;
27 scoped_command_line.GetProcessCommandLine()->AppendSwitch(
28 switches::kSingleProcess);
Xi Han8012e462018-10-05 19:52:3029 base::TaskScheduler::Create("Browser");
30 StartBrowserTaskScheduler();
31 BrowserTaskExecutor::Create();
Francois Doray6d3c649692017-06-16 19:20:2532 MainFunctionParams main_function_params(
33 *scoped_command_line.GetProcessCommandLine());
Xi Han8012e462018-10-05 19:52:3034 BrowserMainLoop browser_main_loop(
35 main_function_params,
36 std::make_unique<base::TaskScheduler::ScopedExecutionFence>());
Francois Doray6d3c649692017-06-16 19:20:2537 browser_main_loop.MainMessageLoopStart();
Xi Han4090dcc2018-07-11 03:15:2038 browser_main_loop.Init();
Francois Doray6d3c649692017-06-16 19:20:2539 browser_main_loop.CreateThreads();
40 EXPECT_GE(base::TaskScheduler::GetInstance()
Jeffrey Hed628419b2017-08-23 18:51:5141 ->GetMaxConcurrentNonBlockedTasksWithTraitsDeprecated(
Francois Doray6d3c649692017-06-16 19:20:2542 {base::TaskPriority::USER_VISIBLE}),
Gabriel Charettef61636f2018-02-05 17:50:1643 base::SysInfo::NumberOfProcessors() - 1);
Francois Doray6d3c649692017-06-16 19:20:2544 browser_main_loop.ShutdownThreadsAndCleanUp();
45 }
Eric Secklere105c2d2018-09-17 21:27:0746 BrowserTaskExecutor::ResetForTesting();
Scott Graham80cb2722017-08-31 02:12:4847 for (int id = BrowserThread::UI; id < BrowserThread::ID_COUNT; ++id) {
48 BrowserThreadImpl::ResetGlobalsForTesting(
49 static_cast<BrowserThread::ID>(id));
50 }
Francois Doray6d3c649692017-06-16 19:20:2551 base::TaskScheduler::GetInstance()->JoinForTesting();
52 base::TaskScheduler::SetInstance(nullptr);
53}
54
55} // namespace content