Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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 { readURI, readURISync } = require("sdk/net/url");
8 const data = require("./fixtures");
10 const utf8text = "Hello, ゼロ!";
11 const latin1text = "Hello, ゼãƒ!";
13 const dataURIutf8 = "data:text/plain;charset=utf-8," + encodeURIComponent(utf8text);
14 const dataURIlatin1 = "data:text/plain;charset=ISO-8859-1," + escape(latin1text);
15 const chromeURI = "chrome://global-platform/locale/accessible.properties";
17 exports["test async readURI"] = function(assert, done) {
18 let content = "";
20 readURI(data.url("test-net-url.txt")).then(function(data) {
21 content = data;
22 assert.equal(content, utf8text, "The URL content is loaded properly");
23 done();
24 }, function() {
25 assert.fail("should not reject");
26 done();
27 })
29 assert.equal(content, "", "The URL content is not load yet");
30 }
32 exports["test readURISync"] = function(assert) {
33 let content = readURISync(data.url("test-net-url.txt"));
35 assert.equal(content, utf8text, "The URL content is loaded properly");
36 }
38 exports["test async readURI with ISO-8859-1 charset"] = function(assert, done) {
39 let content = "";
41 readURI(data.url("test-net-url.txt"), { charset : "ISO-8859-1"}).then(function(data) {
42 content = data;
43 assert.equal(content, latin1text, "The URL content is loaded properly");
44 done();
45 }, function() {
46 assert.fail("should not reject");
47 done();
48 })
50 assert.equal(content, "", "The URL content is not load yet");
51 }
53 exports["test readURISync with ISO-8859-1 charset"] = function(assert) {
54 let content = readURISync(data.url("test-net-url.txt"), "ISO-8859-1");
56 assert.equal(content, latin1text, "The URL content is loaded properly");
57 }
59 exports["test async readURI with not existing file"] = function(assert, done) {
60 readURI(data.url("test-net-url-fake.txt")).then(function(data) {
61 assert.fail("should not resolve");
62 done();
63 }, function(reason) {
64 assert.ok(reason.indexOf("Failed to read:") === 0);
65 done();
66 })
67 }
69 exports["test readURISync with not existing file"] = function(assert) {
70 assert.throws(function() {
71 readURISync(data.url("test-net-url-fake.txt"));
72 }, /NS_ERROR_FILE_NOT_FOUND/);
73 }
75 exports["test async readURI with data URI"] = function(assert, done) {
76 let content = "";
78 readURI(dataURIutf8).then(function(data) {
79 content = data;
80 assert.equal(content, utf8text, "The URL content is loaded properly");
81 done();
82 }, function() {
83 assert.fail("should not reject");
84 done();
85 })
87 assert.equal(content, "", "The URL content is not load yet");
88 }
90 exports["test readURISync with data URI"] = function(assert) {
91 let content = readURISync(dataURIutf8);
93 assert.equal(content, utf8text, "The URL content is loaded properly");
94 }
96 exports["test async readURI with data URI and ISO-8859-1 charset"] = function(assert, done) {
97 let content = "";
99 readURI(dataURIlatin1, { charset : "ISO-8859-1"}).then(function(data) {
100 content = unescape(data);
101 assert.equal(content, latin1text, "The URL content is loaded properly");
102 done();
103 }, function() {
104 assert.fail("should not reject");
105 done();
106 })
108 assert.equal(content, "", "The URL content is not load yet");
109 }
111 exports["test readURISync with data URI and ISO-8859-1 charset"] = function(assert) {
112 let content = unescape(readURISync(dataURIlatin1, "ISO-8859-1"));
114 assert.equal(content, latin1text, "The URL content is loaded properly");
115 }
117 exports["test readURISync with chrome URI"] = function(assert) {
118 let content = readURISync(chromeURI);
120 assert.ok(content, "The URL content is loaded properly");
121 }
123 exports["test async readURI with chrome URI"] = function(assert, done) {
124 let content = "";
126 readURI(chromeURI).then(function(data) {
127 content = data;
128 assert.equal(content, readURISync(chromeURI), "The URL content is loaded properly");
129 done();
130 }, function() {
131 assert.fail("should not reject");
132 done();
133 })
135 assert.equal(content, "", "The URL content is not load yet");
136 }
138 require("test").run(exports)