Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Unified Diff: chrome/test/data/android/webvr_instrumentation/resources/webvr_boilerplate.js

Issue 2588703003: Add WebVR WebVR E2E test capabilities via Android instrumentation (Closed)
Patch Set: Fix copyright header Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/test/data/android/webvr_instrumentation/resources/webvr_boilerplate.js
diff --git a/chrome/test/data/android/webvr_instrumentation/resources/webvr_boilerplate.js b/chrome/test/data/android/webvr_instrumentation/resources/webvr_boilerplate.js
new file mode 100644
index 0000000000000000000000000000000000000000..e57360fb59784cb533e2bde0b852c10fdc2b5760
--- /dev/null
+++ b/chrome/test/data/android/webvr_instrumentation/resources/webvr_boilerplate.js
@@ -0,0 +1,80 @@
+// Copyright 2017 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.
+
+var webglCanvas = document.getElementById("webgl-canvas");
+var glAttribs = {
+ alpha: false,
+};
+var gl = webglCanvas.getContext("webgl", glAttribs);
+var vrDisplay = null;
+var frameData = null;
+
+function onResize() {
+ if (vrDisplay && vrDisplay.isPresenting) {
+ var leftEye = vrDisplay.getEyeParameters("left");
+ var rightEye = vrDisplay.getEyeParameters("right");
+
+ webglCanvas.width = Math.max(leftEye.renderWidth, rightEye.renderWidth) * 2;
+ webglCanvas.height = Math.max(leftEye.renderHeight, rightEye.renderHeight);
+ } else {
+ webglCanvas.width = webglCanvas.offsetWidth * window.devicePixelRatio;
+ webglCanvas.height = webglCanvas.offsetHeight * window.devicePixelRatio;
+ }
+}
+
+function onVrPresentChange() {
+ onResize();
+}
+
+function onVrRequestPresent() {
+ vrDisplay.requestPresent([{source: webglCanvas}]);
+}
+
+function onAnimationFrame(t) {
+ if (vrDisplay == null) {
+ window.requestAnimationFrame(onAnimationFrame);
+ gl.viewport(0, 0, webglCanvas.width, webglCanvas.height);
+ return;
+ }
+ vrDisplay.requestAnimationFrame(onAnimationFrame);
+ // If presenting, set canvas to blue. Otherwise, red.
+ if (vrDisplay.isPresenting) {
+ vrDisplay.getFrameData(frameData);
+
+ gl.clearColor(0.0, 0.0, 1.0, 1.0);
+ gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
+
+ gl.viewport(0, 0, webglCanvas.width * 0.5, webglCanvas.height);
+ gl.viewport(webglCanvas.width * 0.5, 0, webglCanvas.width * 0.5,
+ webglCanvas.height);
+
+ vrDisplay.submitFrame();
+ } else {
+ gl.clearColor(1.0, 0.0, 0.0, 1.0);
+ gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
+
+ gl.viewport(0, 0, webglCanvas.width, webglCanvas.height);
+ }
+}
+
+if (navigator.getVRDisplays) {
+ frameData = new VRFrameData();
+ navigator.getVRDisplays().then( (displays) => {
+ if (displays.length > 0) {
+ vrDisplay = displays[0];
+ }
+ }).then( () => {
+ vrDisplayPromiseDone = true;
+ });
+}
+
+gl.clearColor(1.0, 0.0, 0.0, 1.0);
+gl.enable(gl.DEPTH_TEST);
+gl.enable(gl.CULL_FACE);
+window.addEventListener("resize", onResize, false);
+window.addEventListener("vrdisplaypresentchange", onVrPresentChange, false);
+window.addEventListener('vrdisplayactivate', onVrRequestPresent, false);
+window.requestAnimationFrame(onAnimationFrame);
+webglCanvas.onclick = onVrRequestPresent;
+onResize();

Powered by Google App Engine
This is Rietveld 408576698