forked from mirrors/gecko-dev
Bug 1501932 - Enable ESLint for modules/ (automatic changes). r=njn,aklotz
Differential Revision: https://phabricator.services.mozilla.com/D14645 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
d1e9538986
commit
531ae2db82
56 changed files with 360 additions and 401 deletions
|
|
@ -21,11 +21,11 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1173171
|
|||
// __xhr(method, url, responseType__.
|
||||
// A simple async XMLHttpRequest call.
|
||||
// Returns a promise with the response.
|
||||
let xhr = function (method, url, responseType) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
let xhr = function(method, url, responseType) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
let xhr = new XMLHttpRequest();
|
||||
xhr.open(method, url, true);
|
||||
xhr.onload = function () {
|
||||
xhr.onload = function() {
|
||||
resolve(xhr.response);
|
||||
};
|
||||
xhr.onerror = function() {
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ function test_relative_sub() {
|
|||
// This is the URI we expect to see.
|
||||
var expected = "jar:" + ios.newFileURI(do_get_file(path)).spec +
|
||||
"!/modules/libjar";
|
||||
|
||||
|
||||
Assert.equal(uri.spec, expected);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
// Regression test for bug 333423 - crash enumerating entries of a
|
||||
// Regression test for bug 333423 - crash enumerating entries of a
|
||||
// closed nsIZipReader
|
||||
function run_test() {
|
||||
// the build script have created the zip we can test on in the current dir.
|
||||
|
|
@ -14,6 +14,6 @@ function run_test() {
|
|||
createInstance(Ci.nsIZipReader);
|
||||
zipreader.open(file);
|
||||
zipreader.close();
|
||||
var entries = zipreader.findEntries('*.*');
|
||||
var entries = zipreader.findEntries("*.*");
|
||||
Assert.ok(!entries.hasMore()); // this shouldn't crash
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,8 +16,7 @@ function run_test() {
|
|||
var exception = false;
|
||||
try {
|
||||
channel.asyncOpen(null);
|
||||
}
|
||||
catch(e) {
|
||||
} catch (e) {
|
||||
exception = true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ function run_test() {
|
|||
createInstance(Ci.nsIZipReader);
|
||||
zipReader.open(file);
|
||||
var entry = zipReader.getEntry(ENTRY_NAME);
|
||||
var diff = Math.abs(entry.lastModifiedTime - ENTRY_TIME.getTime()*1000);
|
||||
var diff = Math.abs(entry.lastModifiedTime - ENTRY_TIME.getTime() * 1000);
|
||||
zipReader.close();
|
||||
if (diff >= MAX_TIME_DIFF)
|
||||
do_throw(diff);
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ function run_test() {
|
|||
zipreader.open(file);
|
||||
|
||||
var failed = false;
|
||||
for (let entryPath of zipreader.findEntries('*')) {
|
||||
for (let entryPath of zipreader.findEntries("*")) {
|
||||
let entry = zipreader.getEntry(entryPath);
|
||||
if (!entry.isDirectory) {
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -2,8 +2,7 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
function wrapInputStream(input)
|
||||
{
|
||||
function wrapInputStream(input) {
|
||||
var nsIScriptableInputStream = Ci.nsIScriptableInputStream;
|
||||
var factory = Cc["@mozilla.org/scriptableinputstream;1"];
|
||||
var wrapper = factory.createInstance(nsIScriptableInputStream);
|
||||
|
|
|
|||
|
|
@ -4,8 +4,7 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
function wrapInputStream(input)
|
||||
{
|
||||
function wrapInputStream(input) {
|
||||
let nsIScriptableInputStream = Ci.nsIScriptableInputStream;
|
||||
let factory = Cc["@mozilla.org/scriptableinputstream;1"];
|
||||
let wrapper = factory.createInstance(nsIScriptableInputStream);
|
||||
|
|
@ -27,10 +26,10 @@ function run_test() {
|
|||
zipreader.test(null);
|
||||
return true;
|
||||
}
|
||||
Assert.ok(check_archive_crc())
|
||||
Assert.ok(check_archive_crc());
|
||||
let entries = zipreader.findEntries(null);
|
||||
let stream = wrapInputStream(zipreader.getInputStream("modules/libjar/test/Makefile.in"))
|
||||
let dirstream= wrapInputStream(zipreader.getInputStream("modules/libjar/test/"))
|
||||
let stream = wrapInputStream(zipreader.getInputStream("modules/libjar/test/Makefile.in"));
|
||||
let dirstream = wrapInputStream(zipreader.getInputStream("modules/libjar/test/"));
|
||||
zipreader.close();
|
||||
zipreader = null;
|
||||
Cu.forceGC();
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ const {classes: Cc,
|
|||
interfaces: Ci,
|
||||
results: Cr,
|
||||
utils: Cu,
|
||||
Constructor: ctor
|
||||
Constructor: ctor,
|
||||
} = Components;
|
||||
|
||||
const {NetUtil} = ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
|
||||
|
|
@ -40,33 +40,27 @@ Listener.prototype = {
|
|||
gotStartRequest: false,
|
||||
available: -1,
|
||||
gotStopRequest: false,
|
||||
QueryInterface: function(iid) {
|
||||
if (iid.equals(Ci.nsISupports) ||
|
||||
iid.equals(Ci.nsIRequestObserver))
|
||||
return this;
|
||||
throw Cr.NS_ERROR_NO_INTERFACE;
|
||||
},
|
||||
onDataAvailable: function(request, ctx, stream, offset, count) {
|
||||
QueryInterface: ChromeUtils.generateQI(["nsIRequestObserver"]),
|
||||
onDataAvailable(request, ctx, stream, offset, count) {
|
||||
try {
|
||||
this.available = stream.available();
|
||||
Assert.equal(this.available, count);
|
||||
// Need to consume stream to avoid assertion
|
||||
new nsIBinaryInputStream(stream).readBytes(count);
|
||||
}
|
||||
catch (ex) {
|
||||
} catch (ex) {
|
||||
do_throw(ex);
|
||||
}
|
||||
},
|
||||
onStartRequest: function(request, ctx) {
|
||||
onStartRequest(request, ctx) {
|
||||
this.gotStartRequest = true;
|
||||
},
|
||||
onStopRequest: function(request, ctx, status) {
|
||||
onStopRequest(request, ctx, status) {
|
||||
this.gotStopRequest = true;
|
||||
Assert.equal(status, 0);
|
||||
if (this._callback) {
|
||||
this._callback.call(null, this);
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -74,7 +68,7 @@ Listener.prototype = {
|
|||
*/
|
||||
function testAsync() {
|
||||
var uri = jarBase + "/inner40.zip";
|
||||
var chan = NetUtil.newChannel({uri: uri, loadUsingSystemPrincipal: true});
|
||||
var chan = NetUtil.newChannel({uri, loadUsingSystemPrincipal: true});
|
||||
Assert.ok(chan.contentLength < 0);
|
||||
chan.asyncOpen(new Listener(function(l) {
|
||||
Assert.ok(chan.contentLength > 0);
|
||||
|
|
@ -95,7 +89,7 @@ add_test(testAsync);
|
|||
*/
|
||||
function testZipEntry() {
|
||||
var uri = jarBase + "/inner40.zip";
|
||||
var chan = NetUtil.newChannel({uri: uri, loadUsingSystemPrincipal: true})
|
||||
var chan = NetUtil.newChannel({uri, loadUsingSystemPrincipal: true})
|
||||
.QueryInterface(Ci.nsIJARChannel);
|
||||
var entry = chan.zipEntry;
|
||||
Assert.ok(entry.CRC32 == 0x8b635486);
|
||||
|
|
@ -111,7 +105,7 @@ add_test(testZipEntry);
|
|||
*/
|
||||
add_test(function testSync() {
|
||||
var uri = jarBase + "/inner40.zip";
|
||||
var chan = NetUtil.newChannel({uri: uri, loadUsingSystemPrincipal: true});
|
||||
var chan = NetUtil.newChannel({uri, loadUsingSystemPrincipal: true});
|
||||
var stream = chan.open();
|
||||
Assert.ok(chan.contentLength > 0);
|
||||
Assert.equal(stream.available(), chan.contentLength);
|
||||
|
|
@ -127,7 +121,7 @@ add_test(function testSync() {
|
|||
*/
|
||||
add_test(function testSyncNested() {
|
||||
var uri = "jar:" + jarBase + "/inner40.zip!/foo";
|
||||
var chan = NetUtil.newChannel({uri: uri, loadUsingSystemPrincipal: true});
|
||||
var chan = NetUtil.newChannel({uri, loadUsingSystemPrincipal: true});
|
||||
var stream = chan.open();
|
||||
Assert.ok(chan.contentLength > 0);
|
||||
Assert.equal(stream.available(), chan.contentLength);
|
||||
|
|
@ -142,7 +136,7 @@ add_test(function testSyncNested() {
|
|||
*/
|
||||
add_test(function testAsyncNested(next) {
|
||||
var uri = "jar:" + jarBase + "/inner40.zip!/foo";
|
||||
var chan = NetUtil.newChannel({uri: uri, loadUsingSystemPrincipal: true});
|
||||
var chan = NetUtil.newChannel({uri, loadUsingSystemPrincipal: true});
|
||||
chan.asyncOpen(new Listener(function(l) {
|
||||
Assert.ok(chan.contentLength > 0);
|
||||
Assert.ok(l.gotStartRequest);
|
||||
|
|
@ -162,7 +156,7 @@ add_test(function testSyncCloseUnlocks() {
|
|||
copy.append(fileBase);
|
||||
file.copyTo(copy.parent, copy.leafName);
|
||||
var uri = "jar:" + ios.newFileURI(copy).spec + "!/inner40.zip";
|
||||
var chan = NetUtil.newChannel({uri: uri, loadUsingSystemPrincipal: true});
|
||||
var chan = NetUtil.newChannel({uri, loadUsingSystemPrincipal: true});
|
||||
var stream = chan.open();
|
||||
Assert.ok(chan.contentLength > 0);
|
||||
stream.close();
|
||||
|
|
@ -172,8 +166,7 @@ add_test(function testSyncCloseUnlocks() {
|
|||
|
||||
try {
|
||||
copy.remove(false);
|
||||
}
|
||||
catch (ex) {
|
||||
} catch (ex) {
|
||||
do_throw(ex);
|
||||
}
|
||||
|
||||
|
|
@ -190,9 +183,9 @@ add_test(function testAsyncCloseUnlocks() {
|
|||
file.copyTo(copy.parent, copy.leafName);
|
||||
|
||||
var uri = "jar:" + ios.newFileURI(copy).spec + "!/inner40.zip";
|
||||
var chan = NetUtil.newChannel({uri: uri, loadUsingSystemPrincipal: true});
|
||||
var chan = NetUtil.newChannel({uri, loadUsingSystemPrincipal: true});
|
||||
|
||||
chan.asyncOpen(new Listener(function (l) {
|
||||
chan.asyncOpen(new Listener(function(l) {
|
||||
Assert.ok(chan.contentLength > 0);
|
||||
|
||||
// Drop any jar caches
|
||||
|
|
@ -200,8 +193,7 @@ add_test(function testAsyncCloseUnlocks() {
|
|||
|
||||
try {
|
||||
copy.remove(false);
|
||||
}
|
||||
catch (ex) {
|
||||
} catch (ex) {
|
||||
do_throw(ex);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,8 +4,7 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
function wrapInputStream(input)
|
||||
{
|
||||
function wrapInputStream(input) {
|
||||
var nsIScriptableInputStream = Ci.nsIScriptableInputStream;
|
||||
var factory = Cc["@mozilla.org/scriptableinputstream;1"];
|
||||
var wrapper = factory.createInstance(nsIScriptableInputStream);
|
||||
|
|
@ -26,10 +25,10 @@ function run_test() {
|
|||
zipreader.test(null);
|
||||
return true;
|
||||
}
|
||||
Assert.ok(check_archive_crc())
|
||||
Assert.ok(check_archive_crc());
|
||||
var entries = zipreader.findEntries(null);
|
||||
var stream = wrapInputStream(zipreader.getInputStream("modules/libjar/test/Makefile.in"))
|
||||
var dirstream= wrapInputStream(zipreader.getInputStream("modules/libjar/test/"))
|
||||
var stream = wrapInputStream(zipreader.getInputStream("modules/libjar/test/Makefile.in"));
|
||||
var dirstream = wrapInputStream(zipreader.getInputStream("modules/libjar/test/"));
|
||||
zipreader.close();
|
||||
zipreader = null;
|
||||
Cu.forceGC();
|
||||
|
|
|
|||
|
|
@ -9,12 +9,12 @@ function run_test() {
|
|||
var spec = "jar:" + ios.newFileURI(do_get_file(path)).spec + "!/";
|
||||
var channel = NetUtil.newChannel({
|
||||
uri: spec + "file_that_isnt_in.archive",
|
||||
loadUsingSystemPrincipal: true
|
||||
loadUsingSystemPrincipal: true,
|
||||
});
|
||||
try {
|
||||
instr = channel.open();
|
||||
do_throw("Failed to report that file doesn't exist")
|
||||
do_throw("Failed to report that file doesn't exist");
|
||||
} catch (e) {
|
||||
Assert.ok(e.name == "NS_ERROR_FILE_NOT_FOUND")
|
||||
Assert.ok(e.name == "NS_ERROR_FILE_NOT_FOUND");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
function run_test() {
|
||||
var dirService = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
|
||||
var tmpDir = dirService.get("TmpD", Ci.nsIFile);
|
||||
var dirService = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
|
||||
var tmpDir = dirService.get("TmpD", Ci.nsIFile);
|
||||
|
||||
var zipfile = do_get_file("data/test_umlaute.zip");
|
||||
|
||||
|
|
@ -15,7 +15,7 @@ function run_test() {
|
|||
zipreader.open(zipfile);
|
||||
|
||||
var entries = zipreader.findEntries(null);
|
||||
Assert.ok(entries.hasMore());
|
||||
Assert.ok(entries.hasMore());
|
||||
|
||||
var entryName = entries.getNext();
|
||||
Assert.equal(entryName, "test_\u00FC.txt");
|
||||
|
|
|
|||
|
|
@ -5,20 +5,20 @@
|
|||
|
||||
const NS_ERROR_IN_PROGRESS = 2152398863;
|
||||
|
||||
const PR_RDONLY = 0x01
|
||||
const PR_WRONLY = 0x02
|
||||
const PR_RDWR = 0x04
|
||||
const PR_CREATE_FILE = 0x08
|
||||
const PR_APPEND = 0x10
|
||||
const PR_TRUNCATE = 0x20
|
||||
const PR_SYNC = 0x40
|
||||
const PR_EXCL = 0x80
|
||||
const PR_RDONLY = 0x01;
|
||||
const PR_WRONLY = 0x02;
|
||||
const PR_RDWR = 0x04;
|
||||
const PR_CREATE_FILE = 0x08;
|
||||
const PR_APPEND = 0x10;
|
||||
const PR_TRUNCATE = 0x20;
|
||||
const PR_SYNC = 0x40;
|
||||
const PR_EXCL = 0x80;
|
||||
|
||||
const ZIP_EOCDR_HEADER_SIZE = 22;
|
||||
const ZIP_FILE_HEADER_SIZE = 30;
|
||||
const ZIP_CDS_HEADER_SIZE = 46;
|
||||
const ZIP_METHOD_STORE = 0
|
||||
const ZIP_METHOD_DEFLATE = 8
|
||||
const ZIP_METHOD_STORE = 0;
|
||||
const ZIP_METHOD_DEFLATE = 8;
|
||||
const ZIP_EXTENDED_TIMESTAMP_SIZE = 9;
|
||||
|
||||
const PR_USEC_PER_MSEC = 1000;
|
||||
|
|
|
|||
|
|
@ -11,30 +11,27 @@ const time = 1199145600000; // Jan 1st 2008
|
|||
var TESTS = [
|
||||
{
|
||||
name: "test.txt",
|
||||
compression: Ci.nsIZipWriter.COMPRESSION_DEFAULT
|
||||
compression: Ci.nsIZipWriter.COMPRESSION_DEFAULT,
|
||||
},
|
||||
{
|
||||
name: "test.png",
|
||||
compression: Ci.nsIZipWriter.COMPRESSION_NONE
|
||||
}
|
||||
compression: Ci.nsIZipWriter.COMPRESSION_NONE,
|
||||
},
|
||||
];
|
||||
|
||||
function swap16(n)
|
||||
{
|
||||
return (((n >> 8) & 0xFF) << 0) |
|
||||
(((n >> 0) & 0xFF) << 8);
|
||||
function swap16(n) {
|
||||
return (((n >> 8) & 0xFF) << 0) |
|
||||
(((n >> 0) & 0xFF) << 8);
|
||||
}
|
||||
|
||||
function swap32(n)
|
||||
{
|
||||
return (((n >> 24) & 0xFF) << 0) |
|
||||
(((n >> 16) & 0xFF) << 8) |
|
||||
(((n >> 8) & 0xFF) << 16) |
|
||||
(((n >> 0) & 0xFF) << 24);
|
||||
function swap32(n) {
|
||||
return (((n >> 24) & 0xFF) << 0) |
|
||||
(((n >> 16) & 0xFF) << 8) |
|
||||
(((n >> 8) & 0xFF) << 16) |
|
||||
(((n >> 0) & 0xFF) << 24);
|
||||
}
|
||||
|
||||
function move_to_data(bis, offset)
|
||||
{
|
||||
function move_to_data(bis, offset) {
|
||||
bis.readBytes(18); // Move to compressed size
|
||||
var size = swap32(bis.read32());
|
||||
bis.readBytes(4);
|
||||
|
|
@ -44,11 +41,10 @@ function move_to_data(bis, offset)
|
|||
bis.readBytes(extra_len);
|
||||
offset += ZIP_FILE_HEADER_SIZE + file_len + extra_len;
|
||||
|
||||
return {offset: offset, size: size};
|
||||
return {offset, size};
|
||||
}
|
||||
|
||||
function test_alignment(align_size)
|
||||
{
|
||||
function test_alignment(align_size) {
|
||||
// Create zip for testing.
|
||||
zipW.open(tmpFile, PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE);
|
||||
for (var i = 0; i < TESTS.length; i++) {
|
||||
|
|
@ -103,8 +99,7 @@ function test_alignment(align_size)
|
|||
bis.close();
|
||||
}
|
||||
|
||||
function run_test()
|
||||
{
|
||||
function run_test() {
|
||||
test_alignment(2);
|
||||
test_alignment(4);
|
||||
test_alignment(16);
|
||||
|
|
|
|||
|
|
@ -10,24 +10,22 @@ var TESTS = [
|
|||
{
|
||||
name: "test.txt",
|
||||
size: 232,
|
||||
crc: 0x0373ac26
|
||||
crc: 0x0373ac26,
|
||||
},
|
||||
{
|
||||
name: "test.png",
|
||||
size: 3402,
|
||||
crc: 0x504a5c30
|
||||
}
|
||||
crc: 0x504a5c30,
|
||||
},
|
||||
];
|
||||
|
||||
var size = 0;
|
||||
|
||||
var observer = {
|
||||
onStartRequest: function(request, context)
|
||||
{
|
||||
onStartRequest(request, context) {
|
||||
},
|
||||
|
||||
onStopRequest: function(request, context, status)
|
||||
{
|
||||
onStopRequest(request, context, status) {
|
||||
Assert.equal(status, Cr.NS_OK);
|
||||
|
||||
zipW.close();
|
||||
|
|
@ -57,47 +55,43 @@ var observer = {
|
|||
|
||||
zipR.close();
|
||||
do_test_finished();
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
var methods = {
|
||||
file: function method_file(entry, source)
|
||||
{
|
||||
file: function method_file(entry, source) {
|
||||
zipW.addEntryFile(entry, Ci.nsIZipWriter.COMPRESSION_NONE, source,
|
||||
true);
|
||||
},
|
||||
channel: function method_channel(entry, source)
|
||||
{
|
||||
channel: function method_channel(entry, source) {
|
||||
zipW.addEntryChannel(entry, source.lastModifiedTime * PR_MSEC_PER_SEC,
|
||||
Ci.nsIZipWriter.COMPRESSION_NONE,
|
||||
NetUtil.newChannel({
|
||||
uri: ioSvc.newFileURI(source),
|
||||
loadUsingSystemPrincipal: true
|
||||
loadUsingSystemPrincipal: true,
|
||||
}), true);
|
||||
},
|
||||
stream: function method_stream(entry, source)
|
||||
{
|
||||
stream: function method_stream(entry, source) {
|
||||
zipW.addEntryStream(entry, source.lastModifiedTime * PR_MSEC_PER_SEC,
|
||||
Ci.nsIZipWriter.COMPRESSION_NONE,
|
||||
NetUtil.newChannel({
|
||||
uri: ioSvc.newFileURI(source),
|
||||
loadUsingSystemPrincipal: true
|
||||
loadUsingSystemPrincipal: true,
|
||||
}).open(), true);
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
function run_test()
|
||||
{
|
||||
function run_test() {
|
||||
zipW.open(tmpFile, PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE);
|
||||
|
||||
for (var i = 0; i < TESTS.length; i++) {
|
||||
var source = do_get_file(DATA_DIR+TESTS[i].name);
|
||||
var source = do_get_file(DATA_DIR + TESTS[i].name);
|
||||
for (let method in methods) {
|
||||
var entry = method + "/" + TESTS[i].name;
|
||||
methods[method](entry, source);
|
||||
size += ZIP_FILE_HEADER_SIZE + ZIP_CDS_HEADER_SIZE +
|
||||
(ZIP_EXTENDED_TIMESTAMP_SIZE * 2) +
|
||||
(entry.length*2) + TESTS[i].size;
|
||||
(entry.length * 2) + TESTS[i].size;
|
||||
}
|
||||
}
|
||||
do_test_pending();
|
||||
|
|
|
|||
|
|
@ -6,21 +6,18 @@
|
|||
const FILENAME = "missing.txt";
|
||||
|
||||
var observer = {
|
||||
onStartRequest: function(request, context)
|
||||
{
|
||||
onStartRequest(request, context) {
|
||||
},
|
||||
|
||||
onStopRequest: function(request, context, status)
|
||||
{
|
||||
onStopRequest(request, context, status) {
|
||||
Assert.equal(status, Cr.NS_ERROR_FILE_NOT_FOUND);
|
||||
zipW.close();
|
||||
Assert.equal(ZIP_EOCDR_HEADER_SIZE, tmpFile.fileSize);
|
||||
do_test_finished();
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
function run_test()
|
||||
{
|
||||
function run_test() {
|
||||
zipW.open(tmpFile, PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE);
|
||||
|
||||
var source = tmpDir.clone();
|
||||
|
|
|
|||
|
|
@ -6,21 +6,18 @@
|
|||
const FILENAME = "missing.txt";
|
||||
|
||||
var observer = {
|
||||
onStartRequest: function(request, context)
|
||||
{
|
||||
onStartRequest(request, context) {
|
||||
},
|
||||
|
||||
onStopRequest: function(request, context, status)
|
||||
{
|
||||
onStopRequest(request, context, status) {
|
||||
Assert.equal(status, Cr.NS_ERROR_FILE_NOT_FOUND);
|
||||
zipW.close();
|
||||
Assert.equal(ZIP_EOCDR_HEADER_SIZE, tmpFile.fileSize);
|
||||
do_test_finished();
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
function run_test()
|
||||
{
|
||||
function run_test() {
|
||||
zipW.open(tmpFile, PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE);
|
||||
zipW.removeEntry(FILENAME, true);
|
||||
do_test_pending();
|
||||
|
|
|
|||
|
|
@ -5,16 +5,14 @@
|
|||
|
||||
var TESTS = [
|
||||
"test.txt",
|
||||
"test.png"
|
||||
"test.png",
|
||||
];
|
||||
|
||||
var observer = {
|
||||
onStartRequest: function(request, context)
|
||||
{
|
||||
onStartRequest(request, context) {
|
||||
},
|
||||
|
||||
onStopRequest: function(request, context, status)
|
||||
{
|
||||
onStopRequest(request, context, status) {
|
||||
Assert.equal(status, Cr.NS_OK);
|
||||
|
||||
zipW.close();
|
||||
|
|
@ -23,11 +21,10 @@ var observer = {
|
|||
var newTmpFile = tmpFile.clone();
|
||||
Assert.equal(newTmpFile.fileSize, ZIP_EOCDR_HEADER_SIZE);
|
||||
do_test_finished();
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
function run_test()
|
||||
{
|
||||
function run_test() {
|
||||
// Copy our test zip to the tmp dir so we can modify it
|
||||
var testzip = do_get_file(DATA_DIR + "test.zip");
|
||||
testzip.copyTo(tmpDir, tmpFile.leafName);
|
||||
|
|
|
|||
|
|
@ -21,17 +21,17 @@ BinaryComparer.prototype = {
|
|||
length: null,
|
||||
callback: null,
|
||||
|
||||
onStartRequest: function(aRequest, aContext) {
|
||||
onStartRequest(aRequest, aContext) {
|
||||
},
|
||||
|
||||
onStopRequest: function(aRequest, aContext, aStatusCode) {
|
||||
onStopRequest(aRequest, aContext, aStatusCode) {
|
||||
this.fileStream.close();
|
||||
Assert.equal(aStatusCode, Cr.NS_OK);
|
||||
Assert.equal(this.offset, this.length);
|
||||
this.callback();
|
||||
},
|
||||
|
||||
onDataAvailable: function(aRequest, aContext, aInputStream, aOffset, aCount) {
|
||||
onDataAvailable(aRequest, aContext, aInputStream, aOffset, aCount) {
|
||||
var stream = Cc["@mozilla.org/binaryinputstream;1"].
|
||||
createInstance(Ci.nsIBinaryInputStream);
|
||||
stream.setInputStream(aInputStream);
|
||||
|
|
@ -39,34 +39,30 @@ BinaryComparer.prototype = {
|
|||
for (var i = 0; i < aCount; i++) {
|
||||
try {
|
||||
source = this.fileStream.read8();
|
||||
}
|
||||
catch (e) {
|
||||
} catch (e) {
|
||||
do_throw("Unable to read from file at offset " + this.offset + " " + e);
|
||||
}
|
||||
try {
|
||||
actual = stream.read8();
|
||||
}
|
||||
catch (e) {
|
||||
} catch (e) {
|
||||
do_throw("Unable to read from converted stream at offset " + this.offset + " " + e);
|
||||
}
|
||||
if (source != actual)
|
||||
do_throw("Invalid value " + actual + " at offset " + this.offset + ", should have been " + source);
|
||||
this.offset++;
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
function comparer_callback()
|
||||
{
|
||||
function comparer_callback() {
|
||||
do_test_finished();
|
||||
}
|
||||
|
||||
function run_test()
|
||||
{
|
||||
function run_test() {
|
||||
var source = do_get_file(DATA_DIR + "test_bug399727.html");
|
||||
var comparer = new BinaryComparer(do_get_file(DATA_DIR + "test_bug399727.zlib"),
|
||||
comparer_callback);
|
||||
|
||||
|
||||
// Prepare the stream converter
|
||||
var scs = Cc["@mozilla.org/streamConverters;1"].
|
||||
getService(Ci.nsIStreamConverterService);
|
||||
|
|
|
|||
|
|
@ -9,8 +9,7 @@ const CRC = 0x00000000;
|
|||
// XXX Must use a constant time here away from DST changes. See bug 402434.
|
||||
const time = 1199145600000; // Jan 1st 2008
|
||||
|
||||
function testpass(source)
|
||||
{
|
||||
function testpass(source) {
|
||||
// Should exist.
|
||||
Assert.ok(source.hasEntry(FILENAME));
|
||||
|
||||
|
|
@ -31,8 +30,7 @@ function testpass(source)
|
|||
Assert.equal(entry.CRC32, CRC);
|
||||
}
|
||||
|
||||
function run_test()
|
||||
{
|
||||
function run_test() {
|
||||
zipW.open(tmpFile, PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE);
|
||||
|
||||
// Shouldn't be there to start with.
|
||||
|
|
|
|||
|
|
@ -8,8 +8,7 @@ const FILENAME = "test.txt";
|
|||
const CRC = 0x00000000;
|
||||
const time = Date.now();
|
||||
|
||||
function testpass(source)
|
||||
{
|
||||
function testpass(source) {
|
||||
// Should exist.
|
||||
Assert.ok(source.hasEntry(FILENAME));
|
||||
|
||||
|
|
@ -28,8 +27,7 @@ function testpass(source)
|
|||
Assert.equal(entry.CRC32, CRC);
|
||||
}
|
||||
|
||||
function run_test()
|
||||
{
|
||||
function run_test() {
|
||||
zipW.open(tmpFile, PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE);
|
||||
|
||||
// Shouldn't be there to start with.
|
||||
|
|
|
|||
|
|
@ -6,8 +6,7 @@
|
|||
const DIRNAME = "test/";
|
||||
const time = Date.now();
|
||||
|
||||
function run_test()
|
||||
{
|
||||
function run_test() {
|
||||
// Copy in the test file.
|
||||
var source = do_get_file("data/test.zip");
|
||||
source.copyTo(tmpFile.parent, tmpFile.leafName);
|
||||
|
|
|
|||
|
|
@ -3,71 +3,62 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
function run_test()
|
||||
{
|
||||
function run_test() {
|
||||
var test;
|
||||
// zipW is an uninitialised zipwriter at this point.
|
||||
try {
|
||||
test = zipW.file;
|
||||
do_throw("Should have thrown uninitialized error.");
|
||||
}
|
||||
catch (e) {
|
||||
} catch (e) {
|
||||
Assert.equal(e.result, Cr.NS_ERROR_NOT_INITIALIZED);
|
||||
}
|
||||
|
||||
try {
|
||||
test = zipW.comment;
|
||||
do_throw("Should have thrown uninitialized error.");
|
||||
}
|
||||
catch (e) {
|
||||
} catch (e) {
|
||||
Assert.equal(e.result, Cr.NS_ERROR_NOT_INITIALIZED);
|
||||
}
|
||||
|
||||
try {
|
||||
zipW.comment = "test";
|
||||
do_throw("Should have thrown uninitialized error.");
|
||||
}
|
||||
catch (e) {
|
||||
} catch (e) {
|
||||
Assert.equal(e.result, Cr.NS_ERROR_NOT_INITIALIZED);
|
||||
}
|
||||
|
||||
try {
|
||||
zipW.addEntryDirectory("test", 0, false);
|
||||
do_throw("Should have thrown uninitialized error.");
|
||||
}
|
||||
catch (e) {
|
||||
} catch (e) {
|
||||
Assert.equal(e.result, Cr.NS_ERROR_NOT_INITIALIZED);
|
||||
}
|
||||
|
||||
try {
|
||||
zipW.addEntryFile("test", Ci.nsIZipWriter.COMPRESSION_DEFAULT, tmpDir, false);
|
||||
do_throw("Should have thrown uninitialized error.");
|
||||
}
|
||||
catch (e) {
|
||||
} catch (e) {
|
||||
Assert.equal(e.result, Cr.NS_ERROR_NOT_INITIALIZED);
|
||||
}
|
||||
|
||||
try {
|
||||
zipW.removeEntry("test", false);
|
||||
do_throw("Should have thrown uninitialized error.");
|
||||
}
|
||||
catch (e) {
|
||||
} catch (e) {
|
||||
Assert.equal(e.result, Cr.NS_ERROR_NOT_INITIALIZED);
|
||||
}
|
||||
|
||||
try {
|
||||
zipW.processQueue(null, null);
|
||||
do_throw("Should have thrown uninitialized error.");
|
||||
}
|
||||
catch (e) {
|
||||
} catch (e) {
|
||||
Assert.equal(e.result, Cr.NS_ERROR_NOT_INITIALIZED);
|
||||
}
|
||||
|
||||
try {
|
||||
zipW.close();
|
||||
do_throw("Should have thrown uninitialized error.");
|
||||
}
|
||||
catch (e) {
|
||||
} catch (e) {
|
||||
Assert.equal(e.result, Cr.NS_ERROR_NOT_INITIALIZED);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,17 +5,16 @@ function run_test() {
|
|||
}
|
||||
|
||||
// Add |file| to the zip. |path| is the current path for the file.
|
||||
function AddToZip(zipWriter, path, file)
|
||||
{
|
||||
function AddToZip(zipWriter, path, file) {
|
||||
var currentPath = path + file.leafName;
|
||||
|
||||
|
||||
if (file.isDirectory()) {
|
||||
currentPath += "/";
|
||||
}
|
||||
|
||||
|
||||
// THIS IS WHERE THE ERROR OCCURS, FOR THE FILE "st14-1.tiff" IN "test_bug446708"
|
||||
zipWriter.addEntryFile(currentPath, Ci.nsIZipWriter.COMPRESSION_DEFAULT, file, false);
|
||||
|
||||
|
||||
// if it's a dir, continue adding its contents recursively...
|
||||
if (file.isDirectory()) {
|
||||
var entries = file.QueryInterface(Ci.nsIFile).directoryEntries;
|
||||
|
|
@ -24,14 +23,13 @@ function AddToZip(zipWriter, path, file)
|
|||
AddToZip(zipWriter, currentPath, entry);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ...otherwise, we're done
|
||||
}
|
||||
|
||||
function RecursivelyZipDirectory(bundle)
|
||||
{
|
||||
function RecursivelyZipDirectory(bundle) {
|
||||
zipW.open(tmpFile, PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE);
|
||||
AddToZip(zipW, "", bundle);
|
||||
AddToZip(zipW, "", bundle);
|
||||
zipW.close();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,8 +3,7 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
function run_test()
|
||||
{
|
||||
function run_test() {
|
||||
// In this test we try to open some files that aren't archives:
|
||||
// - An empty file, that is certainly not an archive.
|
||||
// - A file that couldn't be mistaken for archive, since it is too small.
|
||||
|
|
|
|||
|
|
@ -20,17 +20,17 @@ BinaryComparer.prototype = {
|
|||
length: null,
|
||||
callback: null,
|
||||
|
||||
onStartRequest: function(aRequest, aContext) {
|
||||
onStartRequest(aRequest, aContext) {
|
||||
},
|
||||
|
||||
onStopRequest: function(aRequest, aContext, aStatusCode) {
|
||||
onStopRequest(aRequest, aContext, aStatusCode) {
|
||||
this.fileStream.close();
|
||||
Assert.equal(aStatusCode, Cr.NS_OK);
|
||||
Assert.equal(this.offset, this.length);
|
||||
this.callback();
|
||||
},
|
||||
|
||||
onDataAvailable: function(aRequest, aContext, aInputStream, aOffset, aCount) {
|
||||
onDataAvailable(aRequest, aContext, aInputStream, aOffset, aCount) {
|
||||
var stream = Cc["@mozilla.org/binaryinputstream;1"].
|
||||
createInstance(Ci.nsIBinaryInputStream);
|
||||
stream.setInputStream(aInputStream);
|
||||
|
|
@ -38,14 +38,12 @@ BinaryComparer.prototype = {
|
|||
for (var i = 0; i < aCount; i++) {
|
||||
try {
|
||||
source = this.fileStream.read8();
|
||||
}
|
||||
catch (e) {
|
||||
} catch (e) {
|
||||
do_throw("Unable to read from file at offset " + this.offset + " " + e);
|
||||
}
|
||||
try {
|
||||
actual = stream.read8();
|
||||
}
|
||||
catch (e) {
|
||||
} catch (e) {
|
||||
do_throw("Unable to read from converted stream at offset " + this.offset + " " + e);
|
||||
}
|
||||
// The byte at offset 9 is the OS byte (see RFC 1952, section 2.3), which
|
||||
|
|
@ -59,20 +57,18 @@ BinaryComparer.prototype = {
|
|||
do_throw("Invalid value " + actual + " at offset " + this.offset + ", should have been " + source);
|
||||
this.offset++;
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
function comparer_callback()
|
||||
{
|
||||
function comparer_callback() {
|
||||
do_test_finished();
|
||||
}
|
||||
|
||||
function run_test()
|
||||
{
|
||||
function run_test() {
|
||||
var source = do_get_file(DATA_DIR + "test_bug717061.html");
|
||||
var comparer = new BinaryComparer(do_get_file(DATA_DIR + "test_bug717061.gz"),
|
||||
comparer_callback);
|
||||
|
||||
|
||||
// Prepare the stream converter
|
||||
var scs = Cc["@mozilla.org/streamConverters;1"].
|
||||
getService(Ci.nsIStreamConverterService);
|
||||
|
|
|
|||
|
|
@ -3,8 +3,7 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
function run_test()
|
||||
{
|
||||
function run_test() {
|
||||
zipW.open(tmpFile, PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE);
|
||||
zipW.close();
|
||||
|
||||
|
|
|
|||
|
|
@ -9,8 +9,7 @@ const CRC = 0xe6164331;
|
|||
// XXX Must use a constant time here away from DST changes. See bug 402434.
|
||||
const time = 1199145600000; // Jan 1st 2008
|
||||
|
||||
function run_test()
|
||||
{
|
||||
function run_test() {
|
||||
zipW.open(tmpFile, PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE);
|
||||
|
||||
// Shouldn't be there to start with.
|
||||
|
|
|
|||
|
|
@ -8,8 +8,7 @@ const DIRNAME1_CORRECT = "test/";
|
|||
const DIRNAME2 = "test2/";
|
||||
const time = Date.now();
|
||||
|
||||
function run_test()
|
||||
{
|
||||
function run_test() {
|
||||
zipW.open(tmpFile, PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE);
|
||||
|
||||
zipW.addEntryDirectory(DIRNAME1, time * PR_USEC_PER_MSEC, false);
|
||||
|
|
|
|||
|
|
@ -9,19 +9,18 @@ var TESTS = [
|
|||
name: "test.txt",
|
||||
size: 232,
|
||||
crc: 0x0373ac26,
|
||||
time: Date.UTC(2007, 4, 1, 20, 44, 55)
|
||||
time: Date.UTC(2007, 4, 1, 20, 44, 55),
|
||||
},
|
||||
{
|
||||
name: "test.png",
|
||||
size: 3402,
|
||||
crc: 0x504a5c30,
|
||||
time: Date.UTC(2007, 4, 1, 20, 49, 39)
|
||||
}
|
||||
time: Date.UTC(2007, 4, 1, 20, 49, 39),
|
||||
},
|
||||
];
|
||||
var BADENTRY = "unknown.txt";
|
||||
|
||||
function run_test()
|
||||
{
|
||||
function run_test() {
|
||||
// Copy our test zip to the tmp dir so we can modify it
|
||||
var testzip = do_get_file(DATA_DIR + "test.zip");
|
||||
testzip.copyTo(tmpDir, tmpFile.leafName);
|
||||
|
|
@ -43,8 +42,7 @@ function run_test()
|
|||
try {
|
||||
zipW.removeEntry(BADENTRY, false);
|
||||
do_throw("shouldn't be able to remove an entry that doesn't exist");
|
||||
}
|
||||
catch (e) {
|
||||
} catch (e) {
|
||||
Assert.equal(e.result, Cr.NS_ERROR_FILE_NOT_FOUND);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,8 +10,7 @@ const CRC = 0xe6164331;
|
|||
// XXX Must use a constant time here away from DST changes. See bug 402434.
|
||||
const time = 1199145600000; // Jan 1st 2008
|
||||
|
||||
function testpass(source)
|
||||
{
|
||||
function testpass(source) {
|
||||
// Should exist.
|
||||
Assert.ok(source.hasEntry(FILENAME));
|
||||
|
||||
|
|
@ -34,8 +33,7 @@ function testpass(source)
|
|||
Assert.equal(entry.CRC32, CRC);
|
||||
}
|
||||
|
||||
function run_test()
|
||||
{
|
||||
function run_test() {
|
||||
zipW.open(tmpFile, PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE);
|
||||
|
||||
// Shouldn't be there to start with.
|
||||
|
|
|
|||
|
|
@ -8,17 +8,16 @@ var TESTS = [
|
|||
{
|
||||
name: "test.txt",
|
||||
size: 232,
|
||||
crc: 0x0373ac26
|
||||
crc: 0x0373ac26,
|
||||
},
|
||||
{
|
||||
name: "test.png",
|
||||
size: 3402,
|
||||
crc: 0x504a5c30
|
||||
}
|
||||
crc: 0x504a5c30,
|
||||
},
|
||||
];
|
||||
|
||||
function run_test()
|
||||
{
|
||||
function run_test() {
|
||||
zipW.open(tmpFile, PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE);
|
||||
|
||||
var size = 0;
|
||||
|
|
@ -28,7 +27,7 @@ function run_test()
|
|||
false);
|
||||
size += ZIP_FILE_HEADER_SIZE + ZIP_CDS_HEADER_SIZE +
|
||||
(ZIP_EXTENDED_TIMESTAMP_SIZE * 2) +
|
||||
(TESTS[i].name.length*2) + TESTS[i].size;
|
||||
(TESTS[i].name.length * 2) + TESTS[i].size;
|
||||
}
|
||||
|
||||
zipW.close();
|
||||
|
|
|
|||
|
|
@ -6,11 +6,10 @@
|
|||
// Values taken from using zipinfo to list the test.zip contents
|
||||
var TESTS = [
|
||||
"test.txt",
|
||||
"test.png"
|
||||
"test.png",
|
||||
];
|
||||
|
||||
function run_test()
|
||||
{
|
||||
function run_test() {
|
||||
zipW.open(tmpFile, PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE);
|
||||
|
||||
for (var i = 0; i < TESTS.length; i++) {
|
||||
|
|
@ -24,8 +23,7 @@ function run_test()
|
|||
zipW.addEntryFile(TESTS[0], Ci.nsIZipWriter.COMPRESSION_NONE, source,
|
||||
false);
|
||||
do_throw("Should not be able to add the same file twice");
|
||||
}
|
||||
catch (e) {
|
||||
} catch (e) {
|
||||
Assert.equal(e.result, Cr.NS_ERROR_FILE_ALREADY_EXISTS);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,8 +6,7 @@
|
|||
const DATA = "ZIP WRITER TEST COMMENT";
|
||||
const DATA2 = "ANOTHER ONE";
|
||||
|
||||
function run_test()
|
||||
{
|
||||
function run_test() {
|
||||
zipW.open(tmpFile, PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE);
|
||||
zipW.comment = DATA;
|
||||
zipW.close();
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ function build_tests() {
|
|||
for (let o = 0; o <= 7; o++) {
|
||||
TESTS[id] = {
|
||||
name: "test" + u + g + o,
|
||||
permission: (u << 6) + (g << 3) + o
|
||||
permission: (u << 6) + (g << 3) + o,
|
||||
};
|
||||
id++;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
function run_test() {
|
||||
|
||||
/**
|
||||
* Creates MAR from the passed files, compares it to the reference MAR.
|
||||
*
|
||||
|
|
@ -102,7 +101,7 @@ function run_test() {
|
|||
if (outMAR.exists()) {
|
||||
outMAR.remove(false);
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
// Run all the tests
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
function run_test() {
|
||||
|
||||
/**
|
||||
* Extracts a MAR and makes sure each file matches the reference files.
|
||||
*
|
||||
|
|
@ -114,7 +113,7 @@ function run_test() {
|
|||
return extract_and_fail("manipulated_frontend_collision.mar");
|
||||
},
|
||||
// Test collision detection where file B ends in file A's indexes
|
||||
test_collsion_b_onto_a: function test_collsion_b_onto_a() {
|
||||
test_collsion_b_onto_a: function test_collsion_b_onto_a() {
|
||||
return extract_and_fail("manipulated_backend_collision.mar");
|
||||
},
|
||||
// Test collision detection where file C shares indexes with both file A & B
|
||||
|
|
@ -137,7 +136,7 @@ function run_test() {
|
|||
if (outDir.exists()) {
|
||||
outDir.remove(true);
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
// Run all the tests
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
function run_test() {
|
||||
|
||||
/**
|
||||
* Signs a MAR file.
|
||||
*
|
||||
|
|
@ -568,7 +567,7 @@ function run_test() {
|
|||
},
|
||||
// Between each test make sure the out MAR does not exist.
|
||||
cleanup_per_test: function _cleanup_per_test() {
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
cleanup();
|
||||
|
|
|
|||
|
|
@ -4,8 +4,7 @@
|
|||
|
||||
const NS_APP_USER_PROFILE_50_DIR = "ProfD";
|
||||
|
||||
function do_check_throws(f, result, stack)
|
||||
{
|
||||
function do_check_throws(f, result, stack) {
|
||||
if (!stack)
|
||||
stack = Components.stack.caller;
|
||||
|
||||
|
|
@ -22,18 +21,12 @@ var dirSvc = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProper
|
|||
|
||||
// Register current test directory as provider for the profile directory.
|
||||
var provider = {
|
||||
getFile: function(prop, persistent) {
|
||||
getFile(prop, persistent) {
|
||||
persistent.value = true;
|
||||
if (prop == NS_APP_USER_PROFILE_50_DIR)
|
||||
return dirSvc.get("CurProcD", Ci.nsIFile);
|
||||
throw Components.Exception("Tried to get test directory '" + prop + "'", Cr.NS_ERROR_FAILURE);
|
||||
},
|
||||
QueryInterface: function(iid) {
|
||||
if (iid.equals(Ci.nsIDirectoryServiceProvider) ||
|
||||
iid.equals(Ci.nsISupports)) {
|
||||
return this;
|
||||
}
|
||||
throw Cr.NS_ERROR_NO_INTERFACE;
|
||||
}
|
||||
QueryInterface: ChromeUtils.generateQI(["nsIDirectoryServiceProvider"]),
|
||||
};
|
||||
dirSvc.QueryInterface(Ci.nsIDirectoryService).registerProvider(provider);
|
||||
|
|
|
|||
|
|
@ -18,6 +18,6 @@ function run_test() {
|
|||
let pb = ps.getBranch(BRANCH);
|
||||
|
||||
let floatPref = pb.getFloatPref(PREF_NAME);
|
||||
Assert.ok(FLOAT+FUDGE >= floatPref);
|
||||
Assert.ok(FLOAT-FUDGE <= floatPref);
|
||||
Assert.ok(FLOAT + FUDGE >= floatPref);
|
||||
Assert.ok(FLOAT - FUDGE <= floatPref);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/licenses/publicdomain/ */
|
||||
* http://creativecommons.org/licenses/publicdomain/ */
|
||||
|
||||
// Regression test for bug 345529 - crash removing an observer during an
|
||||
// nsPref:changed notification.
|
||||
|
|
@ -9,24 +9,19 @@ function run_test() {
|
|||
var prefs = Cc["@mozilla.org/preferences-service;1"]
|
||||
.getService(Ci.nsIPrefBranch);
|
||||
var observer = {
|
||||
QueryInterface: function QueryInterface(aIID) {
|
||||
if (aIID.equals(Ci.nsIObserver) ||
|
||||
aIID.equals(Ci.nsISupports))
|
||||
return this;
|
||||
throw Cr.NS_NOINTERFACE;
|
||||
},
|
||||
QueryInterface: ChromeUtils.generateQI(["nsIObserver"]),
|
||||
|
||||
observe: function observe(aSubject, aTopic, aState) {
|
||||
prefs.removeObserver(PREF_NAME, observer);
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
prefs.addObserver(PREF_NAME, observer);
|
||||
|
||||
prefs.setCharPref(PREF_NAME, "test0")
|
||||
// This second call isn't needed on a clean profile: it makes sure
|
||||
prefs.setCharPref(PREF_NAME, "test0");
|
||||
// This second call isn't needed on a clean profile: it makes sure
|
||||
// the observer gets called even if the pref already had the value
|
||||
// "test0" before this test.
|
||||
prefs.setCharPref(PREF_NAME, "test1")
|
||||
prefs.setCharPref(PREF_NAME, "test1");
|
||||
|
||||
Assert.ok(true);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,17 +10,12 @@ function run_test() {
|
|||
getService(Ci.nsIPrefBranch);
|
||||
|
||||
var observer = {
|
||||
QueryInterface: function QueryInterface(aIID) {
|
||||
if (aIID.equals(Ci.nsIObserver) ||
|
||||
aIID.equals(Ci.nsISupports))
|
||||
return this;
|
||||
throw Cr.NS_NOINTERFACE;
|
||||
},
|
||||
QueryInterface: ChromeUtils.generateQI(["nsIObserver"]),
|
||||
|
||||
observe: function observe(aSubject, aTopic, aState) {
|
||||
// Don't do anything.
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
/* Set the same pref twice. This shouldn't leak. */
|
||||
pb.addObserver("UserPref.nonexistent.setIntPref", observer);
|
||||
|
|
|
|||
|
|
@ -15,8 +15,8 @@ function run_test() {
|
|||
var myFloat = 9.674;
|
||||
var fudge = 0.001;
|
||||
var floatPref = userprefs.getFloatPref(PREF_NAME);
|
||||
Assert.ok(myFloat+fudge >= floatPref);
|
||||
Assert.ok(myFloat-fudge <= floatPref);
|
||||
Assert.ok(myFloat + fudge >= floatPref);
|
||||
Assert.ok(myFloat - fudge <= floatPref);
|
||||
|
||||
/* Now test some failure conditions. */
|
||||
prefs.unlockPref(PREF_NAME);
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ const PREF_INT = 64;
|
|||
const PREF_STRING = 32;
|
||||
|
||||
function run_test() {
|
||||
|
||||
var ps = Cc["@mozilla.org/preferences-service;1"].
|
||||
getService(Ci.nsIPrefService);
|
||||
|
||||
|
|
@ -52,47 +51,65 @@ function run_test() {
|
|||
// We only have a default value, and we try to set a default value of a
|
||||
// different type --> fails.
|
||||
do_check_throws(function() {
|
||||
defaultBranch.setCharPref("TypeTest.default.bool", "boo"); }, Cr.NS_ERROR_UNEXPECTED);
|
||||
defaultBranch.setCharPref("TypeTest.default.bool", "boo");
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
do_check_throws(function() {
|
||||
defaultBranch.setIntPref("TypeTest.default.bool", 5); }, Cr.NS_ERROR_UNEXPECTED);
|
||||
defaultBranch.setIntPref("TypeTest.default.bool", 5);
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
do_check_throws(function() {
|
||||
defaultBranch.setCharPref("TypeTest.default.int", "boo"); }, Cr.NS_ERROR_UNEXPECTED);
|
||||
defaultBranch.setCharPref("TypeTest.default.int", "boo");
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
do_check_throws(function() {
|
||||
defaultBranch.setBoolPref("TypeTest.default.int", true); }, Cr.NS_ERROR_UNEXPECTED);
|
||||
defaultBranch.setBoolPref("TypeTest.default.int", true);
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
do_check_throws(function() {
|
||||
defaultBranch.setBoolPref("TypeTest.default.char", true); }, Cr.NS_ERROR_UNEXPECTED);
|
||||
defaultBranch.setBoolPref("TypeTest.default.char", true);
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
do_check_throws(function() {
|
||||
defaultBranch.setIntPref("TypeTest.default.char", 6); }, Cr.NS_ERROR_UNEXPECTED);
|
||||
defaultBranch.setIntPref("TypeTest.default.char", 6);
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
|
||||
// We only have a default value, and we try to set a user value of a
|
||||
// different type --> fails.
|
||||
do_check_throws(function() {
|
||||
userBranch.setCharPref("TypeTest.default.bool", "boo"); }, Cr.NS_ERROR_UNEXPECTED);
|
||||
userBranch.setCharPref("TypeTest.default.bool", "boo");
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
do_check_throws(function() {
|
||||
userBranch.setIntPref("TypeTest.default.bool", 5); }, Cr.NS_ERROR_UNEXPECTED);
|
||||
userBranch.setIntPref("TypeTest.default.bool", 5);
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
do_check_throws(function() {
|
||||
userBranch.setCharPref("TypeTest.default.int", "boo"); }, Cr.NS_ERROR_UNEXPECTED);
|
||||
userBranch.setCharPref("TypeTest.default.int", "boo");
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
do_check_throws(function() {
|
||||
userBranch.setBoolPref("TypeTest.default.int", true); }, Cr.NS_ERROR_UNEXPECTED);
|
||||
userBranch.setBoolPref("TypeTest.default.int", true);
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
do_check_throws(function() {
|
||||
userBranch.setBoolPref("TypeTest.default.char", true); }, Cr.NS_ERROR_UNEXPECTED);
|
||||
userBranch.setBoolPref("TypeTest.default.char", true);
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
do_check_throws(function() {
|
||||
userBranch.setIntPref("TypeTest.default.char", 6); }, Cr.NS_ERROR_UNEXPECTED);
|
||||
userBranch.setIntPref("TypeTest.default.char", 6);
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
|
||||
// We only have a user value, and we try to set a default value of a
|
||||
// different type --> fails.
|
||||
do_check_throws(function() {
|
||||
defaultBranch.setCharPref("TypeTest.user.bool", "boo"); }, Cr.NS_ERROR_UNEXPECTED);
|
||||
defaultBranch.setCharPref("TypeTest.user.bool", "boo");
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
do_check_throws(function() {
|
||||
defaultBranch.setIntPref("TypeTest.user.bool", 5); }, Cr.NS_ERROR_UNEXPECTED);
|
||||
defaultBranch.setIntPref("TypeTest.user.bool", 5);
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
do_check_throws(function() {
|
||||
defaultBranch.setCharPref("TypeTest.user.int", "boo"); }, Cr.NS_ERROR_UNEXPECTED);
|
||||
defaultBranch.setCharPref("TypeTest.user.int", "boo");
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
do_check_throws(function() {
|
||||
defaultBranch.setBoolPref("TypeTest.user.int", true); }, Cr.NS_ERROR_UNEXPECTED);
|
||||
defaultBranch.setBoolPref("TypeTest.user.int", true);
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
do_check_throws(function() {
|
||||
defaultBranch.setBoolPref("TypeTest.user.char", true); }, Cr.NS_ERROR_UNEXPECTED);
|
||||
defaultBranch.setBoolPref("TypeTest.user.char", true);
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
do_check_throws(function() {
|
||||
defaultBranch.setIntPref("TypeTest.user.char", 6); }, Cr.NS_ERROR_UNEXPECTED);
|
||||
defaultBranch.setIntPref("TypeTest.user.char", 6);
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
|
||||
// We only have a user value, and we try to set a user value of a
|
||||
// different type --> SUCCEEDS.
|
||||
|
|
@ -112,30 +129,42 @@ function run_test() {
|
|||
// We have both a default value and user value, and we try to set a default
|
||||
// value of a different type --> fails.
|
||||
do_check_throws(function() {
|
||||
defaultBranch.setCharPref("TypeTest.both.bool", "boo"); }, Cr.NS_ERROR_UNEXPECTED);
|
||||
defaultBranch.setCharPref("TypeTest.both.bool", "boo");
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
do_check_throws(function() {
|
||||
defaultBranch.setIntPref("TypeTest.both.bool", 5); }, Cr.NS_ERROR_UNEXPECTED);
|
||||
defaultBranch.setIntPref("TypeTest.both.bool", 5);
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
do_check_throws(function() {
|
||||
defaultBranch.setCharPref("TypeTest.both.int", "boo"); }, Cr.NS_ERROR_UNEXPECTED);
|
||||
defaultBranch.setCharPref("TypeTest.both.int", "boo");
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
do_check_throws(function() {
|
||||
defaultBranch.setBoolPref("TypeTest.both.int", true); }, Cr.NS_ERROR_UNEXPECTED);
|
||||
defaultBranch.setBoolPref("TypeTest.both.int", true);
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
do_check_throws(function() {
|
||||
defaultBranch.setBoolPref("TypeTest.both.char", true); }, Cr.NS_ERROR_UNEXPECTED);
|
||||
defaultBranch.setBoolPref("TypeTest.both.char", true);
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
do_check_throws(function() {
|
||||
defaultBranch.setIntPref("TypeTest.both.char", 6); }, Cr.NS_ERROR_UNEXPECTED);
|
||||
defaultBranch.setIntPref("TypeTest.both.char", 6);
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
|
||||
// We have both a default value and user value, and we try to set a user
|
||||
// value of a different type --> fails.
|
||||
do_check_throws(function() {
|
||||
userBranch.setCharPref("TypeTest.both.bool", "boo"); }, Cr.NS_ERROR_UNEXPECTED);
|
||||
userBranch.setCharPref("TypeTest.both.bool", "boo");
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
do_check_throws(function() {
|
||||
userBranch.setIntPref("TypeTest.both.bool", 5); }, Cr.NS_ERROR_UNEXPECTED);
|
||||
userBranch.setIntPref("TypeTest.both.bool", 5);
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
do_check_throws(function() {
|
||||
userBranch.setCharPref("TypeTest.both.int", "boo"); }, Cr.NS_ERROR_UNEXPECTED);
|
||||
userBranch.setCharPref("TypeTest.both.int", "boo");
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
do_check_throws(function() {
|
||||
userBranch.setBoolPref("TypeTest.both.int", true); }, Cr.NS_ERROR_UNEXPECTED);
|
||||
userBranch.setBoolPref("TypeTest.both.int", true);
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
do_check_throws(function() {
|
||||
userBranch.setBoolPref("TypeTest.both.char", true); }, Cr.NS_ERROR_UNEXPECTED);
|
||||
userBranch.setBoolPref("TypeTest.both.char", true);
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
do_check_throws(function() {
|
||||
userBranch.setIntPref("TypeTest.both.char", 6); }, Cr.NS_ERROR_UNEXPECTED);
|
||||
userBranch.setIntPref("TypeTest.both.char", 6);
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ const PREF_INT = 64;
|
|||
const PREF_STRING = 32;
|
||||
|
||||
function run_test() {
|
||||
|
||||
var ps = Cc["@mozilla.org/preferences-service;1"].
|
||||
getService(Ci.nsIPrefService);
|
||||
|
||||
|
|
@ -20,7 +19,7 @@ function run_test() {
|
|||
let prefFile = do_get_profile();
|
||||
prefFile.append("prefs.js");
|
||||
|
||||
//**************************************************************************//
|
||||
//* *************************************************************************//
|
||||
// prefs are not dirty after a write
|
||||
ps.savePrefFile(null);
|
||||
Assert.ok(!ps.dirty);
|
||||
|
|
@ -58,7 +57,8 @@ function run_test() {
|
|||
Assert.ok(!ps.dirty);
|
||||
// Fail to change type of a pref with default value -> not dirty
|
||||
do_check_throws(function() {
|
||||
userBranch.setCharPref("DirtyTest.existing.bool", "boo"); }, Cr.NS_ERROR_UNEXPECTED);
|
||||
userBranch.setCharPref("DirtyTest.existing.bool", "boo");
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
Assert.ok(!ps.dirty);
|
||||
|
||||
// Set user value same as default, not dirty
|
||||
|
|
|
|||
|
|
@ -9,64 +9,77 @@ const PREF_STRING = 32;
|
|||
|
||||
const MAX_PREF_LENGTH = 1 * 1024 * 1024;
|
||||
|
||||
function makeList(a)
|
||||
{
|
||||
function makeList(a) {
|
||||
var o = {};
|
||||
for(var i=0; i<a.length; i++)
|
||||
{
|
||||
o[a[i]] = '';
|
||||
for (var i = 0; i < a.length; i++) {
|
||||
o[a[i]] = "";
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
|
||||
var ps = Cc["@mozilla.org/preferences-service;1"].
|
||||
getService(Ci.nsIPrefService);
|
||||
|
||||
var pb2= Cc["@mozilla.org/preferences-service;1"].
|
||||
var pb2 = Cc["@mozilla.org/preferences-service;1"].
|
||||
getService(Ci.nsIPrefBranch);
|
||||
|
||||
var pb = Cc["@mozilla.org/preferences-service;1"].
|
||||
getService(Ci.nsIPrefBranch);
|
||||
|
||||
//**************************************************************************//
|
||||
//* *************************************************************************//
|
||||
// Nullsafety
|
||||
|
||||
do_check_throws(function() {
|
||||
pb.getPrefType(null); }, Cr.NS_ERROR_INVALID_ARG);
|
||||
pb.getPrefType(null);
|
||||
}, Cr.NS_ERROR_INVALID_ARG);
|
||||
do_check_throws(function() {
|
||||
pb.getBoolPref(null); }, Cr.NS_ERROR_INVALID_ARG);
|
||||
pb.getBoolPref(null);
|
||||
}, Cr.NS_ERROR_INVALID_ARG);
|
||||
do_check_throws(function() {
|
||||
pb.setBoolPref(null, false); }, Cr.NS_ERROR_INVALID_ARG);
|
||||
pb.setBoolPref(null, false);
|
||||
}, Cr.NS_ERROR_INVALID_ARG);
|
||||
do_check_throws(function() {
|
||||
pb.getIntPref(null); }, Cr.NS_ERROR_INVALID_ARG);
|
||||
pb.getIntPref(null);
|
||||
}, Cr.NS_ERROR_INVALID_ARG);
|
||||
do_check_throws(function() {
|
||||
pb.setIntPref(null, 0); }, Cr.NS_ERROR_INVALID_ARG);
|
||||
pb.setIntPref(null, 0);
|
||||
}, Cr.NS_ERROR_INVALID_ARG);
|
||||
do_check_throws(function() {
|
||||
pb.getCharPref(null); }, Cr.NS_ERROR_INVALID_ARG);
|
||||
pb.getCharPref(null);
|
||||
}, Cr.NS_ERROR_INVALID_ARG);
|
||||
do_check_throws(function() {
|
||||
pb.setCharPref(null, null); }, Cr.NS_ERROR_INVALID_ARG);
|
||||
pb.setCharPref(null, null);
|
||||
}, Cr.NS_ERROR_INVALID_ARG);
|
||||
do_check_throws(function() {
|
||||
pb.getStringPref(null); }, Cr.NS_ERROR_INVALID_ARG);
|
||||
pb.getStringPref(null);
|
||||
}, Cr.NS_ERROR_INVALID_ARG);
|
||||
do_check_throws(function() {
|
||||
pb.setStringPref(null, null); }, Cr.NS_ERROR_INVALID_ARG);
|
||||
pb.setStringPref(null, null);
|
||||
}, Cr.NS_ERROR_INVALID_ARG);
|
||||
do_check_throws(function() {
|
||||
pb.clearUserPref(null); }, Cr.NS_ERROR_INVALID_ARG);
|
||||
pb.clearUserPref(null);
|
||||
}, Cr.NS_ERROR_INVALID_ARG);
|
||||
do_check_throws(function() {
|
||||
pb.prefHasUserValue(null); }, Cr.NS_ERROR_INVALID_ARG);
|
||||
pb.prefHasUserValue(null);
|
||||
}, Cr.NS_ERROR_INVALID_ARG);
|
||||
do_check_throws(function() {
|
||||
pb.lockPref(null); }, Cr.NS_ERROR_INVALID_ARG);
|
||||
pb.lockPref(null);
|
||||
}, Cr.NS_ERROR_INVALID_ARG);
|
||||
do_check_throws(function() {
|
||||
pb.prefIsLocked(null); }, Cr.NS_ERROR_INVALID_ARG);
|
||||
pb.prefIsLocked(null);
|
||||
}, Cr.NS_ERROR_INVALID_ARG);
|
||||
do_check_throws(function() {
|
||||
pb.unlockPref(null); }, Cr.NS_ERROR_INVALID_ARG);
|
||||
pb.unlockPref(null);
|
||||
}, Cr.NS_ERROR_INVALID_ARG);
|
||||
do_check_throws(function() {
|
||||
pb.deleteBranch(null); }, Cr.NS_ERROR_INVALID_ARG);
|
||||
pb.deleteBranch(null);
|
||||
}, Cr.NS_ERROR_INVALID_ARG);
|
||||
do_check_throws(function() {
|
||||
pb.getChildList(null); }, Cr.NS_ERROR_INVALID_ARG);
|
||||
pb.getChildList(null);
|
||||
}, Cr.NS_ERROR_INVALID_ARG);
|
||||
|
||||
//**************************************************************************//
|
||||
//* *************************************************************************//
|
||||
// Nonexisting user preferences
|
||||
|
||||
Assert.equal(pb.prefHasUserValue("UserPref.nonexistent.hasUserValue"), false);
|
||||
|
|
@ -76,23 +89,26 @@ function run_test() {
|
|||
|
||||
// bool...
|
||||
do_check_throws(function() {
|
||||
pb.getBoolPref("UserPref.nonexistent.getBoolPref");}, Cr.NS_ERROR_UNEXPECTED);
|
||||
pb.getBoolPref("UserPref.nonexistent.getBoolPref");
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
pb.setBoolPref("UserPref.nonexistent.setBoolPref", false);
|
||||
Assert.equal(pb.getBoolPref("UserPref.nonexistent.setBoolPref"), false);
|
||||
|
||||
// int...
|
||||
do_check_throws(function() {
|
||||
pb.getIntPref("UserPref.nonexistent.getIntPref");}, Cr.NS_ERROR_UNEXPECTED);
|
||||
pb.getIntPref("UserPref.nonexistent.getIntPref");
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
pb.setIntPref("UserPref.nonexistent.setIntPref", 5);
|
||||
Assert.equal(pb.getIntPref("UserPref.nonexistent.setIntPref"), 5);
|
||||
|
||||
// char
|
||||
do_check_throws(function() {
|
||||
pb.getCharPref("UserPref.nonexistent.getCharPref");}, Cr.NS_ERROR_UNEXPECTED);
|
||||
pb.getCharPref("UserPref.nonexistent.getCharPref");
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
pb.setCharPref("UserPref.nonexistent.setCharPref", "_test");
|
||||
Assert.equal(pb.getCharPref("UserPref.nonexistent.setCharPref"), "_test");
|
||||
|
||||
//**************************************************************************//
|
||||
//* *************************************************************************//
|
||||
// Existing user Prefs and data integrity test (round-trip match)
|
||||
|
||||
pb.setBoolPref("UserPref.existing.bool", true);
|
||||
|
|
@ -125,16 +141,17 @@ function run_test() {
|
|||
pb.clearUserPref("UserPref.existing.char");
|
||||
Assert.ok(!pb.prefHasUserValue("UserPref.existing.char"));
|
||||
|
||||
//**************************************************************************//
|
||||
//* *************************************************************************//
|
||||
// Large value test
|
||||
|
||||
let largeStr = new Array(MAX_PREF_LENGTH + 1).join('x');
|
||||
let largeStr = new Array(MAX_PREF_LENGTH + 1).join("x");
|
||||
pb.setCharPref("UserPref.large.char", largeStr);
|
||||
largeStr += 'x';
|
||||
largeStr += "x";
|
||||
do_check_throws(function() {
|
||||
pb.setCharPref("UserPref.large.char", largeStr); }, Cr.NS_ERROR_ILLEGAL_VALUE);
|
||||
pb.setCharPref("UserPref.large.char", largeStr);
|
||||
}, Cr.NS_ERROR_ILLEGAL_VALUE);
|
||||
|
||||
//**************************************************************************//
|
||||
//* *************************************************************************//
|
||||
// getPrefType test
|
||||
|
||||
// bool...
|
||||
|
|
@ -149,9 +166,9 @@ function run_test() {
|
|||
pb.setCharPref("UserPref.getPrefType.char", "testing1..2");
|
||||
Assert.equal(pb.getPrefType("UserPref.getPrefType.char"), PREF_STRING);
|
||||
|
||||
//**************************************************************************//
|
||||
//* *************************************************************************//
|
||||
// getBranch tests
|
||||
|
||||
|
||||
Assert.equal(ps.root, "");
|
||||
|
||||
// bool ...
|
||||
|
|
@ -184,7 +201,7 @@ function run_test() {
|
|||
pb_3 = ps.getBranch("UserPref.root.charPre");
|
||||
Assert.equal(pb_3.getCharPref("f.anotherPref"), "_another");
|
||||
|
||||
//**************************************************************************//
|
||||
//* *************************************************************************//
|
||||
// getChildlist tests
|
||||
|
||||
// get an already set prefBranch
|
||||
|
|
@ -200,54 +217,56 @@ function run_test() {
|
|||
Assert.ok("intPref.anotherPref" in makeList(prefList));
|
||||
Assert.ok("charPref.anotherPref" in makeList(prefList));
|
||||
|
||||
//**************************************************************************//
|
||||
//* *************************************************************************//
|
||||
// Default branch tests
|
||||
|
||||
// bool...
|
||||
pb1 = ps.getDefaultBranch("");
|
||||
pb1.setBoolPref("DefaultPref.bool", true);
|
||||
Assert.equal(pb1.getBoolPref("DefaultPref.bool"), true);
|
||||
Assert.equal(pb1.getBoolPref("DefaultPref.bool"), true);
|
||||
Assert.ok(!pb1.prefHasUserValue("DefaultPref.bool"));
|
||||
ps.setBoolPref("DefaultPref.bool", false);
|
||||
Assert.ok(pb1.prefHasUserValue("DefaultPref.bool"));
|
||||
Assert.equal(ps.getBoolPref("DefaultPref.bool"), false);
|
||||
Assert.equal(ps.getBoolPref("DefaultPref.bool"), false);
|
||||
|
||||
// int...
|
||||
pb1 = ps.getDefaultBranch("");
|
||||
pb1.setIntPref("DefaultPref.int", 100);
|
||||
Assert.equal(pb1.getIntPref("DefaultPref.int"), 100);
|
||||
Assert.equal(pb1.getIntPref("DefaultPref.int"), 100);
|
||||
Assert.ok(!pb1.prefHasUserValue("DefaultPref.int"));
|
||||
ps.setIntPref("DefaultPref.int", 50);
|
||||
Assert.ok(pb1.prefHasUserValue("DefaultPref.int"));
|
||||
Assert.equal(ps.getIntPref("DefaultPref.int"), 50);
|
||||
Assert.equal(ps.getIntPref("DefaultPref.int"), 50);
|
||||
|
||||
// char...
|
||||
pb1 = ps.getDefaultBranch("");
|
||||
pb1.setCharPref("DefaultPref.char", "_default");
|
||||
Assert.equal(pb1.getCharPref("DefaultPref.char"), "_default");
|
||||
Assert.equal(pb1.getCharPref("DefaultPref.char"), "_default");
|
||||
Assert.ok(!pb1.prefHasUserValue("DefaultPref.char"));
|
||||
ps.setCharPref("DefaultPref.char", "_user");
|
||||
Assert.ok(pb1.prefHasUserValue("DefaultPref.char"));
|
||||
Assert.equal(ps.getCharPref("DefaultPref.char"), "_user");
|
||||
Assert.equal(ps.getCharPref("DefaultPref.char"), "_user");
|
||||
|
||||
//**************************************************************************//
|
||||
//* *************************************************************************//
|
||||
// pref Locking/Unlocking tests
|
||||
|
||||
// locking and unlocking a nonexistent pref should throw
|
||||
do_check_throws(function() {
|
||||
ps.lockPref("DefaultPref.nonexistent");}, Cr.NS_ERROR_ILLEGAL_VALUE);
|
||||
ps.lockPref("DefaultPref.nonexistent");
|
||||
}, Cr.NS_ERROR_ILLEGAL_VALUE);
|
||||
do_check_throws(function() {
|
||||
ps.unlockPref("DefaultPref.nonexistent");}, Cr.NS_ERROR_ILLEGAL_VALUE);
|
||||
ps.unlockPref("DefaultPref.nonexistent");
|
||||
}, Cr.NS_ERROR_ILLEGAL_VALUE);
|
||||
|
||||
// getting a locked pref branch should return the "default" value
|
||||
Assert.ok(!ps.prefIsLocked("DefaultPref.char"));
|
||||
ps.lockPref("DefaultPref.char");
|
||||
Assert.equal(ps.getCharPref("DefaultPref.char"), "_default");
|
||||
Assert.equal(ps.getCharPref("DefaultPref.char"), "_default");
|
||||
Assert.ok(ps.prefIsLocked("DefaultPref.char"));
|
||||
|
||||
// getting an unlocked pref branch should return the "user" value
|
||||
// getting an unlocked pref branch should return the "user" value
|
||||
ps.unlockPref("DefaultPref.char");
|
||||
Assert.equal(ps.getCharPref("DefaultPref.char"), "_user");
|
||||
Assert.equal(ps.getCharPref("DefaultPref.char"), "_user");
|
||||
Assert.ok(!ps.prefIsLocked("DefaultPref.char"));
|
||||
|
||||
// setting the "default" value to a user pref branch should
|
||||
|
|
@ -260,17 +279,17 @@ function run_test() {
|
|||
ps.lockPref("DefaultPref.char");
|
||||
ps.lockPref("DefaultPref.char");
|
||||
|
||||
//**************************************************************************//
|
||||
//* *************************************************************************//
|
||||
// resetBranch test
|
||||
|
||||
// NOT IMPLEMENTED YET in module/libpref. So we're not testing !
|
||||
// uncomment the following if resetBranch ever gets implemented.
|
||||
/*ps.resetBranch("DefaultPref");
|
||||
/* ps.resetBranch("DefaultPref");
|
||||
do_check_eq(ps.getBoolPref("DefaultPref.bool"), true);
|
||||
do_check_eq(ps.getIntPref("DefaultPref.int"), 100);
|
||||
do_check_eq(ps.getCharPref("DefaultPref.char"), "_default");*/
|
||||
|
||||
//**************************************************************************//
|
||||
//* *************************************************************************//
|
||||
// deleteBranch tests
|
||||
|
||||
// TODO : Really, this should throw!, by documentation.
|
||||
|
|
@ -283,21 +302,27 @@ function run_test() {
|
|||
|
||||
// getting prefs on deleted user branches should throw
|
||||
do_check_throws(function() {
|
||||
pb.getBoolPref("DefaultPref.bool");}, Cr.NS_ERROR_UNEXPECTED);
|
||||
pb.getBoolPref("DefaultPref.bool");
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
do_check_throws(function() {
|
||||
pb.getIntPref("DefaultPref.int");}, Cr.NS_ERROR_UNEXPECTED);
|
||||
pb.getIntPref("DefaultPref.int");
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
do_check_throws(function() {
|
||||
pb.getCharPref("DefaultPref.char");}, Cr.NS_ERROR_UNEXPECTED);
|
||||
pb.getCharPref("DefaultPref.char");
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
|
||||
// getting prefs on deleted default branches should throw
|
||||
do_check_throws(function() {
|
||||
pb1.getBoolPref("DefaultPref.bool");}, Cr.NS_ERROR_UNEXPECTED);
|
||||
pb1.getBoolPref("DefaultPref.bool");
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
do_check_throws(function() {
|
||||
pb1.getIntPref("DefaultPref.int");}, Cr.NS_ERROR_UNEXPECTED);
|
||||
pb1.getIntPref("DefaultPref.int");
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
do_check_throws(function() {
|
||||
pb1.getCharPref("DefaultPref.char");}, Cr.NS_ERROR_UNEXPECTED);
|
||||
pb1.getCharPref("DefaultPref.char");
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
|
||||
//**************************************************************************//
|
||||
//* *************************************************************************//
|
||||
// savePrefFile & readPrefFile tests
|
||||
|
||||
// set some prefs
|
||||
|
|
@ -322,11 +347,14 @@ function run_test() {
|
|||
|
||||
// former prefs should have been replaced/lost
|
||||
do_check_throws(function() {
|
||||
pb.getBoolPref("ReadPref.bool");}, Cr.NS_ERROR_UNEXPECTED);
|
||||
pb.getBoolPref("ReadPref.bool");
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
do_check_throws(function() {
|
||||
pb.getIntPref("ReadPref.int");}, Cr.NS_ERROR_UNEXPECTED);
|
||||
pb.getIntPref("ReadPref.int");
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
do_check_throws(function() {
|
||||
pb.getCharPref("ReadPref.char");}, Cr.NS_ERROR_UNEXPECTED);
|
||||
pb.getCharPref("ReadPref.char");
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
|
||||
// loaded prefs should read ok.
|
||||
pb = ps.getBranch("testPref.");
|
||||
|
|
@ -355,7 +383,7 @@ function run_test() {
|
|||
Assert.equal(pb.getBoolPref("bool2"), false);
|
||||
Assert.equal(pb.getIntPref("int1"), 23);
|
||||
|
||||
//**************************************************************************//
|
||||
//* *************************************************************************//
|
||||
// preference Observers
|
||||
|
||||
class PrefObserver {
|
||||
|
|
@ -390,7 +418,7 @@ function run_test() {
|
|||
// notification received, we may go on...
|
||||
do_test_finished();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Indicate that we'll have 3 more async tests pending so that they all
|
||||
// actually get a chance to run.
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@
|
|||
|
||||
// This file tests the `locked` attribute in default pref files.
|
||||
|
||||
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
Components.utils.import("resource://gre/modules/Services.jsm");
|
||||
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
const ps = Services.prefs;
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ function run_test() {
|
|||
var prefs = ps.getBranch(null);
|
||||
|
||||
ps.resetPrefs();
|
||||
ps.readDefaultPrefsFromFile(do_get_file('data/testParser.js'));
|
||||
ps.readDefaultPrefsFromFile(do_get_file("data/testParser.js"));
|
||||
|
||||
Assert.equal(ps.getBoolPref("comment1"), true);
|
||||
Assert.equal(ps.getBoolPref("comment2"), true);
|
||||
|
|
@ -46,7 +46,7 @@ function run_test() {
|
|||
Assert.equal(ps.getCharPref("string.empty"), "");
|
||||
Assert.equal(ps.getCharPref("string.abc"), "abc");
|
||||
Assert.equal(ps.getCharPref("string.long"), "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
|
||||
Assert.equal(ps.getCharPref('string.single-quotes'), '"abc"');
|
||||
Assert.equal(ps.getCharPref("string.single-quotes"), '"abc"');
|
||||
Assert.equal(ps.getCharPref("string.double-quotes"), "'abc'");
|
||||
Assert.equal(ps.getCharPref("string.weird-chars"),
|
||||
"\x0d \x09 \x0b \x0c \x06 \x16");
|
||||
|
|
|
|||
|
|
@ -37,10 +37,6 @@ function saveAndReload() {
|
|||
ps.readUserPrefsFromFile(file);
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
run_next_test();
|
||||
}
|
||||
|
||||
// A sticky pref should not be written if the value is unchanged.
|
||||
add_test(function notWrittenWhenUnchanged() {
|
||||
resetAndLoadDefaults();
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ var ps = Cc["@mozilla.org/preferences-service;1"].
|
|||
getService(Ci.nsIPrefService);
|
||||
|
||||
function makeBuffer(length) {
|
||||
return new Array(length + 1).join('x');
|
||||
return new Array(length + 1).join("x");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -20,7 +20,7 @@ function checkWarning(pref, buffer) {
|
|||
return new Promise(resolve => {
|
||||
let complete = false;
|
||||
let listener = {
|
||||
observe: function(event) {
|
||||
observe(event) {
|
||||
let message = event.message;
|
||||
if (!(message.startsWith("Warning: attempting to write")
|
||||
&& message.includes(pref))) {
|
||||
|
|
@ -33,7 +33,7 @@ function checkWarning(pref, buffer) {
|
|||
info("Warning while setting " + pref);
|
||||
cs.unregisterListener(listener);
|
||||
resolve(true);
|
||||
}
|
||||
},
|
||||
};
|
||||
do_timeout(1000, function() {
|
||||
if (complete) {
|
||||
|
|
@ -49,10 +49,6 @@ function checkWarning(pref, buffer) {
|
|||
});
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
run_next_test();
|
||||
}
|
||||
|
||||
add_task(async function() {
|
||||
// Simple change, shouldn't cause a warning
|
||||
info("Checking that a simple change doesn't cause a warning");
|
||||
|
|
|
|||
|
|
@ -5,9 +5,8 @@ function isParentProcess() {
|
|||
|
||||
function run_test() {
|
||||
if (isParentProcess() == false) {
|
||||
|
||||
do_load_child_test_harness();
|
||||
|
||||
|
||||
var pb = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
|
||||
pb.setBoolPref("Test.IPC.bool.new", true);
|
||||
pb.setIntPref("Test.IPC.int.new", 23);
|
||||
|
|
@ -15,4 +14,4 @@ function run_test() {
|
|||
|
||||
run_test_in_child("test_observed_prefs.js");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ function run_test() {
|
|||
try {
|
||||
let val = pb.getCharPref(pref_name);
|
||||
prefExists = val.length > 128;
|
||||
} catch(e) {
|
||||
} catch (e) {
|
||||
prefExists = false;
|
||||
}
|
||||
ok(!prefExists,
|
||||
|
|
|
|||
|
|
@ -179,14 +179,14 @@ for (let {type, values} of PREFS) {
|
|||
|
||||
return {
|
||||
beforeContent(PREF) {
|
||||
updatePref(PREF, opts.initial)
|
||||
updatePref(PREF, opts.initial);
|
||||
check(PREF, "parent", getPref(PREF), opts.initial);
|
||||
},
|
||||
contentStartup(PREF, contentVal) {
|
||||
check(PREF, "content", contentVal, opts.initial);
|
||||
check(PREF, "parent", getPref(PREF), opts.initial);
|
||||
|
||||
updatePref(PREF, opts.change1)
|
||||
updatePref(PREF, opts.change1);
|
||||
check(PREF, "parent", getPref(PREF), opts.change1);
|
||||
},
|
||||
contentUpdate1(PREF, contentVal) {
|
||||
|
|
@ -194,7 +194,7 @@ for (let {type, values} of PREFS) {
|
|||
check(PREF, "parent", getPref(PREF), opts.change1);
|
||||
|
||||
if (opts.change2) {
|
||||
updatePref(PREF, opts.change2)
|
||||
updatePref(PREF, opts.change2);
|
||||
check(PREF, "parent", getPref(PREF), opts.change2);
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@
|
|||
const PREF1_NAME = "dom.webcomponents.shadowdom.report_usage";
|
||||
const PREF1_VALUE = false;
|
||||
|
||||
const PREF2_NAME = "dom.mutation-events.cssom.disabled"
|
||||
const PREF2_NAME = "dom.mutation-events.cssom.disabled";
|
||||
const PREF2_VALUE = true;
|
||||
|
||||
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
|
@ -55,7 +55,7 @@ add_task(async function test_sharedMap_var_caches() {
|
|||
let values = await contentPage.spawn([PREF1_NAME, PREF2_NAME], (prefs) => {
|
||||
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
return prefs.map(pref => Services.prefs.getBoolPref(pref));
|
||||
})
|
||||
});
|
||||
|
||||
equal(values[0], !PREF1_VALUE,
|
||||
`Expected content value for ${PREF1_NAME}`);
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ function isParentProcess() {
|
|||
|
||||
function run_test() {
|
||||
if (isParentProcess()) {
|
||||
|
||||
do_load_child_test_harness();
|
||||
|
||||
var pb = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
|
||||
|
|
@ -24,7 +23,7 @@ function testPrefClear() {
|
|||
pb.clearUserPref("Test.IPC.bool.new");
|
||||
|
||||
sendCommand(
|
||||
'var pb = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);\n'+
|
||||
'var pb = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);\n' +
|
||||
'pb.prefHasUserValue("Test.IPC.bool.new");\n',
|
||||
checkWasCleared);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,18 +2,18 @@ var pb = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
|
|||
|
||||
// This pref is chosen somewhat arbitrarily --- we just need one
|
||||
// that's guaranteed to have a default value.
|
||||
const kPrefName = 'intl.accept_languages'; // of type char, which we
|
||||
const kPrefName = "intl.accept_languages"; // of type char, which we
|
||||
// assume below
|
||||
var initialValue = null;
|
||||
|
||||
function check_child_pref_info_eq(continuation) {
|
||||
sendCommand(
|
||||
'var pb = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);\n'+
|
||||
'var pb = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);\n' +
|
||||
// Returns concatenation "[value],[isUser]"
|
||||
'pb.getCharPref("'+ kPrefName +'")+ "," +'+
|
||||
'pb.prefHasUserValue("'+ kPrefName +'");',
|
||||
function (info) {
|
||||
let [ value, isUser ] = info.split(',');
|
||||
'pb.getCharPref("' + kPrefName + '")+ "," +' +
|
||||
'pb.prefHasUserValue("' + kPrefName + '");',
|
||||
function(info) {
|
||||
let [ value, isUser ] = info.split(",");
|
||||
Assert.equal(pb.getCharPref(kPrefName), value);
|
||||
Assert.equal(pb.prefHasUserValue(kPrefName), isUser == "true");
|
||||
continuation();
|
||||
|
|
@ -33,11 +33,11 @@ function test_user_setting() {
|
|||
// We rely on setting this before the content process starts up.
|
||||
// When it starts up, it should recognize this as a user pref, not
|
||||
// a default pref.
|
||||
pb.setCharPref(kPrefName, 'i-imaginarylanguage');
|
||||
pb.setCharPref(kPrefName, "i-imaginarylanguage");
|
||||
// NB: processing of the value-change notification in the child
|
||||
// process triggered by the above set happens-before the remaining
|
||||
// code here
|
||||
check_child_pref_info_eq(function () {
|
||||
check_child_pref_info_eq(function() {
|
||||
Assert.equal(pb.prefHasUserValue(kPrefName), true);
|
||||
|
||||
test_cleared_is_default();
|
||||
|
|
@ -49,7 +49,7 @@ function test_cleared_is_default() {
|
|||
// NB: processing of the value-change notification in the child
|
||||
// process triggered by the above set happens-before the remaining
|
||||
// code here
|
||||
check_child_pref_info_eq(function () {
|
||||
check_child_pref_info_eq(function() {
|
||||
Assert.equal(pb.prefHasUserValue(kPrefName), false);
|
||||
|
||||
clean_up();
|
||||
|
|
@ -61,7 +61,7 @@ function clean_up() {
|
|||
// NB: processing of the value-change notification in the child
|
||||
// process triggered by the above set happens-before the remaining
|
||||
// code here
|
||||
check_child_pref_info_eq(function () {
|
||||
check_child_pref_info_eq(function() {
|
||||
do_test_finished();
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue