1 <!DOCTYPE html> 2 <!-- 3 Copyright (c) 2014 The Chromium Authors. All rights reserved. 4 Use of this source code is governed by a BSD-style license that can be 5 found in the LICENSE file. 6 --> 7 <link rel="import" href="/tracing/base/base64.html"> 8 <script> 9 'use strict'; 10 11 tr.b.unittest.testSuite(function() { 12 test('getDecodedLength', function() { 13 assert.isTrue(tr.b.Base64.getDecodedBufferLength('YQ==') >= 1); 14 assert.isTrue(tr.b.Base64.getDecodedBufferLength('YWJjZA==') >= 4); 15 assert.isTrue(tr.b.Base64.getDecodedBufferLength('YWJjZGVm') >= 6); 16 }); 17 18 test('DecodeToTypedArray', function() { 19 var buffer = new DataView(new ArrayBuffer(256)); 20 tr.b.Base64.DecodeToTypedArray('YQ==', buffer); 21 assert.equal(buffer.getInt8(0), 97); 22 23 tr.b.Base64.DecodeToTypedArray('YWJjZA==', buffer); 24 for (var i = 0; i < 4; i++) 25 assert.equal(buffer.getInt8(i), 97 + i); 26 27 tr.b.Base64.DecodeToTypedArray('YWJjZGVm', buffer); 28 for (var i = 0; i < 4; i++) 29 assert.equal(buffer.getInt8(i), 97 + i); 30 }); 31 32 test('DecodeLengthReturn', function() { 33 var buffer = new DataView(new ArrayBuffer(256)); 34 var len = tr.b.Base64.DecodeToTypedArray(btoa('hello'), buffer); 35 assert.equal(len, 5); 36 }); 37 38 test('Base64.atob', function() { 39 var output = tr.b.Base64.atob('aGVsbG8gd29ybGQ='); 40 assert.equal(output, 'hello world'); 41 }); 42 43 test('Base64.btoa', function() { 44 var output = tr.b.Base64.btoa('hello world'); 45 assert.equal(output, 'aGVsbG8gd29ybGQ='); 46 }); 47 }); 48 </script> 49