How to use metricsRecorderPtr method in wpt

Best JavaScript code snippet using wpt

webxr-test.js

Source:webxr-test.js Github

copy

Full Screen

1'use strict';2// This polyfill library implements the WebXR Test API as specified here:3// https://github.com/immersive-web/webxr-test-api4let default_standing = new gfx.mojom.Transform();5default_standing.matrix = [1, 0, 0, 0,6 0, 1, 0, 0,7 0, 0, 1, 0,8 0, 1.65, 0, 1];9const default_stage_parameters = {10 standingTransform: default_standing,11 bounds: null12};13function getMatrixFromTransform(transform) {14 let x = transform.orientation[0];15 let y = transform.orientation[1];16 let z = transform.orientation[2];17 let w = transform.orientation[3];18 let m11 = 1.0 - 2.0 * (y * y + z * z);19 let m21 = 2.0 * (x * y + z * w);20 let m31 = 2.0 * (x * z - y * w);21 let m12 = 2.0 * (x * y - z * w);22 let m22 = 1.0 - 2.0 * (x * x + z * z);23 let m32 = 2.0 * (y * z + x * w);24 let m13 = 2.0 * (x * z + y * w);25 let m23 = 2.0 * (y * z - x * w);26 let m33 = 1.0 - 2.0 * (x * x + y * y);27 let m14 = transform.position[0];28 let m24 = transform.position[1];29 let m34 = transform.position[2];30 // Column-major linearized order is expected.31 return [m11, m21, m31, 0,32 m12, m22, m32, 0,33 m13, m23, m33, 0,34 m14, m24, m34, 1];35}36function composeGFXTransform(fakeTransformInit) {37 let transform = new gfx.mojom.Transform();38 transform.matrix = getMatrixFromTransform(fakeTransformInit);39 return transform;40}41class ChromeXRTest {42 constructor() {43 this.mockVRService_ = new MockVRService(mojo.frameInterfaces);44 }45 simulateDeviceConnection(init_params) {46 return Promise.resolve(this.mockVRService_.addRuntime(init_params));47 }48 disconnectAllDevices() {49 this.mockVRService_.removeAllRuntimes(device);50 return Promise.resolve();51 }52 simulateUserActivation(callback) {53 let button = document.createElement('button');54 button.textContent = 'click to continue test';55 button.style.display = 'block';56 button.style.fontSize = '20px';57 button.style.padding = '10px';58 button.onclick = () => {59 callback();60 document.body.removeChild(button);61 };62 document.body.appendChild(button);63 test_driver.click(button);64 }65}66// Mocking class definitions67// Mock service implements the VRService mojo interface.68class MockVRService {69 constructor() {70 this.bindingSet_ = new mojo.BindingSet(device.mojom.VRService);71 this.runtimes_ = [];72 this.interceptor_ =73 new MojoInterfaceInterceptor(device.mojom.VRService.name, "context", true);74 this.interceptor_.oninterfacerequest = e =>75 this.bindingSet_.addBinding(this, e.handle);76 this.interceptor_.start();77 }78 // Test methods79 addRuntime(fakeDeviceInit) {80 let runtime = new MockRuntime(fakeDeviceInit, this);81 this.runtimes_.push(runtime);82 if (this.client_) {83 this.client_.onDeviceChanged();84 }85 return runtime;86 }87 removeAllRuntimes() {88 if (this.client_) {89 this.client_.onDeviceChanged();90 }91 this.runtimes_ = [];92 }93 removeRuntime(device) {94 let index = this.runtimes_.indexOf(device);95 if (index >= 0) {96 this.runtimes_.splice(index, 1);97 if (this.client_) {98 this.client_.onDeviceChanged();99 }100 }101 }102 setClient(client) {103 if (this.client_) {104 throw new Error("setClient should only be called once");105 }106 this.client_ = client;107 }108 requestSession(sessionOptions, was_activation) {109 let requests = [];110 // Request a session from all the runtimes.111 for (let i = 0; i < this.runtimes_.length; i++) {112 requests[i] = this.runtimes_[i].requestRuntimeSession(sessionOptions);113 }114 return Promise.all(requests).then((results) => {115 // Find and return the first successful result.116 for (let i = 0; i < results.length; i++) {117 if (results[i].session) {118 // Construct a dummy metrics recorder119 let metricsRecorderPtr = new device.mojom.XRSessionMetricsRecorderPtr();120 let metricsRecorderRequest = mojo.makeRequest(metricsRecorderPtr);121 let metricsRecorderBinding = new mojo.Binding(122 device.mojom.XRSessionMetricsRecorder, new MockXRSessionMetricsRecorder(), metricsRecorderRequest);123 let success = {124 session: results[i].session,125 metricsRecorder: metricsRecorderPtr,126 };127 return {128 result: {129 success : success,130 $tag : 0131 }132 };133 }134 }135 // If there were no successful results, returns a null session.136 return {137 result: {138 failureReason : device.mojom.RequestSessionError.NO_RUNTIME_FOUND,139 $tag : 1140 }141 };142 });143 }144 exitPresent() {145 return Promise.resolve();146 }147 supportsSession(sessionOptions) {148 let requests = [];149 // Check supports on all the runtimes.150 for (let i = 0; i < this.runtimes_.length; i++) {151 requests[i] = this.runtimes_[i].runtimeSupportsSession(sessionOptions);152 }153 return Promise.all(requests).then((results) => {154 // Find and return the first successful result.155 for (let i = 0; i < results.length; i++) {156 if (results[i].supportsSession) {157 return results[i];158 }159 }160 // If there were no successful results, returns false.161 return {supportsSession: false};162 });163 };164}165// Implements XRFrameDataProvider and XRPresentationProvider. Maintains a mock166// for XRPresentationProvider.167class MockRuntime {168 // Mapping from string feature names to the corresponding mojo types.169 // This is exposed as a member for extensibility.170 static featureToMojoMap = {171 "viewer": device.mojom.XRSessionFeature.REF_SPACE_VIEWER,172 "local": device.mojom.XRSessionFeature.REF_SPACE_LOCAL,173 "local-floor": device.mojom.XRSessionFeature.REF_SPACE_LOCAL_FLOOR,174 "bounded-floor": device.mojom.XRSessionFeature.REF_SPACE_BOUNDED_FLOOR,175 "unbounded": device.mojom.XRSessionFeature.REF_SPACE_UNBOUNDED };176 constructor(fakeDeviceInit, service) {177 this.sessionClient_ = new device.mojom.XRSessionClientPtr();178 this.presentation_provider_ = new MockXRPresentationProvider();179 this.pose_ = null;180 this.next_frame_id_ = 0;181 this.bounds_ = null;182 this.send_mojo_space_reset_ = false;183 this.service_ = service;184 this.framesOfReference = {};185 this.input_sources_ = [];186 this.next_input_source_index_ = 1;187 // Initialize DisplayInfo first to set the defaults, then override with188 // anything from the deviceInit189 if (fakeDeviceInit.supportsImmersive) {190 this.displayInfo_ = this.getImmersiveDisplayInfo();191 } else {192 this.displayInfo_ = this.getNonImmersiveDisplayInfo();193 }194 if (fakeDeviceInit.supportsEnvironmentIntegration) {195 this.displayInfo_.capabilities.canProvideEnvironmentIntegration = true;196 }197 if (fakeDeviceInit.viewerOrigin != null) {198 this.setViewerOrigin(fakeDeviceInit.viewerOrigin);199 }200 if (fakeDeviceInit.floorOrigin != null) {201 this.setFloorOrigin(fakeDeviceInit.floorOrigin);202 }203 // This appropriately handles if the coordinates are null204 this.setBoundsGeometry(fakeDeviceInit.boundsCoordinates);205 this.setViews(fakeDeviceInit.views);206 // Need to support webVR which doesn't have a notion of features207 this.setFeatures(fakeDeviceInit.supportedFeatures || []);208 }209 // Test API methods.210 disconnect() {211 this.service_.removeRuntime(this);212 this.presentation_provider_.Close();213 if (this.sessionClient_.ptr.isBound()) {214 this.sessionClient_.ptr.reset();215 }216 return Promise.resolve();217 }218 setViews(views) {219 if (views) {220 let changed = false;221 for (let i = 0; i < views.length; i++) {222 if (views[i].eye == 'left') {223 this.displayInfo_.leftEye = this.getEye(views[i]);224 changed = true;225 } else if (views[i].eye == 'right') {226 this.displayInfo_.rightEye = this.getEye(views[i]);227 changed = true;228 }229 }230 if (changed && this.sessionClient_.ptr.isBound()) {231 this.sessionClient_.onChanged(this.displayInfo_);232 }233 }234 }235 setViewerOrigin(origin, emulatedPosition = false) {236 let p = origin.position;237 let q = origin.orientation;238 this.pose_ = {239 orientation: { x: q[0], y: q[1], z: q[2], w: q[3] },240 position: { x: p[0], y: p[1], z: p[2] },241 emulatedPosition: emulatedPosition,242 angularVelocity: null,243 linearVelocity: null,244 angularAcceleration: null,245 linearAcceleration: null,246 inputState: null,247 poseIndex: 0248 };249 }250 clearViewerOrigin() {251 this.pose_ = null;252 }253 simulateVisibilityChange(visibilityState) {254 let mojoState = null;255 switch(visibilityState) {256 case "visible":257 mojoState = device.mojom.XRVisibilityState.VISIBLE;258 break;259 case "visible-blurred":260 mojoState = device.mojom.XRVisibilityState.VISIBLE_BLURRED;261 break;262 case "hidden":263 mojoState = device.mojom.XRVisibilityState.HIDDEN;264 break;265 }266 if (mojoState) {267 this.sessionClient_.onVisibilityStateChanged(mojoState);268 }269 }270 setBoundsGeometry(bounds) {271 if (bounds == null) {272 this.bounds_ = null;273 } else if (bounds.length < 3) {274 throw new Error("Bounds must have a length of at least 3");275 } else {276 this.bounds_ = bounds;277 }278 // We can only set bounds if we have stageParameters set; otherwise, we279 // don't know the transform from local space to bounds space.280 // We'll cache the bounds so that they can be set in the future if the281 // floorLevel transform is set, but we won't update them just yet.282 if (this.displayInfo_.stageParameters) {283 this.displayInfo_.stageParameters.bounds = this.bounds_;284 if (this.sessionClient_.ptr.isBound()) {285 this.sessionClient_.onChanged(this.displayInfo_);286 }287 }288 }289 setFloorOrigin(floorOrigin) {290 if (!this.displayInfo_.stageParameters) {291 this.displayInfo_.stageParameters = default_stage_parameters;292 this.displayInfo_.stageParameters.bounds = this.bounds_;293 }294 this.displayInfo_.stageParameters.standingTransform = new gfx.mojom.Transform();295 this.displayInfo_.stageParameters.standingTransform.matrix =296 getMatrixFromTransform(floorOrigin);297 if (this.sessionClient_.ptr.isBound()) {298 this.sessionClient_.onChanged(this.displayInfo_);299 }300 }301 clearFloorOrigin() {302 if (this.displayInfo_.stageParameters) {303 this.displayInfo_.stageParameters = null;304 if (this.sessionClient_.ptr.isBound()) {305 this.sessionClient_.onChanged(this.displayInfo_);306 }307 }308 }309 simulateResetPose() {310 this.send_mojo_space_reset_ = true;311 }312 simulateInputSourceConnection(fakeInputSourceInit) {313 let index = this.next_input_source_index_;314 this.next_input_source_index_++;315 let source = new MockXRInputSource(fakeInputSourceInit, index, this);316 this.input_sources_.push(source);317 return source;318 }319 // Helper methods320 getNonImmersiveDisplayInfo() {321 let displayInfo = this.getImmersiveDisplayInfo();322 displayInfo.capabilities.canPresent = false;323 displayInfo.leftEye = null;324 displayInfo.rightEye = null;325 return displayInfo;326 }327 // Function to generate some valid display information for the device.328 getImmersiveDisplayInfo() {329 return {330 displayName: 'FakeDevice',331 capabilities: {332 hasPosition: false,333 hasExternalDisplay: false,334 canPresent: true,335 maxLayers: 1336 },337 stageParameters: null,338 leftEye: {339 fieldOfView: {340 upDegrees: 48.316,341 downDegrees: 50.099,342 leftDegrees: 50.899,343 rightDegrees: 35.197344 },345 headFromEye: composeGFXTransform({346 position: [-0.032, 0, 0],347 orientation: [0, 0, 0, 1]348 }),349 renderWidth: 20,350 renderHeight: 20351 },352 rightEye: {353 fieldOfView: {354 upDegrees: 48.316,355 downDegrees: 50.099,356 leftDegrees: 50.899,357 rightDegrees: 35.197358 },359 headFromEye: composeGFXTransform({360 position: [0.032, 0, 0],361 orientation: [0, 0, 0, 1]362 }),363 renderWidth: 20,364 renderHeight: 20365 },366 webxrDefaultFramebufferScale: 0.7,367 };368 }369 // This function converts between the matrix provided by the WebXR test API370 // and the internal data representation.371 getEye(fakeXRViewInit) {372 let fov = null;373 if (fakeXRViewInit.fieldOfView) {374 fov = {375 upDegrees: fakeXRViewInit.fieldOfView.upDegrees,376 downDegrees: fakeXRViewInit.fieldOfView.downDegrees,377 leftDegrees: fakeXRViewInit.fieldOfView.leftDegrees,378 rightDegrees: fakeXRViewInit.fieldOfView.rightDegrees379 };380 } else {381 let m = fakeXRViewInit.projectionMatrix;382 function toDegrees(tan) {383 return Math.atan(tan) * 180 / Math.PI;384 }385 let leftTan = (1 - m[8]) / m[0];386 let rightTan = (1 + m[8]) / m[0];387 let upTan = (1 + m[9]) / m[5];388 let downTan = (1 - m[9]) / m[5];389 fov = {390 upDegrees: toDegrees(upTan),391 downDegrees: toDegrees(downTan),392 leftDegrees: toDegrees(leftTan),393 rightDegrees: toDegrees(rightTan)394 };395 }396 return {397 fieldOfView: fov,398 headFromEye: composeGFXTransform(fakeXRViewInit.viewOffset),399 renderWidth: fakeXRViewInit.resolution.width,400 renderHeight: fakeXRViewInit.resolution.height401 };402 }403 setFeatures(supportedFeatures) {404 function convertFeatureToMojom(feature) {405 if (feature in MockRuntime.featureToMojoMap) {406 return MockRuntime.featureToMojoMap[feature];407 } else {408 return device.mojom.XRSessionFeature.INVALID;409 }410 }411 this.supportedFeatures_ = [];412 for (let i = 0; i < supportedFeatures.length; i++) {413 let feature = convertFeatureToMojom(supportedFeatures[i]);414 if (feature !== device.mojom.XRSessionFeature.INVALID) {415 this.supportedFeatures_.push(feature);416 }417 }418 }419 // These methods are intended to be used by MockXRInputSource only.420 addInputSource(source) {421 let index = this.input_sources_.indexOf(source);422 if (index == -1) {423 this.input_sources_.push(source);424 }425 }426 removeInputSource(source) {427 let index = this.input_sources_.indexOf(source);428 if (index >= 0) {429 this.input_sources_.splice(index, 1);430 }431 }432 // Mojo function implementations.433 // XRFrameDataProvider implementation.434 getFrameData() {435 let mojo_space_reset = this.send_mojo_space_reset_;436 this.send_mojo_space_reset_ = false;437 if (this.pose_) {438 this.pose_.poseIndex++;439 }440 // Setting the input_state to null tests a slightly different path than441 // the browser tests where if the last input source is removed, the device442 // code always sends up an empty array, but it's also valid mojom to send443 // up a null array.444 let input_state = null;445 if (this.input_sources_.length > 0) {446 input_state = [];447 for (let i = 0; i < this.input_sources_.length; i++) {448 input_state.push(this.input_sources_[i].getInputSourceState());449 }450 }451 // Convert current document time to monotonic time.452 let now = window.performance.now() / 1000.0;453 let diff = now - internals.monotonicTimeToZeroBasedDocumentTime(now);454 now += diff;455 now *= 1000000;456 return Promise.resolve({457 frameData: {458 pose: this.pose_,459 mojoSpaceReset: mojo_space_reset,460 inputState: input_state,461 timeDelta: {462 microseconds: now,463 },464 frameId: this.next_frame_id_++,465 bufferHolder: null,466 bufferSize: {}467 }468 });469 }470 getEnvironmentIntegrationProvider(environmentProviderRequest) {471 this.environmentProviderBinding_ = new mojo.AssociatedBinding(472 device.mojom.XREnvironmentIntegrationProvider, this,473 environmentProviderRequest);474 }475 // Note that if getEnvironmentProvider hasn't finished running yet this will476 // be undefined. It's recommended that you allow a successful task to post477 // first before attempting to close.478 closeEnvironmentIntegrationProvider() {479 this.environmentProviderBinding_.close();480 }481 closeDataProvider() {482 this.dataProviderBinding_.close();483 }484 updateSessionGeometry(frame_size, display_rotation) {485 // This function must exist to ensure that calls to it do not crash, but we486 // do not have any use for this data at present.487 }488 // Utility function489 requestRuntimeSession(sessionOptions) {490 return this.runtimeSupportsSession(sessionOptions).then((result) => {491 // The JavaScript bindings convert c_style_names to camelCase names.492 let options = new device.mojom.XRPresentationTransportOptions();493 options.transportMethod =494 device.mojom.XRPresentationTransportMethod.SUBMIT_AS_MAILBOX_HOLDER;495 options.waitForTransferNotification = true;496 options.waitForRenderNotification = true;497 let submit_frame_sink;498 if (result.supportsSession) {499 submit_frame_sink = {500 clientReceiver: this.presentation_provider_.getClientReceiver(),501 provider: this.presentation_provider_.bindProvider(sessionOptions),502 transportOptions: options503 };504 let dataProviderPtr = new device.mojom.XRFrameDataProviderPtr();505 let dataProviderRequest = mojo.makeRequest(dataProviderPtr);506 this.dataProviderBinding_ = new mojo.Binding(507 device.mojom.XRFrameDataProvider, this, dataProviderRequest);508 let clientReceiver = mojo.makeRequest(this.sessionClient_);509 let enabled_features = [];510 for(let i = 0; i < sessionOptions.requiredFeatures.length; i++) {511 if (this.supportedFeatures_.indexOf(sessionOptions.requiredFeatures[i]) !== -1) {512 enabled_features.push(sessionOptions.requiredFeatures[i]);513 } else {514 return Promise.resolve({session: null});515 }516 }517 for (let i =0; i < sessionOptions.optionalFeatures.length; i++) {518 if (this.supportedFeatures_.indexOf(sessionOptions.optionalFeatures[i]) !== -1) {519 enabled_features.push(sessionOptions.optionalFeatures[i]);520 }521 }522 return Promise.resolve({523 session: {524 submitFrameSink: submit_frame_sink,525 dataProvider: dataProviderPtr,526 clientReceiver: clientReceiver,527 displayInfo: this.displayInfo_,528 enabledFeatures: enabled_features,529 }530 });531 } else {532 return Promise.resolve({session: null});533 }534 });535 }536 runtimeSupportsSession(options) {537 return Promise.resolve({538 supportsSession:539 !options.immersive || this.displayInfo_.capabilities.canPresent540 });541 };542}543class MockXRSessionMetricsRecorder {544 reportFeatureUsed(feature) {545 // Do nothing546 }547}548class MockXRInputSource {549 constructor(fakeInputSourceInit, id, pairedDevice) {550 this.source_id_ = id;551 this.pairedDevice_ = pairedDevice;552 this.handedness_ = fakeInputSourceInit.handedness;553 this.target_ray_mode_ = fakeInputSourceInit.targetRayMode;554 this.setPointerOrigin(fakeInputSourceInit.pointerOrigin);555 this.setProfiles(fakeInputSourceInit.profiles);556 this.primary_input_pressed_ = false;557 if (fakeInputSourceInit.selectionStarted != null) {558 this.primary_input_pressed_ = fakeInputSourceInit.selectionStarted;559 }560 this.primary_input_clicked_ = false;561 if (fakeInputSourceInit.selectionClicked != null) {562 this.primary_input_clicked_ = fakeInputSourceInit.selectionClicked;563 }564 this.mojo_from_input_ = null;565 if (fakeInputSourceInit.gripOrigin != null) {566 this.setGripOrigin(fakeInputSourceInit.gripOrigin);567 }568 // This properly handles if supportedButtons were not specified.569 this.setSupportedButtons(fakeInputSourceInit.supportedButtons);570 this.emulated_position_ = false;571 this.desc_dirty_ = true;572 }573 // Webxr-test-api574 setHandedness(handedness) {575 if (this.handedness_ != handedness) {576 this.desc_dirty_ = true;577 this.handedness_ = handedness;578 }579 }580 setTargetRayMode(targetRayMode) {581 if (this.target_ray_mode_ != targetRayMode) {582 this.desc_dirty_ = true;583 this.target_ray_mode_ = targetRayMode;584 }585 }586 setProfiles(profiles) {587 this.desc_dirty_ = true;588 this.profiles_ = profiles;589 }590 setGripOrigin(transform, emulatedPosition = false) {591 this.mojo_from_input_ = new gfx.mojom.Transform();592 this.mojo_from_input_.matrix = getMatrixFromTransform(transform);593 this.emulated_position_ = emulatedPosition;594 }595 clearGripOrigin() {596 if (this.mojo_from_input_ != null) {597 this.mojo_from_input_ = null;598 this.emulated_position_ = false;599 }600 }601 setPointerOrigin(transform, emulatedPosition = false) {602 this.desc_dirty_ = true;603 this.input_from_pointer_ = new gfx.mojom.Transform();604 this.input_from_pointer_.matrix = getMatrixFromTransform(transform);605 this.emulated_position_ = emulatedPosition;606 }607 disconnect() {608 this.pairedDevice_.removeInputSource(this);609 }610 reconnect() {611 this.pairedDevice_.addInputSource(this);612 }613 startSelection() {614 this.primary_input_pressed_ = true;615 if (this.gamepad_) {616 this.gamepad_.buttons[0].pressed = true;617 this.gamepad_.buttons[0].touched = true;618 }619 }620 endSelection() {621 if (!this.primary_input_pressed_) {622 throw new Error("Attempted to end selection which was not started");623 }624 this.primary_input_pressed_ = false;625 this.primary_input_clicked_ = true;626 if (this.gamepad_) {627 this.gamepad_.buttons[0].pressed = false;628 this.gamepad_.buttons[0].touched = false;629 }630 }631 simulateSelect() {632 this.primary_input_clicked_ = true;633 }634 setSupportedButtons(supportedButtons) {635 this.gamepad_ = null;636 this.supported_buttons_ = [];637 // If there are no supported buttons, we can stop now.638 if (supportedButtons == null || supportedButtons.length < 1) {639 return;640 }641 let supported_button_map = {};642 this.gamepad_ = this.getEmptyGamepad();643 for (let i = 0; i < supportedButtons.length; i++) {644 let buttonType = supportedButtons[i].buttonType;645 this.supported_buttons_.push(buttonType);646 supported_button_map[buttonType] = supportedButtons[i];647 }648 // Let's start by building the button state in order of priority:649 // Primary button is index 0.650 this.gamepad_.buttons.push({651 pressed: this.primary_input_pressed_,652 touched: this.primary_input_pressed_,653 value: this.primary_input_pressed_ ? 1.0 : 0.0654 });655 // Now add the rest of our buttons656 this.addGamepadButton(supported_button_map['grip']);657 this.addGamepadButton(supported_button_map['touchpad']);658 this.addGamepadButton(supported_button_map['thumbstick']);659 this.addGamepadButton(supported_button_map['optional-button']);660 this.addGamepadButton(supported_button_map['optional-thumbstick']);661 // Finally, back-fill placeholder buttons/axes662 for (let i = 0; i < this.gamepad_.buttons.length; i++) {663 if (this.gamepad_.buttons[i] == null) {664 this.gamepad_.buttons[i] = {665 pressed: false,666 touched: false,667 value: 0668 }669 }670 }671 for (let i=0; i < this.gamepad_.axes.length; i++) {672 if (this.gamepad_.axes[i] == null) {673 this.gamepad_.axes[i] = 0;674 }675 }676 }677 updateButtonState(buttonState) {678 if (this.supported_buttons_.indexOf(buttonState.buttonType) == -1) {679 throw new Error("Tried to update state on an unsupported button");680 }681 let buttonIndex = this.getButtonIndex(buttonState.buttonType);682 let axesStartIndex = this.getAxesStartIndex(buttonState.buttonType);683 if (buttonIndex == -1) {684 throw new Error("Unknown Button Type!");685 }686 this.gamepad_.buttons[buttonIndex].pressed = buttonState.pressed;687 this.gamepad_.buttons[buttonIndex].touched = buttonState.touched;688 this.gamepad_.buttons[buttonIndex].value = buttonState.pressedValue;689 if (axesStartIndex != -1) {690 this.gamepad_.axes[axesStartIndex] = buttonState.xValue == null ? 0.0 : buttonState.xValue;691 this.gamepad_.axes[axesStartIndex + 1] = buttonState.yValue == null ? 0.0 : buttonState.yValue;692 }693 }694 // Helpers for Mojom695 getInputSourceState() {696 let input_state = new device.mojom.XRInputSourceState();697 input_state.sourceId = this.source_id_;698 input_state.primaryInputPressed = this.primary_input_pressed_;699 input_state.primaryInputClicked = this.primary_input_clicked_;700 input_state.mojoFromInput = this.mojo_from_input_;701 input_state.gamepad = this.gamepad_;702 input_state.emulatedPosition = this.emulated_position_;703 if (this.desc_dirty_) {704 let input_desc = new device.mojom.XRInputSourceDescription();705 switch (this.target_ray_mode_) {706 case 'gaze':707 input_desc.targetRayMode = device.mojom.XRTargetRayMode.GAZING;708 break;709 case 'tracked-pointer':710 input_desc.targetRayMode = device.mojom.XRTargetRayMode.POINTING;711 break;712 }713 switch (this.handedness_) {714 case 'left':715 input_desc.handedness = device.mojom.XRHandedness.LEFT;716 break;717 case 'right':718 input_desc.handedness = device.mojom.XRHandedness.RIGHT;719 break;720 default:721 input_desc.handedness = device.mojom.XRHandedness.NONE;722 break;723 }724 input_desc.inputFromPointer = this.input_from_pointer_;725 input_desc.profiles = this.profiles_;726 input_state.description = input_desc;727 this.desc_dirty_ = false;728 }729 return input_state;730 }731 getEmptyGamepad() {732 // Mojo complains if some of the properties on Gamepad are null, so set733 // everything to reasonable defaults that tests can override.734 let gamepad = new device.mojom.Gamepad();735 gamepad.connected = true;736 gamepad.id = "";737 gamepad.timestamp = 0;738 gamepad.axes = [];739 gamepad.buttons = [];740 gamepad.mapping = "xr-standard";741 gamepad.display_id = 0;742 switch (this.handedness_) {743 case 'left':744 gamepad.hand = device.mojom.GamepadHand.GamepadHandLeft;745 break;746 case 'right':747 gamepad.hand = device.mojom.GamepadHand.GamepadHandRight;748 break;749 default:750 gamepad.hand = device.mojom.GamepadHand.GamepadHandNone;751 break;752 }753 return gamepad;754 }755 addGamepadButton(buttonState) {756 if (buttonState == null) {757 return;758 }759 let buttonIndex = this.getButtonIndex(buttonState.buttonType);760 let axesStartIndex = this.getAxesStartIndex(buttonState.buttonType);761 if (buttonIndex == -1) {762 throw new Error("Unknown Button Type!");763 }764 this.gamepad_.buttons[buttonIndex] = {765 pressed: buttonState.pressed,766 touched: buttonState.touched,767 value: buttonState.pressedValue768 };769 // Add x/y value if supported.770 if (axesStartIndex != -1) {771 this.gamepad_.axes[axesStartIndex] = (buttonState.xValue == null ? 0.0 : buttonSate.xValue);772 this.gamepad_.axes[axesStartIndex + 1] = (buttonState.yValue == null ? 0.0 : buttonSate.yValue);773 }774 }775 // General Helper methods776 getButtonIndex(buttonType) {777 switch (buttonType) {778 case 'grip':779 return 1;780 case 'touchpad':781 return 2;782 case 'thumbstick':783 return 3;784 case 'optional-button':785 return 4;786 case 'optional-thumbstick':787 return 5;788 default:789 return -1;790 }791 }792 getAxesStartIndex(buttonType) {793 switch (buttonType) {794 case 'touchpad':795 return 0;796 case 'thumbstick':797 return 2;798 case 'optional-thumbstick':799 return 4;800 default:801 return -1;802 }803 }804}805// Mojo helper classes806class MockXRPresentationProvider {807 constructor() {808 this.binding_ = new mojo.Binding(device.mojom.XRPresentationProvider, this);809 this.submit_frame_count_ = 0;810 this.missing_frame_count_ = 0;811 }812 bindProvider(request) {813 let providerPtr = new device.mojom.XRPresentationProviderPtr();814 let providerRequest = mojo.makeRequest(providerPtr);815 this.binding_.close();816 this.binding_ = new mojo.Binding(817 device.mojom.XRPresentationProvider, this, providerRequest);818 return providerPtr;819 }820 getClientReceiver() {821 this.submitFrameClient_ = new device.mojom.XRPresentationClientPtr();822 return mojo.makeRequest(this.submitFrameClient_);823 }824 // XRPresentationProvider mojo implementation825 submitFrameMissing(frameId, mailboxHolder, timeWaited) {826 this.missing_frame_count_++;827 }828 submitFrame(frameId, mailboxHolder, timeWaited) {829 this.submit_frame_count_++;830 // Trigger the submit completion callbacks here. WARNING: The831 // Javascript-based mojo mocks are *not* re-entrant. It's OK to832 // wait for these notifications on the next frame, but waiting833 // within the current frame would never finish since the incoming834 // calls would be queued until the current execution context finishes.835 this.submitFrameClient_.onSubmitFrameTransferred(true);836 this.submitFrameClient_.onSubmitFrameRendered();837 }838 // Utility methods839 Close() {840 this.binding_.close();841 }842}843// This is a temporary workaround for the fact that spinning up webxr before844// the mojo interceptors are created will cause the interceptors to not get845// registered, so we have to create this before we query xr;846let XRTest = new ChromeXRTest();847// This test API is also used to run Chrome's internal legacy VR tests; however,848// those fail if navigator.xr has been used. Those tests will set a bool telling849// us not to try to check navigator.xr850if ((typeof legacy_vr_test === 'undefined') || !legacy_vr_test) {851 // Some tests may run in the http context where navigator.xr isn't exposed852 // This should just be to test that it isn't exposed, but don't try to set up853 // the test framework in this case.854 if (navigator.xr) {855 navigator.xr.test = XRTest;856 }857} else {858 navigator.vr = { test: XRTest };...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org');3var options = {4};5wpt.runTest(options, function(err, data) {6 if (err) {7 console.log(err);8 } else {9 console.log(data.data.testId);10 wpt.metricsRecorderPtr(data.data.testId, function(err, data) {11 if (err) {12 console.log(err);13 } else {14 console.log(data);15 }16 });17 }18});19* [WebPageTest](

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptAgent = require('wptAgent');2wptAgent.metricsRecorderPtr('test', 'custom', 1, 'ms');3wptAgent.metricsRecorder('test', 'custom', 1, 'ms');4var wptAgent = require('wptAgent');5wptAgent.metricsRecorderPtr('test', 'custom', 1, 'ms');6wptAgent.metricsRecorder('test', 'custom', 1, 'ms');7var wptAgent = require('wptAgent');8wptAgent.metricsRecorderPtr('test', 'custom', 1, 'ms');9wptAgent.metricsRecorder('test', 'custom', 1, 'ms');10var wptAgent = require('wptAgent');11wptAgent.metricsRecorderPtr('test', 'custom', 1, 'ms');12wptAgent.metricsRecorder('test', 'custom', 1, 'ms');13var wptAgent = require('wptAgent');14wptAgent.metricsRecorderPtr('test', 'custom', 1, 'ms');15wptAgent.metricsRecorder('test', 'custom', 1, 'ms');16var wptAgent = require('wptAgent');17wptAgent.metricsRecorderPtr('test', 'custom', 1, 'ms');18wptAgent.metricsRecorder('test', 'custom', 1, 'ms');19var wptAgent = require('wptAgent');20wptAgent.metricsRecorderPtr('test', 'custom', 1, 'ms');

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptHook = require("wptHook");2wptHook.metricsRecorderPtr("customMetricName", 123);3wptHook.metricsRecorderPtr("customMetricName", 456);4wptHook.metricsRecorderPtr("customMetricName", 789);5wptHook.metricsRecorderPtr("customMetricName", 101112);6var wptHook = require("wptHook");7wptHook.metricsRecorderPtr("customMetricName", 123);8wptHook.metricsRecorderPtr("customMetricName", 456);9wptHook.metricsRecorderPtr("customMetricName", 789);10wptHook.metricsRecorderPtr("customMetricName", 101112);11var wptHook = require("wptHook");12wptHook.metricsRecorderPtr("customMetricName", 123);13wptHook.metricsRecorderPtr("customMetricName", 456);14wptHook.metricsRecorderPtr("customMetricName", 789);15wptHook.metricsRecorderPtr("customMetricName", 101112);16var wptHook = require("wptHook");17wptHook.metricsRecorder("customMetricName", 123);18wptHook.metricsRecorder("customMetricName", 456);19wptHook.metricsRecorder("customMetricName", 789);20wptHook.metricsRecorder("customMetricName", 101112);

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptHook = require('wptHook');2var metricsRecorderPtr = wptHook.metricsRecorderPtr;3metricsRecorderPtr('testMetric', 1, 'testUnits');4var wptHook = require('wptHook');5var metricsRecorderPtr = wptHook.metricsRecorderPtr;6metricsRecorderPtr('testMetric', 1, 'testUnits');7var wptHook = require('wptHook');8var metricsRecorderPtr = wptHook.metricsRecorderPtr;9metricsRecorderPtr('testMetric', 1, 'testUnits');10var wptHook = require('wptHook');11var metricsRecorderPtr = wptHook.metricsRecorderPtr;12metricsRecorderPtr('testMetric', 1, 'testUnits');13var wptHook = require('wptHook');14var metricsRecorderPtr = wptHook.metricsRecorderPtr;15metricsRecorderPtr('testMetric', 1, 'testUnits');16var wptHook = require('wptHook');17var metricsRecorderPtr = wptHook.metricsRecorderPtr;18metricsRecorderPtr('testMetric', 1, 'testUnits');19var wptHook = require('wptHook');20var metricsRecorderPtr = wptHook.metricsRecorderPtr;21metricsRecorderPtr('testMetric', 1, 'testUnits');22var wptHook = require('wptHook');23var metricsRecorderPtr = wptHook.metricsRecorderPtr;24metricsRecorderPtr('testMetric', 1, 'testUnits');25var wptHook = require('wptHook');

Full Screen

Using AI Code Generation

copy

Full Screen

1wptHook.metricsRecorderPtr = recorder;2recorder.recordMetric("testMetricName", 100);3wptHook.metricsRecorderPtr.recordMetric("testMetricName", 100);4wptHook.metricsRecorderPtr = recorder;5recorder.recordMetric("testMetricName", 100);6wptHook.metricsRecorderPtr.recordMetric("testMetricName", 100);7wptHook.metricsRecorderPtr = recorder;8recorder.recordMetric("testMetricName", 100);9wptHook.metricsRecorderPtr.recordMetric("testMetricName", 100);10wptHook.metricsRecorderPtr = recorder;11recorder.recordMetric("testMetricName", 100);12wptHook.metricsRecorderPtr.recordMetric("testMetricName", 100);

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful