# Test Chrome Parts On testing, we sometimes use `test_ash_chrome` or `test_lacros_chrome` to make the test less costful. ## Executable `test_ash_chrome` and `test_lacros_chrome` is created as executable file. The build rule is in [chrome/test/BUILD.gn](https://source.chromium.org/chromium/chromium/src/+/main:chrome/test/BUILD.gn;l=12552;drc=9a8865864ef150806ec280fac0aaa520a5d59394). [chrome_exe_main_aura.cc](https://source.chromium.org/chromium/chromium/src/+/main:chrome/app/chrome_exe_main_aura.cc;l=16;drc=4a8573cb240df29b0e4d9820303538fb28e31d84) has main function. [ChromeMain](https://source.chromium.org/chromium/chromium/src/+/main:chrome/app/chrome_exe_main_aura.cc;l=13;drc=a002cb035f709dcb195fd5c8a1bb2f7b2260c613) is declared as extern. In production, ChromeMain is defined as [chrome_main.cc](https://source.chromium.org/chromium/chromium/src/+/main:chrome/app/chrome_main.cc;l=55-81;drc=c7be05398c9bf694dc2565ef4b095d7a59586aaa). As for test_ash/lacros_chrome, [test_chrome_main.cc](https://source.chromium.org/chromium/chromium/src/+/main:chrome/test/base/chromeos/test_chrome_main.cc;l=20;drc=9b237796481d49b6ef6ee03cde02b2d64d4a73b2) has its definition. ## TestChromeBase [TestChromeBase](https://source.chromium.org/chromium/chromium/src/+/main:chrome/test/base/chromeos/test_chrome_base.h;l=20;drc=8f57934dc9dd175acdc5fc56e2e6b7c3cb8e3b95) is constructed inside ChromeMain and [Start](https://source.chromium.org/chromium/chromium/src/+/main:chrome/test/base/chromeos/test_chrome_base.cc;l=36;drc=221d6bf1f071258e70afb3c3af89407d2f6ed4cb)ed in test_chrome_main.cc. Depending on whether we have `kHeadless` switch or not, we run [ContentMain](https://source.chromium.org/chromium/chromium/src/+/main:content/app/content_main.cc;l=340;drc=a002cb035f709dcb195fd5c8a1bb2f7b2260c613) or [HeadlessShellMain](https://source.chromium.org/chromium/chromium/src/+/main:headless/app/headless_shell.cc;l=238;drc=a002cb035f709dcb195fd5c8a1bb2f7b2260c613). Each main gets `params` and it has [`created_main_gets_closure`](https://source.chromium.org/chromium/chromium/src/+/main:content/public/app/content_main.h;l=63;drc=a002cb035f709dcb195fd5c8a1bb2f7b2260c613). This property is used by BrowserTestBase and invoked after BrowserMainParts has been created and before PreEarlyInitialization. For TestChromeBase, it registered [TestAshChromeBrowserMainExtraParts](https://source.chromium.org/chromium/chromium/src/+/main:chrome/test/base/chromeos/test_ash_chrome_browser_main_extra_parts.h;l=15;drc=a002cb035f709dcb195fd5c8a1bb2f7b2260c613) or [TestLacrosChromeBrowserMainExtraParts](https://source.chromium.org/chromium/chromium/src/+/main:chrome/test/base/chromeos/test_lacros_chrome_browser_main_extra_parts.h;l=19;drc=221d6bf1f071258e70afb3c3af89407d2f6ed4cb). By registering this, we can customize the extra parts without corrputing the production code. For example, Lacros gets TestController remote and construct [StandaloneBrowserTestController](https://source.chromium.org/chromium/chromium/src/+/main:chrome/test/base/chromeos/test_lacros_chrome_browser_main_extra_parts.cc;l=26-27;drc=221d6bf1f071258e70afb3c3af89407d2f6ed4cb). ## Ash Browser Test Starter [AshBrowserTestStarter](https://source.chromium.org/chromium/chromium/src/+/main:chrome/test/base/chromeos/ash_browser_test_starter.h;l=22;drc=eff91e0244e11278e77b729821a2ddfb4dbe3328) is a class for Ash to start lacros. It is used by ash tests that require Lacros e.g. [AshRequiresLacrosBrowserTestBase](https://source.chromium.org/chromium/chromium/src/+/main:chrome/browser/ash/crosapi/ash_requires_lacros_browsertestbase.cc;l=22;drc=a002cb035f709dcb195fd5c8a1bb2f7b2260c613). It has [StartLacros](https://source.chromium.org/chromium/chromium/src/+/main:chrome/test/base/chromeos/ash_browser_test_starter.cc;l=214;drc=a002cb035f709dcb195fd5c8a1bb2f7b2260c613) API. StartLacros sets up BrowserManager by setting fake device ownership waiter, and then create new Lacros window by queing [BrowserAction::NewWindow](https://source.chromium.org/chromium/chromium/src/+/main:chrome/browser/ash/crosapi/browser_action.cc;l=417;drc=a002cb035f709dcb195fd5c8a1bb2f7b2260c613). [PrepareEnvironmentForLacros](https://source.chromium.org/chromium/chromium/src/+/main:chrome/test/base/chromeos/ash_browser_test_starter.cc;l=120;drc=a002cb035f709dcb195fd5c8a1bb2f7b2260c613) prepares the command line and it is added via [standalone_browser::AddLacrosArguments](https://source.chromium.org/chromium/chromium/src/+/main:chrome/test/base/chromeos/ash_browser_test_starter.cc;l=209;drc=a002cb035f709dcb195fd5c8a1bb2f7b2260c613) which appends [`kLacrosChromeAdditionalArgs`](https://source.chromium.org/chromium/chromium/src/+/main:ash/constants/ash_switches.cc;l=787;drc=a002cb035f709dcb195fd5c8a1bb2f7b2260c613). This allows Ash to work with Lacros. This must be run if you want to StartLacros. This must be called after SetUpOnMainThread.