summaryrefslogtreecommitdiffstats
path: root/comm/mailnews/base/test/unit/test_testsuite_base64.js
blob: a6faae3640d932bd79eb6a3a47043451447f6bc3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/**
 * Tests functions atob() and btoa() in mailnews/test/resources/MailTestUtils.jsm .
 *
 * Note:
 * btoa() = base64 encode
 * atob() = base64 decode
 * (i.e. "binary" = plain, and "ascii" = encoded)
 */

function run_test() {
  var plain = "testtesttest";
  var encoded = "dGVzdHRlc3R0ZXN0";

  // correct encoding according to spec
  Assert.equal(btoa(plain), encoded); // encode
  Assert.equal(atob(encoded), plain); // decode

  // roundtrip works
  Assert.equal(atob(btoa(plain)), plain);
  Assert.equal(btoa(atob(encoded)), encoded);
  return true;
}