gecko-dev/netwerk/test/unit/test_data_protocol.js
Ehsan Akhgari 868c13b5e5 Bug 1547397 - Part 2: Move some xpcshell tests for cookies out of extensions/cookies; r=baku
Differential Revision: https://phabricator.services.mozilla.com/D29115

--HG--
rename : extensions/cookie/test/unit/head_cookies.js => netwerk/test/unit/head_cookies.js
rename : extensions/cookie/test/unit/test_bug526789.js => netwerk/test/unit/test_bug526789.js
rename : extensions/cookie/test/unit/test_bug650522.js => netwerk/test/unit/test_bug650522.js
rename : extensions/cookie/test/unit/test_bug667087.js => netwerk/test/unit/test_bug667087.js
rename : extensions/cookie/test/unit/test_cookies_async_failure.js => netwerk/test/unit/test_cookies_async_failure.js
rename : extensions/cookie/test/unit/test_cookies_persistence.js => netwerk/test/unit/test_cookies_persistence.js
rename : extensions/cookie/test/unit/test_cookies_privatebrowsing.js => netwerk/test/unit/test_cookies_privatebrowsing.js
rename : extensions/cookie/test/unit/test_cookies_profile_close.js => netwerk/test/unit/test_cookies_profile_close.js
rename : extensions/cookie/test/unit/test_cookies_read.js => netwerk/test/unit/test_cookies_read.js
rename : extensions/cookie/test/unit/test_cookies_sync_failure.js => netwerk/test/unit/test_cookies_sync_failure.js
rename : extensions/cookie/test/unit/test_cookies_thirdparty.js => netwerk/test/unit/test_cookies_thirdparty.js
rename : extensions/cookie/test/unit/test_cookies_thirdparty_nonsecure_session.js => netwerk/test/unit/test_cookies_thirdparty_nonsecure_session.js
rename : extensions/cookie/test/unit/test_cookies_thirdparty_session.js => netwerk/test/unit/test_cookies_thirdparty_session.js
rename : extensions/cookie/test/unit/test_domain_eviction.js => netwerk/test/unit/test_domain_eviction.js
rename : extensions/cookie/test/unit/test_eviction.js => netwerk/test/unit/test_eviction.js
rename : extensions/cookie/test/unit/test_schema_2_migration.js => netwerk/test/unit/test_schema_2_migration.js
rename : extensions/cookie/test/unit/test_schema_3_migration.js => netwerk/test/unit/test_schema_3_migration.js
extra : moz-landing-system : lando
2019-04-30 14:06:27 +00:00

63 lines
3.2 KiB
JavaScript

/* run some tests on the data: protocol handler */
// The behaviour wrt spaces is:
// - Textual content keeps all spaces
// - Other content strips unescaped spaces
// - Base64 content strips escaped and unescaped spaces
var urls = [
["data:,", "text/plain", ""],
["data:,foo", "text/plain", "foo"],
["data:application/octet-stream,foo bar", "application/octet-stream", "foobar"],
["data:application/octet-stream,foo%20bar", "application/octet-stream", "foo bar"],
["data:application/xhtml+xml,foo bar", "application/xhtml+xml", "foo bar"],
["data:application/xhtml+xml,foo%20bar", "application/xhtml+xml", "foo bar"],
["data:text/plain,foo%00 bar", "text/plain", "foo\x00 bar"],
["data:text/plain;x=y,foo%00 bar", "text/plain", "foo\x00 bar"],
["data:;x=y,foo%00 bar", "text/plain", "foo\x00 bar"],
["data:text/plain;base64,Zm9 vI%20GJ%0Dhc%0Ag==", "text/plain", "foo bar"],
["DATA:TEXT/PLAIN;BASE64,Zm9 vI%20GJ%0Dhc%0Ag==", "text/plain", "foo bar"],
["DaTa:;BaSe64,Zm9 vI%20GJ%0Dhc%0Ag==", "text/plain", "foo bar"],
["data:;x=y;base64,Zm9 vI%20GJ%0Dhc%0Ag==", "text/plain", "foo bar"],
// Bug 774240
["data:application/octet-stream;base64=y,foobar", "application/octet-stream", "foobar"],
// Bug 781693
["data:text/plain;base64;x=y,dGVzdA==", "text/plain", "test"],
["data:text/plain;x=y;base64,dGVzdA==", "text/plain", "test"],
["data:text/plain;x=y;base64,", "text/plain", ""],
["data: ;charset=x ; base64,WA", "text/plain", "X", "x"],
["data:base64,WA", "text/plain", "WA", "US-ASCII"],
];
function run_test() {
dump("*** run_test\n");
function on_read_complete(request, data, idx) {
dump("*** run_test.on_read_complete\n");
if (request.nsIChannel.contentType != urls[idx][1])
do_throw("Type mismatch! Is <" + chan.contentType + ">, should be <" + urls[idx][1] + ">");
if (urls[idx][3] && request.nsIChannel.contentCharset !== urls[idx][3]) {
do_throw(`Charset mismatch! Test <${urls[idx][0]}> - Is <${request.nsIChannel.contentCharset}>, should be <${urls[idx][3]}>`);
}
/* read completed successfully. now compare the data. */
if (data != urls[idx][2])
do_throw("Stream contents do not match with direct read! Is <" + data + ">, should be <" + urls[idx][2] + ">");
do_test_finished();
}
var ios = Cc["@mozilla.org/network/io-service;1"].
getService(Ci.nsIIOService);
for (var i = 0; i < urls.length; ++i) {
dump("*** opening channel " + i + "\n");
do_test_pending();
var chan = NetUtil.newChannel({
uri: urls[i][0],
loadUsingSystemPrincipal: true
});
chan.contentType = "foo/bar"; // should be ignored
chan.asyncOpen(new ChannelListener(on_read_complete, i));
}
}