1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 var assertEq = chrome.test.assertEq;
6 var assertTrue = chrome.test.assertTrue;
7 var callbackPass = chrome.test.callbackPass;
9 function makeCompareCallback(buf) {
10 return function(array) {
11 assertEq(buf.byteLength, array.length);
12 for (var i = 0; i < buf.length; i++) {
13 assertEq(buf[i], array[i]);
18 function makeBuffer() {
20 var ab = new ArrayBuffer(bufferSize);
21 var view = new Uint8Array(ab);
22 for (var i = 0; i < bufferSize; i++) {
29 function sendBuffer() {
30 var view = makeBuffer();
31 chrome.idltest.sendArrayBuffer(
32 view.buffer, callbackPass(makeCompareCallback(view.buffer)));
35 function sendBufferView() {
36 var view = makeBuffer();
37 chrome.idltest.sendArrayBufferView(
38 view, callbackPass(makeCompareCallback(view.buffer)));
41 function sendBufferSlice() {
42 var view = makeBuffer();
43 var bufferSlice = view.buffer.slice(64);
44 assertEq(64, bufferSlice.byteLength);
45 chrome.idltest.sendArrayBuffer(
46 bufferSlice, callbackPass(makeCompareCallback(bufferSlice)));
49 function getBuffer() {
50 chrome.idltest.getArrayBuffer(callbackPass(function(buffer) {
51 assertTrue(buffer.__proto__ == (new ArrayBuffer()).__proto__);
52 var view = new Uint8Array(buffer);
53 var expected = "hello world";
54 assertEq(view.byteLength, expected.length);
55 for (var i = 0; i < view.byteLength; i++) {
56 assertTrue(expected[i] == String.fromCharCode(view[i]));
62 chrome.test.runTests(tests);