зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1561435 - Format modules/, a=automatic-formatting
# ignore-this-changeset Differential Revision: https://phabricator.services.mozilla.com/D35916 --HG-- extra : source : 3faab607a196e49a51059a8639b8e44afb078edc
This commit is contained in:
Родитель
9e9be26a9b
Коммит
8c3cfe4881
|
@ -45,7 +45,6 @@ module.exports = {
|
|||
"overrides": [{
|
||||
"files": [
|
||||
"devtools/**",
|
||||
"modules/**",
|
||||
"mozglue/**",
|
||||
"netwerk/**",
|
||||
"nsprpub/**",
|
||||
|
|
|
@ -40,7 +40,6 @@ toolkit/components/telemetry/datareporting-prefs.js
|
|||
toolkit/components/telemetry/healthreport-prefs.js
|
||||
|
||||
# Ignore all top-level directories for now.
|
||||
modules/**
|
||||
mozglue/**
|
||||
netwerk/**
|
||||
nsprpub/**
|
||||
|
|
|
@ -4,16 +4,20 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
const {NetUtil} = ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
const { NetUtil } = ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
|
||||
|
||||
// Check that reading non existant inner jars results in the right error
|
||||
|
||||
add_task(async function() {
|
||||
var file = do_get_file("data/test_bug597702.zip");
|
||||
var outerJarBase = "jar:" + Services.io.newFileURI(file).spec + "!/";
|
||||
var goodSpec = "jar:" + outerJarBase + "inner.jar!/hello#!/ignore%20this%20part";
|
||||
var goodChannel = NetUtil.newChannel({uri: goodSpec, loadUsingSystemPrincipal: true});
|
||||
var goodSpec =
|
||||
"jar:" + outerJarBase + "inner.jar!/hello#!/ignore%20this%20part";
|
||||
var goodChannel = NetUtil.newChannel({
|
||||
uri: goodSpec,
|
||||
loadUsingSystemPrincipal: true,
|
||||
});
|
||||
var instr = goodChannel.open();
|
||||
|
||||
ok(!!instr, "Should be able to open channel");
|
||||
|
@ -22,8 +26,12 @@ add_task(async function() {
|
|||
add_task(async function() {
|
||||
var file = do_get_file("data/test_bug597702.zip");
|
||||
var outerJarBase = "jar:" + Services.io.newFileURI(file).spec + "!/";
|
||||
var goodSpec = "jar:" + outerJarBase + "inner.jar!/hello?ignore%20this%20part!/";
|
||||
var goodChannel = NetUtil.newChannel({uri: goodSpec, loadUsingSystemPrincipal: true});
|
||||
var goodSpec =
|
||||
"jar:" + outerJarBase + "inner.jar!/hello?ignore%20this%20part!/";
|
||||
var goodChannel = NetUtil.newChannel({
|
||||
uri: goodSpec,
|
||||
loadUsingSystemPrincipal: true,
|
||||
});
|
||||
var instr = goodChannel.open();
|
||||
|
||||
ok(!!instr, "Should be able to open channel");
|
||||
|
@ -33,7 +41,10 @@ add_task(async function() {
|
|||
var file = do_get_file("data/test_bug597702.zip");
|
||||
var outerJarBase = "jar:" + Services.io.newFileURI(file).spec + "!/";
|
||||
var goodSpec = "jar:" + outerJarBase + "inner.jar!/hello?ignore#this!/part";
|
||||
var goodChannel = NetUtil.newChannel({uri: goodSpec, loadUsingSystemPrincipal: true});
|
||||
var goodChannel = NetUtil.newChannel({
|
||||
uri: goodSpec,
|
||||
loadUsingSystemPrincipal: true,
|
||||
});
|
||||
var instr = goodChannel.open();
|
||||
|
||||
ok(!!instr, "Should be able to open channel");
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// Regression test for bug 278262 - JAR URIs should resolve relative URIs in the base section.
|
||||
|
||||
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
const path = "data/test_bug333423.zip";
|
||||
|
||||
|
@ -11,8 +11,8 @@ function test_relative_sub() {
|
|||
var uri = ios.newURI("../modules/libjar", null, base);
|
||||
|
||||
// This is the URI we expect to see.
|
||||
var expected = "jar:" + ios.newFileURI(do_get_file(path)).spec +
|
||||
"!/modules/libjar";
|
||||
var expected =
|
||||
"jar:" + ios.newFileURI(do_get_file(path)).spec + "!/modules/libjar";
|
||||
|
||||
Assert.equal(uri.spec, expected);
|
||||
}
|
||||
|
@ -23,8 +23,7 @@ function test_relative_base() {
|
|||
var uri = ios.newURI("jar:../" + path + "!/", null, base);
|
||||
|
||||
// This is the URI we expect to see.
|
||||
var expected = "jar:" + ios.newFileURI(do_get_file(path)).spec +
|
||||
"!/";
|
||||
var expected = "jar:" + ios.newFileURI(do_get_file(path)).spec + "!/";
|
||||
|
||||
Assert.equal(uri.spec, expected);
|
||||
}
|
||||
|
|
|
@ -10,8 +10,9 @@ function run_test() {
|
|||
// the build script have created the zip we can test on in the current dir.
|
||||
var file = do_get_file("data/test_bug333423.zip");
|
||||
|
||||
var zipreader = Cc["@mozilla.org/libjar/zip-reader;1"].
|
||||
createInstance(Ci.nsIZipReader);
|
||||
var zipreader = Cc["@mozilla.org/libjar/zip-reader;1"].createInstance(
|
||||
Ci.nsIZipReader
|
||||
);
|
||||
zipreader.open(file);
|
||||
zipreader.close();
|
||||
var entries = zipreader.findEntries("*.*");
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
// Regression test for bug 336691 - nsZipArchive::Test shouldn't try to ExtractFile on directories.
|
||||
function run_test() {
|
||||
var file = do_get_file("data/test_bug336691.zip");
|
||||
var zipReader = Cc["@mozilla.org/libjar/zip-reader;1"].
|
||||
createInstance(Ci.nsIZipReader);
|
||||
var zipReader = Cc["@mozilla.org/libjar/zip-reader;1"].createInstance(
|
||||
Ci.nsIZipReader
|
||||
);
|
||||
zipReader.open(file);
|
||||
zipReader.test(null); // We shouldn't crash here.
|
||||
zipReader.close();
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
const {NetUtil} = ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
const { NetUtil } = ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
|
||||
|
||||
// Regression test for bug 370103 - crash when passing a null listener to
|
||||
// nsIChannel.asyncOpen
|
||||
|
@ -10,7 +10,10 @@ function run_test() {
|
|||
url = "jar:" + url + "!/test_bug370103";
|
||||
|
||||
// Try opening channel with null listener
|
||||
var channel = NetUtil.newChannel({uri: url, loadUsingSystemPrincipal: true});
|
||||
var channel = NetUtil.newChannel({
|
||||
uri: url,
|
||||
loadUsingSystemPrincipal: true,
|
||||
});
|
||||
|
||||
var exception = false;
|
||||
try {
|
||||
|
|
|
@ -10,12 +10,14 @@ var ENTRY_TIME = new Date(Date.UTC(2007, 4, 7, 13, 35, 49, 0));
|
|||
|
||||
function run_test() {
|
||||
var file = do_get_file(path);
|
||||
var zipReader = Cc["@mozilla.org/libjar/zip-reader;1"].
|
||||
createInstance(Ci.nsIZipReader);
|
||||
var zipReader = Cc["@mozilla.org/libjar/zip-reader;1"].createInstance(
|
||||
Ci.nsIZipReader
|
||||
);
|
||||
zipReader.open(file);
|
||||
var entry = zipReader.getEntry(ENTRY_NAME);
|
||||
var diff = Math.abs(entry.lastModifiedTime - ENTRY_TIME.getTime() * 1000);
|
||||
zipReader.close();
|
||||
if (diff >= MAX_TIME_DIFF)
|
||||
if (diff >= MAX_TIME_DIFF) {
|
||||
do_throw(diff);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +1,15 @@
|
|||
function run_test() {
|
||||
const zipCache = Cc["@mozilla.org/libjar/zip-reader-cache;1"]
|
||||
.createInstance(Ci.nsIZipReaderCache);
|
||||
const zipCache = Cc["@mozilla.org/libjar/zip-reader-cache;1"].createInstance(
|
||||
Ci.nsIZipReaderCache
|
||||
);
|
||||
zipCache.init(1024);
|
||||
try {
|
||||
zipCache.getZip(null);
|
||||
do_throw("Shouldn't get here!");
|
||||
} catch (e) {
|
||||
if (!(e instanceof Ci.nsIException &&
|
||||
e.result == Cr.NS_ERROR_INVALID_POINTER)) {
|
||||
if (
|
||||
!(e instanceof Ci.nsIException && e.result == Cr.NS_ERROR_INVALID_POINTER)
|
||||
) {
|
||||
throw e;
|
||||
}
|
||||
// do nothing, this test passes
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
function run_test() {
|
||||
var zReader = Cc["@mozilla.org/libjar/zip-reader;1"]
|
||||
.createInstance(Ci.nsIZipReader);
|
||||
var zReader = Cc["@mozilla.org/libjar/zip-reader;1"].createInstance(
|
||||
Ci.nsIZipReader
|
||||
);
|
||||
try {
|
||||
zReader.open(null);
|
||||
do_throw("Shouldn't get here!");
|
||||
} catch (e) {
|
||||
if (!(e instanceof Ci.nsIException &&
|
||||
e.result == Cr.NS_ERROR_NULL_POINTER)) {
|
||||
if (
|
||||
!(e instanceof Ci.nsIException && e.result == Cr.NS_ERROR_NULL_POINTER)
|
||||
) {
|
||||
throw e;
|
||||
}
|
||||
// do nothing, this test passes
|
||||
|
|
|
@ -1,13 +1,17 @@
|
|||
// Make sure we behave appropriately when asking for content-disposition
|
||||
|
||||
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
const {NetUtil} = ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
const { NetUtil } = ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
|
||||
|
||||
const path = "data/test_bug589292.zip";
|
||||
|
||||
function run_test() {
|
||||
var spec = "jar:" + Services.io.newFileURI(do_get_file(path)).spec + "!/foo.txt";
|
||||
var channel = NetUtil.newChannel({uri: spec, loadUsingSystemPrincipal: true});
|
||||
var spec =
|
||||
"jar:" + Services.io.newFileURI(do_get_file(path)).spec + "!/foo.txt";
|
||||
var channel = NetUtil.newChannel({
|
||||
uri: spec,
|
||||
loadUsingSystemPrincipal: true,
|
||||
});
|
||||
channel.open();
|
||||
try {
|
||||
channel.contentDisposition;
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* 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/. */
|
||||
|
||||
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
const {NetUtil} = ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
const { NetUtil } = ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
|
||||
|
||||
// Check that reading non existant inner jars results in the right error
|
||||
|
||||
|
@ -12,8 +12,14 @@ function run_test() {
|
|||
var outerJarBase = "jar:" + Services.io.newFileURI(file).spec + "!/";
|
||||
var goodSpec = "jar:" + outerJarBase + "inner.jar!/hello";
|
||||
var badSpec = "jar:" + outerJarBase + "jar_that_isnt_in_the.jar!/hello";
|
||||
var goodChannel = NetUtil.newChannel({uri: goodSpec, loadUsingSystemPrincipal: true});
|
||||
var badChannel = NetUtil.newChannel({uri: badSpec, loadUsingSystemPrincipal: true});
|
||||
var goodChannel = NetUtil.newChannel({
|
||||
uri: goodSpec,
|
||||
loadUsingSystemPrincipal: true,
|
||||
});
|
||||
var badChannel = NetUtil.newChannel({
|
||||
uri: badSpec,
|
||||
loadUsingSystemPrincipal: true,
|
||||
});
|
||||
|
||||
try {
|
||||
goodChannel.open();
|
||||
|
|
|
@ -2,14 +2,17 @@
|
|||
* 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/. */
|
||||
|
||||
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
const {NetUtil} = ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
const { NetUtil } = ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
|
||||
|
||||
// Check that the zip cache can expire entries from nested jars
|
||||
|
||||
function open_inner_zip(base, idx) {
|
||||
var spec = "jar:" + base + "inner" + idx + ".zip!/foo";
|
||||
var channel = NetUtil.newChannel({uri: spec, loadUsingSystemPrincipal: true});
|
||||
var channel = NetUtil.newChannel({
|
||||
uri: spec,
|
||||
loadUsingSystemPrincipal: true,
|
||||
});
|
||||
channel.open();
|
||||
}
|
||||
|
||||
|
|
|
@ -2,15 +2,18 @@
|
|||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
const {NetUtil} = ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
const { NetUtil } = ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
|
||||
|
||||
// Check that we don't crash on reading a directory entry signature
|
||||
|
||||
function run_test() {
|
||||
var file = do_get_file("data/test_bug658093.zip");
|
||||
var spec = "jar:" + Services.io.newFileURI(file).spec + "!/0000";
|
||||
var channel = NetUtil.newChannel({uri: spec, loadUsingSystemPrincipal: true});
|
||||
var channel = NetUtil.newChannel({
|
||||
uri: spec,
|
||||
loadUsingSystemPrincipal: true,
|
||||
});
|
||||
var failed = false;
|
||||
try {
|
||||
channel.open();
|
||||
|
|
|
@ -7,8 +7,9 @@
|
|||
function run_test() {
|
||||
var file = do_get_file("data/test_corrupt3.zip");
|
||||
|
||||
var zipreader = Cc["@mozilla.org/libjar/zip-reader;1"].
|
||||
createInstance(Ci.nsIZipReader);
|
||||
var zipreader = Cc["@mozilla.org/libjar/zip-reader;1"].createInstance(
|
||||
Ci.nsIZipReader
|
||||
);
|
||||
zipreader.open(file);
|
||||
|
||||
var failed = false;
|
||||
|
@ -25,4 +26,3 @@ function run_test() {
|
|||
|
||||
Assert.ok(failed);
|
||||
}
|
||||
|
||||
|
|
|
@ -15,8 +15,9 @@ function run_test() {
|
|||
// the build script have created the zip we can test on in the current dir.
|
||||
var file = do_get_file("data/test_corrupt.zip");
|
||||
|
||||
var zipreader = Cc["@mozilla.org/libjar/zip-reader;1"].
|
||||
createInstance(Ci.nsIZipReader);
|
||||
var zipreader = Cc["@mozilla.org/libjar/zip-reader;1"].createInstance(
|
||||
Ci.nsIZipReader
|
||||
);
|
||||
zipreader.open(file);
|
||||
// var entries = zipreader.findEntries(null);
|
||||
// the signature for file is corrupt, should not segfault
|
||||
|
@ -29,4 +30,3 @@ function run_test() {
|
|||
}
|
||||
Assert.ok(failed);
|
||||
}
|
||||
|
||||
|
|
|
@ -7,8 +7,9 @@ function run_test() {
|
|||
// the build script have created the zip we can test on in the current dir.
|
||||
var file = do_get_file("data/test_corrupt2.zip");
|
||||
|
||||
var zipreader = Cc["@mozilla.org/libjar/zip-reader;1"].
|
||||
createInstance(Ci.nsIZipReader);
|
||||
var zipreader = Cc["@mozilla.org/libjar/zip-reader;1"].createInstance(
|
||||
Ci.nsIZipReader
|
||||
);
|
||||
var failed = false;
|
||||
try {
|
||||
zipreader.open(file);
|
||||
|
@ -18,4 +19,3 @@ function run_test() {
|
|||
}
|
||||
Assert.ok(failed);
|
||||
}
|
||||
|
||||
|
|
|
@ -18,8 +18,9 @@ function run_test() {
|
|||
// public key and signature fields in the header are both empty.
|
||||
let file = do_get_file("data/test_crx_dummy.crx");
|
||||
|
||||
let zipreader = Cc["@mozilla.org/libjar/zip-reader;1"].
|
||||
createInstance(Ci.nsIZipReader);
|
||||
let zipreader = Cc["@mozilla.org/libjar/zip-reader;1"].createInstance(
|
||||
Ci.nsIZipReader
|
||||
);
|
||||
zipreader.open(file);
|
||||
// do crc stuff
|
||||
function check_archive_crc() {
|
||||
|
@ -28,12 +29,15 @@ function run_test() {
|
|||
}
|
||||
Assert.ok(check_archive_crc());
|
||||
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();
|
||||
Assert.ok(stream.read(1024).length > 0);
|
||||
Assert.ok(dirstream.read(100).length > 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -9,8 +9,9 @@ function run_test() {
|
|||
// open a bogus file
|
||||
var file = do_get_file("/");
|
||||
|
||||
var zipreader = Cc["@mozilla.org/libjar/zip-reader;1"].
|
||||
createInstance(Ci.nsIZipReader);
|
||||
var zipreader = Cc["@mozilla.org/libjar/zip-reader;1"].createInstance(
|
||||
Ci.nsIZipReader
|
||||
);
|
||||
var failed = false;
|
||||
try {
|
||||
zipreader.open(file);
|
||||
|
@ -20,4 +21,3 @@ function run_test() {
|
|||
Assert.ok(failed);
|
||||
zipreader = null;
|
||||
}
|
||||
|
||||
|
|
|
@ -6,20 +6,20 @@
|
|||
* Tests some basic jar channel functionality
|
||||
*/
|
||||
|
||||
const { Constructor: ctor } = Components;
|
||||
|
||||
const {Constructor: ctor} = Components;
|
||||
|
||||
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
const {NetUtil} = ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
const { NetUtil } = ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
|
||||
|
||||
const ios = Services.io;
|
||||
const dirSvc = Services.dirsvc;
|
||||
const obs = Services.obs;
|
||||
|
||||
const nsIBinaryInputStream = ctor("@mozilla.org/binaryinputstream;1",
|
||||
"nsIBinaryInputStream",
|
||||
"setInputStream"
|
||||
);
|
||||
const nsIBinaryInputStream = ctor(
|
||||
"@mozilla.org/binaryinputstream;1",
|
||||
"nsIBinaryInputStream",
|
||||
"setInputStream"
|
||||
);
|
||||
|
||||
const fileBase = "test_bug637286.zip";
|
||||
const file = do_get_file("data/" + fileBase);
|
||||
|
@ -27,50 +27,52 @@ const jarBase = "jar:" + ios.newFileURI(file).spec + "!";
|
|||
const tmpDir = dirSvc.get("TmpD", Ci.nsIFile);
|
||||
|
||||
function Listener(callback) {
|
||||
this._callback = callback;
|
||||
this._callback = callback;
|
||||
}
|
||||
Listener.prototype = {
|
||||
gotStartRequest: false,
|
||||
available: -1,
|
||||
gotStopRequest: false,
|
||||
QueryInterface: ChromeUtils.generateQI(["nsIRequestObserver"]),
|
||||
onDataAvailable(request, 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) {
|
||||
do_throw(ex);
|
||||
}
|
||||
},
|
||||
onStartRequest(request) {
|
||||
this.gotStartRequest = true;
|
||||
},
|
||||
onStopRequest(request, status) {
|
||||
this.gotStopRequest = true;
|
||||
Assert.equal(status, 0);
|
||||
if (this._callback) {
|
||||
this._callback.call(null, this);
|
||||
}
|
||||
},
|
||||
gotStartRequest: false,
|
||||
available: -1,
|
||||
gotStopRequest: false,
|
||||
QueryInterface: ChromeUtils.generateQI(["nsIRequestObserver"]),
|
||||
onDataAvailable(request, 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) {
|
||||
do_throw(ex);
|
||||
}
|
||||
},
|
||||
onStartRequest(request) {
|
||||
this.gotStartRequest = true;
|
||||
},
|
||||
onStopRequest(request, status) {
|
||||
this.gotStopRequest = true;
|
||||
Assert.equal(status, 0);
|
||||
if (this._callback) {
|
||||
this._callback.call(null, this);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* Basic reading test for asynchronously opened jar channel
|
||||
*/
|
||||
function testAsync() {
|
||||
var uri = jarBase + "/inner40.zip";
|
||||
var chan = NetUtil.newChannel({uri, loadUsingSystemPrincipal: true});
|
||||
Assert.ok(chan.contentLength < 0);
|
||||
chan.asyncOpen(new Listener(function(l) {
|
||||
Assert.ok(chan.contentLength > 0);
|
||||
Assert.ok(l.gotStartRequest);
|
||||
Assert.ok(l.gotStopRequest);
|
||||
Assert.equal(l.available, chan.contentLength);
|
||||
var uri = jarBase + "/inner40.zip";
|
||||
var chan = NetUtil.newChannel({ uri, loadUsingSystemPrincipal: true });
|
||||
Assert.ok(chan.contentLength < 0);
|
||||
chan.asyncOpen(
|
||||
new Listener(function(l) {
|
||||
Assert.ok(chan.contentLength > 0);
|
||||
Assert.ok(l.gotStartRequest);
|
||||
Assert.ok(l.gotStopRequest);
|
||||
Assert.equal(l.available, chan.contentLength);
|
||||
|
||||
run_next_test();
|
||||
}));
|
||||
run_next_test();
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
add_test(testAsync);
|
||||
|
@ -82,8 +84,10 @@ add_test(testAsync);
|
|||
*/
|
||||
function testZipEntry() {
|
||||
var uri = jarBase + "/inner40.zip";
|
||||
var chan = NetUtil.newChannel({uri, loadUsingSystemPrincipal: true})
|
||||
.QueryInterface(Ci.nsIJARChannel);
|
||||
var chan = NetUtil.newChannel({
|
||||
uri,
|
||||
loadUsingSystemPrincipal: true,
|
||||
}).QueryInterface(Ci.nsIJARChannel);
|
||||
var entry = chan.zipEntry;
|
||||
Assert.ok(entry.CRC32 == 0x8b635486);
|
||||
Assert.ok(entry.realSize == 184);
|
||||
|
@ -92,52 +96,52 @@ function testZipEntry() {
|
|||
|
||||
add_test(testZipEntry);
|
||||
|
||||
|
||||
/**
|
||||
* Basic reading test for synchronously opened jar channels
|
||||
*/
|
||||
add_test(function testSync() {
|
||||
var uri = jarBase + "/inner40.zip";
|
||||
var chan = NetUtil.newChannel({uri, loadUsingSystemPrincipal: true});
|
||||
var stream = chan.open();
|
||||
Assert.ok(chan.contentLength > 0);
|
||||
Assert.equal(stream.available(), chan.contentLength);
|
||||
stream.close();
|
||||
stream.close(); // should still not throw
|
||||
var uri = jarBase + "/inner40.zip";
|
||||
var chan = NetUtil.newChannel({ uri, loadUsingSystemPrincipal: true });
|
||||
var stream = chan.open();
|
||||
Assert.ok(chan.contentLength > 0);
|
||||
Assert.equal(stream.available(), chan.contentLength);
|
||||
stream.close();
|
||||
stream.close(); // should still not throw
|
||||
|
||||
run_next_test();
|
||||
run_next_test();
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* Basic reading test for synchronously opened, nested jar channels
|
||||
*/
|
||||
add_test(function testSyncNested() {
|
||||
var uri = "jar:" + jarBase + "/inner40.zip!/foo";
|
||||
var chan = NetUtil.newChannel({uri, loadUsingSystemPrincipal: true});
|
||||
var stream = chan.open();
|
||||
Assert.ok(chan.contentLength > 0);
|
||||
Assert.equal(stream.available(), chan.contentLength);
|
||||
stream.close();
|
||||
stream.close(); // should still not throw
|
||||
var uri = "jar:" + jarBase + "/inner40.zip!/foo";
|
||||
var chan = NetUtil.newChannel({ uri, loadUsingSystemPrincipal: true });
|
||||
var stream = chan.open();
|
||||
Assert.ok(chan.contentLength > 0);
|
||||
Assert.equal(stream.available(), chan.contentLength);
|
||||
stream.close();
|
||||
stream.close(); // should still not throw
|
||||
|
||||
run_next_test();
|
||||
run_next_test();
|
||||
});
|
||||
|
||||
/**
|
||||
* Basic reading test for asynchronously opened, nested jar channels
|
||||
*/
|
||||
add_test(function testAsyncNested(next) {
|
||||
var uri = "jar:" + jarBase + "/inner40.zip!/foo";
|
||||
var chan = NetUtil.newChannel({uri, loadUsingSystemPrincipal: true});
|
||||
chan.asyncOpen(new Listener(function(l) {
|
||||
Assert.ok(chan.contentLength > 0);
|
||||
Assert.ok(l.gotStartRequest);
|
||||
Assert.ok(l.gotStopRequest);
|
||||
Assert.equal(l.available, chan.contentLength);
|
||||
var uri = "jar:" + jarBase + "/inner40.zip!/foo";
|
||||
var chan = NetUtil.newChannel({ uri, loadUsingSystemPrincipal: true });
|
||||
chan.asyncOpen(
|
||||
new Listener(function(l) {
|
||||
Assert.ok(chan.contentLength > 0);
|
||||
Assert.ok(l.gotStartRequest);
|
||||
Assert.ok(l.gotStopRequest);
|
||||
Assert.equal(l.available, chan.contentLength);
|
||||
|
||||
run_next_test();
|
||||
}));
|
||||
run_next_test();
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
/**
|
||||
|
@ -145,25 +149,25 @@ add_test(function testAsyncNested(next) {
|
|||
* opened jar channel stream
|
||||
*/
|
||||
add_test(function testSyncCloseUnlocks() {
|
||||
var copy = tmpDir.clone();
|
||||
copy.append(fileBase);
|
||||
file.copyTo(copy.parent, copy.leafName);
|
||||
var uri = "jar:" + ios.newFileURI(copy).spec + "!/inner40.zip";
|
||||
var chan = NetUtil.newChannel({uri, loadUsingSystemPrincipal: true});
|
||||
var stream = chan.open();
|
||||
Assert.ok(chan.contentLength > 0);
|
||||
stream.close();
|
||||
var copy = tmpDir.clone();
|
||||
copy.append(fileBase);
|
||||
file.copyTo(copy.parent, copy.leafName);
|
||||
var uri = "jar:" + ios.newFileURI(copy).spec + "!/inner40.zip";
|
||||
var chan = NetUtil.newChannel({ uri, loadUsingSystemPrincipal: true });
|
||||
var stream = chan.open();
|
||||
Assert.ok(chan.contentLength > 0);
|
||||
stream.close();
|
||||
|
||||
// Drop any jar caches
|
||||
obs.notifyObservers(null, "chrome-flush-caches");
|
||||
// Drop any jar caches
|
||||
obs.notifyObservers(null, "chrome-flush-caches");
|
||||
|
||||
try {
|
||||
copy.remove(false);
|
||||
} catch (ex) {
|
||||
do_throw(ex);
|
||||
}
|
||||
try {
|
||||
copy.remove(false);
|
||||
} catch (ex) {
|
||||
do_throw(ex);
|
||||
}
|
||||
|
||||
run_next_test();
|
||||
run_next_test();
|
||||
});
|
||||
|
||||
/**
|
||||
|
@ -171,30 +175,31 @@ add_test(function testSyncCloseUnlocks() {
|
|||
* opened jar channel stream
|
||||
*/
|
||||
add_test(function testAsyncCloseUnlocks() {
|
||||
var copy = tmpDir.clone();
|
||||
copy.append(fileBase);
|
||||
file.copyTo(copy.parent, copy.leafName);
|
||||
var copy = tmpDir.clone();
|
||||
copy.append(fileBase);
|
||||
file.copyTo(copy.parent, copy.leafName);
|
||||
|
||||
var uri = "jar:" + ios.newFileURI(copy).spec + "!/inner40.zip";
|
||||
var chan = NetUtil.newChannel({uri, loadUsingSystemPrincipal: true});
|
||||
var uri = "jar:" + ios.newFileURI(copy).spec + "!/inner40.zip";
|
||||
var chan = NetUtil.newChannel({ uri, loadUsingSystemPrincipal: true });
|
||||
|
||||
chan.asyncOpen(new Listener(function(l) {
|
||||
Assert.ok(chan.contentLength > 0);
|
||||
chan.asyncOpen(
|
||||
new Listener(function(l) {
|
||||
Assert.ok(chan.contentLength > 0);
|
||||
|
||||
// Drop any jar caches
|
||||
obs.notifyObservers(null, "chrome-flush-caches");
|
||||
// Drop any jar caches
|
||||
obs.notifyObservers(null, "chrome-flush-caches");
|
||||
|
||||
try {
|
||||
copy.remove(false);
|
||||
} catch (ex) {
|
||||
do_throw(ex);
|
||||
}
|
||||
try {
|
||||
copy.remove(false);
|
||||
} catch (ex) {
|
||||
do_throw(ex);
|
||||
}
|
||||
|
||||
run_next_test();
|
||||
}));
|
||||
run_next_test();
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
function run_test() {
|
||||
return run_next_test();
|
||||
}
|
||||
|
|
|
@ -17,8 +17,9 @@ function run_test() {
|
|||
// the build script have created the zip we can test on in the current dir.
|
||||
var file = do_get_file("data/test_bug333423.zip");
|
||||
|
||||
var zipreader = Cc["@mozilla.org/libjar/zip-reader;1"].
|
||||
createInstance(Ci.nsIZipReader);
|
||||
var zipreader = Cc["@mozilla.org/libjar/zip-reader;1"].createInstance(
|
||||
Ci.nsIZipReader
|
||||
);
|
||||
zipreader.open(file);
|
||||
// do crc stuff
|
||||
function check_archive_crc() {
|
||||
|
@ -27,12 +28,15 @@ function run_test() {
|
|||
}
|
||||
Assert.ok(check_archive_crc());
|
||||
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();
|
||||
Assert.ok(stream.read(1024).length > 0);
|
||||
Assert.ok(dirstream.read(100).length > 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// Should report file not found on non-existent files
|
||||
|
||||
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
const {NetUtil} = ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
const { NetUtil } = ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
|
||||
const path = "data/test_bug333423.zip";
|
||||
|
||||
function run_test() {
|
||||
|
@ -14,6 +14,6 @@ function run_test() {
|
|||
channel.open();
|
||||
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,4 +1,4 @@
|
|||
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
function run_test() {
|
||||
var tmpDir = Services.dirsvc.get("TmpD", Ci.nsIFile);
|
||||
|
@ -11,7 +11,9 @@ function run_test() {
|
|||
testFile.remove(false);
|
||||
}
|
||||
|
||||
var zipreader = Cc["@mozilla.org/libjar/zip-reader;1"].createInstance(Ci.nsIZipReader);
|
||||
var zipreader = Cc["@mozilla.org/libjar/zip-reader;1"].createInstance(
|
||||
Ci.nsIZipReader
|
||||
);
|
||||
zipreader.open(zipfile);
|
||||
|
||||
var entries = zipreader.findEntries(null);
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
// Make sure uncompressed files pass crc
|
||||
function run_test() {
|
||||
var file = do_get_file("data/uncompressed.zip");
|
||||
var zipReader = Cc["@mozilla.org/libjar/zip-reader;1"].
|
||||
createInstance(Ci.nsIZipReader);
|
||||
var zipReader = Cc["@mozilla.org/libjar/zip-reader;1"].createInstance(
|
||||
Ci.nsIZipReader
|
||||
);
|
||||
zipReader.open(file);
|
||||
zipReader.test("hello");
|
||||
zipReader.close();
|
||||
|
|
|
@ -5,14 +5,14 @@
|
|||
|
||||
const NS_ERROR_IN_PROGRESS = 2152398863;
|
||||
|
||||
const PR_RDONLY = 0x01;
|
||||
const PR_WRONLY = 0x02;
|
||||
const PR_RDWR = 0x04;
|
||||
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_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;
|
||||
|
@ -22,24 +22,30 @@ const ZIP_METHOD_DEFLATE = 8;
|
|||
const ZIP_EXTENDED_TIMESTAMP_SIZE = 9;
|
||||
|
||||
const PR_USEC_PER_MSEC = 1000;
|
||||
const PR_USEC_PER_SEC = 1000000;
|
||||
const PR_MSEC_PER_SEC = 1000;
|
||||
const PR_USEC_PER_SEC = 1000000;
|
||||
const PR_MSEC_PER_SEC = 1000;
|
||||
|
||||
const DATA_DIR = "data/";
|
||||
|
||||
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
var ioSvc = Services.io;
|
||||
|
||||
var ZipWriter = Components.Constructor("@mozilla.org/zipwriter;1",
|
||||
"nsIZipWriter");
|
||||
var ZipReader = Components.Constructor("@mozilla.org/libjar/zip-reader;1",
|
||||
"nsIZipReader", "open");
|
||||
var ZipWriter = Components.Constructor(
|
||||
"@mozilla.org/zipwriter;1",
|
||||
"nsIZipWriter"
|
||||
);
|
||||
var ZipReader = Components.Constructor(
|
||||
"@mozilla.org/libjar/zip-reader;1",
|
||||
"nsIZipReader",
|
||||
"open"
|
||||
);
|
||||
|
||||
var tmpDir = do_get_profile();
|
||||
var tmpFile = tmpDir.clone();
|
||||
tmpFile.append("zipwriter-test.zip");
|
||||
if (tmpFile.exists())
|
||||
if (tmpFile.exists()) {
|
||||
tmpFile.remove(true);
|
||||
}
|
||||
|
||||
var zipW = new ZipWriter();
|
||||
|
||||
|
@ -49,6 +55,7 @@ registerCleanupFunction(function() {
|
|||
} catch (e) {
|
||||
// Just ignore a failure here and attempt to delete the file anyway.
|
||||
}
|
||||
if (tmpFile.exists())
|
||||
if (tmpFile.exists()) {
|
||||
tmpFile.remove(true);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -20,15 +20,16 @@ var TESTS = [
|
|||
];
|
||||
|
||||
function swap16(n) {
|
||||
return (((n >> 8) & 0xFF) << 0) |
|
||||
(((n >> 0) & 0xFF) << 8);
|
||||
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);
|
||||
return (
|
||||
(((n >> 24) & 0xff) << 0) |
|
||||
(((n >> 16) & 0xff) << 8) |
|
||||
(((n >> 8) & 0xff) << 16) |
|
||||
(((n >> 0) & 0xff) << 24)
|
||||
);
|
||||
}
|
||||
|
||||
function move_to_data(bis, offset) {
|
||||
|
@ -41,7 +42,7 @@ function move_to_data(bis, offset) {
|
|||
bis.readBytes(extra_len);
|
||||
offset += ZIP_FILE_HEADER_SIZE + file_len + extra_len;
|
||||
|
||||
return {offset, size};
|
||||
return { offset, size };
|
||||
}
|
||||
|
||||
function test_alignment(align_size) {
|
||||
|
@ -51,18 +52,25 @@ function test_alignment(align_size) {
|
|||
var source = do_get_file(DATA_DIR + TESTS[i].name);
|
||||
zipW.addEntryFile(TESTS[i].name, TESTS[i].compression, source, false);
|
||||
}
|
||||
var stream = Cc["@mozilla.org/io/string-input-stream;1"]
|
||||
.createInstance(Ci.nsIStringInputStream);
|
||||
var stream = Cc["@mozilla.org/io/string-input-stream;1"].createInstance(
|
||||
Ci.nsIStringInputStream
|
||||
);
|
||||
stream.setData(DATA, DATA.length);
|
||||
zipW.addEntryStream(FILENAME, time * PR_USEC_PER_MSEC,
|
||||
Ci.nsIZipWriter.COMPRESSION_NONE, stream, false);
|
||||
zipW.addEntryStream(
|
||||
FILENAME,
|
||||
time * PR_USEC_PER_MSEC,
|
||||
Ci.nsIZipWriter.COMPRESSION_NONE,
|
||||
stream,
|
||||
false
|
||||
);
|
||||
zipW.alignStoredFiles(align_size);
|
||||
zipW.close();
|
||||
|
||||
// Check data can be decompressed.
|
||||
var zipR = new ZipReader(tmpFile);
|
||||
stream = Cc["@mozilla.org/scriptableinputstream;1"]
|
||||
.createInstance(Ci.nsIScriptableInputStream);
|
||||
stream = Cc["@mozilla.org/scriptableinputstream;1"].createInstance(
|
||||
Ci.nsIScriptableInputStream
|
||||
);
|
||||
stream.init(zipR.getInputStream(FILENAME));
|
||||
var result = stream.read(DATA.length);
|
||||
Assert.equal(result, DATA);
|
||||
|
@ -70,11 +78,13 @@ function test_alignment(align_size) {
|
|||
zipR.close();
|
||||
|
||||
// Check data is correct and aligned.
|
||||
var fis = Cc["@mozilla.org/network/file-input-stream;1"]
|
||||
.createInstance(Ci.nsIFileInputStream);
|
||||
var fis = Cc["@mozilla.org/network/file-input-stream;1"].createInstance(
|
||||
Ci.nsIFileInputStream
|
||||
);
|
||||
fis.init(tmpFile, -1, -1, null);
|
||||
let bis = Cc["@mozilla.org/binaryinputstream;1"]
|
||||
.createInstance(Ci.nsIBinaryInputStream);
|
||||
let bis = Cc["@mozilla.org/binaryinputstream;1"].createInstance(
|
||||
Ci.nsIBinaryInputStream
|
||||
);
|
||||
bis.setInputStream(fis);
|
||||
var offset = 0;
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
const {NetUtil} = ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
|
||||
const { NetUtil } = ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
|
||||
|
||||
// Values taken from using zipinfo to list the test.zip contents
|
||||
var TESTS = [
|
||||
|
@ -22,8 +22,7 @@ var TESTS = [
|
|||
var size = 0;
|
||||
|
||||
var observer = {
|
||||
onStartRequest(request) {
|
||||
},
|
||||
onStartRequest(request) {},
|
||||
|
||||
onStopRequest(request, status) {
|
||||
Assert.equal(status, Cr.NS_OK);
|
||||
|
@ -46,8 +45,10 @@ var observer = {
|
|||
Assert.equal(entry.realSize, TESTS[i].size);
|
||||
Assert.equal(entry.size, TESTS[i].size);
|
||||
Assert.equal(entry.CRC32, TESTS[i].crc);
|
||||
Assert.equal(Math.floor(entry.lastModifiedTime / PR_USEC_PER_SEC),
|
||||
Math.floor(source.lastModifiedTime / PR_MSEC_PER_SEC));
|
||||
Assert.equal(
|
||||
Math.floor(entry.lastModifiedTime / PR_USEC_PER_SEC),
|
||||
Math.floor(source.lastModifiedTime / PR_MSEC_PER_SEC)
|
||||
);
|
||||
|
||||
zipR.test(entryName);
|
||||
}
|
||||
|
@ -60,24 +61,31 @@ var observer = {
|
|||
|
||||
var methods = {
|
||||
file: function method_file(entry, source) {
|
||||
zipW.addEntryFile(entry, Ci.nsIZipWriter.COMPRESSION_NONE, source,
|
||||
true);
|
||||
zipW.addEntryFile(entry, Ci.nsIZipWriter.COMPRESSION_NONE, source, true);
|
||||
},
|
||||
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,
|
||||
}), true);
|
||||
zipW.addEntryChannel(
|
||||
entry,
|
||||
source.lastModifiedTime * PR_MSEC_PER_SEC,
|
||||
Ci.nsIZipWriter.COMPRESSION_NONE,
|
||||
NetUtil.newChannel({
|
||||
uri: ioSvc.newFileURI(source),
|
||||
loadUsingSystemPrincipal: true,
|
||||
}),
|
||||
true
|
||||
);
|
||||
},
|
||||
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,
|
||||
}).open(), true);
|
||||
zipW.addEntryStream(
|
||||
entry,
|
||||
source.lastModifiedTime * PR_MSEC_PER_SEC,
|
||||
Ci.nsIZipWriter.COMPRESSION_NONE,
|
||||
NetUtil.newChannel({
|
||||
uri: ioSvc.newFileURI(source),
|
||||
loadUsingSystemPrincipal: true,
|
||||
}).open(),
|
||||
true
|
||||
);
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -89,9 +97,12 @@ function run_test() {
|
|||
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;
|
||||
size +=
|
||||
ZIP_FILE_HEADER_SIZE +
|
||||
ZIP_CDS_HEADER_SIZE +
|
||||
ZIP_EXTENDED_TIMESTAMP_SIZE * 2 +
|
||||
entry.length * 2 +
|
||||
TESTS[i].size;
|
||||
}
|
||||
}
|
||||
do_test_pending();
|
||||
|
|
|
@ -6,8 +6,7 @@
|
|||
const FILENAME = "missing.txt";
|
||||
|
||||
var observer = {
|
||||
onStartRequest(request) {
|
||||
},
|
||||
onStartRequest(request) {},
|
||||
|
||||
onStopRequest(request, status) {
|
||||
Assert.equal(status, Cr.NS_ERROR_FILE_NOT_FOUND);
|
||||
|
|
|
@ -6,8 +6,7 @@
|
|||
const FILENAME = "missing.txt";
|
||||
|
||||
var observer = {
|
||||
onStartRequest(request) {
|
||||
},
|
||||
onStartRequest(request) {},
|
||||
|
||||
onStopRequest(request, status) {
|
||||
Assert.equal(status, Cr.NS_ERROR_FILE_NOT_FOUND);
|
||||
|
|
|
@ -3,14 +3,10 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
var TESTS = [
|
||||
"test.txt",
|
||||
"test.png",
|
||||
];
|
||||
var TESTS = ["test.txt", "test.png"];
|
||||
|
||||
var observer = {
|
||||
onStartRequest(request) {
|
||||
},
|
||||
onStartRequest(request) {},
|
||||
|
||||
onStopRequest(request, status) {
|
||||
Assert.equal(status, Cr.NS_OK);
|
||||
|
|
|
@ -4,12 +4,14 @@
|
|||
*/
|
||||
|
||||
function BinaryComparer(file, callback) {
|
||||
var fstream = Cc["@mozilla.org/network/file-input-stream;1"].
|
||||
createInstance(Ci.nsIFileInputStream);
|
||||
var fstream = Cc["@mozilla.org/network/file-input-stream;1"].createInstance(
|
||||
Ci.nsIFileInputStream
|
||||
);
|
||||
fstream.init(file, -1, 0, 0);
|
||||
this.length = file.fileSize;
|
||||
this.fileStream = Cc["@mozilla.org/binaryinputstream;1"].
|
||||
createInstance(Ci.nsIBinaryInputStream);
|
||||
this.fileStream = Cc["@mozilla.org/binaryinputstream;1"].createInstance(
|
||||
Ci.nsIBinaryInputStream
|
||||
);
|
||||
this.fileStream.setInputStream(fstream);
|
||||
this.offset = 0;
|
||||
this.callback = callback;
|
||||
|
@ -21,8 +23,7 @@ BinaryComparer.prototype = {
|
|||
length: null,
|
||||
callback: null,
|
||||
|
||||
onStartRequest(aRequest) {
|
||||
},
|
||||
onStartRequest(aRequest) {},
|
||||
|
||||
onStopRequest(aRequest, aStatusCode) {
|
||||
this.fileStream.close();
|
||||
|
@ -32,8 +33,9 @@ BinaryComparer.prototype = {
|
|||
},
|
||||
|
||||
onDataAvailable(aRequest, aInputStream, aOffset, aCount) {
|
||||
var stream = Cc["@mozilla.org/binaryinputstream;1"].
|
||||
createInstance(Ci.nsIBinaryInputStream);
|
||||
var stream = Cc["@mozilla.org/binaryinputstream;1"].createInstance(
|
||||
Ci.nsIBinaryInputStream
|
||||
);
|
||||
stream.setInputStream(aInputStream);
|
||||
var source, actual;
|
||||
for (var i = 0; i < aCount; i++) {
|
||||
|
@ -45,10 +47,23 @@ BinaryComparer.prototype = {
|
|||
try {
|
||||
actual = stream.read8();
|
||||
} catch (e) {
|
||||
do_throw("Unable to read from converted stream at offset " + this.offset + " " + 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
|
||||
);
|
||||
}
|
||||
if (source != actual)
|
||||
do_throw("Invalid value " + actual + " at offset " + this.offset + ", should have been " + source);
|
||||
this.offset++;
|
||||
}
|
||||
},
|
||||
|
@ -60,22 +75,32 @@ function comparer_callback() {
|
|||
|
||||
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);
|
||||
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);
|
||||
var converter = scs.asyncConvertData("uncompressed", "deflate", comparer, null);
|
||||
var scs = Cc["@mozilla.org/streamConverters;1"].getService(
|
||||
Ci.nsIStreamConverterService
|
||||
);
|
||||
var converter = scs.asyncConvertData(
|
||||
"uncompressed",
|
||||
"deflate",
|
||||
comparer,
|
||||
null
|
||||
);
|
||||
|
||||
// Open the expected output file
|
||||
var fstream = Cc["@mozilla.org/network/file-input-stream;1"].
|
||||
createInstance(Ci.nsIFileInputStream);
|
||||
var fstream = Cc["@mozilla.org/network/file-input-stream;1"].createInstance(
|
||||
Ci.nsIFileInputStream
|
||||
);
|
||||
fstream.init(source, -1, 0, 0);
|
||||
|
||||
// Set up a pump to push data from the file to the stream converter
|
||||
var pump = Cc["@mozilla.org/network/input-stream-pump;1"].
|
||||
createInstance(Ci.nsIInputStreamPump);
|
||||
var pump = Cc["@mozilla.org/network/input-stream-pump;1"].createInstance(
|
||||
Ci.nsIInputStreamPump
|
||||
);
|
||||
pump.init(fstream, 0, 0, true);
|
||||
pump.asyncRead(converter, null);
|
||||
do_test_pending();
|
||||
|
|
|
@ -38,11 +38,17 @@ function run_test() {
|
|||
|
||||
Assert.ok(!zipW.inQueue);
|
||||
|
||||
var stream = Cc["@mozilla.org/io/string-input-stream;1"]
|
||||
.createInstance(Ci.nsIStringInputStream);
|
||||
var stream = Cc["@mozilla.org/io/string-input-stream;1"].createInstance(
|
||||
Ci.nsIStringInputStream
|
||||
);
|
||||
stream.setData(DATA, DATA.length);
|
||||
zipW.addEntryStream(FILENAME, time * PR_USEC_PER_MSEC,
|
||||
Ci.nsIZipWriter.COMPRESSION_BEST, stream, false);
|
||||
zipW.addEntryStream(
|
||||
FILENAME,
|
||||
time * PR_USEC_PER_MSEC,
|
||||
Ci.nsIZipWriter.COMPRESSION_BEST,
|
||||
stream,
|
||||
false
|
||||
);
|
||||
|
||||
// Check that zip state is right at this stage.
|
||||
testpass(zipW);
|
||||
|
@ -57,8 +63,9 @@ function run_test() {
|
|||
var zipR = new ZipReader(tmpFile);
|
||||
testpass(zipR);
|
||||
zipR.test(FILENAME);
|
||||
stream = Cc["@mozilla.org/scriptableinputstream;1"]
|
||||
.createInstance(Ci.nsIScriptableInputStream);
|
||||
stream = Cc["@mozilla.org/scriptableinputstream;1"].createInstance(
|
||||
Ci.nsIScriptableInputStream
|
||||
);
|
||||
stream.init(zipR.getInputStream(FILENAME));
|
||||
var result = stream.read(DATA.length);
|
||||
stream.close();
|
||||
|
|
|
@ -51,8 +51,9 @@ function run_test() {
|
|||
var zipR = new ZipReader(tmpFile);
|
||||
testpass(zipR);
|
||||
zipR.test(FILENAME);
|
||||
var stream = Cc["@mozilla.org/scriptableinputstream;1"]
|
||||
.createInstance(Ci.nsIScriptableInputStream);
|
||||
var stream = Cc["@mozilla.org/scriptableinputstream;1"].createInstance(
|
||||
Ci.nsIScriptableInputStream
|
||||
);
|
||||
stream.init(zipR.getInputStream(FILENAME));
|
||||
var result = stream.read(DATA.length);
|
||||
stream.close();
|
||||
|
|
|
@ -23,8 +23,11 @@ function run_test() {
|
|||
|
||||
// Adding the directory would have added a fixed amount to the file size.
|
||||
// Any difference suggests the CDS was written out incorrectly.
|
||||
var extra = ZIP_FILE_HEADER_SIZE + ZIP_CDS_HEADER_SIZE +
|
||||
(DIRNAME.length * 2) + (ZIP_EXTENDED_TIMESTAMP_SIZE * 2);
|
||||
var extra =
|
||||
ZIP_FILE_HEADER_SIZE +
|
||||
ZIP_CDS_HEADER_SIZE +
|
||||
DIRNAME.length * 2 +
|
||||
ZIP_EXTENDED_TIMESTAMP_SIZE * 2;
|
||||
|
||||
Assert.equal(source.fileSize + extra, tmpFile.fileSize);
|
||||
}
|
||||
|
|
|
@ -34,7 +34,12 @@ function run_test() {
|
|||
}
|
||||
|
||||
try {
|
||||
zipW.addEntryFile("test", Ci.nsIZipWriter.COMPRESSION_DEFAULT, tmpDir, false);
|
||||
zipW.addEntryFile(
|
||||
"test",
|
||||
Ci.nsIZipWriter.COMPRESSION_DEFAULT,
|
||||
tmpDir,
|
||||
false
|
||||
);
|
||||
do_throw("Should have thrown uninitialized error.");
|
||||
} catch (e) {
|
||||
Assert.equal(e.result, Cr.NS_ERROR_NOT_INITIALIZED);
|
||||
|
|
|
@ -13,7 +13,12 @@ function AddToZip(zipWriter, path, file) {
|
|||
}
|
||||
|
||||
// THIS IS WHERE THE ERROR OCCURS, FOR THE FILE "st14-1.tiff" IN "test_bug446708"
|
||||
zipWriter.addEntryFile(currentPath, Ci.nsIZipWriter.COMPRESSION_DEFAULT, file, false);
|
||||
zipWriter.addEntryFile(
|
||||
currentPath,
|
||||
Ci.nsIZipWriter.COMPRESSION_DEFAULT,
|
||||
file,
|
||||
false
|
||||
);
|
||||
|
||||
// if it's a dir, continue adding its contents recursively...
|
||||
if (file.isDirectory()) {
|
||||
|
@ -32,4 +37,3 @@ function RecursivelyZipDirectory(bundle) {
|
|||
AddToZip(zipW, "", bundle);
|
||||
zipW.close();
|
||||
}
|
||||
|
||||
|
|
|
@ -18,11 +18,15 @@ function run_test() {
|
|||
// Opening the invalid file should fail (but not crash)
|
||||
try {
|
||||
zipW.open(invalidFile, PR_RDWR);
|
||||
do_throw("Should have thrown NS_ERROR_FILE_CORRUPTED on " +
|
||||
invalidArchive + " !");
|
||||
do_throw(
|
||||
"Should have thrown NS_ERROR_FILE_CORRUPTED on " + invalidArchive + " !"
|
||||
);
|
||||
} catch (e) {
|
||||
if (!(e instanceof Ci.nsIException &&
|
||||
e.result == Cr.NS_ERROR_FILE_CORRUPTED)) {
|
||||
if (
|
||||
!(
|
||||
e instanceof Ci.nsIException && e.result == Cr.NS_ERROR_FILE_CORRUPTED
|
||||
)
|
||||
) {
|
||||
throw e;
|
||||
}
|
||||
// do nothing
|
||||
|
|
|
@ -3,12 +3,14 @@
|
|||
*/
|
||||
|
||||
function BinaryComparer(file, callback) {
|
||||
var fstream = Cc["@mozilla.org/network/file-input-stream;1"].
|
||||
createInstance(Ci.nsIFileInputStream);
|
||||
var fstream = Cc["@mozilla.org/network/file-input-stream;1"].createInstance(
|
||||
Ci.nsIFileInputStream
|
||||
);
|
||||
fstream.init(file, -1, 0, 0);
|
||||
this.length = file.fileSize;
|
||||
this.fileStream = Cc["@mozilla.org/binaryinputstream;1"].
|
||||
createInstance(Ci.nsIBinaryInputStream);
|
||||
this.fileStream = Cc["@mozilla.org/binaryinputstream;1"].createInstance(
|
||||
Ci.nsIBinaryInputStream
|
||||
);
|
||||
this.fileStream.setInputStream(fstream);
|
||||
this.offset = 0;
|
||||
this.callback = callback;
|
||||
|
@ -20,8 +22,7 @@ BinaryComparer.prototype = {
|
|||
length: null,
|
||||
callback: null,
|
||||
|
||||
onStartRequest(aRequest) {
|
||||
},
|
||||
onStartRequest(aRequest) {},
|
||||
|
||||
onStopRequest(aRequest, aStatusCode) {
|
||||
this.fileStream.close();
|
||||
|
@ -31,8 +32,9 @@ BinaryComparer.prototype = {
|
|||
},
|
||||
|
||||
onDataAvailable(aRequest, aInputStream, aOffset, aCount) {
|
||||
var stream = Cc["@mozilla.org/binaryinputstream;1"].
|
||||
createInstance(Ci.nsIBinaryInputStream);
|
||||
var stream = Cc["@mozilla.org/binaryinputstream;1"].createInstance(
|
||||
Ci.nsIBinaryInputStream
|
||||
);
|
||||
stream.setInputStream(aInputStream);
|
||||
var source, actual;
|
||||
for (var i = 0; i < aCount; i++) {
|
||||
|
@ -44,8 +46,12 @@ BinaryComparer.prototype = {
|
|||
try {
|
||||
actual = stream.read8();
|
||||
} catch (e) {
|
||||
do_throw("Unable to read from converted stream at offset " +
|
||||
this.offset + " " + 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
|
||||
// can legitimately differ when the source is compressed on different
|
||||
|
@ -53,8 +59,14 @@ BinaryComparer.prototype = {
|
|||
// system, but we want the test to work correctly everywhere. So ignore
|
||||
// the byte at offset 9.
|
||||
if (this.offset != 9 && source != actual) {
|
||||
do_throw("Invalid value " + actual + " at offset " +
|
||||
this.offset + ", should have been " + source);
|
||||
do_throw(
|
||||
"Invalid value " +
|
||||
actual +
|
||||
" at offset " +
|
||||
this.offset +
|
||||
", should have been " +
|
||||
source
|
||||
);
|
||||
}
|
||||
this.offset++;
|
||||
}
|
||||
|
@ -67,22 +79,27 @@ function comparer_callback() {
|
|||
|
||||
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);
|
||||
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);
|
||||
var scs = Cc["@mozilla.org/streamConverters;1"].getService(
|
||||
Ci.nsIStreamConverterService
|
||||
);
|
||||
var converter = scs.asyncConvertData("uncompressed", "gzip", comparer, null);
|
||||
|
||||
// Open the expected output file
|
||||
var fstream = Cc["@mozilla.org/network/file-input-stream;1"].
|
||||
createInstance(Ci.nsIFileInputStream);
|
||||
var fstream = Cc["@mozilla.org/network/file-input-stream;1"].createInstance(
|
||||
Ci.nsIFileInputStream
|
||||
);
|
||||
fstream.init(source, -1, 0, 0);
|
||||
|
||||
// Set up a pump to push data from the file to the stream converter
|
||||
var pump = Cc["@mozilla.org/network/input-stream-pump;1"].
|
||||
createInstance(Ci.nsIInputStreamPump);
|
||||
var pump = Cc["@mozilla.org/network/input-stream-pump;1"].createInstance(
|
||||
Ci.nsIInputStreamPump
|
||||
);
|
||||
pump.init(fstream, 0, 0, true);
|
||||
pump.asyncRead(converter, null);
|
||||
do_test_pending();
|
||||
|
|
|
@ -17,11 +17,17 @@ function run_test() {
|
|||
|
||||
Assert.ok(!zipW.inQueue);
|
||||
|
||||
var stream = Cc["@mozilla.org/io/string-input-stream;1"]
|
||||
.createInstance(Ci.nsIStringInputStream);
|
||||
var stream = Cc["@mozilla.org/io/string-input-stream;1"].createInstance(
|
||||
Ci.nsIStringInputStream
|
||||
);
|
||||
stream.setData(DATA, DATA.length);
|
||||
zipW.addEntryStream(FILENAME, time * PR_USEC_PER_MSEC,
|
||||
Ci.nsIZipWriter.COMPRESSION_BEST, stream, false);
|
||||
zipW.addEntryStream(
|
||||
FILENAME,
|
||||
time * PR_USEC_PER_MSEC,
|
||||
Ci.nsIZipWriter.COMPRESSION_BEST,
|
||||
stream,
|
||||
false
|
||||
);
|
||||
|
||||
var entry = zipW.getEntry(FILENAME);
|
||||
|
||||
|
@ -41,8 +47,9 @@ function run_test() {
|
|||
|
||||
zipR.test(FILENAME);
|
||||
|
||||
stream = Cc["@mozilla.org/scriptableinputstream;1"]
|
||||
.createInstance(Ci.nsIScriptableInputStream);
|
||||
stream = Cc["@mozilla.org/scriptableinputstream;1"].createInstance(
|
||||
Ci.nsIScriptableInputStream
|
||||
);
|
||||
stream.init(zipR.getInputStream(FILENAME));
|
||||
var result = stream.read(DATA.length);
|
||||
stream.close();
|
||||
|
|
|
@ -41,20 +41,31 @@ function run_test() {
|
|||
|
||||
Assert.ok(!zipW.inQueue);
|
||||
|
||||
var stream = Cc["@mozilla.org/io/string-input-stream;1"]
|
||||
.createInstance(Ci.nsIStringInputStream);
|
||||
var stream = Cc["@mozilla.org/io/string-input-stream;1"].createInstance(
|
||||
Ci.nsIStringInputStream
|
||||
);
|
||||
stream.setData(DATA, DATA.length);
|
||||
zipW.addEntryStream(FILENAME, time * PR_USEC_PER_MSEC,
|
||||
Ci.nsIZipWriter.COMPRESSION_NONE, stream, false);
|
||||
zipW.addEntryStream(
|
||||
FILENAME,
|
||||
time * PR_USEC_PER_MSEC,
|
||||
Ci.nsIZipWriter.COMPRESSION_NONE,
|
||||
stream,
|
||||
false
|
||||
);
|
||||
|
||||
// Check that zip state is right at this stage.
|
||||
testpass(zipW);
|
||||
zipW.close();
|
||||
|
||||
Assert.equal(tmpFile.fileSize,
|
||||
DATA.length + ZIP_FILE_HEADER_SIZE + ZIP_CDS_HEADER_SIZE +
|
||||
(ZIP_EXTENDED_TIMESTAMP_SIZE * 2) +
|
||||
(FILENAME.length * 2) + ZIP_EOCDR_HEADER_SIZE);
|
||||
Assert.equal(
|
||||
tmpFile.fileSize,
|
||||
DATA.length +
|
||||
ZIP_FILE_HEADER_SIZE +
|
||||
ZIP_CDS_HEADER_SIZE +
|
||||
ZIP_EXTENDED_TIMESTAMP_SIZE * 2 +
|
||||
FILENAME.length * 2 +
|
||||
ZIP_EOCDR_HEADER_SIZE
|
||||
);
|
||||
|
||||
// Check to see if we get the same results loading afresh.
|
||||
zipW.open(tmpFile, PR_RDWR);
|
||||
|
@ -65,8 +76,9 @@ function run_test() {
|
|||
var zipR = new ZipReader(tmpFile);
|
||||
testpass(zipR);
|
||||
zipR.test(FILENAME);
|
||||
stream = Cc["@mozilla.org/scriptableinputstream;1"]
|
||||
.createInstance(Ci.nsIScriptableInputStream);
|
||||
stream = Cc["@mozilla.org/scriptableinputstream;1"].createInstance(
|
||||
Ci.nsIScriptableInputStream
|
||||
);
|
||||
stream.init(zipR.getInputStream(FILENAME));
|
||||
var result = stream.read(DATA.length);
|
||||
stream.close();
|
||||
|
|
|
@ -23,11 +23,18 @@ function run_test() {
|
|||
var size = 0;
|
||||
for (let i = 0; i < TESTS.length; i++) {
|
||||
let source = do_get_file(DATA_DIR + TESTS[i].name);
|
||||
zipW.addEntryFile(TESTS[i].name, Ci.nsIZipWriter.COMPRESSION_NONE, source,
|
||||
false);
|
||||
size += ZIP_FILE_HEADER_SIZE + ZIP_CDS_HEADER_SIZE +
|
||||
(ZIP_EXTENDED_TIMESTAMP_SIZE * 2) +
|
||||
(TESTS[i].name.length * 2) + TESTS[i].size;
|
||||
zipW.addEntryFile(
|
||||
TESTS[i].name,
|
||||
Ci.nsIZipWriter.COMPRESSION_NONE,
|
||||
source,
|
||||
false
|
||||
);
|
||||
size +=
|
||||
ZIP_FILE_HEADER_SIZE +
|
||||
ZIP_CDS_HEADER_SIZE +
|
||||
ZIP_EXTENDED_TIMESTAMP_SIZE * 2 +
|
||||
TESTS[i].name.length * 2 +
|
||||
TESTS[i].size;
|
||||
}
|
||||
|
||||
zipW.close();
|
||||
|
@ -46,8 +53,10 @@ function run_test() {
|
|||
Assert.equal(entry.realSize, TESTS[i].size);
|
||||
Assert.equal(entry.size, TESTS[i].size);
|
||||
Assert.equal(entry.CRC32, TESTS[i].crc);
|
||||
Assert.equal(Math.floor(entry.lastModifiedTime / PR_USEC_PER_SEC),
|
||||
Math.floor(source.lastModifiedTime / PR_MSEC_PER_SEC));
|
||||
Assert.equal(
|
||||
Math.floor(entry.lastModifiedTime / PR_USEC_PER_SEC),
|
||||
Math.floor(source.lastModifiedTime / PR_MSEC_PER_SEC)
|
||||
);
|
||||
|
||||
zipR.test(TESTS[i].name);
|
||||
}
|
||||
|
|
|
@ -4,24 +4,29 @@
|
|||
*/
|
||||
|
||||
// Values taken from using zipinfo to list the test.zip contents
|
||||
var TESTS = [
|
||||
"test.txt",
|
||||
"test.png",
|
||||
];
|
||||
var TESTS = ["test.txt", "test.png"];
|
||||
|
||||
function run_test() {
|
||||
zipW.open(tmpFile, PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE);
|
||||
|
||||
for (let i = 0; i < TESTS.length; i++) {
|
||||
let source = do_get_file(DATA_DIR + TESTS[i]);
|
||||
zipW.addEntryFile(TESTS[i], Ci.nsIZipWriter.COMPRESSION_NONE, source,
|
||||
false);
|
||||
zipW.addEntryFile(
|
||||
TESTS[i],
|
||||
Ci.nsIZipWriter.COMPRESSION_NONE,
|
||||
source,
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
let source = do_get_file(DATA_DIR + TESTS[0]);
|
||||
zipW.addEntryFile(TESTS[0], Ci.nsIZipWriter.COMPRESSION_NONE, source,
|
||||
false);
|
||||
zipW.addEntryFile(
|
||||
TESTS[0],
|
||||
Ci.nsIZipWriter.COMPRESSION_NONE,
|
||||
source,
|
||||
false
|
||||
);
|
||||
do_throw("Should not be able to add the same file twice");
|
||||
} catch (e) {
|
||||
Assert.equal(e.result, Cr.NS_ERROR_FILE_ALREADY_EXISTS);
|
||||
|
|
|
@ -27,8 +27,9 @@ function build_tests() {
|
|||
function run_test() {
|
||||
build_tests();
|
||||
|
||||
var foStream = Cc["@mozilla.org/network/file-output-stream;1"].
|
||||
createInstance(Ci.nsIFileOutputStream);
|
||||
var foStream = Cc["@mozilla.org/network/file-output-stream;1"].createInstance(
|
||||
Ci.nsIFileOutputStream
|
||||
);
|
||||
|
||||
var tmp = tmpDir.clone();
|
||||
tmp.append("temp-permissions");
|
||||
|
@ -48,12 +49,26 @@ function run_test() {
|
|||
// This reduces the coverage of the test but there isn't much we can do
|
||||
var perm = file.permissions & 0xfff;
|
||||
if (TESTS[i].permission != perm) {
|
||||
dump("File permissions for " + TESTS[i].name + " were " + perm.toString(8) + "\n");
|
||||
dump(
|
||||
"File permissions for " +
|
||||
TESTS[i].name +
|
||||
" were " +
|
||||
perm.toString(8) +
|
||||
"\n"
|
||||
);
|
||||
TESTS[i].permission = perm;
|
||||
}
|
||||
|
||||
zipW.addEntryFile(TESTS[i].name, Ci.nsIZipWriter.COMPRESSION_NONE, file, false);
|
||||
Assert.equal(zipW.getEntry(TESTS[i].name).permissions, TESTS[i].permission | 0o400);
|
||||
zipW.addEntryFile(
|
||||
TESTS[i].name,
|
||||
Ci.nsIZipWriter.COMPRESSION_NONE,
|
||||
file,
|
||||
false
|
||||
);
|
||||
Assert.equal(
|
||||
zipW.getEntry(TESTS[i].name).permissions,
|
||||
TESTS[i].permission | 0o400
|
||||
);
|
||||
file.permissions = 0o600;
|
||||
file.remove(true);
|
||||
}
|
||||
|
@ -62,14 +77,20 @@ function run_test() {
|
|||
zipW.open(tmpFile, PR_RDWR);
|
||||
for (let i = 0; i < TESTS.length; i++) {
|
||||
dump("Testing zipwriter file permissions for " + TESTS[i].name + "\n");
|
||||
Assert.equal(zipW.getEntry(TESTS[i].name).permissions, TESTS[i].permission | 0o400);
|
||||
Assert.equal(
|
||||
zipW.getEntry(TESTS[i].name).permissions,
|
||||
TESTS[i].permission | 0o400
|
||||
);
|
||||
}
|
||||
zipW.close();
|
||||
|
||||
var zipR = new ZipReader(tmpFile);
|
||||
for (let i = 0; i < TESTS.length; i++) {
|
||||
dump("Testing zipreader file permissions for " + TESTS[i].name + "\n");
|
||||
Assert.equal(zipR.getEntry(TESTS[i].name).permissions, TESTS[i].permission | 0o400);
|
||||
Assert.equal(
|
||||
zipR.getEntry(TESTS[i].name).permissions,
|
||||
TESTS[i].permission | 0o400
|
||||
);
|
||||
dump("Testing extracted file permissions for " + TESTS[i].name + "\n");
|
||||
zipR.extract(TESTS[i].name, file);
|
||||
Assert.equal(file.permissions & 0xfff, TESTS[i].permission);
|
||||
|
|
|
@ -31,14 +31,16 @@ function compareBinaryData(arr1, arr2) {
|
|||
* @return a byte array for the data in the file.
|
||||
*/
|
||||
function getBinaryFileData(file) {
|
||||
let fileStream = Cc["@mozilla.org/network/file-input-stream;1"].
|
||||
createInstance(Ci.nsIFileInputStream);
|
||||
let fileStream = Cc[
|
||||
"@mozilla.org/network/file-input-stream;1"
|
||||
].createInstance(Ci.nsIFileInputStream);
|
||||
// Open as RD_ONLY with default permissions.
|
||||
fileStream.init(file, -1, -1, null);
|
||||
|
||||
// Check the returned size versus the expected size.
|
||||
let stream = Cc["@mozilla.org/binaryinputstream;1"].
|
||||
createInstance(Ci.nsIBinaryInputStream);
|
||||
let stream = Cc["@mozilla.org/binaryinputstream;1"].createInstance(
|
||||
Ci.nsIBinaryInputStream
|
||||
);
|
||||
stream.setInputStream(fileStream);
|
||||
let bytes = stream.readByteArray(stream.available());
|
||||
fileStream.close();
|
||||
|
@ -67,9 +69,11 @@ function run_tests(obj) {
|
|||
let ranCount = 0;
|
||||
// hasOwnProperty ensures we only see direct properties and not all
|
||||
for (let f in obj) {
|
||||
if (typeof obj[f] === "function" &&
|
||||
obj.hasOwnProperty(f) &&
|
||||
f.toString().indexOf("test_") === 0) {
|
||||
if (
|
||||
typeof obj[f] === "function" &&
|
||||
obj.hasOwnProperty(f) &&
|
||||
f.toString().indexOf("test_") === 0
|
||||
) {
|
||||
obj[f]();
|
||||
cleanup_per_test();
|
||||
ranCount++;
|
||||
|
@ -90,8 +94,7 @@ function createMAR(outMAR, dataDir, files) {
|
|||
Assert.ok(files.length > 0);
|
||||
|
||||
// Get an nsIProcess to the signmar binary.
|
||||
let process = Cc["@mozilla.org/process/util;1"].
|
||||
createInstance(Ci.nsIProcess);
|
||||
let process = Cc["@mozilla.org/process/util;1"].createInstance(Ci.nsIProcess);
|
||||
let signmarBin = do_get_file("signmar" + BIN_SUFFIX);
|
||||
|
||||
// Make sure the signmar binary exists and is an executable.
|
||||
|
@ -110,8 +113,16 @@ function createMAR(outMAR, dataDir, files) {
|
|||
}
|
||||
|
||||
// Setup the command line arguments to create the MAR.
|
||||
let args = ["-C", dataDir.path, "-H", "\@MAR_CHANNEL_ID\@",
|
||||
"-V", "13.0a1", "-c", outMAR.path];
|
||||
let args = [
|
||||
"-C",
|
||||
dataDir.path,
|
||||
"-H",
|
||||
"@MAR_CHANNEL_ID@",
|
||||
"-V",
|
||||
"13.0a1",
|
||||
"-c",
|
||||
outMAR.path,
|
||||
];
|
||||
args = args.concat(files);
|
||||
|
||||
info("Running: " + signmarBin.path + " " + args.join(" "));
|
||||
|
@ -133,8 +144,7 @@ function createMAR(outMAR, dataDir, files) {
|
|||
*/
|
||||
function extractMAR(mar, dataDir) {
|
||||
// Get an nsIProcess to the signmar binary.
|
||||
let process = Cc["@mozilla.org/process/util;1"].
|
||||
createInstance(Ci.nsIProcess);
|
||||
let process = Cc["@mozilla.org/process/util;1"].createInstance(Ci.nsIProcess);
|
||||
let signmarBin = do_get_file("signmar" + BIN_SUFFIX);
|
||||
|
||||
// Make sure the signmar binary exists and is an executable.
|
||||
|
|
|
@ -83,8 +83,11 @@ function run_test() {
|
|||
},
|
||||
// Test creating a MAR file with multiple files inside of it.
|
||||
test_multiple_file: function _test_multiple_file() {
|
||||
return run_one_test("multiple_file.mar",
|
||||
["0_sized_file", "1_byte_file", "binary_data_file"]);
|
||||
return run_one_test("multiple_file.mar", [
|
||||
"0_sized_file",
|
||||
"1_byte_file",
|
||||
"binary_data_file",
|
||||
]);
|
||||
},
|
||||
// Test creating a MAR file on top of a different one that already exists
|
||||
// at the location the new one will be created at.
|
||||
|
|
|
@ -93,8 +93,11 @@ function run_test() {
|
|||
},
|
||||
// Test extracting a MAR file with multiple files inside of it.
|
||||
test_multiple_file: function _test_multiple_file() {
|
||||
return extract_and_compare("multiple_file.mar",
|
||||
["0_sized_file", "1_byte_file", "binary_data_file"]);
|
||||
return extract_and_compare("multiple_file.mar", [
|
||||
"0_sized_file",
|
||||
"1_byte_file",
|
||||
"binary_data_file",
|
||||
]);
|
||||
},
|
||||
// Test collision detection where file A + B are the same offset
|
||||
test_collision_same_offset: function test_collision_same_offset() {
|
||||
|
|
|
@ -10,8 +10,9 @@ function run_test() {
|
|||
*/
|
||||
function signMAR(inMAR, outMAR, certs, wantSuccess, useShortHandCmdLine) {
|
||||
// Get a process to the signmar binary from the dist/bin directory.
|
||||
let process = Cc["@mozilla.org/process/util;1"].
|
||||
createInstance(Ci.nsIProcess);
|
||||
let process = Cc["@mozilla.org/process/util;1"].createInstance(
|
||||
Ci.nsIProcess
|
||||
);
|
||||
let signmarBin = do_get_file("signmar" + BIN_SUFFIX);
|
||||
|
||||
// Make sure the signmar binary exists and is an executable.
|
||||
|
@ -58,8 +59,9 @@ function run_test() {
|
|||
*/
|
||||
function extractMARSignature(inMAR, sigIndex, extractedSig, wantSuccess) {
|
||||
// Get a process to the signmar binary from the dist/bin directory.
|
||||
let process = Cc["@mozilla.org/process/util;1"].
|
||||
createInstance(Ci.nsIProcess);
|
||||
let process = Cc["@mozilla.org/process/util;1"].createInstance(
|
||||
Ci.nsIProcess
|
||||
);
|
||||
let signmarBin = do_get_file("signmar" + BIN_SUFFIX);
|
||||
|
||||
// Make sure the signmar binary exists and is an executable.
|
||||
|
@ -99,8 +101,9 @@ function run_test() {
|
|||
*/
|
||||
function importMARSignature(inMAR, sigIndex, sigFile, outMAR, wantSuccess) {
|
||||
// Get a process to the signmar binary from the dist/bin directory.
|
||||
let process = Cc["@mozilla.org/process/util;1"].
|
||||
createInstance(Ci.nsIProcess);
|
||||
let process = Cc["@mozilla.org/process/util;1"].createInstance(
|
||||
Ci.nsIProcess
|
||||
);
|
||||
let signmarBin = do_get_file("signmar" + BIN_SUFFIX);
|
||||
|
||||
// Make sure the signmar binary exists and is an executable.
|
||||
|
@ -135,8 +138,9 @@ function run_test() {
|
|||
*/
|
||||
function verifyMAR(signedMAR, wantSuccess, certs, useShortHandCmdLine) {
|
||||
// Get a process to the signmar binary from the dist/bin directory.
|
||||
let process = Cc["@mozilla.org/process/util;1"].
|
||||
createInstance(Ci.nsIProcess);
|
||||
let process = Cc["@mozilla.org/process/util;1"].createInstance(
|
||||
Ci.nsIProcess
|
||||
);
|
||||
let signmarBin = do_get_file("signmar" + BIN_SUFFIX);
|
||||
|
||||
// Make sure the signmar binary exists and is an executable.
|
||||
|
@ -200,8 +204,9 @@ function run_test() {
|
|||
*/
|
||||
function stripMARSignature(signedMAR, outMAR, wantSuccess) {
|
||||
// Get a process to the signmar binary from the dist/bin directory.
|
||||
let process = Cc["@mozilla.org/process/util;1"].
|
||||
createInstance(Ci.nsIProcess);
|
||||
let process = Cc["@mozilla.org/process/util;1"].createInstance(
|
||||
Ci.nsIProcess
|
||||
);
|
||||
let signmarBin = do_get_file("signmar" + BIN_SUFFIX);
|
||||
|
||||
// Make sure the signmar binary exists and is an executable.
|
||||
|
@ -281,8 +286,13 @@ function run_test() {
|
|||
outMAR.remove(false);
|
||||
}
|
||||
Assert.ok(!outMAR.exists());
|
||||
signMAR(inMAR, outMAR, ["mycert", "mycert2", "mycert3"],
|
||||
wantSuccess, true);
|
||||
signMAR(
|
||||
inMAR,
|
||||
outMAR,
|
||||
["mycert", "mycert2", "mycert3"],
|
||||
wantSuccess,
|
||||
true
|
||||
);
|
||||
Assert.ok(outMAR.exists());
|
||||
let outMARData = getBinaryFileData(outMAR);
|
||||
let refMAR = do_get_file("data/multiple_signed_pib.mar");
|
||||
|
@ -566,8 +576,7 @@ function run_test() {
|
|||
Assert.ok(!extractedSig.exists());
|
||||
},
|
||||
// Between each test make sure the out MAR does not exist.
|
||||
cleanup_per_test: function _cleanup_per_test() {
|
||||
},
|
||||
cleanup_per_test: function _cleanup_per_test() {},
|
||||
};
|
||||
|
||||
cleanup();
|
||||
|
|
|
@ -5,8 +5,9 @@
|
|||
const NS_APP_USER_PROFILE_50_DIR = "ProfD";
|
||||
|
||||
function do_check_throws(f, result, stack) {
|
||||
if (!stack)
|
||||
if (!stack) {
|
||||
stack = Components.stack.caller;
|
||||
}
|
||||
|
||||
try {
|
||||
f();
|
||||
|
@ -17,16 +18,22 @@ function do_check_throws(f, result, stack) {
|
|||
ok(false, "expected result " + result + ", none thrown");
|
||||
}
|
||||
|
||||
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
// Register current test directory as provider for the profile directory.
|
||||
var provider = {
|
||||
getFile(prop, persistent) {
|
||||
persistent.value = true;
|
||||
if (prop == NS_APP_USER_PROFILE_50_DIR)
|
||||
if (prop == NS_APP_USER_PROFILE_50_DIR) {
|
||||
return Services.dirsvc.get("CurProcD", Ci.nsIFile);
|
||||
throw Components.Exception("Tried to get test directory '" + prop + "'", Cr.NS_ERROR_FAILURE);
|
||||
}
|
||||
throw Components.Exception(
|
||||
"Tried to get test directory '" + prop + "'",
|
||||
Cr.NS_ERROR_FAILURE
|
||||
);
|
||||
},
|
||||
QueryInterface: ChromeUtils.generateQI(["nsIDirectoryServiceProvider"]),
|
||||
};
|
||||
Services.dirsvc.QueryInterface(Ci.nsIDirectoryService).registerProvider(provider);
|
||||
Services.dirsvc
|
||||
.QueryInterface(Ci.nsIDirectoryService)
|
||||
.registerProvider(provider);
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
/* Tests for changing the type of a preference (bug 985998) */
|
||||
|
||||
const PREF_INVALID = 0;
|
||||
const PREF_BOOL = 128;
|
||||
const PREF_INT = 64;
|
||||
const PREF_STRING = 32;
|
||||
const PREF_BOOL = 128;
|
||||
const PREF_INT = 64;
|
||||
const PREF_STRING = 32;
|
||||
|
||||
function run_test() {
|
||||
var ps = Services.prefs;
|
||||
|
|
|
@ -7,8 +7,9 @@
|
|||
function run_test() {
|
||||
const ps = Services.prefs;
|
||||
let prefName = "test.default.values.bool";
|
||||
do_check_throws(function() { ps.getBoolPref(prefName); },
|
||||
Cr.NS_ERROR_UNEXPECTED);
|
||||
do_check_throws(function() {
|
||||
ps.getBoolPref(prefName);
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
strictEqual(ps.getBoolPref(prefName, false), false);
|
||||
strictEqual(ps.getBoolPref(prefName, true), true);
|
||||
ps.setBoolPref(prefName, true);
|
||||
|
@ -17,8 +18,9 @@ function run_test() {
|
|||
strictEqual(ps.getBoolPref(prefName, true), true);
|
||||
|
||||
prefName = "test.default.values.char";
|
||||
do_check_throws(function() { ps.getCharPref(prefName); },
|
||||
Cr.NS_ERROR_UNEXPECTED);
|
||||
do_check_throws(function() {
|
||||
ps.getCharPref(prefName);
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
strictEqual(ps.getCharPref(prefName, ""), "");
|
||||
strictEqual(ps.getCharPref(prefName, "string"), "string");
|
||||
ps.setCharPref(prefName, "foo");
|
||||
|
@ -26,8 +28,9 @@ function run_test() {
|
|||
strictEqual(ps.getCharPref(prefName, "string"), "foo");
|
||||
|
||||
prefName = "test.default.values.string";
|
||||
do_check_throws(function() { ps.getCharPref(prefName); },
|
||||
Cr.NS_ERROR_UNEXPECTED);
|
||||
do_check_throws(function() {
|
||||
ps.getCharPref(prefName);
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
strictEqual(ps.getStringPref(prefName, ""), "");
|
||||
strictEqual(ps.getStringPref(prefName, "éèçàê€"), "éèçàê€");
|
||||
ps.setStringPref(prefName, "éèçàê€");
|
||||
|
@ -35,8 +38,9 @@ function run_test() {
|
|||
strictEqual(ps.getStringPref(prefName, "string"), "éèçàê€");
|
||||
|
||||
prefName = "test.default.values.float";
|
||||
do_check_throws(function() { ps.getFloatPref(prefName); },
|
||||
Cr.NS_ERROR_UNEXPECTED);
|
||||
do_check_throws(function() {
|
||||
ps.getFloatPref(prefName);
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
strictEqual(ps.getFloatPref(prefName, 3.5), 3.5);
|
||||
strictEqual(ps.getFloatPref(prefName, 0), 0);
|
||||
ps.setCharPref(prefName, 1.75);
|
||||
|
@ -44,8 +48,9 @@ function run_test() {
|
|||
strictEqual(ps.getFloatPref(prefName, 3.5), 1.75);
|
||||
|
||||
prefName = "test.default.values.int";
|
||||
do_check_throws(function() { ps.getIntPref(prefName); },
|
||||
Cr.NS_ERROR_UNEXPECTED);
|
||||
do_check_throws(function() {
|
||||
ps.getIntPref(prefName);
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
strictEqual(ps.getIntPref(prefName, 3), 3);
|
||||
strictEqual(ps.getIntPref(prefName, 0), 0);
|
||||
ps.setIntPref(prefName, 42);
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
/* Tests for handling of the preferences 'dirty' flag (bug 985998) */
|
||||
|
||||
const PREF_INVALID = 0;
|
||||
const PREF_BOOL = 128;
|
||||
const PREF_INT = 64;
|
||||
const PREF_STRING = 32;
|
||||
const PREF_BOOL = 128;
|
||||
const PREF_INT = 64;
|
||||
const PREF_STRING = 32;
|
||||
|
||||
function run_test() {
|
||||
const ps = Services.prefs;
|
||||
|
@ -57,7 +57,7 @@ function run_test() {
|
|||
// 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);
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
Assert.ok(!ps.dirty);
|
||||
|
||||
// Set user value same as default, not dirty
|
||||
|
|
|
@ -3,9 +3,9 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
const PREF_INVALID = 0;
|
||||
const PREF_BOOL = 128;
|
||||
const PREF_INT = 64;
|
||||
const PREF_STRING = 32;
|
||||
const PREF_BOOL = 128;
|
||||
const PREF_INT = 64;
|
||||
const PREF_STRING = 32;
|
||||
|
||||
const MAX_PREF_LENGTH = 1 * 1024 * 1024;
|
||||
|
||||
|
@ -25,59 +25,62 @@ function run_test() {
|
|||
|
||||
do_check_throws(function() {
|
||||
ps.getPrefType(null);
|
||||
}, Cr.NS_ERROR_INVALID_ARG);
|
||||
}, Cr.NS_ERROR_INVALID_ARG);
|
||||
do_check_throws(function() {
|
||||
ps.getBoolPref(null);
|
||||
}, Cr.NS_ERROR_INVALID_ARG);
|
||||
}, Cr.NS_ERROR_INVALID_ARG);
|
||||
do_check_throws(function() {
|
||||
ps.setBoolPref(null, false);
|
||||
}, Cr.NS_ERROR_INVALID_ARG);
|
||||
}, Cr.NS_ERROR_INVALID_ARG);
|
||||
do_check_throws(function() {
|
||||
ps.getIntPref(null);
|
||||
}, Cr.NS_ERROR_INVALID_ARG);
|
||||
}, Cr.NS_ERROR_INVALID_ARG);
|
||||
do_check_throws(function() {
|
||||
ps.setIntPref(null, 0);
|
||||
}, Cr.NS_ERROR_INVALID_ARG);
|
||||
}, Cr.NS_ERROR_INVALID_ARG);
|
||||
do_check_throws(function() {
|
||||
ps.getCharPref(null);
|
||||
}, Cr.NS_ERROR_INVALID_ARG);
|
||||
}, Cr.NS_ERROR_INVALID_ARG);
|
||||
do_check_throws(function() {
|
||||
ps.setCharPref(null, null);
|
||||
}, Cr.NS_ERROR_INVALID_ARG);
|
||||
}, Cr.NS_ERROR_INVALID_ARG);
|
||||
do_check_throws(function() {
|
||||
ps.getStringPref(null);
|
||||
}, Cr.NS_ERROR_INVALID_ARG);
|
||||
}, Cr.NS_ERROR_INVALID_ARG);
|
||||
do_check_throws(function() {
|
||||
ps.setStringPref(null, null);
|
||||
}, Cr.NS_ERROR_INVALID_ARG);
|
||||
}, Cr.NS_ERROR_INVALID_ARG);
|
||||
do_check_throws(function() {
|
||||
ps.clearUserPref(null);
|
||||
}, Cr.NS_ERROR_INVALID_ARG);
|
||||
}, Cr.NS_ERROR_INVALID_ARG);
|
||||
do_check_throws(function() {
|
||||
ps.prefHasUserValue(null);
|
||||
}, Cr.NS_ERROR_INVALID_ARG);
|
||||
}, Cr.NS_ERROR_INVALID_ARG);
|
||||
do_check_throws(function() {
|
||||
ps.lockPref(null);
|
||||
}, Cr.NS_ERROR_INVALID_ARG);
|
||||
}, Cr.NS_ERROR_INVALID_ARG);
|
||||
do_check_throws(function() {
|
||||
ps.prefIsLocked(null);
|
||||
}, Cr.NS_ERROR_INVALID_ARG);
|
||||
}, Cr.NS_ERROR_INVALID_ARG);
|
||||
do_check_throws(function() {
|
||||
ps.unlockPref(null);
|
||||
}, Cr.NS_ERROR_INVALID_ARG);
|
||||
}, Cr.NS_ERROR_INVALID_ARG);
|
||||
do_check_throws(function() {
|
||||
ps.deleteBranch(null);
|
||||
}, Cr.NS_ERROR_INVALID_ARG);
|
||||
}, Cr.NS_ERROR_INVALID_ARG);
|
||||
do_check_throws(function() {
|
||||
ps.getChildList(null);
|
||||
}, Cr.NS_ERROR_INVALID_ARG);
|
||||
}, Cr.NS_ERROR_INVALID_ARG);
|
||||
|
||||
//* *************************************************************************//
|
||||
// Nonexisting user preferences
|
||||
|
||||
Assert.equal(ps.prefHasUserValue("UserPref.nonexistent.hasUserValue"), false);
|
||||
ps.clearUserPref("UserPref.nonexistent.clearUserPref"); // shouldn't throw
|
||||
Assert.equal(ps.getPrefType("UserPref.nonexistent.getPrefType"), PREF_INVALID);
|
||||
Assert.equal(
|
||||
ps.getPrefType("UserPref.nonexistent.getPrefType"),
|
||||
PREF_INVALID
|
||||
);
|
||||
Assert.equal(ps.root, "");
|
||||
|
||||
// bool...
|
||||
|
@ -328,8 +331,9 @@ function run_test() {
|
|||
savePrefFile.append("data");
|
||||
savePrefFile.append("savePref.js");
|
||||
|
||||
if (savePrefFile.exists())
|
||||
if (savePrefFile.exists()) {
|
||||
savePrefFile.remove(false);
|
||||
}
|
||||
savePrefFile.create(Ci.nsIFile.NORMAL_FILE_TYPE, 0o666);
|
||||
ps.savePrefFile(savePrefFile);
|
||||
ps.resetPrefs();
|
||||
|
@ -396,9 +400,9 @@ function run_test() {
|
|||
}
|
||||
|
||||
QueryInterface(aIID) {
|
||||
if (aIID.equals(Ci.nsIObserver) ||
|
||||
aIID.equals(Ci.nsISupports))
|
||||
if (aIID.equals(Ci.nsIObserver) || aIID.equals(Ci.nsISupports)) {
|
||||
return this;
|
||||
}
|
||||
throw Cr.NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
|
|
|
@ -40,24 +40,32 @@ 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.long"),
|
||||
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||
);
|
||||
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");
|
||||
Assert.equal(ps.getCharPref("string.escapes"), "\" \' \\ \n \r");
|
||||
Assert.equal(
|
||||
ps.getCharPref("string.weird-chars"),
|
||||
"\x0d \x09 \x0b \x0c \x06 \x16"
|
||||
);
|
||||
Assert.equal(ps.getCharPref("string.escapes"), "\" ' \\ \n \r");
|
||||
|
||||
// This one is ASCII, so we can use getCharPref() and getStringPref
|
||||
// interchangeably.
|
||||
Assert.equal(ps.getCharPref("string.x-escapes1"),
|
||||
"Mozilla0\x4d\x6F\x7a\x69\x6c\x6C\x610");
|
||||
Assert.equal(ps.getStringPref("string.x-escapes1"),
|
||||
"Mozilla0Mozilla0");
|
||||
Assert.equal(
|
||||
ps.getCharPref("string.x-escapes1"),
|
||||
"Mozilla0\x4d\x6F\x7a\x69\x6c\x6C\x610"
|
||||
);
|
||||
Assert.equal(ps.getStringPref("string.x-escapes1"), "Mozilla0Mozilla0");
|
||||
|
||||
// This one has chars with value > 127, so it's not valid UTF8, so we can't
|
||||
// use getStringPref on it.
|
||||
Assert.equal(ps.getCharPref("string.x-escapes2"),
|
||||
"AA A_umlaut\xc4 y_umlaut\xff");
|
||||
Assert.equal(
|
||||
ps.getCharPref("string.x-escapes2"),
|
||||
"AA A_umlaut\xc4 y_umlaut\xff"
|
||||
);
|
||||
|
||||
// The following strings use \uNNNN escapes, which are UTF16 code points.
|
||||
// libpref stores them internally as UTF8 byte sequences. In each case we get
|
||||
|
@ -70,18 +78,30 @@ function run_test() {
|
|||
// in JS. I.e. code points that are multiple bytes in UTF8 become multiple
|
||||
// 16-bit chars in JS.
|
||||
|
||||
Assert.equal(ps.getStringPref("string.u-escapes1"),
|
||||
"A\u0041 A_umlaut\u00c4 y_umlaut\u00ff0");
|
||||
Assert.equal(ps.getCharPref("string.u-escapes1"),
|
||||
"A\x41 A_umlaut\xc3\x84 y_umlaut\xc3\xbf0");
|
||||
Assert.equal(
|
||||
ps.getStringPref("string.u-escapes1"),
|
||||
"A\u0041 A_umlaut\u00c4 y_umlaut\u00ff0"
|
||||
);
|
||||
Assert.equal(
|
||||
ps.getCharPref("string.u-escapes1"),
|
||||
"A\x41 A_umlaut\xc3\x84 y_umlaut\xc3\xbf0"
|
||||
);
|
||||
|
||||
Assert.equal(ps.getStringPref("string.u-escapes2"),
|
||||
"S_acute\u015a y_grave\u1Ef3");
|
||||
Assert.equal(ps.getCharPref("string.u-escapes2"),
|
||||
"S_acute\xc5\x9a y_grave\xe1\xbb\xb3");
|
||||
Assert.equal(
|
||||
ps.getStringPref("string.u-escapes2"),
|
||||
"S_acute\u015a y_grave\u1Ef3"
|
||||
);
|
||||
Assert.equal(
|
||||
ps.getCharPref("string.u-escapes2"),
|
||||
"S_acute\xc5\x9a y_grave\xe1\xbb\xb3"
|
||||
);
|
||||
|
||||
Assert.equal(ps.getStringPref("string.u-surrogates"),
|
||||
"cyclone\uD83C\uDF00 grinning_face\uD83D\uDE00");
|
||||
Assert.equal(ps.getCharPref("string.u-surrogates"),
|
||||
"cyclone\xF0\x9F\x8C\x80 grinning_face\xF0\x9F\x98\x80");
|
||||
Assert.equal(
|
||||
ps.getStringPref("string.u-surrogates"),
|
||||
"cyclone\uD83C\uDF00 grinning_face\uD83D\uDE00"
|
||||
);
|
||||
Assert.equal(
|
||||
ps.getCharPref("string.u-surrogates"),
|
||||
"cyclone\xF0\x9F\x8C\x80 grinning_face\xF0\x9F\x98\x80"
|
||||
);
|
||||
}
|
||||
|
|
|
@ -62,8 +62,11 @@ add_test(function writtenOnceLoadedWithoutChange() {
|
|||
resetAndLoadAll();
|
||||
// reset and re-read what we just wrote - it should be written.
|
||||
saveAndReload();
|
||||
Assert.strictEqual(ps.getBoolPref("testPref.sticky.bool"), false,
|
||||
"user_pref was written with default value");
|
||||
Assert.strictEqual(
|
||||
ps.getBoolPref("testPref.sticky.bool"),
|
||||
false,
|
||||
"user_pref was written with default value"
|
||||
);
|
||||
run_next_test();
|
||||
});
|
||||
|
||||
|
@ -75,8 +78,11 @@ add_test(function writtenOnceLoadedWithChangeNonDefault() {
|
|||
// Set a new val and check we wrote it.
|
||||
ps.setBoolPref("testPref.sticky.bool", false);
|
||||
saveAndReload();
|
||||
Assert.strictEqual(ps.getBoolPref("testPref.sticky.bool"), false,
|
||||
"user_pref was written with custom value");
|
||||
Assert.strictEqual(
|
||||
ps.getBoolPref("testPref.sticky.bool"),
|
||||
false,
|
||||
"user_pref was written with custom value"
|
||||
);
|
||||
run_next_test();
|
||||
});
|
||||
|
||||
|
@ -88,8 +94,11 @@ add_test(function writtenOnceLoadedWithChangeNonDefault() {
|
|||
// Set a new val and check we wrote it.
|
||||
ps.setBoolPref("testPref.sticky.bool", true);
|
||||
saveAndReload();
|
||||
Assert.strictEqual(ps.getBoolPref("testPref.sticky.bool"), true,
|
||||
"user_pref was written with custom value");
|
||||
Assert.strictEqual(
|
||||
ps.getBoolPref("testPref.sticky.bool"),
|
||||
true,
|
||||
"user_pref was written with custom value"
|
||||
);
|
||||
run_next_test();
|
||||
});
|
||||
|
||||
|
@ -102,27 +111,37 @@ add_test(function hasUserValue() {
|
|||
// sticky pref without user value.
|
||||
resetAndLoadDefaults();
|
||||
Assert.strictEqual(ps.getBoolPref("testPref.sticky.bool"), false);
|
||||
Assert.ok(!ps.prefHasUserValue("testPref.sticky.bool"),
|
||||
"should not initially reflect a user value");
|
||||
Assert.ok(
|
||||
!ps.prefHasUserValue("testPref.sticky.bool"),
|
||||
"should not initially reflect a user value"
|
||||
);
|
||||
|
||||
ps.setBoolPref("testPref.sticky.bool", false);
|
||||
Assert.ok(ps.prefHasUserValue("testPref.sticky.bool"),
|
||||
"should reflect a user value after set to default");
|
||||
Assert.ok(
|
||||
ps.prefHasUserValue("testPref.sticky.bool"),
|
||||
"should reflect a user value after set to default"
|
||||
);
|
||||
|
||||
ps.setBoolPref("testPref.sticky.bool", true);
|
||||
Assert.ok(ps.prefHasUserValue("testPref.sticky.bool"),
|
||||
"should reflect a user value after change to non-default");
|
||||
Assert.ok(
|
||||
ps.prefHasUserValue("testPref.sticky.bool"),
|
||||
"should reflect a user value after change to non-default"
|
||||
);
|
||||
|
||||
ps.clearUserPref("testPref.sticky.bool");
|
||||
Assert.ok(!ps.prefHasUserValue("testPref.sticky.bool"),
|
||||
"should reset to no user value");
|
||||
Assert.ok(
|
||||
!ps.prefHasUserValue("testPref.sticky.bool"),
|
||||
"should reset to no user value"
|
||||
);
|
||||
ps.setBoolPref("testPref.sticky.bool", false, "expected default");
|
||||
|
||||
// And make sure the pref immediately reflects a user value after load.
|
||||
resetAndLoadAll();
|
||||
Assert.strictEqual(ps.getBoolPref("testPref.sticky.bool"), false);
|
||||
Assert.ok(ps.prefHasUserValue("testPref.sticky.bool"),
|
||||
"should have a user value when loaded value is the default");
|
||||
Assert.ok(
|
||||
ps.prefHasUserValue("testPref.sticky.bool"),
|
||||
"should have a user value when loaded value is the default"
|
||||
);
|
||||
run_next_test();
|
||||
});
|
||||
|
||||
|
@ -160,6 +179,9 @@ add_test(function observerFires() {
|
|||
}
|
||||
ps.addObserver("testPref.sticky.bool", observe);
|
||||
|
||||
ps.setBoolPref("testPref.sticky.bool", ps.getBoolPref("testPref.sticky.bool"));
|
||||
ps.setBoolPref(
|
||||
"testPref.sticky.bool",
|
||||
ps.getBoolPref("testPref.sticky.bool")
|
||||
);
|
||||
// and the observer will fire triggering the next text.
|
||||
});
|
||||
|
|
|
@ -16,8 +16,12 @@ function checkWarning(pref, buffer) {
|
|||
let listener = {
|
||||
observe(event) {
|
||||
let message = event.message;
|
||||
if (!(message.startsWith("Warning: attempting to write")
|
||||
&& message.includes(pref))) {
|
||||
if (
|
||||
!(
|
||||
message.startsWith("Warning: attempting to write") &&
|
||||
message.includes(pref)
|
||||
)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
if (complete) {
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
function isParentProcess() {
|
||||
let appInfo = Cc["@mozilla.org/xre/app-info;1"];
|
||||
return (!appInfo || Services.appinfo.processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT);
|
||||
let appInfo = Cc["@mozilla.org/xre/app-info;1"];
|
||||
return (
|
||||
!appInfo ||
|
||||
Services.appinfo.processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT
|
||||
);
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
function isParentProcess() {
|
||||
return (Services.appinfo.processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT);
|
||||
return Services.appinfo.processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT;
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
|
|
|
@ -6,10 +6,10 @@
|
|||
// Non-string preferences are not tested here, because their behavior
|
||||
// should not be affected by this filtering.
|
||||
//
|
||||
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
function isParentProcess() {
|
||||
return (Services.appinfo.processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT);
|
||||
return Services.appinfo.processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT;
|
||||
}
|
||||
|
||||
function makeBuffer(length) {
|
||||
|
@ -30,9 +30,9 @@ const largeString = makeBuffer(MAX_ADVISABLE_PREF_LENGTH + 1);
|
|||
const smallString = makeBuffer(4);
|
||||
|
||||
const testValues = [
|
||||
{name: "None", value: undefined},
|
||||
{name: "Small", value: smallString},
|
||||
{name: "Large", value: largeString},
|
||||
{ name: "None", value: undefined },
|
||||
{ name: "Small", value: smallString },
|
||||
{ name: "Large", value: largeString },
|
||||
];
|
||||
|
||||
function prefName(def, user) {
|
||||
|
@ -95,8 +95,10 @@ function run_test() {
|
|||
} catch (e) {
|
||||
prefExists = false;
|
||||
}
|
||||
ok(!prefExists,
|
||||
"Pref " + pref_name + " should not be set in the child");
|
||||
ok(
|
||||
!prefExists,
|
||||
"Pref " + pref_name + " should not be set in the child"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,10 +4,10 @@
|
|||
|
||||
// Locked status should be communicated to children.
|
||||
|
||||
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
function isParentProcess() {
|
||||
return (Services.appinfo.processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT);
|
||||
return Services.appinfo.processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT;
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
|
@ -34,5 +34,8 @@ function run_test() {
|
|||
|
||||
ok(pb.prefIsLocked(bprefname), bprefname + " should be locked in the child");
|
||||
ok(pb.prefIsLocked(iprefname), iprefname + " should be locked in the child");
|
||||
ok(!pb.prefIsLocked(sprefname), sprefname + " should be unlocked in the child");
|
||||
ok(
|
||||
!pb.prefIsLocked(sprefname),
|
||||
sprefname + " should be unlocked in the child"
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
function isParentProcess() {
|
||||
return (Services.appinfo.processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT);
|
||||
return Services.appinfo.processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT;
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
|
|
|
@ -9,14 +9,16 @@
|
|||
// process, and changes after that point are stored as entries in a dynamic hash
|
||||
// table, on top of the snapshot.
|
||||
|
||||
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
const {ExtensionTestUtils} = ChromeUtils.import("resource://testing-common/ExtensionXPCShellUtils.jsm");
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
const { ExtensionTestUtils } = ChromeUtils.import(
|
||||
"resource://testing-common/ExtensionXPCShellUtils.jsm"
|
||||
);
|
||||
|
||||
ExtensionTestUtils.init(this);
|
||||
|
||||
let contentPage;
|
||||
|
||||
const {prefs} = Services;
|
||||
const { prefs } = Services;
|
||||
const defaultPrefs = prefs.getDefaultBranch("");
|
||||
|
||||
const FRAME_SCRIPT_INIT = `
|
||||
|
@ -74,7 +76,15 @@ function getPrefs(prefNames) {
|
|||
return result;
|
||||
}
|
||||
|
||||
function checkPref(pref, proc, val, type, userVal, defaultVal, expectedFlags = {}) {
|
||||
function checkPref(
|
||||
pref,
|
||||
proc,
|
||||
val,
|
||||
type,
|
||||
userVal,
|
||||
defaultVal,
|
||||
expectedFlags = {}
|
||||
) {
|
||||
info(`Check "${pref}" ${proc} value`);
|
||||
|
||||
equal(val.type, type, `Expected type for "${pref}"`);
|
||||
|
@ -108,10 +118,16 @@ const TESTS = {
|
|||
ok(childList.includes(PREF), `Child list includes "${PREF}"`);
|
||||
|
||||
prefs.clearUserPref(PREF);
|
||||
ok(!getPrefList().includes(PREF), `Parent list doesn't include "${PREF}"`);
|
||||
ok(
|
||||
!getPrefList().includes(PREF),
|
||||
`Parent list doesn't include "${PREF}"`
|
||||
);
|
||||
},
|
||||
contentUpdate1(PREF, val, childList) {
|
||||
ok(!getPrefList().includes(PREF), `Parent list doesn't include "${PREF}"`);
|
||||
ok(
|
||||
!getPrefList().includes(PREF),
|
||||
`Parent list doesn't include "${PREF}"`
|
||||
);
|
||||
ok(!childList.includes(PREF), `Child list doesn't include "${PREF}"`);
|
||||
|
||||
prefs.setCharPref(PREF, "foo");
|
||||
|
@ -128,7 +144,10 @@ const TESTS = {
|
|||
},
|
||||
"doesNotExists.thenDoes": {
|
||||
contentStartup(PREF, val, childList) {
|
||||
ok(!getPrefList().includes(PREF), `Parent list doesn't include "${PREF}"`);
|
||||
ok(
|
||||
!getPrefList().includes(PREF),
|
||||
`Parent list doesn't include "${PREF}"`
|
||||
);
|
||||
ok(!childList.includes(PREF), `Child list doesn't include "${PREF}"`);
|
||||
|
||||
prefs.setIntPref(PREF, 42);
|
||||
|
@ -145,23 +164,41 @@ const TESTS = {
|
|||
};
|
||||
|
||||
const PREFS = [
|
||||
{type: "Bool", values: [true, false, true]},
|
||||
{type: "Int", values: [24, 42, 73]},
|
||||
{type: "String", values: ["meh", "hem", "hrm"]},
|
||||
{ type: "Bool", values: [true, false, true] },
|
||||
{ type: "Int", values: [24, 42, 73] },
|
||||
{ type: "String", values: ["meh", "hem", "hrm"] },
|
||||
];
|
||||
|
||||
for (let {type, values} of PREFS) {
|
||||
for (let { type, values } of PREFS) {
|
||||
let set = `set${type}Pref`;
|
||||
|
||||
function prefTest(opts) {
|
||||
function check(pref, proc, val, {expectedVal, defaultVal = undefined, expectedDefault = defaultVal, expectedFlags = {}}) {
|
||||
checkPref(pref, proc, val, type, expectedVal, expectedDefault, expectedFlags);
|
||||
function check(
|
||||
pref,
|
||||
proc,
|
||||
val,
|
||||
{
|
||||
expectedVal,
|
||||
defaultVal = undefined,
|
||||
expectedDefault = defaultVal,
|
||||
expectedFlags = {},
|
||||
}
|
||||
) {
|
||||
checkPref(
|
||||
pref,
|
||||
proc,
|
||||
val,
|
||||
type,
|
||||
expectedVal,
|
||||
expectedDefault,
|
||||
expectedFlags
|
||||
);
|
||||
}
|
||||
|
||||
function updatePref(PREF,
|
||||
{userVal = undefined,
|
||||
defaultVal = undefined,
|
||||
flags = {}}) {
|
||||
function updatePref(
|
||||
PREF,
|
||||
{ userVal = undefined, defaultVal = undefined, flags = {} }
|
||||
) {
|
||||
info(`Update "${PREF}"`);
|
||||
if (userVal !== undefined) {
|
||||
prefs[set](PREF, userVal);
|
||||
|
@ -211,54 +248,76 @@ for (let {type, values} of PREFS) {
|
|||
let defaultVal = values[+!i];
|
||||
|
||||
TESTS[`type.${type}.${i}.default`] = prefTest({
|
||||
initial: {defaultVal, expectedVal: defaultVal},
|
||||
change1: {defaultVal: values[2], expectedVal: values[2]},
|
||||
initial: { defaultVal, expectedVal: defaultVal },
|
||||
change1: { defaultVal: values[2], expectedVal: values[2] },
|
||||
});
|
||||
|
||||
TESTS[`type.${type}.${i}.user`] = prefTest({
|
||||
initial: {userVal, expectedVal: userVal},
|
||||
change1: {defaultVal: values[2], expectedVal: userVal},
|
||||
change2: {userVal: values[2],
|
||||
expectedDefault: values[2],
|
||||
expectedVal: values[2]},
|
||||
initial: { userVal, expectedVal: userVal },
|
||||
change1: { defaultVal: values[2], expectedVal: userVal },
|
||||
change2: {
|
||||
userVal: values[2],
|
||||
expectedDefault: values[2],
|
||||
expectedVal: values[2],
|
||||
},
|
||||
});
|
||||
|
||||
TESTS[`type.${type}.${i}.both`] = prefTest({
|
||||
initial: {userVal, defaultVal, expectedVal: userVal},
|
||||
change1: {defaultVal: values[2], expectedVal: userVal},
|
||||
change2: {userVal: values[2],
|
||||
expectedDefault: values[2],
|
||||
expectedVal: values[2]},
|
||||
initial: { userVal, defaultVal, expectedVal: userVal },
|
||||
change1: { defaultVal: values[2], expectedVal: userVal },
|
||||
change2: {
|
||||
userVal: values[2],
|
||||
expectedDefault: values[2],
|
||||
expectedVal: values[2],
|
||||
},
|
||||
});
|
||||
|
||||
TESTS[`type.${type}.${i}.both.thenLock`] = prefTest({
|
||||
initial: {userVal, defaultVal, expectedVal: userVal},
|
||||
change1: {expectedDefault: defaultVal,
|
||||
expectedVal: defaultVal,
|
||||
flags: {locked: true},
|
||||
expectFlags: {locked: true}},
|
||||
initial: { userVal, defaultVal, expectedVal: userVal },
|
||||
change1: {
|
||||
expectedDefault: defaultVal,
|
||||
expectedVal: defaultVal,
|
||||
flags: { locked: true },
|
||||
expectFlags: { locked: true },
|
||||
},
|
||||
});
|
||||
|
||||
TESTS[`type.${type}.${i}.both.thenUnlock`] = prefTest({
|
||||
initial: {userVal, defaultVal, expectedVal: defaultVal,
|
||||
flags: {locked: true}, expectedFlags: {locked: true}},
|
||||
change1: {expectedDefault: defaultVal,
|
||||
expectedVal: userVal,
|
||||
flags: {locked: false},
|
||||
expectFlags: {locked: false}},
|
||||
initial: {
|
||||
userVal,
|
||||
defaultVal,
|
||||
expectedVal: defaultVal,
|
||||
flags: { locked: true },
|
||||
expectedFlags: { locked: true },
|
||||
},
|
||||
change1: {
|
||||
expectedDefault: defaultVal,
|
||||
expectedVal: userVal,
|
||||
flags: { locked: false },
|
||||
expectFlags: { locked: false },
|
||||
},
|
||||
});
|
||||
|
||||
TESTS[`type.${type}.${i}.both.locked`] = prefTest({
|
||||
initial: {userVal, defaultVal, expectedVal: defaultVal,
|
||||
flags: {locked: true}, expectedFlags: {locked: true}},
|
||||
change1: {userVal: values[2],
|
||||
expectedDefault: defaultVal,
|
||||
expectedVal: defaultVal,
|
||||
expectedFlags: {locked: true}},
|
||||
change2: {defaultVal: values[2],
|
||||
expectedDefault: defaultVal,
|
||||
expectedVal: defaultVal,
|
||||
expectedFlags: {locked: true}},
|
||||
initial: {
|
||||
userVal,
|
||||
defaultVal,
|
||||
expectedVal: defaultVal,
|
||||
flags: { locked: true },
|
||||
expectedFlags: { locked: true },
|
||||
},
|
||||
change1: {
|
||||
userVal: values[2],
|
||||
expectedDefault: defaultVal,
|
||||
expectedVal: defaultVal,
|
||||
expectedFlags: { locked: true },
|
||||
},
|
||||
change2: {
|
||||
defaultVal: values[2],
|
||||
expectedDefault: defaultVal,
|
||||
expectedVal: defaultVal,
|
||||
expectedFlags: { locked: true },
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -270,16 +329,20 @@ add_task(async function test_sharedMap_prefs() {
|
|||
for (let [pref, ops] of Object.entries(TESTS)) {
|
||||
if (ops[op]) {
|
||||
info(`Running ${op} for "${pref}"`);
|
||||
await ops[op](pref,
|
||||
prefValues[pref] || undefined,
|
||||
prefValues.childList || undefined);
|
||||
await ops[op](
|
||||
pref,
|
||||
prefValues[pref] || undefined,
|
||||
prefValues.childList || undefined
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
await runChecks("beforeContent");
|
||||
|
||||
contentPage = await ExtensionTestUtils.loadContentPage("about:blank", {remote: true});
|
||||
contentPage = await ExtensionTestUtils.loadContentPage("about:blank", {
|
||||
remote: true,
|
||||
});
|
||||
registerCleanupFunction(() => contentPage.close());
|
||||
|
||||
contentPage.addFrameScriptHelper(FRAME_SCRIPT_INIT);
|
||||
|
|
|
@ -25,40 +25,56 @@ const PREF1_VALUE = false;
|
|||
const PREF2_NAME = "dom.mutation-events.cssom.disabled";
|
||||
const PREF2_VALUE = true;
|
||||
|
||||
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
const {ExtensionTestUtils} = ChromeUtils.import("resource://testing-common/ExtensionXPCShellUtils.jsm");
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
const { ExtensionTestUtils } = ChromeUtils.import(
|
||||
"resource://testing-common/ExtensionXPCShellUtils.jsm"
|
||||
);
|
||||
|
||||
ExtensionTestUtils.init(this);
|
||||
|
||||
const {prefs} = Services;
|
||||
const { prefs } = Services;
|
||||
const defaultPrefs = prefs.getDefaultBranch("");
|
||||
|
||||
add_task(async function test_sharedMap_var_caches() {
|
||||
equal(prefs.getBoolPref(PREF1_NAME), PREF1_VALUE,
|
||||
`Expected initial value for ${PREF1_NAME}`);
|
||||
equal(prefs.getBoolPref(PREF2_NAME), PREF2_VALUE,
|
||||
`Expected initial value for ${PREF2_NAME}`);
|
||||
equal(
|
||||
prefs.getBoolPref(PREF1_NAME),
|
||||
PREF1_VALUE,
|
||||
`Expected initial value for ${PREF1_NAME}`
|
||||
);
|
||||
equal(
|
||||
prefs.getBoolPref(PREF2_NAME),
|
||||
PREF2_VALUE,
|
||||
`Expected initial value for ${PREF2_NAME}`
|
||||
);
|
||||
|
||||
defaultPrefs.setBoolPref(PREF1_NAME, !PREF1_VALUE);
|
||||
prefs.setBoolPref(PREF2_NAME, !PREF2_VALUE);
|
||||
|
||||
equal(prefs.getBoolPref(PREF1_NAME), !PREF1_VALUE,
|
||||
`Expected updated value for ${PREF1_NAME}`);
|
||||
equal(prefs.getBoolPref(PREF2_NAME), !PREF2_VALUE,
|
||||
`Expected updated value for ${PREF2_NAME}`);
|
||||
equal(
|
||||
prefs.getBoolPref(PREF1_NAME),
|
||||
!PREF1_VALUE,
|
||||
`Expected updated value for ${PREF1_NAME}`
|
||||
);
|
||||
equal(
|
||||
prefs.getBoolPref(PREF2_NAME),
|
||||
!PREF2_VALUE,
|
||||
`Expected updated value for ${PREF2_NAME}`
|
||||
);
|
||||
|
||||
let contentPage = await ExtensionTestUtils.loadContentPage("about:blank", {remote: true});
|
||||
let contentPage = await ExtensionTestUtils.loadContentPage("about:blank", {
|
||||
remote: true,
|
||||
});
|
||||
registerCleanupFunction(() => contentPage.close());
|
||||
|
||||
/* eslint-disable no-shadow */
|
||||
let values = await contentPage.spawn([PREF1_NAME, PREF2_NAME], (prefs) => {
|
||||
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
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));
|
||||
});
|
||||
/* eslint-enable no-shadow */
|
||||
|
||||
equal(values[0], !PREF1_VALUE,
|
||||
`Expected content value for ${PREF1_NAME}`);
|
||||
equal(values[1], !PREF2_VALUE,
|
||||
`Expected content value for ${PREF2_NAME}`);
|
||||
equal(values[0], !PREF1_VALUE, `Expected content value for ${PREF1_NAME}`);
|
||||
equal(values[1], !PREF2_VALUE, `Expected content value for ${PREF2_NAME}`);
|
||||
});
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
function isParentProcess() {
|
||||
return Services.appinfo.processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT;
|
||||
|
@ -24,12 +24,13 @@ function testPrefClear() {
|
|||
pb.clearUserPref("Test.IPC.bool.new");
|
||||
|
||||
sendCommand(
|
||||
'var pb = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);\n' +
|
||||
'pb.prefHasUserValue("Test.IPC.bool.new");\n',
|
||||
checkWasCleared);
|
||||
'var pb = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);\n' +
|
||||
'pb.prefHasUserValue("Test.IPC.bool.new");\n',
|
||||
checkWasCleared
|
||||
);
|
||||
}
|
||||
|
||||
function checkWasCleared(existsStr) {
|
||||
Assert.equal(existsStr, "false");
|
||||
do_test_finished();
|
||||
Assert.equal(existsStr, "false");
|
||||
do_test_finished();
|
||||
}
|
||||
|
|
|
@ -1,24 +1,29 @@
|
|||
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
const pb = Services.prefs;
|
||||
|
||||
// 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
|
||||
// assume below
|
||||
// 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' +
|
||||
// Returns concatenation "[value],[isUser]"
|
||||
'pb.getCharPref("' + kPrefName + '")+ "," +' +
|
||||
'pb.prefHasUserValue("' + kPrefName + '");',
|
||||
// Returns concatenation "[value],[isUser]"
|
||||
'pb.getCharPref("' +
|
||||
kPrefName +
|
||||
'")+ "," +' +
|
||||
'pb.prefHasUserValue("' +
|
||||
kPrefName +
|
||||
'");',
|
||||
function(info) {
|
||||
let [ value, isUser ] = info.split(",");
|
||||
let [value, isUser] = info.split(",");
|
||||
Assert.equal(pb.getCharPref(kPrefName), value);
|
||||
Assert.equal(pb.prefHasUserValue(kPrefName), isUser == "true");
|
||||
continuation();
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
|
|
Загрузка…
Ссылка в новой задаче