|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright 2020 Google LLC |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +import { expect } from 'chai'; |
| 19 | + |
| 20 | +import * as rn from '../../../src/platform/rn/base64'; |
| 21 | + |
| 22 | +const BASE64_ENCODED = 'GRBoQgKB9LW1'; |
| 23 | +const BASE64_DECODED = '\u0019\u0010\u0068\u0042\u0002\u0081\u00f4\u00b5\u00b5'; |
| 24 | + |
| 25 | +describe('atob', () => { |
| 26 | + // eslint-disable-next-line no-restricted-properties |
| 27 | + (typeof atob !== 'undefined' ? it : it.skip)( |
| 28 | + 'decodes with native support', |
| 29 | + () => { |
| 30 | + const decoded = atob(BASE64_ENCODED); |
| 31 | + expect(decoded).to.equal(BASE64_DECODED); |
| 32 | + } |
| 33 | + ); |
| 34 | + |
| 35 | + // eslint-disable-next-line no-restricted-properties |
| 36 | + (typeof atob !== 'undefined' ? it : it.skip)( |
| 37 | + 'roundtrips with native support', |
| 38 | + () => { |
| 39 | + expect(atob(btoa(BASE64_ENCODED))).to.equal(BASE64_ENCODED); |
| 40 | + } |
| 41 | + ); |
| 42 | + |
| 43 | + it('decodes with polyfill', () => { |
| 44 | + const decoded = rn.decodeBase64(BASE64_ENCODED); |
| 45 | + expect(decoded).to.equal(BASE64_DECODED); |
| 46 | + }); |
| 47 | + |
| 48 | + it('roundtrips with polyfill', () => { |
| 49 | + expect(rn.encodeBase64(rn.decodeBase64(BASE64_ENCODED))).to.equal( |
| 50 | + BASE64_ENCODED |
| 51 | + ); |
| 52 | + }); |
| 53 | +}); |
| 54 | + |
| 55 | +describe('btoa', () => { |
| 56 | + // eslint-disable-next-line no-restricted-properties |
| 57 | + (typeof btoa !== 'undefined' ? it : it.skip)( |
| 58 | + 'encodes with native support', |
| 59 | + () => { |
| 60 | + const encoded = btoa(BASE64_DECODED); |
| 61 | + expect(encoded).to.equal(BASE64_ENCODED); |
| 62 | + } |
| 63 | + ); |
| 64 | + |
| 65 | + // eslint-disable-next-line no-restricted-properties |
| 66 | + (typeof btoa !== 'undefined' ? it : it.skip)( |
| 67 | + 'roundtrips with native support', |
| 68 | + () => { |
| 69 | + expect(atob(btoa(BASE64_DECODED))).to.equal(BASE64_DECODED); |
| 70 | + } |
| 71 | + ); |
| 72 | + |
| 73 | + it('encodes with polyfill', () => { |
| 74 | + const encoded = rn.encodeBase64(BASE64_DECODED); |
| 75 | + expect(encoded).to.equal(BASE64_ENCODED); |
| 76 | + }); |
| 77 | + |
| 78 | + it('roundtrips with polyfill', () => { |
| 79 | + expect(rn.decodeBase64(rn.encodeBase64(BASE64_DECODED))).to.equal( |
| 80 | + BASE64_DECODED |
| 81 | + ); |
| 82 | + }); |
| 83 | +}); |
0 commit comments