aorecomp

Anarchy Online classic in the browser

git clone https://aorecomp.ubeagle.com/code/aorecomp.git


client/tests/browser_capture.html (1140B)


      1 <!doctype html>
      2 <meta charset="utf-8">
      3 <title>Browser frame capture test</title>
      4 <canvas id="canvas" width="2" height="2"></canvas>
      5 <pre id="result">Running</pre>
      6 <script>
      7 const frames = [];
      8 var Module = {
      9   canvas: document.querySelector('#canvas'),
     10   onAbort: message => { document.querySelector('#result').textContent = 'FAIL: ' + message; },
     11   captureFrame: (pixels, width, height, time) => { frames.push({pixels: Array.from(pixels), width, height, time}); },
     12   assertCapture: () => {
     13     const expected = [[0, 0, 255, 255, 255, 255, 255, 255, 255, 0, 0, 255, 0, 255, 0, 255],
     14                       [255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255]];
     15     if (JSON.stringify(frames.map(frame => frame.pixels)) !== JSON.stringify(expected) ||
     16         frames.some(frame => frame.width !== 2 || frame.height !== 2) || frames[1].time < frames[0].time)
     17       throw new Error('Capture omitted, reordered, inverted or added frames');
     18     document.querySelector('#result').textContent = 'PASS: exact consecutive frames, orientation, count, cancellation and bound';
     19   }
     20 };
     21 </script>
     22 <script src="capture-test.js"></script>