Add a wasm debugger test that uses a WebGL surface

Change-Id: I9fef343d8ae958ca6382f6a781a31b6a583728bd
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/241756
Commit-Queue: Nathaniel Nifong <nifong@google.com>
Reviewed-by: Kevin Lubick <kjlubick@google.com>
This commit is contained in:
Nathaniel Nifong 2019-09-16 13:58:30 -04:00 committed by Skia Commit-Bot
parent 556d00eaad
commit d3d13af110
3 changed files with 52 additions and 29 deletions

View File

@ -14,6 +14,7 @@ module.exports = function(config) {
{ pattern: 'debugger/sample.skp', included:false, served:true},
'../../modules/pathkit/tests/testReporter.js',
'debugger/bin/debugger.js',
'tests/debuggerinit.js',
'tests/*.spec.js'
],

View File

@ -0,0 +1,15 @@
jasmine.DEFAULT_TIMEOUT_INTERVAL = 20000;
let Debugger = null;
const LoadDebugger = new Promise(function(resolve, reject) {
if (Debugger) {
resolve();
} else {
DebuggerInit({
locateFile: (file) => '/debugger/bin/'+file,
}).ready().then((_Debugger) => {
Debugger = _Debugger;
resolve();
});
}
});

View File

@ -3,29 +3,20 @@
jasmine.DEFAULT_TIMEOUT_INTERVAL = 20000;
describe('Debugger\'s Startup Behavior', function() {
// Note, don't try to print the CanvasKit object - it can cause Karma/Jasmine to lock up.
var Debugger = null;
const LoadDebugger = new Promise(function(resolve, reject) {
if (Debugger) {
resolve();
} else {
DebuggerInit({
locateFile: (file) => '/debugger/bin/'+file,
}).ready().then((_Debugger) => {
Debugger = _Debugger;
resolve();
});
}
});
let container = document.createElement('div');
document.body.appendChild(container);
container.innerHTML = `<canvas id=debugger_view width=720 height=1280></canvas>`;
it('can load and draw a skp file', function(done) {
beforeEach(function() {
container.innerHTML = `<canvas id=debugger_view width=720 height=1280></canvas>`;
});
afterEach(function() {
container.innerHTML = '';
});
it('can load and draw a skp file on an Canvas2D', function(done) {
LoadDebugger.then(catchException(done, () => {
const surface = Debugger.MakeSWCanvasSurface(document.getElementById('debugger_view'));
const player = new Debugger.SkpDebugPlayer();
fetch('/debugger/sample.skp').then(function(response) {
// Load test file
@ -33,19 +24,35 @@ describe('Debugger\'s Startup Behavior', function() {
throw new Error("HTTP error, status = " + response.status);
}
response.arrayBuffer().then(function(buffer) {
let fileContents = new Uint8Array(buffer);
const fileContents = new Uint8Array(buffer);
console.log('fetched /debugger/sample.skp');
const size = fileContents.byteLength;
expect(size).toEqual(662976);
const player = Debugger.SkpFilePlayer(fileContents);
// Draw picture
player.drawTo(surface, 789); // number of commands in sample file
surface.flush();
// Allocate memory in wasm to hold the skp file selected by the user.
const fileMemPtr = Debugger._malloc(size);
// Make a typed array view of that memory
let fileMem = new Uint8Array(Debugger.buffer, fileMemPtr, size);
// Copy the file into it
fileMem.set(fileContents);
// Hand off pointer to wasm
player.loadSkp(fileMemPtr, size);
console.log('drew picture to canvas element');
surface.dispose();
done();
});
});
}));
});
it('can load and draw a skp file on a Web GL canvas', function(done) {
LoadDebugger.then(catchException(done, () => {
const surface = Debugger.MakeWebGLCanvasSurface(
document.getElementById('debugger_view'));
fetch('/debugger/sample.skp').then(function(response) {
// Load test file
if (!response.ok) {
throw new Error("HTTP error, status = " + response.status);
}
response.arrayBuffer().then(function(buffer) {
const fileContents = new Uint8Array(buffer);
console.log('fetched /debugger/sample.skp');
const player = Debugger.SkpFilePlayer(fileContents);
// Draw picture
player.drawTo(surface, 789); // number of commands in sample file
surface.flush();