Skip to content

Commit

Permalink
LaCrOS: Replace defined(OS_CHROMEOS) with BUILDFLAG(IS_CHROMEOS_ASH)
Browse files Browse the repository at this point in the history
The change is mostly mechanical replacing defined(OS_CHROMEOS) with
BUILDFLAG(IS_CHROMEOS_ASH) and GN variable is_chromeos with
is_chromeos_ash with some special cases (For those cases please
refer to http://go/lacros-macros).

The patch is made in preparation to switching lacros build from
target_os=linux to target_os=chromeos. This will prevent lacros from
changing behaviour after the switch.

Bug: 1052397
Change-Id: Ic46914d41965026956ec9adea34137fda5fdca16
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2550002
Commit-Queue: Yuta Hijikata <[email protected]>
Reviewed-by: Avi Drissman <[email protected]>
Cr-Commit-Position: refs/heads/master@{#830477}
  • Loading branch information
Yuta Hijikata authored and Commit Bot committed Nov 24, 2020
1 parent f26572f commit c58ac2d
Show file tree
Hide file tree
Showing 33 changed files with 284 additions and 231 deletions.
132 changes: 68 additions & 64 deletions chrome/test/BUILD.gn

Large diffs are not rendered by default.

13 changes: 7 additions & 6 deletions chrome/test/base/browser_with_test_window_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "base/location.h"
#include "base/run_loop.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/net/system_network_context_manager.h"
#include "chrome/browser/profiles/profile_destroyer.h"
#include "chrome/browser/ui/browser.h"
Expand All @@ -28,7 +29,7 @@
#include "chrome/browser/ui/views/chrome_constrained_window_views_client.h"
#include "components/constrained_window/constrained_window_views.h"

#if defined(OS_CHROMEOS)
#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h"
#include "content/public/browser/context_factory.h"
#endif
Expand All @@ -43,7 +44,7 @@ BrowserWithTestWindowTest::~BrowserWithTestWindowTest() {}

void BrowserWithTestWindowTest::SetUp() {
testing::Test::SetUp();
#if defined(OS_CHROMEOS)
#if BUILDFLAG(IS_CHROMEOS_ASH)
ash_test_helper_.SetUp();
#endif

Expand Down Expand Up @@ -103,7 +104,7 @@ void BrowserWithTestWindowTest::TearDown() {
tablet_state_.reset();
#endif

#if defined(OS_CHROMEOS)
#if BUILDFLAG(IS_CHROMEOS_ASH)
// If initialized, the KioskAppManager will register an observer to
// CrosSettings and will need to be destroyed before it. Having it destroyed
// as part of the teardown will avoid unexpected test failures.
Expand All @@ -124,7 +125,7 @@ void BrowserWithTestWindowTest::TearDown() {
}

gfx::NativeWindow BrowserWithTestWindowTest::GetContext() {
#if defined(OS_CHROMEOS)
#if BUILDFLAG(IS_CHROMEOS_ASH)
return ash_test_helper_.GetContext();
#elif defined(TOOLKIT_VIEWS)
return views_test_helper_->GetContext();
Expand Down Expand Up @@ -207,7 +208,7 @@ std::unique_ptr<Browser> BrowserWithTestWindowTest::CreateBrowser(
return std::unique_ptr<Browser>(Browser::Create(params));
}

#if defined(OS_CHROMEOS)
#if BUILDFLAG(IS_CHROMEOS_ASH)
chromeos::ScopedCrosSettingsTestHelper*
BrowserWithTestWindowTest::GetCrosSettingsHelper() {
return &cros_settings_test_helper_;
Expand All @@ -217,7 +218,7 @@ chromeos::StubInstallAttributes*
BrowserWithTestWindowTest::GetInstallAttributes() {
return GetCrosSettingsHelper()->InstallAttributes();
}
#endif // defined(OS_CHROMEOS)
#endif // BUILDFLAG(IS_CHROMEOS_ASH)

BrowserWithTestWindowTest::BrowserWithTestWindowTest(
std::unique_ptr<content::BrowserTaskEnvironment> task_environment,
Expand Down
12 changes: 6 additions & 6 deletions chrome/test/base/browser_with_test_window_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#if defined(TOOLKIT_VIEWS)
#include "chrome/test/views/chrome_test_views_delegate.h"

#if defined(OS_CHROMEOS)
#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "ash/test/ash_test_helper.h"
#include "ash/test/ash_test_views_delegate.h"
#include "chrome/browser/chromeos/login/users/scoped_test_user_manager.h"
Expand Down Expand Up @@ -137,7 +137,7 @@ class BrowserWithTestWindowTest : public testing::Test {
return window_.release();
}

#if defined(OS_CHROMEOS)
#if BUILDFLAG(IS_CHROMEOS_ASH)
ash::AshTestHelper* ash_test_helper() { return &ash_test_helper_; }
#endif

Expand Down Expand Up @@ -189,15 +189,15 @@ class BrowserWithTestWindowTest : public testing::Test {

#if defined(TOOLKIT_VIEWS)
views::TestViewsDelegate* test_views_delegate() {
#if defined(OS_CHROMEOS)
#if BUILDFLAG(IS_CHROMEOS_ASH)
return test_views_delegate_.get();
#else
return views_test_helper_->test_views_delegate();
#endif
}
#endif

#if defined(OS_CHROMEOS)
#if BUILDFLAG(IS_CHROMEOS_ASH)
chromeos::ScopedCrosSettingsTestHelper* GetCrosSettingsHelper();
chromeos::StubInstallAttributes* GetInstallAttributes();
#endif
Expand All @@ -213,7 +213,7 @@ class BrowserWithTestWindowTest : public testing::Test {
// We need to create a MessageLoop, otherwise a bunch of things fails.
std::unique_ptr<content::BrowserTaskEnvironment> task_environment_;

#if defined(OS_CHROMEOS)
#if BUILDFLAG(IS_CHROMEOS_ASH)
chromeos::ScopedCrosSettingsTestHelper cros_settings_test_helper_;
chromeos::ScopedTestUserManager test_user_manager_;
#endif
Expand All @@ -228,7 +228,7 @@ class BrowserWithTestWindowTest : public testing::Test {
std::unique_ptr<BrowserWindow> window_; // Usually a TestBrowserWindow.
std::unique_ptr<Browser> browser_;

#if defined(OS_CHROMEOS)
#if BUILDFLAG(IS_CHROMEOS_ASH)
ash::AshTestHelper ash_test_helper_;
std::unique_ptr<views::TestViewsDelegate> test_views_delegate_ =
std::make_unique<ChromeTestViewsDelegate<ash::AshTestViewsDelegate>>();
Expand Down
5 changes: 3 additions & 2 deletions chrome/test/base/chrome_render_view_host_test_harness.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

#include "base/bind.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/signin/signin_error_controller_factory.h"

#if defined(OS_CHROMEOS)
#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "ash/shell.h"
#endif

Expand All @@ -26,7 +27,7 @@ TestingProfile* ChromeRenderViewHostTestHarness::profile() {

void ChromeRenderViewHostTestHarness::TearDown() {
RenderViewHostTestHarness::TearDown();
#if defined(OS_CHROMEOS)
#if BUILDFLAG(IS_CHROMEOS_ASH)
ash::Shell::DeleteInstance();
#endif
}
Expand Down
13 changes: 10 additions & 3 deletions chrome/test/base/chrome_test_launcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "base/test/test_file_util.h"
#include "base/test/test_switches.h"
#include "base/time/time.h"
#include "build/chromeos_buildflags.h"
#include "chrome/app/chrome_main_delegate.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_switches.h"
Expand Down Expand Up @@ -59,8 +60,10 @@
#include "chrome/installer/util/firewall_manager_win.h"
#endif

// TODO(crbug.com/1052397): Revisit the macro expression once build flag switch
// of lacros-chrome is complete.
#if defined(OS_WIN) || defined(OS_MAC) || \
(defined(OS_LINUX) && !defined(OS_CHROMEOS))
(defined(OS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS))
#include "chrome/browser/first_run/scoped_relaunch_chrome_browser_override.h"
#include "chrome/browser/upgrade_detector/installed_version_poller.h"
#include "testing/gtest/include/gtest/gtest.h"
Expand All @@ -74,8 +77,10 @@ int ChromeTestSuiteRunner::RunTestSuite(int argc, char** argv) {
// Android browser tests run child processes as threads instead.
content::ContentTestSuiteBase::RegisterInProcessThreads();
#endif
// TODO(crbug.com/1052397): Revisit the macro expression once build flag switch
// of lacros-chrome is complete.
#if defined(OS_WIN) || defined(OS_MAC) || \
(defined(OS_LINUX) && !defined(OS_CHROMEOS))
(defined(OS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS))
InstalledVersionPoller::ScopedDisableForTesting disable_polling(
InstalledVersionPoller::MakeScopedDisableForTesting());
#endif
Expand Down Expand Up @@ -225,8 +230,10 @@ int LaunchChromeTests(size_t parallel_jobs,
network_service_test_helper.get()));
}

// TODO(crbug.com/1052397): Revisit the macro expression once build flag switch
// of lacros-chrome is complete.
#if defined(OS_WIN) || defined(OS_MAC) || \
(defined(OS_LINUX) && !defined(OS_CHROMEOS))
(defined(OS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS))
// Cause a test failure for any test that triggers an unexpected relaunch.
// Tests that fail here should likely be restructured to put the "before
// relaunch" code into a PRE_ test with its own
Expand Down
8 changes: 4 additions & 4 deletions chrome/test/base/chrome_test_suite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "chrome/test/base/chrome_test_suite.h"

#if defined(OS_CHROMEOS)
#if BUILDFLAG(IS_CHROMEOS_ASH)
#include <stdio.h>
#include <unistd.h>
#endif
Expand All @@ -27,7 +27,7 @@
#include "media/base/media.h"
#include "testing/gtest/include/gtest/gtest.h"

#if defined(OS_CHROMEOS)
#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "base/process/process_metrics.h"
#include "chromeos/constants/chromeos_paths.h"
#endif
Expand All @@ -46,7 +46,7 @@
namespace {

bool IsCrosPythonProcess() {
#if defined(OS_CHROMEOS)
#if BUILDFLAG(IS_CHROMEOS_ASH)
char buf[80];
int num_read = readlink(base::kProcSelfExe, buf, sizeof(buf) - 1);
if (num_read == -1)
Expand All @@ -56,7 +56,7 @@ bool IsCrosPythonProcess() {
return !strncmp(strrchr(buf, '/'), kPythonPrefix, sizeof(kPythonPrefix) - 1);
#else
return false;
#endif // defined(OS_CHROMEOS)
#endif // BUILDFLAG(IS_CHROMEOS_ASH)
}

} // namespace
Expand Down
7 changes: 4 additions & 3 deletions chrome/test/base/chrome_unit_test_suite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "base/path_service.h"
#include "base/process/process_handle.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_content_browser_client.h"
#include "chrome/browser/data_use_measurement/chrome_data_use_measurement.h"
Expand All @@ -31,7 +32,7 @@
#include "ui/base/ui_base_paths.h"
#include "ui/gl/test/gl_surface_test_support.h"

#if defined(OS_CHROMEOS)
#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "chromeos/constants/chromeos_paths.h"
#endif

Expand Down Expand Up @@ -141,14 +142,14 @@ void ChromeUnitTestSuite::InitializeProviders() {
content::RegisterPathProvider();
ui::RegisterPathProvider();
component_updater::RegisterPathProvider(chrome::DIR_COMPONENTS,
#if defined(OS_CHROMEOS)
#if BUILDFLAG(IS_CHROMEOS_ASH)
chromeos::DIR_PREINSTALLED_COMPONENTS,
#else
chrome::DIR_INTERNAL_PLUGINS,
#endif
chrome::DIR_USER_DATA);

#if defined(OS_CHROMEOS)
#if BUILDFLAG(IS_CHROMEOS_ASH)
chromeos::RegisterPathProvider();
#endif

Expand Down
28 changes: 14 additions & 14 deletions chrome/test/base/in_process_browser_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
#include "components/storage_monitor/test_storage_monitor.h"
#endif

#if defined(OS_CHROMEOS)
#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "ash/public/cpp/test/shell_test_api.h"
#include "ash/shell.h"
#include "base/system/sys_info.h"
Expand All @@ -106,9 +106,9 @@
#include "components/user_manager/user_names.h"
#include "ui/display/display_switches.h"
#include "ui/events/test/event_generator.h"
#endif // defined(OS_CHROMEOS)
#endif // BUILDFLAG(IS_CHROMEOS_ASH)

#if !defined(OS_CHROMEOS) && defined(USE_X11)
#if !BUILDFLAG(IS_CHROMEOS_ASH) && defined(USE_X11)
#include "ui/views/test/test_desktop_screen_x11.h"
#endif

Expand All @@ -121,14 +121,14 @@
#include "ui/views/widget/widget.h"
#endif

#if BUILDFLAG(IS_LACROS)
#if BUILDFLAG(IS_CHROMEOS_LACROS)
#include "ui/aura/test/ui_controls_factory_aura.h"
#include "ui/base/test/ui_controls.h"
#endif

namespace {

#if defined(OS_CHROMEOS)
#if BUILDFLAG(IS_CHROMEOS_ASH)
class FakeDeviceSyncImplFactory
: public chromeos::device_sync::DeviceSyncImpl::Factory {
public:
Expand All @@ -154,7 +154,7 @@ FakeDeviceSyncImplFactory* GetFakeDeviceSyncImplFactory() {
static base::NoDestructor<FakeDeviceSyncImplFactory> factory;
return factory.get();
}
#endif // defined(OS_CHROMEOS)
#endif // BUILDFLAG(IS_CHROMEOS_ASH)

#if !defined(OS_ANDROID)
// An observer that returns back to test code after a new profile is
Expand Down Expand Up @@ -192,14 +192,14 @@ void InProcessBrowserTest::RunScheduledLayouts() {
#if defined(TOOLKIT_VIEWS)
views::Widget::Widgets widgets_to_layout;

#if defined(OS_CHROMEOS)
#if BUILDFLAG(IS_CHROMEOS_ASH)
// WidgetTest::GetAllWidgets() doesn't work for ChromeOS in a production
// environment. We must get the Widgets ourself.
for (aura::Window* root_window : ash::Shell::GetAllRootWindows())
views::Widget::GetAllChildWidgets(root_window, &widgets_to_layout);
#else
widgets_to_layout = views::test::WidgetTest::GetAllWidgets();
#endif // defined(OS_CHROMEOS)
#endif // BUILDFLAG(IS_CHROMEOS_ASH)

for (views::Widget* widget : widgets_to_layout)
widget->LayoutRootViewIfNecessary();
Expand Down Expand Up @@ -260,7 +260,7 @@ void InProcessBrowserTest::SetUp() {
ASSERT_TRUE(SetUpUserDataDirectory())
<< "Could not set up user data directory.";

#if defined(OS_CHROMEOS)
#if BUILDFLAG(IS_CHROMEOS_ASH)
// No need to redirect log for test.
command_line->AppendSwitch(switches::kDisableLoggingRedirect);

Expand Down Expand Up @@ -317,7 +317,7 @@ void InProcessBrowserTest::SetUp() {
chrome_browser_net::NetErrorTabHelper::set_state_for_testing(
chrome_browser_net::NetErrorTabHelper::TESTING_FORCE_DISABLED);

#if defined(OS_CHROMEOS) || BUILDFLAG(IS_CHROMEOS_LACROS)
#if BUILDFLAG(IS_CHROMEOS_ASH) || BUILDFLAG(IS_CHROMEOS_LACROS)
// On Chrome OS, access to files via file: scheme is restricted. Enable
// access to all files here since browser_tests and interactive_ui_tests
// rely on the ability to open any files via file: scheme.
Expand Down Expand Up @@ -372,7 +372,7 @@ void InProcessBrowserTest::TearDown() {
OSCryptMocker::TearDown();
#endif

#if defined(OS_CHROMEOS)
#if BUILDFLAG(IS_CHROMEOS_ASH)
chromeos::device_sync::DeviceSyncImpl::Factory::SetCustomFactory(nullptr);
#endif
}
Expand Down Expand Up @@ -443,7 +443,7 @@ bool InProcessBrowserTest::SetUpUserDataDirectory() {
}

void InProcessBrowserTest::SetScreenInstance() {
#if defined(USE_X11) && !defined(OS_CHROMEOS)
#if defined(USE_X11) && !BUILDFLAG(IS_CHROMEOS_ASH)
if (!features::IsUsingOzonePlatform()) {
DCHECK(!display::Screen::GetScreen());
display::Screen::SetScreenInstance(
Expand Down Expand Up @@ -579,7 +579,7 @@ void InProcessBrowserTest::PreRunTestOnMainThread() {

SelectFirstBrowser();
if (browser_) {
#if defined(OS_CHROMEOS)
#if BUILDFLAG(IS_CHROMEOS_ASH)
// There are cases where windows get created maximized by default.
if (browser_->window()->IsMaximized())
browser_->window()->Restore();
Expand All @@ -594,7 +594,7 @@ void InProcessBrowserTest::PreRunTestOnMainThread() {
// The ozone implementation of CreateUIControlsAura differs from other
// implementation in that it requires a WindowTreeHost. Thus, it must be
// initialized here rather than earlier.
#if BUILDFLAG(IS_LACROS)
#if BUILDFLAG(IS_CHROMEOS_LACROS)
BrowserWindow* window = browser_->window();
CHECK(window);
ui_controls::InstallUIControlsAura(
Expand Down
Loading

0 comments on commit c58ac2d

Please sign in to comment.