Skip to content

Commit

Permalink
Use BraveMainDelegate for brave_browser_tests
Browse files Browse the repository at this point in the history
So far, ChromeMainDelegate is used.
  • Loading branch information
simonhong committed Jun 5, 2018
1 parent d2e3b5a commit 6ed2120
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 1 deletion.
28 changes: 27 additions & 1 deletion test/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,32 @@ group("brave_browser_tests_deps") {
]
}

static_library("browser_test_support") {
testonly = true
deps = [
"//chrome/test:test_support",
]

sources = [
"base/brave_test_launcher_delegate.cc",
"base/brave_test_launcher_delegate.h",
"//brave/app/brave_main_delegate.cc",
"//brave/app/brave_main_delegate.h",
]
}

static_library("browser_tests_runner") {
testonly = true

deps = [
":browser_test_support",
]

sources = [
"base/browser_tests_main.cc",
]
}

test("brave_browser_tests") {
sources = [
"//brave/browser/extensions/api/brave_shields_api_browsertest.cc",
Expand All @@ -90,9 +116,9 @@ test("brave_browser_tests") {
defines = [ "HAS_OUT_OF_PROC_TEST_RUNNER" ]
deps = [
"//chrome/browser/ui",
"//chrome/test:browser_tests_runner",
"//ppapi/buildflags",
":brave_browser_tests_deps",
":browser_tests_runner",
]
data_deps = [
"//ppapi:ppapi_tests",
Expand Down
18 changes: 18 additions & 0 deletions test/base/brave_test_launcher_delegate.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "brave/test/base/brave_test_launcher_delegate.h"

#include "brave/app/brave_main_delegate.h"

BraveTestLauncherDelegate::BraveTestLauncherDelegate(
ChromeTestSuiteRunner* runner)
: ChromeTestLauncherDelegate(runner) {}

BraveTestLauncherDelegate::~BraveTestLauncherDelegate() = default;

content::ContentMainDelegate*
BraveTestLauncherDelegate::CreateContentMainDelegate() {
return new BraveMainDelegate();
}
24 changes: 24 additions & 0 deletions test/base/brave_test_launcher_delegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef BRAVE_TEST_BASE_BRAVE_TEST_LAUNCHER_H_
#define BRAVE_TEST_BASE_BRAVE_TEST_LAUNCHER_H_

#include "chrome/test/base/chrome_test_launcher.h"
#include "base/macros.h"

class BraveTestLauncherDelegate : public ChromeTestLauncherDelegate {
public:
// Does not take ownership of ChromeTestSuiteRunner.
explicit BraveTestLauncherDelegate(ChromeTestSuiteRunner* runner);
~BraveTestLauncherDelegate() override;

private:
// ChromeLauncherDelegate:
content::ContentMainDelegate* CreateContentMainDelegate() override;

This comment has been minimized.

Copy link
@bridiver

bridiver Nov 3, 2023

Collaborator

there is something wrong here because this method should be behind a !IS_ANDROID flag, but it builds anyway like this so that means it isn't used during android tests or the build would break


DISALLOW_COPY_AND_ASSIGN(BraveTestLauncherDelegate);
};

#endif // BRAVE_TEST_BASE_BRAVE_TEST_LAUNCHER_H_
36 changes: 36 additions & 0 deletions test/base/browser_tests_main.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "base/command_line.h"
#include "base/test/launcher/test_launcher.h"
#include "brave/test/base/brave_test_launcher_delegate.h"
#include "build/build_config.h"

#if defined(OS_WIN)
#include "base/test/test_switches.h"
#include "base/win/win_util.h"
#endif // defined(OS_WIN)

int main(int argc, char** argv) {

This comment has been minimized.

Copy link
@bridiver

bridiver Nov 3, 2023

Collaborator

we should not be copying code like this. This file is not out-of-date with upstream. Even a patch is better than copying code, but I think this can be a chromium src override

base::CommandLine::Init(argc, argv);
size_t parallel_jobs = base::NumParallelJobs();
if (parallel_jobs == 0U) {
return 1;
} else if (parallel_jobs > 1U) {
parallel_jobs /= 2U;
}

#if defined(OS_WIN)
// Enable high-DPI for interactive tests where the user is expected to
// manually verify results.
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kTestLauncherInteractive)) {
base::win::EnableHighDPISupport();
}
#endif // defined(OS_WIN)

ChromeTestSuiteRunner runner;
BraveTestLauncherDelegate delegate(&runner);
return LaunchChromeTests(parallel_jobs, &delegate, argc, argv);
}

0 comments on commit 6ed2120

Please sign in to comment.