Upstream version 9.37.197.0
[platform/framework/web/crosswalk.git] / src / third_party / trace-viewer / third_party / tvcm / src / tvcm / base64_test.js
1 // Copyright (c) 2014 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.
4
5 'use strict';
6
7 tvcm.require('tvcm.base64');
8
9 tvcm.unittest.testSuite('tvcm.base64_test', function() {
10
11   test('getDecodedLength', function() {
12     assertTrue(tvcm.Base64.getDecodedBufferLength('YQ==') >= 1);
13     assertTrue(tvcm.Base64.getDecodedBufferLength('YWJjZA==') >= 4);
14     assertTrue(tvcm.Base64.getDecodedBufferLength('YWJjZGVm') >= 6);
15   });
16
17   test('DecodeToTypedArray', function() {
18     var buffer = new DataView(new ArrayBuffer(256));
19     tvcm.Base64.DecodeToTypedArray('YQ==', buffer);
20     assertTrue(buffer.getInt8(0) == 97);
21
22     tvcm.Base64.DecodeToTypedArray('YWJjZA==', buffer);
23     for (var i = 0; i < 4; i++)
24       assertTrue(buffer.getInt8(i) == 97 + i);
25
26     tvcm.Base64.DecodeToTypedArray('YWJjZGVm', buffer);
27     for (var i = 0; i < 4; i++)
28       assertTrue(buffer.getInt8(i) == 97 + i);
29   });
30
31   test('DecodeLengthReturn', function() {
32     var buffer = new DataView(new ArrayBuffer(256));
33     var len = tvcm.Base64.DecodeToTypedArray(btoa('hello'), buffer);
34     assertEquals(5, len);
35   });
36
37 });