Improve web engine detection in webxr_util.js (#23200)

The check (window.XRTest === undefined) is not valid to discriminate between Chromium and other browsers. Improve engine detection so that we don't end up accessing entities that do not exist in other engines (like navigator.xr.test.Debug).
diff --git a/webxr/resources/webxr_util.js b/webxr/resources/webxr_util.js
index 188284e..20585ef 100644
--- a/webxr/resources/webxr_util.js
+++ b/webxr/resources/webxr_util.js
@@ -10,19 +10,21 @@
 // Debugging message helper, by default does nothing. Implementations can
 // override this.
 var xr_debug = function(name, msg) {}
+var isChromiumBased = 'MojoInterfaceInterceptor' in self;
+var isWebKitBased = 'internals' in self && 'xrTest' in internals;
 
 function xr_promise_test(name, func, properties) {
   promise_test(async (t) => {
     // Perform any required test setup:
     xr_debug(name, 'setup');
 
-    if (window.XRTest === undefined) {
+    if (isChromiumBased) {
       // Chrome setup
       await loadChromiumResources;
       xr_debug = navigator.xr.test.Debug;
     }
 
-    if (self.internals && internals.xrTest && navigator.xr) {
+    if (isWebKitBased) {
       // WebKit setup
       await setupWebKitWebXRTestAPI;
     }
@@ -161,7 +163,7 @@
 
 // Code for loading test API in Chromium.
 let loadChromiumResources = Promise.resolve().then(() => {
-  if (!('MojoInterfaceInterceptor' in self)) {
+  if (!isChromiumBased) {
     // Do nothing on non-Chromium-based browsers or when the Mojo bindings are
     // not present in the global namespace.
     return;
@@ -206,7 +208,7 @@
 });
 
 let setupWebKitWebXRTestAPI = Promise.resolve().then(() => {
-  if (!self.internals || !internals.xrTest) {
+  if (!isWebKitBased) {
     // Do nothing on non-WebKit-based browsers.
     return;
   }