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.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | "use strict"; |
michael@0 | 6 | |
michael@0 | 7 | const base64 = require("sdk/base64"); |
michael@0 | 8 | |
michael@0 | 9 | const text = "Awesome!"; |
michael@0 | 10 | const b64text = "QXdlc29tZSE="; |
michael@0 | 11 | |
michael@0 | 12 | const utf8text = "✓ à la mode"; |
michael@0 | 13 | const b64utf8text = "4pyTIMOgIGxhIG1vZGU="; |
michael@0 | 14 | |
michael@0 | 15 | exports["test base64.encode"] = function (assert) { |
michael@0 | 16 | assert.equal(base64.encode(text), b64text, "encode correctly") |
michael@0 | 17 | } |
michael@0 | 18 | |
michael@0 | 19 | exports["test base64.decode"] = function (assert) { |
michael@0 | 20 | assert.equal(base64.decode(b64text), text, "decode correctly") |
michael@0 | 21 | } |
michael@0 | 22 | |
michael@0 | 23 | exports["test base64.encode Unicode"] = function (assert) { |
michael@0 | 24 | |
michael@0 | 25 | assert.equal(base64.encode(utf8text, "utf-8"), b64utf8text, |
michael@0 | 26 | "encode correctly Unicode strings.") |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | exports["test base64.decode Unicode"] = function (assert) { |
michael@0 | 30 | |
michael@0 | 31 | assert.equal(base64.decode(b64utf8text, "utf-8"), utf8text, |
michael@0 | 32 | "decode correctly Unicode strings.") |
michael@0 | 33 | } |
michael@0 | 34 | |
michael@0 | 35 | exports["test base64.encode with wrong charset"] = function (assert) { |
michael@0 | 36 | |
michael@0 | 37 | assert.throws(function() { |
michael@0 | 38 | base64.encode(utf8text, "utf-16"); |
michael@0 | 39 | }, "The charset argument can be only 'utf-8'"); |
michael@0 | 40 | |
michael@0 | 41 | assert.throws(function() { |
michael@0 | 42 | base64.encode(utf8text, ""); |
michael@0 | 43 | }, "The charset argument can be only 'utf-8'"); |
michael@0 | 44 | |
michael@0 | 45 | assert.throws(function() { |
michael@0 | 46 | base64.encode(utf8text, 8); |
michael@0 | 47 | }, "The charset argument can be only 'utf-8'"); |
michael@0 | 48 | |
michael@0 | 49 | } |
michael@0 | 50 | |
michael@0 | 51 | exports["test base64.decode with wrong charset"] = function (assert) { |
michael@0 | 52 | |
michael@0 | 53 | assert.throws(function() { |
michael@0 | 54 | base64.decode(utf8text, "utf-16"); |
michael@0 | 55 | }, "The charset argument can be only 'utf-8'"); |
michael@0 | 56 | |
michael@0 | 57 | assert.throws(function() { |
michael@0 | 58 | base64.decode(utf8text, ""); |
michael@0 | 59 | }, "The charset argument can be only 'utf-8'"); |
michael@0 | 60 | |
michael@0 | 61 | assert.throws(function() { |
michael@0 | 62 | base64.decode(utf8text, 8); |
michael@0 | 63 | }, "The charset argument can be only 'utf-8'"); |
michael@0 | 64 | |
michael@0 | 65 | } |
michael@0 | 66 | |
michael@0 | 67 | exports["test encode/decode Unicode without utf-8 as charset"] = function (assert) { |
michael@0 | 68 | |
michael@0 | 69 | assert.notEqual(base64.decode(base64.encode(utf8text)), utf8text, |
michael@0 | 70 | "Unicode strings needs 'utf-8' charset" |
michael@0 | 71 | ); |
michael@0 | 72 | |
michael@0 | 73 | } |
michael@0 | 74 | |
michael@0 | 75 | require("test").run(exports); |