Commit b18b2a9d authored by James Cook's avatar James Cook Committed by Commit Bot

lacros: Provide default LacrosInitParams when running tests

browser_tests disable all crosapi calls and do not call
LacrosChromeService::Init(). LacrosChromeServiceImpl::init_params_ is
therefore "null". However, because LacrosInitParams is a small mojo
struct, it is an InlinedStructPtr, and init_params_.get() returns
a non-null pointer. This means existing code in lacros can call
LacrosChromeServiceImpl::init_params() and get a non-null value.

A later CL increases the size of LacrosInitParams, so it cannot be
inlined. This causes browser_tests failures because init_params()
starts returning null.

We want some value for InitParams in tests. Therefore create a
default-constructed version in tests.

Bug: none
Change-Id: I3ee0b15a276d0f04fc024ba3fbd7d2d1a892a72b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2463568
Commit-Queue: James Cook <jamescook@chromium.org>
Commit-Queue: Erik Chen <erikchen@chromium.org>
Auto-Submit: James Cook <jamescook@chromium.org>
Reviewed-by: default avatarErik Chen <erikchen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#815711}
parent db9ad9d4
...@@ -197,6 +197,12 @@ LacrosChromeServiceImpl::LacrosChromeServiceImpl( ...@@ -197,6 +197,12 @@ LacrosChromeServiceImpl::LacrosChromeServiceImpl(
std::unique_ptr<LacrosChromeServiceDelegate> delegate) std::unique_ptr<LacrosChromeServiceDelegate> delegate)
: delegate_(std::move(delegate)), : delegate_(std::move(delegate)),
sequenced_state_(nullptr, base::OnTaskRunnerDeleter(nullptr)) { sequenced_state_(nullptr, base::OnTaskRunnerDeleter(nullptr)) {
if (g_disable_all_crosapi_for_tests) {
// Tests don't call LacrosChromeService::Init(), so provide LacrosInitParams
// with default values.
init_params_ = crosapi::mojom::LacrosInitParams::New();
}
// The sequence on which this object was constructed, and thus affine to. // The sequence on which this object was constructed, and thus affine to.
scoped_refptr<base::SequencedTaskRunner> affine_sequence = scoped_refptr<base::SequencedTaskRunner> affine_sequence =
base::SequencedTaskRunnerHandle::Get(); base::SequencedTaskRunnerHandle::Get();
...@@ -316,6 +322,7 @@ void LacrosChromeServiceImpl::BindReceiver( ...@@ -316,6 +322,7 @@ void LacrosChromeServiceImpl::BindReceiver(
} }
} }
// static
void LacrosChromeServiceImpl::DisableCrosapiForTests() { void LacrosChromeServiceImpl::DisableCrosapiForTests() {
g_disable_all_crosapi_for_tests = true; g_disable_all_crosapi_for_tests = true;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment