Bug 1805269 - Don't allow getting gamepad and VR test services outside of automation. r=smaug,cmartin

These interfaces are already disabled by prefs, but they are ironically
probably not well tested, so just add an extra check.

Differential Revision: https://phabricator.services.mozilla.com/D164496
This commit is contained in:
Andrew McCreight 2022-12-13 18:20:46 +00:00
Родитель 136a940fe6
Коммит 9edebfc628
3 изменённых файлов: 16 добавлений и 6 удалений

Просмотреть файл

@ -1594,7 +1594,12 @@ void Navigator::GetGamepads(nsTArray<RefPtr<Gamepad>>& aGamepads,
win->GetGamepads(aGamepads);
}
GamepadServiceTest* Navigator::RequestGamepadServiceTest() {
GamepadServiceTest* Navigator::RequestGamepadServiceTest(ErrorResult& aRv) {
if (!xpc::IsInAutomation()) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
if (!mGamepadServiceTest) {
mGamepadServiceTest = GamepadServiceTest::CreateTestService(mWindow);
}
@ -1759,7 +1764,12 @@ void Navigator::NotifyActiveVRDisplaysChanged() {
Navigator_Binding::ClearCachedActiveVRDisplaysValue(this);
}
VRServiceTest* Navigator::RequestVRServiceTest() {
VRServiceTest* Navigator::RequestVRServiceTest(ErrorResult& aRv) {
if (!xpc::IsInAutomation()) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
// Ensure that the Mock VR devices are not released prematurely
nsGlobalWindowInner* win = nsGlobalWindowInner::Cast(mWindow);
win->NotifyHasXRSession();

Просмотреть файл

@ -175,13 +175,13 @@ class Navigator final : public nsISupports, public nsWrapperCache {
MediaDevices* GetExtantMediaDevices() const { return mMediaDevices; };
void GetGamepads(nsTArray<RefPtr<Gamepad>>& aGamepads, ErrorResult& aRv);
GamepadServiceTest* RequestGamepadServiceTest();
GamepadServiceTest* RequestGamepadServiceTest(ErrorResult& aRv);
already_AddRefed<Promise> GetVRDisplays(ErrorResult& aRv);
void FinishGetVRDisplays(bool isWebVRSupportedInwindow, Promise* p);
void GetActiveVRDisplays(nsTArray<RefPtr<VRDisplay>>& aDisplays) const;
void OnXRPermissionRequestAllow();
void OnXRPermissionRequestCancel();
VRServiceTest* RequestVRServiceTest();
VRServiceTest* RequestVRServiceTest(ErrorResult& aRv);
bool IsWebVRContentDetected() const;
bool IsWebVRContentPresenting() const;
void RequestVRPresentation(VRDisplay& aDisplay);

Просмотреть файл

@ -209,7 +209,7 @@ partial interface Navigator {
sequence<Gamepad?> getGamepads();
};
partial interface Navigator {
[Pref="dom.gamepad.test.enabled"]
[Throws, Pref="dom.gamepad.test.enabled"]
GamepadServiceTest requestGamepadServiceTest();
};
@ -228,7 +228,7 @@ partial interface Navigator {
undefined requestVRPresentation(VRDisplay display);
};
partial interface Navigator {
[Pref="dom.vr.puppet.enabled"]
[Throws, Pref="dom.vr.puppet.enabled"]
VRServiceTest requestVRServiceTest();
};