Create test interface for xr_device_service
When previously splitting xr_device_service into a test/internal
interface, one usage within mock_xr_device_hook_base was missed. This
change adds a test-specific method for that class as well.
This change also exposes an "internal" function that the test functions
may call. This is necessary because when xr_test_utils is moved to
content/public/test, xr_device_service will not be able to depend on
it; however, the reverse dependency (xr_test_utils depending on
xr_device_service) is allowed.
Bug: 1031622
Change-Id: Iec2efde6b620fc9ce336f3e0d6472410c9156621
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2151467
Commit-Queue: Alexander Cooper <alcooper@chromium.org>
Commit-Queue: Klaus Weidner <klausw@chromium.org>
Auto-Submit: Alexander Cooper <alcooper@chromium.org>
Reviewed-by: Klaus Weidner <klausw@chromium.org>
Cr-Commit-Position: refs/heads/master@{#759458}
diff --git a/chrome/browser/vr/BUILD.gn b/chrome/browser/vr/BUILD.gn
index e3ef3aa..761d60d 100644
--- a/chrome/browser/vr/BUILD.gn
+++ b/chrome/browser/vr/BUILD.gn
@@ -254,7 +254,6 @@
"vr_export.h",
"vr_web_contents_observer.cc",
"vr_web_contents_observer.h",
- "xr_test_utils.h",
]
sources += [
@@ -572,6 +571,8 @@
"test/mock_ui_browser_interface.h",
"test/vr_test_suite.cc",
"test/vr_test_suite.h",
+ "xr_test_utils.cc",
+ "xr_test_utils.h",
]
public_deps = [
@@ -669,7 +670,9 @@
]
deps = [
+ # TODO(alcooper) remove vr_test_support when xr_test_utils moves
":vr_common",
+ ":vr_test_support",
"//chrome/common:constants",
"//chrome/test:xr_browser_tests_common",
"//device/vr:vr",
diff --git a/chrome/browser/vr/DEPS b/chrome/browser/vr/DEPS
index c3fea28..ce34ba1 100644
--- a/chrome/browser/vr/DEPS
+++ b/chrome/browser/vr/DEPS
@@ -24,7 +24,9 @@
"+device/vr/test/test_hook.h",
"+third_party/openvr/src/headers/openvr.h",
],
- ".*mock.*" : [
- "+chrome/browser/vr/service",
+ # xr_test_utils will be moving to content/public/test, where it can depend on
+ # internal content code.
+ "xr_test_utils\.cc" : [
+ "+chrome/browser/vr/service/xr_device_service.h",
]
}
diff --git a/chrome/browser/vr/service/DEPS b/chrome/browser/vr/service/DEPS
index 5a0de0f..36f024f9b 100644
--- a/chrome/browser/vr/service/DEPS
+++ b/chrome/browser/vr/service/DEPS
@@ -12,7 +12,6 @@
"+chrome/browser/vr/metrics/session_metrics_helper.h",
"+chrome/browser/vr/vr_export.h",
"+chrome/browser/vr/xr_runtime_manager_statics.h",
- "+chrome/browser/vr/xr_test_utils.h",
]
specific_include_rules = {
diff --git a/chrome/browser/vr/service/xr_device_service.cc b/chrome/browser/vr/service/xr_device_service.cc
index bcdda1c..da0ca82b 100644
--- a/chrome/browser/vr/service/xr_device_service.cc
+++ b/chrome/browser/vr/service/xr_device_service.cc
@@ -6,7 +6,6 @@
#include "base/no_destructor.h"
#include "build/build_config.h"
-#include "chrome/browser/vr/xr_test_utils.h"
#include "content/public/browser/service_process_host.h"
namespace vr {
@@ -51,7 +50,7 @@
return *remote;
}
-void SetXRDeviceServiceStartupCallbackForTesting(
+void SetXRDeviceServiceStartupCallbackForTestingInternal(
base::RepeatingClosure callback) {
GetStartupCallback() = std::move(callback);
}
diff --git a/chrome/browser/vr/service/xr_device_service.h b/chrome/browser/vr/service/xr_device_service.h
index f69ce67c..bcdf8eda 100644
--- a/chrome/browser/vr/service/xr_device_service.h
+++ b/chrome/browser/vr/service/xr_device_service.h
@@ -14,9 +14,11 @@
// Acquires a remote handle to the sandboxed isolated XR Device Service
// instance, launching a process to host the service if necessary.
-VR_EXPORT const mojo::Remote<device::mojom::XRDeviceService>&
+const VR_EXPORT mojo::Remote<device::mojom::XRDeviceService>&
GetXRDeviceService();
+void VR_EXPORT SetXRDeviceServiceStartupCallbackForTestingInternal(
+ base::RepeatingClosure callback);
} // namespace vr
#endif // CHROME_BROWSER_VR_SERVICE_XR_DEVICE_SERVICE_H_
diff --git a/chrome/browser/vr/test/mock_xr_device_hook_base.cc b/chrome/browser/vr/test/mock_xr_device_hook_base.cc
index 94e97bf5..dffeeca 100644
--- a/chrome/browser/vr/test/mock_xr_device_hook_base.cc
+++ b/chrome/browser/vr/test/mock_xr_device_hook_base.cc
@@ -3,7 +3,7 @@
// found in the LICENSE file.
#include "chrome/browser/vr/test/mock_xr_device_hook_base.h"
-#include "chrome/browser/vr/service/xr_device_service.h"
+#include "chrome/browser/vr/xr_test_utils.h"
#include "device/vr/public/mojom/isolated_xr_service.mojom.h"
// TODO(https://crbug.com/891832): Remove these conversion functions as part of
@@ -52,7 +52,7 @@
MockXRDeviceHookBase::MockXRDeviceHookBase()
: tracked_classes_{
device_test::mojom::TrackedDeviceClass::kTrackedDeviceInvalid} {
- vr::GetXRDeviceService()->BindTestHook(
+ vr::GetXRDeviceServiceForTesting()->BindTestHook(
service_test_hook_.BindNewPipeAndPassReceiver());
mojo::ScopedAllowSyncCallForTesting scoped_allow_sync;
diff --git a/chrome/browser/vr/xr_test_utils.cc b/chrome/browser/vr/xr_test_utils.cc
new file mode 100644
index 0000000..2a7c82c
--- /dev/null
+++ b/chrome/browser/vr/xr_test_utils.cc
@@ -0,0 +1,21 @@
+// Copyright 2020 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/vr/xr_test_utils.h"
+
+#include "chrome/browser/vr/service/xr_device_service.h"
+
+namespace vr {
+
+const mojo::Remote<device::mojom::XRDeviceService>&
+GetXRDeviceServiceForTesting() {
+ return GetXRDeviceService();
+}
+
+void SetXRDeviceServiceStartupCallbackForTesting(
+ base::RepeatingClosure callback) {
+ SetXRDeviceServiceStartupCallbackForTestingInternal(std::move(callback));
+}
+
+} // namespace vr
diff --git a/chrome/browser/vr/xr_test_utils.h b/chrome/browser/vr/xr_test_utils.h
index eeb56a02..3e5f4cf 100644
--- a/chrome/browser/vr/xr_test_utils.h
+++ b/chrome/browser/vr/xr_test_utils.h
@@ -6,7 +6,8 @@
#define CHROME_BROWSER_VR_XR_TEST_UTILS_H_
#include "base/callback_forward.h"
-#include "chrome/browser/vr/vr_export.h"
+#include "device/vr/public/mojom/isolated_xr_service.mojom-forward.h"
+#include "mojo/public/cpp/bindings/remote.h"
namespace vr {
@@ -14,9 +15,15 @@
// Service instance before other client code can use it. Any time a new instance
// of the service is started by |GetXRDeviceService()|, this callback (if
// non-null) is invoked.
-VR_EXPORT void SetXRDeviceServiceStartupCallbackForTesting(
+void SetXRDeviceServiceStartupCallbackForTesting(
base::RepeatingClosure callback);
+// Acquires a remote handle to the sandboxed isolated XR Device Service
+// instance, launching a process to host the service if necessary.
+// This is really just a wrapper for |GetXRDeviceService| which is only exposed
+// internally to content/browser.
+const mojo::Remote<device::mojom::XRDeviceService>&
+GetXRDeviceServiceForTesting();
} // namespace vr
#endif // CHROME_BROWSER_VR_XR_TEST_UTILS_H_