Blame view

public/assets/addons/fastflow/plugins/node-qrcode-master/test/e2e/toDataURL.test.js 6.8 KB
2db47680   hexiaodong   chore: 初始提交 php 遗...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
  const test = require('tap').test
  const QRCode = require('lib')
  const QRCodeBrowser = require('lib/browser')
  const { createCanvas } = require('canvas')
  const Helpers = require('test/helpers')
  
  test('toDataURL - no promise available', function (t) {
    Helpers.removeNativePromise()
  
    t.throw(function () { QRCode.toDataURL() },
      'Should throw if no arguments are provided')
  
    t.throw(function () { QRCode.toDataURL(function () {}) },
      'Should throw if text is not provided')
  
    t.throw(function () { QRCode.toDataURL('some text') },
      'Should throw if a callback is not provided')
  
    t.throw(function () { QRCode.toDataURL('some text', {}) },
      'Should throw if a callback is not a function')
  
    t.throw(function () { QRCodeBrowser.toDataURL() },
      'Should throw if no arguments are provided (browser)')
  
    t.throw(function () { QRCodeBrowser.toDataURL(function () {}) },
      'Should throw if text is not provided (browser)')
  
    t.throw(function () { QRCodeBrowser.toDataURL('some text') },
      'Should throw if a callback is not provided (browser)')
  
    t.throw(function () { QRCodeBrowser.toDataURL('some text', {}) },
      'Should throw if a callback is not a function (browser)')
  
    t.end()
  
    Helpers.restoreNativePromise()
  })
  
  test('toDataURL - image/png', function (t) {
    const expectedDataURL = [
      'data:image/png;base64,',
      'iVBORw0KGgoAAAANSUhEUgAAAHQAAAB0CAYAAABUmhYnAAAAAklEQVR4AewaftIAAAKzSU',
      'RBVO3BQW7kQAwEwSxC//9y7h55akCQxvYQjIj/scYo1ijFGqVYoxRrlGKNUqxRijVKsUYp',
      '1ijFGqVYoxRrlGKNUqxRijXKxUNJ+EkqdyShU+mS0Kl0SfhJKk8Ua5RijVKsUS5epvKmJD',
      'yh8iaVNyXhTcUapVijFGuUiw9Lwh0qdyShU+mS0Kl0Kk8k4Q6VTyrWKMUapVijXHw5lROV',
      'kyR0Kt+sWKMUa5RijXIxTBI6lS4JkxVrlGKNUqxRLj5M5Tcl4UTlCZW/pFijFGuUYo1y8b',
      'Ik/KQkdCpdEjqVLgmdykkS/rJijVKsUYo1ysVDKt9M5UTlmxRrlGKNUqxRLh5Kwh0qXRJ+',
      'UxLuULkjCZ3KJxVrlGKNUqxRLh5S6ZLQqXRJ6FS6JHQqXRKeSEKn0iWhUzlJwolKl4QTlS',
      'eKNUqxRinWKBe/LAmdSpeETuUkCZ1Kl4QTlS4Jd6h0SehUuiS8qVijFGuUYo1y8WFJ6FS6',
      'JJyofFISOpVOpUtCp3KicqLypmKNUqxRijXKxYep3JGEE5UuCZ3KHSp3qHRJ6FR+U7FGKd',
      'YoxRol/scXS8ITKidJeEKlS8KJyhPFGqVYoxRrlIuHkvCTVE5U7kjCicpJEk6S8JOKNUqx',
      'RinWKBcvU3lTEu5IwolKp/KEyh1J6FTeVKxRijVKsUa5+LAk3KHyJpWTJHQqdyShU/lNxR',
      'qlWKMUa5SLL6fSJaFLwhNJeCIJP6lYoxRrlGKNcvHlknCicpKEE5UuCSdJOFHpktCpPFGs',
      'UYo1SrFGufgwlZ+k0iWhU+lUnlDpktCpdEnoVN5UrFGKNUqxRrl4WRL+EpU7ktCpdCpdEj',
      'qVO5LQqTxRrFGKNUqxRon/scYo1ijFGqVYoxRrlGKNUqxRijVKsUYp1ijFGqVYoxRrlGKN',
      'UqxRijXKP0OHEepgrecVAAAAAElFTkSuQmCC'].join('')
  
    t.plan(8)
  
    t.throw(function () { QRCode.toDataURL() },
      'Should throw if no arguments are provided')
  
    QRCode.toDataURL('i am a pony!', {
      errorCorrectionLevel: 'L',
      type: 'image/png'
    }, function (err, url) {
      t.ok(!err, 'there should be no error ' + err)
      t.equals(url, expectedDataURL,
        'url should match expected value for error correction L')
    })
  
    QRCode.toDataURL('i am a pony!', {
      version: 1, // force version=1 to trigger an error
      errorCorrectionLevel: 'H',
      type: 'image/png'
    }, function (err, url) {
      t.ok(err, 'there should be an error ')
      t.notOk(url, 'url should be null')
    })
  
    t.equals(typeof QRCode.toDataURL('i am a pony!').then, 'function',
      'Should return a promise')
  
    QRCode.toDataURL('i am a pony!', {
      errorCorrectionLevel: 'L',
      type: 'image/png'
    }).then(function (url) {
      t.equals(url, expectedDataURL,
        'url should match expected value for error correction L (promise)')
    })
  
    QRCode.toDataURL('i am a pony!', {
      version: 1, // force version=1 to trigger an error
      errorCorrectionLevel: 'H',
      type: 'image/png'
    }).catch(function (err) {
      t.ok(err, 'there should be an error (promise)')
    })
  })
  
  test('Canvas toDataURL - image/png', function (t) {
    const expectedDataURL = [
      'data:image/png;base64,',
      'iVBORw0KGgoAAAANSUhEUgAAAIQAAACECAYAAABRRIOnAAAABmJLR0QA/wD/AP+gvaeTAA',
      'AC20lEQVR4nO3dQY7jMAwEwM1i///lzGUurYtWEEknQNV1EidjNGhFpuTX+/1+/4Fff5/+',
      'AnwWgSAIBEEgCAJBEAiCQBAEgiAQBIEgCARBIAgCQRAIgkAQ/t0e4PV6VXyP/7a2b6yff9',
      'vecXq83eufPj+nVAiCQBAEgnA9hlhVt2jursGn1/hbt2OW6fNzSoUgCARBIAjlY4jV6TWu',
      'ex7hdt7g6TFA9zIaFYIgEASBILSPIbrdjhlWt/civn2prApBEAiCQBC+fgzR3R8xfa/kaS',
      'oEQSAIAkFoH0N82u/y03sVuzFJ9xhlmgpBEAiCQBDKxxDTv8u7+x9uP3/3+k+jQhAEgiAQ',
      'hOsxxNO/o0/7G07/fuvp83NKhSAIBEEgCK/u52VUzwNUr6Ponkc4Pb3V+1OcUiEIAkEQCE',
      'L5HlPT17zuPZ1ux0Dde2BVUyEIAkEQCEL5vYzTa271NfF2nUb1vMj097mlQhAEgiAQhPG1',
      'nbf3IqbnBXZjnuq9sKfncVYqBEEgCAJBGL+XsTqdp6g+/qr7Gr2q/n/0Q1BKIAgCQSjvqa',
      'z+3b07/qq6h3G6Z3P3/h1jCEoJBEEgCO3zEJ/ej3Cq+hlb3etSTqkQBIEgCATh4+YhqucF',
      'nu5fmD7+LRWCIBAEgSA83g+xmu45nH4m1+3nd1MhCAJBEAhC+x5T3br7I05193d0P5tchS',
      'AIBEEgCOXzEN1un3lV/Qyt6nUe3f0OOyoEQSAIAkEo3x+ielrj9Bq96h5z7Dx9b+eUCkEQ',
      'CIJAENr3mJpemzjdU7l7/7dRIQgCQRAIwvg+ldWm13Wc6t4Hs5oKQRAIgkAQvn4MUb1WdP',
      'q5nKevt08lowSCIBCE9jHE9F7R0/MGu7/f9lDqh+BRAkEQCML12s6n12Wcqp5n6N5X8/Tz',
      'zENQSiAIAkH4+v0hqKVCEASCIBAEgSAIBEEgCAJBEAiCQBAEgiAQBIEgCARBIAgCQfgBlZ',
      '7HAm5AupgAAAAASUVORK5CYII='].join('')
  
    t.plan(11)
  
    t.throw(function () { QRCodeBrowser.toDataURL() },
      'Should throw if no arguments are provided')
  
    t.throw(function () { QRCodeBrowser.toDataURL(function () {}) },
      'Should throw if text is not provided')
  
    const canvas = createCanvas(200, 200)
    QRCodeBrowser.toDataURL(canvas, 'i am a pony!', {
      errorCorrectionLevel: 'H',
      type: 'image/png'
    }, function (err, url) {
      t.ok(!err, 'there should be no error ' + err)
      t.equals(url, expectedDataURL, 'url generated should match expected value')
    })
  
    QRCodeBrowser.toDataURL(canvas, 'i am a pony!', {
      version: 1, // force version=1 to trigger an error
      errorCorrectionLevel: 'H',
      type: 'image/png'
    }, function (err, url) {
      t.ok(err, 'there should be an error ')
      t.notOk(url, 'url should be null')
    })
  
    QRCodeBrowser.toDataURL(canvas, 'i am a pony!', {
      errorCorrectionLevel: 'H',
      type: 'image/png'
    }).then(function (url) {
      t.equals(url, expectedDataURL, 'url generated should match expected value (promise)')
    })
  
    QRCodeBrowser.toDataURL(canvas, 'i am a pony!', {
      version: 1, // force version=1 to trigger an error
      errorCorrectionLevel: 'H',
      type: 'image/png'
    }).catch(function (err) {
      t.ok(err, 'there should be an error (promise)')
    })
  
    // Mock document object
    global.document = {
      createElement: function (el) {
        if (el === 'canvas') {
          return createCanvas(200, 200)
        }
      }
    }
  
    QRCodeBrowser.toDataURL('i am a pony!', {
      errorCorrectionLevel: 'H',
      type: 'image/png'
    }, function (err, url) {
      t.ok(!err, 'there should be no error ' + err)
      t.equals(url, expectedDataURL, 'url generated should match expected value')
    })
  
    QRCodeBrowser.toDataURL('i am a pony!', {
      errorCorrectionLevel: 'H',
      type: 'image/png'
    }).then(function (url) {
      t.equals(url, expectedDataURL, 'url generated should match expected value (promise)')
    })
  })