1// The increased timeout is especially needed with larger binaries 2// like in the debug/gpu build 3jasmine.DEFAULT_TIMEOUT_INTERVAL = 20000; 4 5describe('Debugger\'s Startup Behavior', function() { 6 // Note, don't try to print the CanvasKit object - it can cause Karma/Jasmine to lock up. 7 var Debugger = null; 8 const LoadDebugger = new Promise(function(resolve, reject) { 9 if (Debugger) { 10 resolve(); 11 } else { 12 DebuggerInit({ 13 locateFile: (file) => '/debugger/bin/'+file, 14 }).ready().then((_Debugger) => { 15 Debugger = _Debugger; 16 resolve(); 17 }); 18 } 19 }); 20 21 let container = document.createElement('div'); 22 document.body.appendChild(container); 23 container.innerHTML = `<canvas id=debugger_view width=720 height=1280></canvas>`; 24 25 it('can load and draw a skp file', function(done) { 26 LoadDebugger.then(catchException(done, () => { 27 const surface = Debugger.MakeSWCanvasSurface(document.getElementById('debugger_view')); 28 const player = new Debugger.SkpDebugPlayer(); 29 30 fetch('/debugger/sample.skp').then(function(response) { 31 // Load test file 32 if (!response.ok) { 33 throw new Error("HTTP error, status = " + response.status); 34 } 35 response.arrayBuffer().then(function(buffer) { 36 let fileContents = new Uint8Array(buffer); 37 console.log('fetched /debugger/sample.skp'); 38 const size = fileContents.byteLength; 39 expect(size).toEqual(662976); 40 41 // Allocate memory in wasm to hold the skp file selected by the user. 42 const fileMemPtr = Debugger._malloc(size); 43 // Make a typed array view of that memory 44 let fileMem = new Uint8Array(Debugger.buffer, fileMemPtr, size); 45 // Copy the file into it 46 fileMem.set(fileContents); 47 // Hand off pointer to wasm 48 player.loadSkp(fileMemPtr, size); 49 // Draw picture 50 player.drawTo(surface, 789); // number of commands in sample file 51 surface.flush(); 52 53 console.log('drew picture to canvas element'); 54 surface.dispose(); 55 done(); 56 }); 57 }); 58 })); 59 }); 60}); 61