| <html> |
| <head> |
| <script type="text/javascript" src="../http/tests/inspector-protocol/resources/protocol-test.js"></script> |
| <script> |
| |
| var sampleRate = 44100.0; |
| var renderLengthSeconds = 0.125; |
| |
| function createSinWaveBuffer(context, lengthInSeconds, frequency) |
| { |
| var audioBuffer = context.createBuffer(1, lengthInSeconds * sampleRate, sampleRate); |
| var data = audioBuffer.getChannelData(0); |
| for (var i = 0; i < audioBuffer.length; ++i) |
| data[i] = Math.sin(frequency * 2 * Math.PI * i / sampleRate); |
| return audioBuffer; |
| } |
| |
| function runPageTest() |
| { |
| testRunner.waitUntilDone(); |
| |
| // Create offline audio context. |
| var context = new webkitOfflineAudioContext(1, sampleRate * renderLengthSeconds, sampleRate); |
| |
| var bufferSource = context.createBufferSource(); |
| bufferSource.buffer = createSinWaveBuffer(context, renderLengthSeconds, 880); |
| bufferSource.connect(context.destination); |
| context.oncomplete = runTest; |
| context.startRendering(); |
| } |
| |
| function test() |
| { |
| function sizeForType(entry, typeNames) |
| { |
| for (var index = 0; index < typeNames.length; ++index) { |
| var typeName = typeNames[index]; |
| var found = 0; |
| for (var i = 0; i < entry.children.length; ++i) { |
| var childEntry = entry.children[i]; |
| if (childEntry.name === typeName) { |
| if (index === typeNames.length - 1) |
| return childEntry.size; |
| |
| if (!childEntry.children) |
| return -1; |
| |
| entry = childEntry; |
| found = 1; |
| break; |
| } |
| } |
| if (!found) |
| return -1; |
| } |
| |
| return -1; |
| } |
| |
| function receivedSizeMoreThan(messageObject, typeNames, expectedSize) |
| { |
| var entry = messageObject["result"]["distribution"]; |
| var size = sizeForType(entry, typeNames); |
| if (size > expectedSize) |
| InspectorTest.log("PASS: received size for type " + typeNames.join('.') + " is more than " + expectedSize); |
| else |
| InspectorTest.log("FAIL: received size " + size + " for type " + typeNames.join('.') + " is less than " + expectedSize); |
| } |
| |
| function handleMemorySnapshot(messageObject) |
| { |
| if ("error" in messageObject) |
| InspectorTest.log(messageObject.error.message); |
| else |
| receivedSizeMoreThan(messageObject, ["Audio"], 15000000); |
| |
| InspectorTest.completeTest(); |
| } |
| |
| InspectorTest.sendCommand("Memory.getProcessMemoryDistribution", {}, handleMemorySnapshot); |
| } |
| </script> |
| </head> |
| <body onLoad="runPageTest();"> |
| </body> |
| </html> |