0

[CodeHealth] Spanify WebXR test code

Bug: 351564777
Change-Id: Ib298fe5406c9d1e8dff25e9e87515532dbd5cb29
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6130368
Auto-Submit: Alexander Cooper <alcooper@chromium.org>
Commit-Queue: Alexander Cooper <alcooper@chromium.org>
Reviewed-by: Brandon Jones <bajones@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1401551}
This commit is contained in:
Alexander Cooper
2025-01-02 12:30:51 -08:00
committed by Chromium LUCI CQ
parent 136fa2c404
commit dd576ab923
5 changed files with 18 additions and 36 deletions

@@ -2,11 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif
#include "chrome/browser/vr/test/mock_xr_device_hook_base.h" #include "chrome/browser/vr/test/mock_xr_device_hook_base.h"
#include "content/public/test/xr_test_utils.h" #include "content/public/test/xr_test_utils.h"
@@ -227,8 +222,7 @@ device::ControllerFrameData MockXRDeviceHookBase::CreateValidController(
device::ControllerFrameData ret; device::ControllerFrameData ret;
// Because why shouldn't a 64 button controller exist? // Because why shouldn't a 64 button controller exist?
ret.supported_buttons = UINT64_MAX; ret.supported_buttons = UINT64_MAX;
memset(ret.axis_data, 0, std::ranges::fill(ret.axis_data, device::ControllerAxisData{});
sizeof(device::ControllerAxisData) * device::kMaxNumAxes);
ret.role = role; ret.role = role;
ret.is_valid = true; ret.is_valid = true;
// Identity matrix. // Identity matrix.

@@ -63,8 +63,8 @@ class MockXRDeviceHookBase : public device_test::mojom::XRTestHook {
void SetCanCreateSession(bool can_create_session); void SetCanCreateSession(bool can_create_session);
protected: protected:
device_test::mojom::TrackedDeviceClass std::array<device_test::mojom::TrackedDeviceClass, device::kMaxTrackedDevices>
tracked_classes_[device::kMaxTrackedDevices]; tracked_classes_;
base::flat_map<unsigned int, device::ControllerFrameData> base::flat_map<unsigned int, device::ControllerFrameData>
controller_data_map_; controller_data_map_;
std::queue<device_test::mojom::EventData> event_data_queue_; std::queue<device_test::mojom::EventData> event_data_queue_;

@@ -2,11 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif
#include <atomic> #include <atomic>
#include "base/containers/contains.h" #include "base/containers/contains.h"
@@ -175,7 +170,8 @@ class WebXrControllerInputMock : public MockXRDeviceHookBase {
bool is_valid) { bool is_valid) {
auto controller_data = GetCurrentControllerData(index); auto controller_data = GetCurrentControllerData(index);
controller_data.pose_data.is_valid = is_valid; controller_data.pose_data.is_valid = is_valid;
device_to_origin.GetColMajorF(controller_data.pose_data.device_to_origin); device_to_origin.GetColMajorF(
controller_data.pose_data.device_to_origin.data());
UpdateControllerAndWait(index, controller_data); UpdateControllerAndWait(index, controller_data);
} }
@@ -840,11 +836,11 @@ WEBXR_VR_ALL_RUNTIMES_BROWSER_TEST_F(TestControllerInputRegistered) {
} }
std::string TransformToColMajorString(const gfx::Transform& t) { std::string TransformToColMajorString(const gfx::Transform& t) {
float array[16]; std::array<float, 16> array;
t.GetColMajorF(array); t.GetColMajorF(array.data());
std::string array_string = "["; std::string array_string = "[";
for (int i = 0; i < 16; i++) { for (const auto& val : array) {
array_string += base::NumberToString(array[i]) + ","; array_string += base::NumberToString(val) + ",";
} }
array_string.pop_back(); array_string.pop_back();
array_string.push_back(']'); array_string.push_back(']');

@@ -2,11 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/342213636): Remove this and spanify to fix the errors.
#pragma allow_unsafe_buffers
#endif
#include "components/webxr/xr_test_hook_wrapper.h" #include "components/webxr/xr_test_hook_wrapper.h"
#include "base/task/single_thread_task_runner.h" #include "base/task/single_thread_task_runner.h"
@@ -36,7 +31,7 @@ device::PoseFrameData MojoToDevicePoseFrameData(
device::PoseFrameData ret = {}; device::PoseFrameData ret = {};
ret.is_valid = !!pose->device_to_origin; ret.is_valid = !!pose->device_to_origin;
if (ret.is_valid) { if (ret.is_valid) {
pose->device_to_origin->GetColMajorF(ret.device_to_origin); pose->device_to_origin->GetColMajorF(ret.device_to_origin.data());
} }
return ret; return ret;

@@ -2,11 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/351564777): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif
#ifndef DEVICE_VR_TEST_TEST_HOOK_H_ #ifndef DEVICE_VR_TEST_TEST_HOOK_H_
#define DEVICE_VR_TEST_TEST_HOOK_H_ #define DEVICE_VR_TEST_TEST_HOOK_H_
@@ -89,14 +84,16 @@ struct ViewData {
}; };
struct PoseFrameData { struct PoseFrameData {
float device_to_origin[16]; std::array<float, 16> device_to_origin;
bool is_valid; bool is_valid;
}; };
struct DeviceConfig { struct DeviceConfig {
float interpupillary_distance; float interpupillary_distance;
float viewport_left[4]; // raw projection left {left, right, top, bottom} std::array<float, 4>
float viewport_right[4]; // raw projection right {left, right, top, bottom} viewport_left; // raw projection left {left, right, top, bottom}
std::array<float, 4>
viewport_right; // raw projection right {left, right, top, bottom}
}; };
struct ControllerAxisData { struct ControllerAxisData {
@@ -140,10 +137,10 @@ struct COMPONENT_EXPORT(VR_TEST_HOOK) ControllerFrameData {
uint64_t buttons_pressed = 0; uint64_t buttons_pressed = 0;
uint64_t buttons_touched = 0; uint64_t buttons_touched = 0;
uint64_t supported_buttons = 0; uint64_t supported_buttons = 0;
ControllerAxisData axis_data[kMaxNumAxes]; std::array<ControllerAxisData, kMaxNumAxes> axis_data;
PoseFrameData pose_data = {}; PoseFrameData pose_data = {};
ControllerRole role = kControllerRoleInvalid; ControllerRole role = kControllerRoleInvalid;
XRHandJointData hand_data[kNumJointsForTest]; std::array<XRHandJointData, kNumJointsForTest> hand_data;
bool has_hand_data = false; bool has_hand_data = false;
bool is_valid = false; bool is_valid = false;
@@ -159,7 +156,7 @@ inline gfx::Transform PoseFrameDataToTransform(PoseFrameData data) {
// we're given data in column-major order. Construct in column-major order and // we're given data in column-major order. Construct in column-major order and
// transpose since it looks cleaner than manually transposing the arguments // transpose since it looks cleaner than manually transposing the arguments
// passed to the constructor. // passed to the constructor.
float* t = data.device_to_origin; auto& t = data.device_to_origin;
return gfx::Transform::ColMajor(t[0], t[1], t[2], t[3], t[4], t[5], t[6], return gfx::Transform::ColMajor(t[0], t[1], t[2], t[3], t[4], t[5], t[6],
t[7], t[8], t[9], t[10], t[11], t[12], t[13], t[7], t[8], t[9], t[10], t[11], t[12], t[13],
t[14], t[15]); t[14], t[15]);