2
<html xmlns="http://www.w3.org/1999/xhtml">
4
<title>Native Base64 Tests</title>
5
<script src="include/util.js"></script>
6
<script src="include/webutil.js"></script>
7
<script src="include/base64.js"></script>
10
<h1>Native Base64 Tests</h1>
14
<textarea id="debug" style="font-size: 9px;" cols=80 rows=25></textarea>
23
cell.innerHTML += str + "\n";
24
cell.scrollTop = cell.scrollHeight;
27
function assertRun(code, result) {
29
var actual = eval(code);
31
debug("FAIL: '" + code + "' threw an exception");
35
if (actual !== result) {
36
debug("FAIL: '" + code + "' returned '" + actual + "', expected '" + result + "'");
40
debug("PASS: '" + code + "' returned expected '" + result +"'");
45
function Base64_decode(data) {
46
var arr = Base64.decode (data);
47
return arr.map(function (num) {
48
return String.fromCharCode(num); } ).join('');
52
window.onload = function() {
57
assertRun('window.btoa("hello world")', 'aGVsbG8gd29ybGQ=');
58
assertRun('window.btoa("a")', 'YQ==');
59
assertRun('window.btoa("ab")', 'YWI=');
60
assertRun('window.btoa("abc")', 'YWJj');
61
assertRun('window.btoa("abcd")', 'YWJjZA==');
62
assertRun('window.btoa("abcde")', 'YWJjZGU=');
63
assertRun('window.btoa("abcdef")', 'YWJjZGVm');
64
assertRun('window.btoa("abcdefg")', 'YWJjZGVmZw==');
65
assertRun('window.btoa("abcdefgh")', 'YWJjZGVmZ2g=');
67
assertRun('window.atob("aGVsbG8gd29ybGQ=")', 'hello world');
68
assertRun('Base64_decode("aGVsbG8gd29ybGQ=")', 'hello world');
69
assertRun('window.atob("YQ==")', 'a');
70
assertRun('Base64_decode("YQ==")', 'a');
71
assertRun('window.atob("YWI=")', 'ab');
72
assertRun('Base64_decode("YWI=")', 'ab');
73
assertRun('window.atob("YWJj")', 'abc');
74
assertRun('Base64_decode("YWJj")', 'abc');
75
assertRun('window.atob("YWJjZA==")', 'abcd');
76
assertRun('Base64_decode("YWJjZA==")', 'abcd');
77
assertRun('window.atob("YWJjZGU=")', 'abcde');
78
assertRun('Base64_decode("YWJjZGU=")', 'abcde');
79
assertRun('window.atob("YWJjZGVm")', 'abcdef');
80
assertRun('Base64_decode("YWJjZGVm")', 'abcdef');
82
assertRun('typeof window.btoa', 'function');
83
assertRun('window.btoa("")', '');
84
assertRun('window.btoa(null)', '');
85
assertRun('window.atob(window.btoa(window))', window.toString()); // "[object DOMWindow]"
86
assertRun('window.btoa("\\u0080\\u0081")', 'gIE=');
88
debug("Tests failed: " + fail);
89
debug("Tests passed: " + pass);