~ubuntu-branches/ubuntu/saucy/emscripten/saucy-proposed

« back to all changes in this revision

Viewing changes to third_party/websockify/tests/base64.html

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2013-05-02 13:11:51 UTC
  • Revision ID: package-import@ubuntu.com-20130502131151-q8dvteqr1ef2x7xz
Tags: upstream-1.4.1~20130504~adb56cb
ImportĀ upstreamĀ versionĀ 1.4.1~20130504~adb56cb

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<!DOCTYPE html> 
 
2
<html xmlns="http://www.w3.org/1999/xhtml"> 
 
3
  <head> 
 
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> 
 
8
  </head> 
 
9
  <body> 
 
10
        <h1>Native Base64 Tests</h1> 
 
11
 
 
12
        <br> 
 
13
        Messages:<br> 
 
14
        <textarea id="debug" style="font-size: 9px;" cols=80 rows=25></textarea> 
 
15
    
 
16
        <br>
 
17
  </body> 
 
18
 
 
19
<script> 
 
20
    function debug(str) {
 
21
        console.log(str);
 
22
        cell = $D('debug');
 
23
        cell.innerHTML += str + "\n";
 
24
        cell.scrollTop = cell.scrollHeight;
 
25
    }
 
26
 
 
27
    function assertRun(code, result) {
 
28
        try {
 
29
            var actual = eval(code);
 
30
        } catch (exc) {
 
31
            debug("FAIL: '" + code + "' threw an exception");
 
32
            fail += 1;
 
33
            return false;
 
34
        }
 
35
        if (actual !== result) {
 
36
            debug("FAIL: '" + code + "' returned '" + actual + "', expected '" + result + "'");
 
37
            fail += 1;
 
38
            return false;
 
39
        }
 
40
        debug("PASS: '" + code + "' returned expected '" + result +"'");
 
41
        pass += 1;
 
42
        return true;
 
43
    }
 
44
 
 
45
    function Base64_decode(data) {
 
46
        var arr = Base64.decode (data);
 
47
        return arr.map(function (num) {
 
48
            return String.fromCharCode(num); } ).join('');
 
49
 
 
50
    }
 
51
 
 
52
    window.onload = function() {
 
53
        var str;
 
54
        debug('onload');
 
55
        fail = 0;
 
56
        pass = 0;
 
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=');
 
66
 
 
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');
 
81
 
 
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=');
 
87
 
 
88
        debug("Tests failed: " + fail);
 
89
        debug("Tests passed: " + pass);
 
90
    }
 
91
</script>