summaryrefslogtreecommitdiff
path: root/chromium/content/browser/browser_thread_browsertest.cc
blob: f79d7f9daadf4ecae42bdbae4e4e002374884e15 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/bind.h"
#include "base/callback_helpers.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_refptr.h"
#include "base/memory/weak_ptr.h"
#include "base/run_loop.h"
#include "base/test/gtest_util.h"
#include "build/build_config.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/content_browser_test.h"
#include "content/public/test/test_utils.h"

namespace content {

class BrowserThreadPostTaskBeforeInitBrowserTest : public ContentBrowserTest {
 protected:
  void SetUp() override {
    // This should fail because the ThreadPool + TaskExecutor weren't created
    // yet.
    EXPECT_DCHECK_DEATH(
        GetIOThreadTaskRunner({})->PostTask(FROM_HERE, base::DoNothing()));

    // Obtaining a TaskRunner should also fail.
    EXPECT_DCHECK_DEATH(GetIOThreadTaskRunner({}));

    ContentBrowserTest::SetUp();
  }
};

IN_PROC_BROWSER_TEST_F(BrowserThreadPostTaskBeforeInitBrowserTest,
                       ExpectFailures) {}

IN_PROC_BROWSER_TEST_F(ContentBrowserTest, ExpectedThreadPriorities) {
  base::ThreadPriorityForTest expected_priority =
      base::ThreadPriorityForTest::kNormal;
#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_CHROMEOS)
  // In browser main loop the kCompositing thread type is set.
  // Only Windows, Android and ChromeOS will set kDisplay priority for
  // kCompositing thread type. We omit Windows here as it has a special
  // treatment for the UI thread.
#if BUILDFLAG(IS_CHROMEOS)
  // TODO(1340997): ChromeOS results a kNormal priority unexpectedly.
  expected_priority = base::ThreadPriorityForTest::kNormal;
#else
  expected_priority = base::ThreadPriorityForTest::kDisplay;
#endif
#endif  // BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_CHROMEOS)

  EXPECT_EQ(base::PlatformThread::GetCurrentThreadPriorityForTest(),
            expected_priority);

  // Browser IO thread is set to kCompositing except for Windows, so the
  // `expected_priority` for browser IO is the same as browser main's.
  GetIOThreadTaskRunner({})->PostTask(
      FROM_HERE,
      base::BindOnce(
          [](base::ThreadPriorityForTest expected_priority) {
            EXPECT_EQ(base::PlatformThread::GetCurrentThreadPriorityForTest(),
                      expected_priority);
          },
          expected_priority));
  BrowserThread::RunAllPendingTasksOnThreadForTesting(BrowserThread::IO);
}

}  // namespace content