Thu, 15 Jan 2015 15:59:08 +0100
Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 "use strict";
7 const base64 = require("sdk/base64");
9 const text = "Awesome!";
10 const b64text = "QXdlc29tZSE=";
12 const utf8text = "✓ à la mode";
13 const b64utf8text = "4pyTIMOgIGxhIG1vZGU=";
15 exports["test base64.encode"] = function (assert) {
16 assert.equal(base64.encode(text), b64text, "encode correctly")
17 }
19 exports["test base64.decode"] = function (assert) {
20 assert.equal(base64.decode(b64text), text, "decode correctly")
21 }
23 exports["test base64.encode Unicode"] = function (assert) {
25 assert.equal(base64.encode(utf8text, "utf-8"), b64utf8text,
26 "encode correctly Unicode strings.")
27 }
29 exports["test base64.decode Unicode"] = function (assert) {
31 assert.equal(base64.decode(b64utf8text, "utf-8"), utf8text,
32 "decode correctly Unicode strings.")
33 }
35 exports["test base64.encode with wrong charset"] = function (assert) {
37 assert.throws(function() {
38 base64.encode(utf8text, "utf-16");
39 }, "The charset argument can be only 'utf-8'");
41 assert.throws(function() {
42 base64.encode(utf8text, "");
43 }, "The charset argument can be only 'utf-8'");
45 assert.throws(function() {
46 base64.encode(utf8text, 8);
47 }, "The charset argument can be only 'utf-8'");
49 }
51 exports["test base64.decode with wrong charset"] = function (assert) {
53 assert.throws(function() {
54 base64.decode(utf8text, "utf-16");
55 }, "The charset argument can be only 'utf-8'");
57 assert.throws(function() {
58 base64.decode(utf8text, "");
59 }, "The charset argument can be only 'utf-8'");
61 assert.throws(function() {
62 base64.decode(utf8text, 8);
63 }, "The charset argument can be only 'utf-8'");
65 }
67 exports["test encode/decode Unicode without utf-8 as charset"] = function (assert) {
69 assert.notEqual(base64.decode(base64.encode(utf8text)), utf8text,
70 "Unicode strings needs 'utf-8' charset"
71 );
73 }
75 require("test").run(exports);