Bug 1501932 - Enable ESLint for modules/ (manual changes). r=aklotz,njn

Differential Revision: https://phabricator.services.mozilla.com/D14647

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Ya'ar Hever 2019-02-21 00:50:18 +00:00
parent 531ae2db82
commit 5886d1854f
48 changed files with 336 additions and 398 deletions

View file

@ -22,7 +22,6 @@ extensions/spellcheck/**
extensions/universalchardet/**
image/**
layout/**
modules/**
netwerk/cookie/test/browser/**
netwerk/test/browser/**
netwerk/test/mochitests/**

View file

@ -23,16 +23,16 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1173171
// Returns a promise with the response.
let xhr = function(method, url, responseType) {
return new Promise(function(resolve, reject) {
let xhr = new XMLHttpRequest();
xhr.open(method, url, true);
xhr.onload = function() {
resolve(xhr.response);
let xhrInstance = new XMLHttpRequest();
xhrInstance.open(method, url, true);
xhrInstance.onload = function() {
resolve(xhrInstance.response);
};
xhr.onerror = function() {
xhrInstance.onerror = function() {
resolve(null);
};
xhr.responseType = responseType;
xhr.send();
xhrInstance.responseType = responseType;
xhrInstance.send();
});
};
@ -40,7 +40,6 @@ let jarURL = "jar:http://mochi.test:8888/tests/modules/libjar/test/mochitest/bug
// Test behavior when blocking is deactivated and activated.
add_task(async function() {
let shouldBlock = true;
let response = await xhr("GET", jarURL, "document");
is(response, null, "Remote jars should be blocked.");
});

View file

@ -4,15 +4,14 @@
"use strict";
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 ios = Cc["@mozilla.org/network/io-service;1"].
getService(Ci.nsIIOService);
var outerJarBase = "jar:" + ios.newFileURI(file).spec + "!/";
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 instr = goodChannel.open();
@ -22,9 +21,7 @@ add_task(async function() {
add_task(async function() {
var file = do_get_file("data/test_bug597702.zip");
var ios = Cc["@mozilla.org/network/io-service;1"].
getService(Ci.nsIIOService);
var outerJarBase = "jar:" + ios.newFileURI(file).spec + "!/";
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 instr = goodChannel.open();
@ -34,9 +31,7 @@ add_task(async function() {
add_task(async function() {
var file = do_get_file("data/test_bug597702.zip");
var ios = Cc["@mozilla.org/network/io-service;1"].
getService(Ci.nsIIOService);
var outerJarBase = "jar:" + ios.newFileURI(file).spec + "!/";
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 instr = goodChannel.open();

View file

@ -1,11 +1,11 @@
// 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 path = "data/test_bug333423.zip";
function test_relative_sub() {
var ios = Cc["@mozilla.org/network/io-service;1"].
getService(Ci.nsIIOService);
var ios = Services.io;
var spec = "jar:" + ios.newFileURI(do_get_file(path)).spec + "!/";
var base = ios.newURI(spec);
var uri = ios.newURI("../modules/libjar", null, base);
@ -18,9 +18,7 @@ function test_relative_sub() {
}
function test_relative_base() {
var ios = Cc["@mozilla.org/network/io-service;1"].
getService(Ci.nsIIOService);
var ios = Services.io;
var base = ios.newFileURI(do_get_file("data/empty"));
var uri = ios.newURI("jar:../" + path + "!/", null, base);

View file

@ -1,13 +1,12 @@
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
function run_test() {
// Compose the jar: url
var ioService = Cc["@mozilla.org/network/io-service;1"].
getService(Ci.nsIIOService);
var file = do_get_file("data/test_bug370103.jar");
var url = ioService.newFileURI(file).spec;
var url = Services.io.newFileURI(file).spec;
url = "jar:" + url + "!/test_bug370103";
// Try opening channel with null listener

View file

@ -1,18 +1,16 @@
// 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 path = "data/test_bug589292.zip";
function run_test() {
var ios = Cc["@mozilla.org/network/io-service;1"].
getService(Ci.nsIIOService);
var spec = "jar:" + ios.newFileURI(do_get_file(path)).spec + "!/foo.txt";
var spec = "jar:" + Services.io.newFileURI(do_get_file(path)).spec + "!/foo.txt";
var channel = NetUtil.newChannel({uri: spec, loadUsingSystemPrincipal: true});
instr = channel.open();
var val;
channel.open();
try {
val = channel.contentDisposition;
channel.contentDisposition;
Assert.ok(false, "The channel has content disposition?!");
} catch (e) {
// This is what we want to happen - there's no underlying channel, so no

View file

@ -2,31 +2,29 @@
* 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");
// Check that reading non existant inner jars results in the right error
function run_test() {
var file = do_get_file("data/test_bug597702.zip");
var ios = Cc["@mozilla.org/network/io-service;1"].
getService(Ci.nsIIOService);
var outerJarBase = "jar:" + ios.newFileURI(file).spec + "!/";
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});
try {
instr = goodChannel.open();
goodChannel.open();
} catch (e) {
do_throw("Failed to open file in inner jar");
}
try {
instr = badChannel.open();
badChannel.open();
do_throw("Failed to report that file doesn't exist");
} catch (e) {
Assert.ok(e.name == "NS_ERROR_FILE_NOT_FOUND");
}
}

View file

@ -2,25 +2,23 @@
* 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");
// Check that the zip cache can expire entries from nested jars
var ios = Cc["@mozilla.org/network/io-service;1"].
getService(Ci.nsIIOService);
function open_inner_zip(base, idx) {
var spec = "jar:" + base + "inner" + idx + ".zip!/foo";
var channel = NetUtil.newChannel({uri: spec, loadUsingSystemPrincipal: true});
var stream = channel.open();
var spec = "jar:" + base + "inner" + idx + ".zip!/foo";
var channel = NetUtil.newChannel({uri: spec, loadUsingSystemPrincipal: true});
channel.open();
}
function run_test() {
var file = do_get_file("data/test_bug637286.zip");
var outerJarBase = "jar:" + ios.newFileURI(file).spec + "!/";
var outerJarBase = "jar:" + Services.io.newFileURI(file).spec + "!/";
for (var i = 0; i < 40; i++) {
open_inner_zip(outerJarBase, i);
gc();
}
}

View file

@ -2,19 +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");
// Check that we don't crash on reading a directory entry signature
var ios = Cc["@mozilla.org/network/io-service;1"].
getService(Ci.nsIIOService);
function run_test() {
var file = do_get_file("data/test_bug658093.zip");
var spec = "jar:" + ios.newFileURI(file).spec + "!/0000";
var spec = "jar:" + Services.io.newFileURI(file).spec + "!/0000";
var channel = NetUtil.newChannel({uri: spec, loadUsingSystemPrincipal: true});
var failed = false;
try {
var stream = channel.open();
channel.open();
} catch (e) {
failed = true;
}

View file

@ -8,7 +8,7 @@ function run_test() {
var file = do_get_file("data/test_corrupt3.zip");
var zipreader = Cc["@mozilla.org/libjar/zip-reader;1"].
createInstance(Ci.nsIZipReader);
createInstance(Ci.nsIZipReader);
zipreader.open(file);
var failed = false;
@ -16,7 +16,7 @@ function run_test() {
let entry = zipreader.getEntry(entryPath);
if (!entry.isDirectory) {
try {
let inputStream = zipreader.getInputStream(entryPath);
zipreader.getInputStream(entryPath);
} catch (e) {
failed = true;
}

View file

@ -19,7 +19,7 @@ function run_test() {
let file = do_get_file("data/test_crx_dummy.crx");
let zipreader = Cc["@mozilla.org/libjar/zip-reader;1"].
createInstance(Ci.nsIZipReader);
createInstance(Ci.nsIZipReader);
zipreader.open(file);
// do crc stuff
function check_archive_crc() {
@ -27,7 +27,7 @@ function run_test() {
return true;
}
Assert.ok(check_archive_crc());
let entries = zipreader.findEntries(null);
zipreader.findEntries(null);
let stream = wrapInputStream(zipreader.getInputStream("modules/libjar/test/Makefile.in"));
let dirstream = wrapInputStream(zipreader.getInputStream("modules/libjar/test/"));
zipreader.close();

View file

@ -7,21 +7,14 @@
*/
const {classes: Cc,
interfaces: Ci,
results: Cr,
utils: Cu,
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 ios = Cc["@mozilla.org/network/io-service;1"].
getService(Ci.nsIIOService);
const dirSvc = Cc["@mozilla.org/file/directory_service;1"].
getService(Ci.nsIProperties);
const obs = Cc["@mozilla.org/observer-service;1"].
getService(Ci.nsIObserverService);
const ios = Services.io;
const dirSvc = Services.dirsvc;
const obs = Services.obs;
const nsIBinaryInputStream = ctor("@mozilla.org/binaryinputstream;1",
"nsIBinaryInputStream",
@ -88,13 +81,13 @@ add_test(testAsync);
* Basic test for nsIZipReader.
*/
function testZipEntry() {
var uri = jarBase + "/inner40.zip";
var chan = NetUtil.newChannel({uri, loadUsingSystemPrincipal: true})
.QueryInterface(Ci.nsIJARChannel);
var entry = chan.zipEntry;
Assert.ok(entry.CRC32 == 0x8b635486);
Assert.ok(entry.realSize == 184);
run_next_test();
var uri = jarBase + "/inner40.zip";
var chan = NetUtil.newChannel({uri, loadUsingSystemPrincipal: true})
.QueryInterface(Ci.nsIJARChannel);
var entry = chan.zipEntry;
Assert.ok(entry.CRC32 == 0x8b635486);
Assert.ok(entry.realSize == 184);
run_next_test();
}
add_test(testZipEntry);

View file

@ -18,7 +18,7 @@ function run_test() {
var file = do_get_file("data/test_bug333423.zip");
var zipreader = Cc["@mozilla.org/libjar/zip-reader;1"].
createInstance(Ci.nsIZipReader);
createInstance(Ci.nsIZipReader);
zipreader.open(file);
// do crc stuff
function check_archive_crc() {
@ -26,7 +26,7 @@ function run_test() {
return true;
}
Assert.ok(check_archive_crc());
var entries = zipreader.findEntries(null);
zipreader.findEntries(null);
var stream = wrapInputStream(zipreader.getInputStream("modules/libjar/test/Makefile.in"));
var dirstream = wrapInputStream(zipreader.getInputStream("modules/libjar/test/"));
zipreader.close();

View file

@ -1,18 +1,17 @@
// 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 path = "data/test_bug333423.zip";
function run_test() {
var ios = Cc["@mozilla.org/network/io-service;1"].
getService(Ci.nsIIOService);
var spec = "jar:" + ios.newFileURI(do_get_file(path)).spec + "!/";
var spec = "jar:" + Services.io.newFileURI(do_get_file(path)).spec + "!/";
var channel = NetUtil.newChannel({
uri: spec + "file_that_isnt_in.archive",
loadUsingSystemPrincipal: true,
});
try {
instr = channel.open();
channel.open();
do_throw("Failed to report that file doesn't exist");
} catch (e) {
Assert.ok(e.name == "NS_ERROR_FILE_NOT_FOUND");

View file

@ -1,7 +1,7 @@
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
function run_test() {
var dirService = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
var tmpDir = dirService.get("TmpD", Ci.nsIFile);
var tmpDir = Services.dirsvc.get("TmpD", Ci.nsIFile);
var zipfile = do_get_file("data/test_umlaute.zip");

View file

@ -27,13 +27,13 @@ const PR_MSEC_PER_SEC = 1000;
const DATA_DIR = "data/";
var ioSvc = Cc["@mozilla.org/network/io-service;1"]
.getService(Ci.nsIIOService);
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
var ioSvc = Services.io;
var ZipWriter = Components.Constructor("@mozilla.org/zipwriter;1",
"nsIZipWriter");
"nsIZipWriter");
var ZipReader = Components.Constructor("@mozilla.org/libjar/zip-reader;1",
"nsIZipReader", "open");
"nsIZipReader", "open");
var tmpDir = do_get_profile();
var tmpFile = tmpDir.clone();

View file

@ -21,14 +21,14 @@ var TESTS = [
function swap16(n) {
return (((n >> 8) & 0xFF) << 0) |
(((n >> 0) & 0xFF) << 8);
(((n >> 0) & 0xFF) << 8);
}
function swap32(n) {
return (((n >> 24) & 0xFF) << 0) |
(((n >> 16) & 0xFF) << 8) |
(((n >> 8) & 0xFF) << 16) |
(((n >> 0) & 0xFF) << 24);
(((n >> 16) & 0xFF) << 8) |
(((n >> 8) & 0xFF) << 16) |
(((n >> 0) & 0xFF) << 24);
}
function move_to_data(bis, offset) {
@ -37,7 +37,7 @@ function move_to_data(bis, offset) {
bis.readBytes(4);
var file_len = swap16(bis.read16());
var extra_len = swap16(bis.read16());
var file = bis.readBytes(file_len);
bis.readBytes(file_len);
bis.readBytes(extra_len);
offset += ZIP_FILE_HEADER_SIZE + file_len + extra_len;
@ -52,17 +52,17 @@ function test_alignment(align_size) {
zipW.addEntryFile(TESTS[i].name, TESTS[i].compression, source, false);
}
var stream = Cc["@mozilla.org/io/string-input-stream;1"]
.createInstance(Ci.nsIStringInputStream);
.createInstance(Ci.nsIStringInputStream);
stream.setData(DATA, DATA.length);
zipW.addEntryStream(FILENAME, time * PR_USEC_PER_MSEC,
Ci.nsIZipWriter.COMPRESSION_NONE, stream, false);
Ci.nsIZipWriter.COMPRESSION_NONE, stream, false);
zipW.alignStoredFiles(align_size);
zipW.close();
// Check data can be decompressed.
var zipR = new ZipReader(tmpFile);
var 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);
@ -71,10 +71,10 @@ function test_alignment(align_size) {
// Check data is correct and aligned.
var fis = Cc["@mozilla.org/network/file-input-stream;1"]
.createInstance(Ci.nsIFileInputStream);
.createInstance(Ci.nsIFileInputStream);
fis.init(tmpFile, -1, -1, null);
let bis = Cc["@mozilla.org/binaryinputstream;1"]
.createInstance(Ci.nsIBinaryInputStream);
.createInstance(Ci.nsIBinaryInputStream);
bis.setInputStream(fis);
var offset = 0;
@ -91,7 +91,7 @@ function test_alignment(align_size) {
ret = move_to_data(bis, offset); // "test_data.txt"
offset = ret.offset;
var result = bis.readBytes(DATA.length);
result = bis.readBytes(DATA.length);
Assert.equal(result, DATA);
Assert.equal(offset % align_size, 0);

View file

@ -39,10 +39,10 @@ function run_test() {
Assert.ok(!zipW.inQueue);
var stream = Cc["@mozilla.org/io/string-input-stream;1"]
.createInstance(Ci.nsIStringInputStream);
.createInstance(Ci.nsIStringInputStream);
stream.setData(DATA, DATA.length);
zipW.addEntryStream(FILENAME, time * PR_USEC_PER_MSEC,
Ci.nsIZipWriter.COMPRESSION_BEST, stream, false);
Ci.nsIZipWriter.COMPRESSION_BEST, stream, false);
// Check that zip state is right at this stage.
testpass(zipW);
@ -57,8 +57,8 @@ function run_test() {
var zipR = new ZipReader(tmpFile);
testpass(zipR);
zipR.test(FILENAME);
var 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();

View file

@ -4,17 +4,16 @@
*/
function run_test() {
var test;
// zipW is an uninitialised zipwriter at this point.
try {
test = zipW.file;
zipW.file;
do_throw("Should have thrown uninitialized error.");
} catch (e) {
Assert.equal(e.result, Cr.NS_ERROR_NOT_INITIALIZED);
}
try {
test = zipW.comment;
zipW.comment;
do_throw("Should have thrown uninitialized error.");
} catch (e) {
Assert.equal(e.result, Cr.NS_ERROR_NOT_INITIALIZED);

View file

@ -4,11 +4,11 @@
function BinaryComparer(file, callback) {
var fstream = Cc["@mozilla.org/network/file-input-stream;1"].
createInstance(Ci.nsIFileInputStream);
createInstance(Ci.nsIFileInputStream);
fstream.init(file, -1, 0, 0);
this.length = file.fileSize;
this.fileStream = Cc["@mozilla.org/binaryinputstream;1"].
createInstance(Ci.nsIBinaryInputStream);
createInstance(Ci.nsIBinaryInputStream);
this.fileStream.setInputStream(fstream);
this.offset = 0;
this.callback = callback;
@ -32,7 +32,7 @@ BinaryComparer.prototype = {
onDataAvailable(aRequest, aContext, aInputStream, aOffset, aCount) {
var stream = Cc["@mozilla.org/binaryinputstream;1"].
createInstance(Ci.nsIBinaryInputStream);
createInstance(Ci.nsIBinaryInputStream);
stream.setInputStream(aInputStream);
var source, actual;
for (var i = 0; i < aCount; i++) {
@ -44,17 +44,18 @@ 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
// operating systems. The actual .gz for this test was created on a Unix
// system, but we want the test to work correctly everywhere. So ignore
// the byte at offset 9.
if (this.offset == 9)
;
else if (source != actual)
do_throw("Invalid value " + actual + " at offset " + this.offset + ", should have been " + source);
if (this.offset != 9 && source != actual) {
do_throw("Invalid value " + actual + " at offset " +
this.offset + ", should have been " + source);
}
this.offset++;
}
},
@ -67,21 +68,21 @@ 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);
comparer_callback);
// Prepare the stream converter
var scs = Cc["@mozilla.org/streamConverters;1"].
getService(Ci.nsIStreamConverterService);
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);
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);
createInstance(Ci.nsIInputStreamPump);
pump.init(fstream, 0, 0, true);
pump.asyncRead(converter, null);
do_test_pending();

View file

@ -41,7 +41,7 @@ function run_test() {
zipR.test(FILENAME);
var stream = Cc["@mozilla.org/scriptableinputstream;1"]
stream = Cc["@mozilla.org/scriptableinputstream;1"]
.createInstance(Ci.nsIScriptableInputStream);
stream.init(zipR.getInputStream(FILENAME));
var result = stream.read(DATA.length);

View file

@ -29,7 +29,7 @@ function run_test() {
zipW.open(tmpFile, PR_RDWR);
for (var i = 0; i < TESTS.length; i++) {
for (let i = 0; i < TESTS.length; i++) {
Assert.ok(zipW.hasEntry(TESTS[i].name));
var entry = zipW.getEntry(TESTS[i].name);
Assert.ok(entry != null);
@ -46,7 +46,7 @@ function run_test() {
Assert.equal(e.result, Cr.NS_ERROR_FILE_NOT_FOUND);
}
for (var i = 0; i < TESTS.length; i++) {
for (let i = 0; i < TESTS.length; i++) {
zipW.removeEntry(TESTS[i].name, false);
}

View file

@ -65,7 +65,7 @@ function run_test() {
var zipR = new ZipReader(tmpFile);
testpass(zipR);
zipR.test(FILENAME);
var stream = Cc["@mozilla.org/scriptableinputstream;1"]
stream = Cc["@mozilla.org/scriptableinputstream;1"]
.createInstance(Ci.nsIScriptableInputStream);
stream.init(zipR.getInputStream(FILENAME));
var result = stream.read(DATA.length);

View file

@ -21,8 +21,8 @@ function run_test() {
zipW.open(tmpFile, PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE);
var size = 0;
for (var i = 0; i < TESTS.length; i++) {
var source = do_get_file(DATA_DIR + TESTS[i].name);
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 +
@ -38,8 +38,8 @@ function run_test() {
// Test the stored data with the zipreader
var zipR = new ZipReader(tmpFile);
for (var i = 0; i < TESTS.length; i++) {
var source = do_get_file(DATA_DIR + TESTS[i].name);
for (let i = 0; i < TESTS.length; i++) {
let source = do_get_file(DATA_DIR + TESTS[i].name);
Assert.ok(zipR.hasEntry(TESTS[i].name));
var entry = zipR.getEntry(TESTS[i].name);

View file

@ -12,14 +12,14 @@ var TESTS = [
function run_test() {
zipW.open(tmpFile, PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE);
for (var i = 0; i < TESTS.length; i++) {
var source = do_get_file(DATA_DIR + TESTS[i]);
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);
}
try {
var source = do_get_file(DATA_DIR + TESTS[0]);
let source = do_get_file(DATA_DIR + TESTS[0]);
zipW.addEntryFile(TESTS[0], Ci.nsIZipWriter.COMPRESSION_NONE, source,
false);
do_throw("Should not be able to add the same file twice");
@ -28,7 +28,7 @@ function run_test() {
}
// Remove all the tests and see if we are left with an empty zip
for (var i = 0; i < TESTS.length; i++) {
for (let i = 0; i < TESTS.length; i++) {
zipW.removeEntry(TESTS[i], false);
}

View file

@ -17,16 +17,16 @@ function do_check_throws(f, result, stack) {
ok(false, "expected result " + result + ", none thrown");
}
var dirSvc = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
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)
return dirSvc.get("CurProcD", Ci.nsIFile);
return Services.dirsvc.get("CurProcD", Ci.nsIFile);
throw Components.Exception("Tried to get test directory '" + prop + "'", Cr.NS_ERROR_FAILURE);
},
QueryInterface: ChromeUtils.generateQI(["nsIDirectoryServiceProvider"]),
};
dirSvc.QueryInterface(Ci.nsIDirectoryService).registerProvider(provider);
Services.dirsvc.QueryInterface(Ci.nsIDirectoryService).registerProvider(provider);

View file

@ -9,13 +9,11 @@ function run_test() {
const FLOAT = 9.674;
const FUDGE = 0.001;
let ps = Cc["@mozilla.org/preferences-service;1"]
.getService(Ci.nsIPrefService);
let prefs = ps.getDefaultBranch(null);
let prefs = Services.prefs.getDefaultBranch(null);
/* Test with a non-default branch */
prefs.setCharPref(FULL_PREF_NAME, FLOAT);
let pb = ps.getBranch(BRANCH);
let pb = Services.prefs.getBranch(BRANCH);
let floatPref = pb.getFloatPref(PREF_NAME);
Assert.ok(FLOAT + FUDGE >= floatPref);

View file

@ -6,22 +6,20 @@
function run_test() {
const PREF_NAME = "testPref";
var prefs = Cc["@mozilla.org/preferences-service;1"]
.getService(Ci.nsIPrefBranch);
var observer = {
QueryInterface: ChromeUtils.generateQI(["nsIObserver"]),
observe: function observe(aSubject, aTopic, aState) {
prefs.removeObserver(PREF_NAME, observer);
Services.prefs.removeObserver(PREF_NAME, observer);
},
};
prefs.addObserver(PREF_NAME, observer);
Services.prefs.addObserver(PREF_NAME, observer);
prefs.setCharPref(PREF_NAME, "test0");
Services.prefs.setCharPref(PREF_NAME, "test0");
// This second call isn't needed on a clean profile: it makes sure
// the observer gets called even if the pref already had the value
// "test0" before this test.
prefs.setCharPref(PREF_NAME, "test1");
Services.prefs.setCharPref(PREF_NAME, "test1");
Assert.ok(true);
}

View file

@ -4,10 +4,8 @@
function run_test() {
const PREF_NAME = "testPref";
var ps = Cc["@mozilla.org/preferences-service;1"]
.getService(Ci.nsIPrefService);
var prefs = ps.getDefaultBranch(null);
var userprefs = ps.getBranch(null);
var prefs = Services.prefs.getDefaultBranch(null);
var userprefs = Services.prefs.getBranch(null);
prefs.setCharPref(PREF_NAME, "test0");
prefs.lockPref(PREF_NAME);
@ -16,11 +14,11 @@ function run_test() {
var file = do_get_profile();
file.append("prefs.js");
ps.savePrefFile(file);
Services.prefs.savePrefFile(file);
prefs.unlockPref(PREF_NAME);
prefs.setCharPref(PREF_NAME, "test1");
ps.readUserPrefsFromFile(file);
Services.prefs.readUserPrefsFromFile(file);
Assert.equal("test1", userprefs.getCharPref(PREF_NAME));
Assert.equal(false, userprefs.prefHasUserValue(PREF_NAME));

View file

@ -3,12 +3,6 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
function run_test() {
var ps = Cc["@mozilla.org/preferences-service;1"].
getService(Ci.nsIPrefService);
var pb = Cc["@mozilla.org/preferences-service;1"].
getService(Ci.nsIPrefBranch);
var observer = {
QueryInterface: ChromeUtils.generateQI(["nsIObserver"]),
@ -18,6 +12,6 @@ function run_test() {
};
/* Set the same pref twice. This shouldn't leak. */
pb.addObserver("UserPref.nonexistent.setIntPref", observer);
pb.addObserver("UserPref.nonexistent.setIntPref", observer);
Services.prefs.addObserver("UserPref.nonexistent.setIntPref", observer);
Services.prefs.addObserver("UserPref.nonexistent.setIntPref", observer);
}

View file

@ -4,10 +4,8 @@
function run_test() {
const PREF_NAME = "testPref";
var ps = Cc["@mozilla.org/preferences-service;1"]
.getService(Ci.nsIPrefService);
var prefs = ps.getDefaultBranch(null);
var userprefs = ps.getBranch(null);
var prefs = Services.prefs.getDefaultBranch(null);
var userprefs = Services.prefs.getBranch(null);
/* First, test to make sure we can parse a float from a string properly. */
prefs.setCharPref(PREF_NAME, "9.674");

View file

@ -10,8 +10,7 @@ const PREF_INT = 64;
const PREF_STRING = 32;
function run_test() {
var ps = Cc["@mozilla.org/preferences-service;1"].
getService(Ci.nsIPrefService);
var ps = Services.prefs;
let defaultBranch = ps.getDefaultBranch("");
let userBranch = ps.getBranch("");
@ -38,11 +37,11 @@ function run_test() {
// Prefs that have both a default and a user value -- we can't change their
// type.
defaultBranch.setBoolPref("TypeTest.both.bool", true);
userBranch.setBoolPref("TypeTest.both.bool", false);
userBranch.setBoolPref("TypeTest.both.bool", false);
defaultBranch.setIntPref("TypeTest.both.int", 25);
userBranch.setIntPref("TypeTest.both.int", 26);
userBranch.setIntPref("TypeTest.both.int", 26);
defaultBranch.setCharPref("TypeTest.both.char", "yo");
userBranch.setCharPref("TypeTest.both.char", "ya");
userBranch.setCharPref("TypeTest.both.char", "ya");
Assert.equal(userBranch.getBoolPref("TypeTest.both.bool"), false);
Assert.equal(userBranch.getIntPref("TypeTest.both.int"), 26);
@ -52,64 +51,64 @@ function run_test() {
// different type --> fails.
do_check_throws(function() {
defaultBranch.setCharPref("TypeTest.default.bool", "boo");
}, Cr.NS_ERROR_UNEXPECTED);
}, Cr.NS_ERROR_UNEXPECTED);
do_check_throws(function() {
defaultBranch.setIntPref("TypeTest.default.bool", 5);
}, Cr.NS_ERROR_UNEXPECTED);
}, Cr.NS_ERROR_UNEXPECTED);
do_check_throws(function() {
defaultBranch.setCharPref("TypeTest.default.int", "boo");
}, Cr.NS_ERROR_UNEXPECTED);
}, Cr.NS_ERROR_UNEXPECTED);
do_check_throws(function() {
defaultBranch.setBoolPref("TypeTest.default.int", true);
}, Cr.NS_ERROR_UNEXPECTED);
}, Cr.NS_ERROR_UNEXPECTED);
do_check_throws(function() {
defaultBranch.setBoolPref("TypeTest.default.char", true);
}, Cr.NS_ERROR_UNEXPECTED);
}, Cr.NS_ERROR_UNEXPECTED);
do_check_throws(function() {
defaultBranch.setIntPref("TypeTest.default.char", 6);
}, Cr.NS_ERROR_UNEXPECTED);
}, Cr.NS_ERROR_UNEXPECTED);
// We only have a default value, and we try to set a user value of a
// different type --> fails.
do_check_throws(function() {
userBranch.setCharPref("TypeTest.default.bool", "boo");
}, Cr.NS_ERROR_UNEXPECTED);
}, Cr.NS_ERROR_UNEXPECTED);
do_check_throws(function() {
userBranch.setIntPref("TypeTest.default.bool", 5);
}, Cr.NS_ERROR_UNEXPECTED);
}, Cr.NS_ERROR_UNEXPECTED);
do_check_throws(function() {
userBranch.setCharPref("TypeTest.default.int", "boo");
}, Cr.NS_ERROR_UNEXPECTED);
}, Cr.NS_ERROR_UNEXPECTED);
do_check_throws(function() {
userBranch.setBoolPref("TypeTest.default.int", true);
}, Cr.NS_ERROR_UNEXPECTED);
}, Cr.NS_ERROR_UNEXPECTED);
do_check_throws(function() {
userBranch.setBoolPref("TypeTest.default.char", true);
}, Cr.NS_ERROR_UNEXPECTED);
}, Cr.NS_ERROR_UNEXPECTED);
do_check_throws(function() {
userBranch.setIntPref("TypeTest.default.char", 6);
}, Cr.NS_ERROR_UNEXPECTED);
}, Cr.NS_ERROR_UNEXPECTED);
// We only have a user value, and we try to set a default value of a
// different type --> fails.
do_check_throws(function() {
defaultBranch.setCharPref("TypeTest.user.bool", "boo");
}, Cr.NS_ERROR_UNEXPECTED);
}, Cr.NS_ERROR_UNEXPECTED);
do_check_throws(function() {
defaultBranch.setIntPref("TypeTest.user.bool", 5);
}, Cr.NS_ERROR_UNEXPECTED);
}, Cr.NS_ERROR_UNEXPECTED);
do_check_throws(function() {
defaultBranch.setCharPref("TypeTest.user.int", "boo");
}, Cr.NS_ERROR_UNEXPECTED);
}, Cr.NS_ERROR_UNEXPECTED);
do_check_throws(function() {
defaultBranch.setBoolPref("TypeTest.user.int", true);
}, Cr.NS_ERROR_UNEXPECTED);
}, Cr.NS_ERROR_UNEXPECTED);
do_check_throws(function() {
defaultBranch.setBoolPref("TypeTest.user.char", true);
}, Cr.NS_ERROR_UNEXPECTED);
}, Cr.NS_ERROR_UNEXPECTED);
do_check_throws(function() {
defaultBranch.setIntPref("TypeTest.user.char", 6);
}, Cr.NS_ERROR_UNEXPECTED);
}, Cr.NS_ERROR_UNEXPECTED);
// We only have a user value, and we try to set a user value of a
// different type --> SUCCEEDS.
@ -130,41 +129,41 @@ function run_test() {
// value of a different type --> fails.
do_check_throws(function() {
defaultBranch.setCharPref("TypeTest.both.bool", "boo");
}, Cr.NS_ERROR_UNEXPECTED);
}, Cr.NS_ERROR_UNEXPECTED);
do_check_throws(function() {
defaultBranch.setIntPref("TypeTest.both.bool", 5);
}, Cr.NS_ERROR_UNEXPECTED);
}, Cr.NS_ERROR_UNEXPECTED);
do_check_throws(function() {
defaultBranch.setCharPref("TypeTest.both.int", "boo");
}, Cr.NS_ERROR_UNEXPECTED);
}, Cr.NS_ERROR_UNEXPECTED);
do_check_throws(function() {
defaultBranch.setBoolPref("TypeTest.both.int", true);
}, Cr.NS_ERROR_UNEXPECTED);
}, Cr.NS_ERROR_UNEXPECTED);
do_check_throws(function() {
defaultBranch.setBoolPref("TypeTest.both.char", true);
}, Cr.NS_ERROR_UNEXPECTED);
}, Cr.NS_ERROR_UNEXPECTED);
do_check_throws(function() {
defaultBranch.setIntPref("TypeTest.both.char", 6);
}, Cr.NS_ERROR_UNEXPECTED);
}, Cr.NS_ERROR_UNEXPECTED);
// We have both a default value and user value, and we try to set a user
// value of a different type --> fails.
do_check_throws(function() {
userBranch.setCharPref("TypeTest.both.bool", "boo");
}, Cr.NS_ERROR_UNEXPECTED);
}, Cr.NS_ERROR_UNEXPECTED);
do_check_throws(function() {
userBranch.setIntPref("TypeTest.both.bool", 5);
}, Cr.NS_ERROR_UNEXPECTED);
}, Cr.NS_ERROR_UNEXPECTED);
do_check_throws(function() {
userBranch.setCharPref("TypeTest.both.int", "boo");
}, Cr.NS_ERROR_UNEXPECTED);
}, Cr.NS_ERROR_UNEXPECTED);
do_check_throws(function() {
userBranch.setBoolPref("TypeTest.both.int", true);
}, Cr.NS_ERROR_UNEXPECTED);
}, Cr.NS_ERROR_UNEXPECTED);
do_check_throws(function() {
userBranch.setBoolPref("TypeTest.both.char", true);
}, Cr.NS_ERROR_UNEXPECTED);
}, Cr.NS_ERROR_UNEXPECTED);
do_check_throws(function() {
userBranch.setIntPref("TypeTest.both.char", 6);
}, Cr.NS_ERROR_UNEXPECTED);
}, Cr.NS_ERROR_UNEXPECTED);
}

View file

@ -5,10 +5,7 @@
/* Tests for providing a default value to get{Bool,Char,Float,Int}Pref */
function run_test() {
var ps = Cc["@mozilla.org/preferences-service;1"]
.getService(Ci.nsIPrefService)
.QueryInterface(Ci.nsIPrefBranch);
const ps = Services.prefs;
let prefName = "test.default.values.bool";
do_check_throws(function() { ps.getBoolPref(prefName); },
Cr.NS_ERROR_UNEXPECTED);

View file

@ -10,8 +10,7 @@ const PREF_INT = 64;
const PREF_STRING = 32;
function run_test() {
var ps = Cc["@mozilla.org/preferences-service;1"].
getService(Ci.nsIPrefService);
const ps = Services.prefs;
let defaultBranch = ps.getDefaultBranch("");
let userBranch = ps.getBranch("");

View file

@ -18,153 +18,146 @@ function makeList(a) {
}
function run_test() {
var ps = Cc["@mozilla.org/preferences-service;1"].
getService(Ci.nsIPrefService);
var pb2 = Cc["@mozilla.org/preferences-service;1"].
getService(Ci.nsIPrefBranch);
var pb = Cc["@mozilla.org/preferences-service;1"].
getService(Ci.nsIPrefBranch);
const ps = Services.prefs;
//* *************************************************************************//
// Nullsafety
do_check_throws(function() {
pb.getPrefType(null);
ps.getPrefType(null);
}, Cr.NS_ERROR_INVALID_ARG);
do_check_throws(function() {
pb.getBoolPref(null);
ps.getBoolPref(null);
}, Cr.NS_ERROR_INVALID_ARG);
do_check_throws(function() {
pb.setBoolPref(null, false);
ps.setBoolPref(null, false);
}, Cr.NS_ERROR_INVALID_ARG);
do_check_throws(function() {
pb.getIntPref(null);
ps.getIntPref(null);
}, Cr.NS_ERROR_INVALID_ARG);
do_check_throws(function() {
pb.setIntPref(null, 0);
ps.setIntPref(null, 0);
}, Cr.NS_ERROR_INVALID_ARG);
do_check_throws(function() {
pb.getCharPref(null);
ps.getCharPref(null);
}, Cr.NS_ERROR_INVALID_ARG);
do_check_throws(function() {
pb.setCharPref(null, null);
ps.setCharPref(null, null);
}, Cr.NS_ERROR_INVALID_ARG);
do_check_throws(function() {
pb.getStringPref(null);
ps.getStringPref(null);
}, Cr.NS_ERROR_INVALID_ARG);
do_check_throws(function() {
pb.setStringPref(null, null);
ps.setStringPref(null, null);
}, Cr.NS_ERROR_INVALID_ARG);
do_check_throws(function() {
pb.clearUserPref(null);
ps.clearUserPref(null);
}, Cr.NS_ERROR_INVALID_ARG);
do_check_throws(function() {
pb.prefHasUserValue(null);
ps.prefHasUserValue(null);
}, Cr.NS_ERROR_INVALID_ARG);
do_check_throws(function() {
pb.lockPref(null);
ps.lockPref(null);
}, Cr.NS_ERROR_INVALID_ARG);
do_check_throws(function() {
pb.prefIsLocked(null);
ps.prefIsLocked(null);
}, Cr.NS_ERROR_INVALID_ARG);
do_check_throws(function() {
pb.unlockPref(null);
ps.unlockPref(null);
}, Cr.NS_ERROR_INVALID_ARG);
do_check_throws(function() {
pb.deleteBranch(null);
ps.deleteBranch(null);
}, Cr.NS_ERROR_INVALID_ARG);
do_check_throws(function() {
pb.getChildList(null);
ps.getChildList(null);
}, Cr.NS_ERROR_INVALID_ARG);
//* *************************************************************************//
// Nonexisting user preferences
Assert.equal(pb.prefHasUserValue("UserPref.nonexistent.hasUserValue"), false);
pb.clearUserPref("UserPref.nonexistent.clearUserPref"); // shouldn't throw
Assert.equal(pb.getPrefType("UserPref.nonexistent.getPrefType"), PREF_INVALID);
Assert.equal(pb.root, "");
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.root, "");
// bool...
do_check_throws(function() {
pb.getBoolPref("UserPref.nonexistent.getBoolPref");
}, Cr.NS_ERROR_UNEXPECTED);
pb.setBoolPref("UserPref.nonexistent.setBoolPref", false);
Assert.equal(pb.getBoolPref("UserPref.nonexistent.setBoolPref"), false);
ps.getBoolPref("UserPref.nonexistent.getBoolPref");
}, Cr.NS_ERROR_UNEXPECTED);
ps.setBoolPref("UserPref.nonexistent.setBoolPref", false);
Assert.equal(ps.getBoolPref("UserPref.nonexistent.setBoolPref"), false);
// int...
do_check_throws(function() {
pb.getIntPref("UserPref.nonexistent.getIntPref");
}, Cr.NS_ERROR_UNEXPECTED);
pb.setIntPref("UserPref.nonexistent.setIntPref", 5);
Assert.equal(pb.getIntPref("UserPref.nonexistent.setIntPref"), 5);
ps.getIntPref("UserPref.nonexistent.getIntPref");
}, Cr.NS_ERROR_UNEXPECTED);
ps.setIntPref("UserPref.nonexistent.setIntPref", 5);
Assert.equal(ps.getIntPref("UserPref.nonexistent.setIntPref"), 5);
// char
do_check_throws(function() {
pb.getCharPref("UserPref.nonexistent.getCharPref");
}, Cr.NS_ERROR_UNEXPECTED);
pb.setCharPref("UserPref.nonexistent.setCharPref", "_test");
Assert.equal(pb.getCharPref("UserPref.nonexistent.setCharPref"), "_test");
ps.getCharPref("UserPref.nonexistent.getCharPref");
}, Cr.NS_ERROR_UNEXPECTED);
ps.setCharPref("UserPref.nonexistent.setCharPref", "_test");
Assert.equal(ps.getCharPref("UserPref.nonexistent.setCharPref"), "_test");
//* *************************************************************************//
// Existing user Prefs and data integrity test (round-trip match)
pb.setBoolPref("UserPref.existing.bool", true);
pb.setIntPref("UserPref.existing.int", 23);
pb.setCharPref("UserPref.existing.char", "hey");
ps.setBoolPref("UserPref.existing.bool", true);
ps.setIntPref("UserPref.existing.int", 23);
ps.setCharPref("UserPref.existing.char", "hey");
// getPref should return the pref value
Assert.equal(pb.getBoolPref("UserPref.existing.bool"), true);
Assert.equal(pb.getIntPref("UserPref.existing.int"), 23);
Assert.equal(pb.getCharPref("UserPref.existing.char"), "hey");
Assert.equal(ps.getBoolPref("UserPref.existing.bool"), true);
Assert.equal(ps.getIntPref("UserPref.existing.int"), 23);
Assert.equal(ps.getCharPref("UserPref.existing.char"), "hey");
// setPref should not complain and should change the value of the pref
pb.setBoolPref("UserPref.existing.bool", false);
Assert.equal(pb.getBoolPref("UserPref.existing.bool"), false);
pb.setIntPref("UserPref.existing.int", 24);
Assert.equal(pb.getIntPref("UserPref.existing.int"), 24);
pb.setCharPref("UserPref.existing.char", "hej då!");
Assert.equal(pb.getCharPref("UserPref.existing.char"), "hej då!");
ps.setBoolPref("UserPref.existing.bool", false);
Assert.equal(ps.getBoolPref("UserPref.existing.bool"), false);
ps.setIntPref("UserPref.existing.int", 24);
Assert.equal(ps.getIntPref("UserPref.existing.int"), 24);
ps.setCharPref("UserPref.existing.char", "hej då!");
Assert.equal(ps.getCharPref("UserPref.existing.char"), "hej då!");
// prefHasUserValue should return true now
Assert.ok(pb.prefHasUserValue("UserPref.existing.bool"));
Assert.ok(pb.prefHasUserValue("UserPref.existing.int"));
Assert.ok(pb.prefHasUserValue("UserPref.existing.char"));
Assert.ok(ps.prefHasUserValue("UserPref.existing.bool"));
Assert.ok(ps.prefHasUserValue("UserPref.existing.int"));
Assert.ok(ps.prefHasUserValue("UserPref.existing.char"));
// clearUserPref should remove the pref
pb.clearUserPref("UserPref.existing.bool");
Assert.ok(!pb.prefHasUserValue("UserPref.existing.bool"));
pb.clearUserPref("UserPref.existing.int");
Assert.ok(!pb.prefHasUserValue("UserPref.existing.int"));
pb.clearUserPref("UserPref.existing.char");
Assert.ok(!pb.prefHasUserValue("UserPref.existing.char"));
ps.clearUserPref("UserPref.existing.bool");
Assert.ok(!ps.prefHasUserValue("UserPref.existing.bool"));
ps.clearUserPref("UserPref.existing.int");
Assert.ok(!ps.prefHasUserValue("UserPref.existing.int"));
ps.clearUserPref("UserPref.existing.char");
Assert.ok(!ps.prefHasUserValue("UserPref.existing.char"));
//* *************************************************************************//
// Large value test
let largeStr = new Array(MAX_PREF_LENGTH + 1).join("x");
pb.setCharPref("UserPref.large.char", largeStr);
ps.setCharPref("UserPref.large.char", largeStr);
largeStr += "x";
do_check_throws(function() {
pb.setCharPref("UserPref.large.char", largeStr);
}, Cr.NS_ERROR_ILLEGAL_VALUE);
ps.setCharPref("UserPref.large.char", largeStr);
}, Cr.NS_ERROR_ILLEGAL_VALUE);
//* *************************************************************************//
// getPrefType test
// bool...
pb.setBoolPref("UserPref.getPrefType.bool", true);
Assert.equal(pb.getPrefType("UserPref.getPrefType.bool"), PREF_BOOL);
ps.setBoolPref("UserPref.getPrefType.bool", true);
Assert.equal(ps.getPrefType("UserPref.getPrefType.bool"), PREF_BOOL);
// int...
pb.setIntPref("UserPref.getPrefType.int", -234);
Assert.equal(pb.getPrefType("UserPref.getPrefType.int"), PREF_INT);
ps.setIntPref("UserPref.getPrefType.int", -234);
Assert.equal(ps.getPrefType("UserPref.getPrefType.int"), PREF_INT);
// char...
pb.setCharPref("UserPref.getPrefType.char", "testing1..2");
Assert.equal(pb.getPrefType("UserPref.getPrefType.char"), PREF_STRING);
ps.setCharPref("UserPref.getPrefType.char", "testing1..2");
Assert.equal(ps.getPrefType("UserPref.getPrefType.char"), PREF_STRING);
//* *************************************************************************//
// getBranch tests
@ -172,7 +165,7 @@ function run_test() {
Assert.equal(ps.root, "");
// bool ...
pb.setBoolPref("UserPref.root.boolPref", true);
ps.setBoolPref("UserPref.root.boolPref", true);
let pb_1 = ps.getBranch("UserPref.root.");
Assert.equal(pb_1.getBoolPref("boolPref"), true);
let pb_2 = ps.getBranch("UserPref.root.boolPref");
@ -182,7 +175,7 @@ function run_test() {
Assert.equal(pb_3.getBoolPref("f.anotherPref"), false);
// int ...
pb.setIntPref("UserPref.root.intPref", 23);
ps.setIntPref("UserPref.root.intPref", 23);
pb_1 = ps.getBranch("UserPref.root.");
Assert.equal(pb_1.getIntPref("intPref"), 23);
pb_2 = ps.getBranch("UserPref.root.intPref");
@ -192,7 +185,7 @@ function run_test() {
Assert.equal(pb_3.getIntPref("f.anotherPref"), 69);
// char...
pb.setCharPref("UserPref.root.charPref", "_char");
ps.setCharPref("UserPref.root.charPref", "_char");
pb_1 = ps.getBranch("UserPref.root.");
Assert.equal(pb_1.getCharPref("charPref"), "_char");
pb_2 = ps.getBranch("UserPref.root.charPref");
@ -205,7 +198,7 @@ function run_test() {
// getChildlist tests
// get an already set prefBranch
pb1 = ps.getBranch("UserPref.root.");
let pb1 = ps.getBranch("UserPref.root.");
let prefList = pb1.getChildList("");
Assert.equal(prefList.length, 6);
@ -253,10 +246,10 @@ function run_test() {
// locking and unlocking a nonexistent pref should throw
do_check_throws(function() {
ps.lockPref("DefaultPref.nonexistent");
}, Cr.NS_ERROR_ILLEGAL_VALUE);
}, Cr.NS_ERROR_ILLEGAL_VALUE);
do_check_throws(function() {
ps.unlockPref("DefaultPref.nonexistent");
}, Cr.NS_ERROR_ILLEGAL_VALUE);
}, Cr.NS_ERROR_ILLEGAL_VALUE);
// getting a locked pref branch should return the "default" value
Assert.ok(!ps.prefIsLocked("DefaultPref.char"));
@ -297,30 +290,30 @@ function run_test() {
// ps.deleteBranch("UserPref.nonexistent.deleteBranch");}, Cr.NS_ERROR_UNEXPECTED);
ps.deleteBranch("DefaultPref");
pb = ps.getBranch("DefaultPref");
let pb = ps.getBranch("DefaultPref");
pb1 = ps.getDefaultBranch("DefaultPref");
// getting prefs on deleted user branches should throw
do_check_throws(function() {
pb.getBoolPref("DefaultPref.bool");
}, Cr.NS_ERROR_UNEXPECTED);
}, Cr.NS_ERROR_UNEXPECTED);
do_check_throws(function() {
pb.getIntPref("DefaultPref.int");
}, Cr.NS_ERROR_UNEXPECTED);
}, Cr.NS_ERROR_UNEXPECTED);
do_check_throws(function() {
pb.getCharPref("DefaultPref.char");
}, Cr.NS_ERROR_UNEXPECTED);
}, Cr.NS_ERROR_UNEXPECTED);
// getting prefs on deleted default branches should throw
do_check_throws(function() {
pb1.getBoolPref("DefaultPref.bool");
}, Cr.NS_ERROR_UNEXPECTED);
}, Cr.NS_ERROR_UNEXPECTED);
do_check_throws(function() {
pb1.getIntPref("DefaultPref.int");
}, Cr.NS_ERROR_UNEXPECTED);
}, Cr.NS_ERROR_UNEXPECTED);
do_check_throws(function() {
pb1.getCharPref("DefaultPref.char");
}, Cr.NS_ERROR_UNEXPECTED);
}, Cr.NS_ERROR_UNEXPECTED);
//* *************************************************************************//
// savePrefFile & readPrefFile tests
@ -348,13 +341,13 @@ function run_test() {
// former prefs should have been replaced/lost
do_check_throws(function() {
pb.getBoolPref("ReadPref.bool");
}, Cr.NS_ERROR_UNEXPECTED);
}, Cr.NS_ERROR_UNEXPECTED);
do_check_throws(function() {
pb.getIntPref("ReadPref.int");
}, Cr.NS_ERROR_UNEXPECTED);
}, Cr.NS_ERROR_UNEXPECTED);
do_check_throws(function() {
pb.getCharPref("ReadPref.char");
}, Cr.NS_ERROR_UNEXPECTED);
}, Cr.NS_ERROR_UNEXPECTED);
// loaded prefs should read ok.
pb = ps.getBranch("testPref.");
@ -405,7 +398,7 @@ function run_test() {
QueryInterface(aIID) {
if (aIID.equals(Ci.nsIObserver) ||
aIID.equals(Ci.nsISupports))
return this;
return this;
throw Cr.NS_NOINTERFACE;
}
@ -426,15 +419,15 @@ function run_test() {
do_test_pending();
do_test_pending();
let observer = new PrefObserver(pb2, "ReadPref.int", 76);
let observer = new PrefObserver(ps, "ReadPref.int", 76);
ps.setIntPref("ReadPref.int", 76);
// removed observer should not fire
pb2.removeObserver("ReadPref.int", observer);
ps.removeObserver("ReadPref.int", observer);
ps.setIntPref("ReadPref.int", 32);
// let's test observers once more with a non-root prefbranch
pb = pb2.getBranch("ReadPref.");
pb = ps.getBranch("ReadPref.");
observer = new PrefObserver(pb, "int", 76);
ps.setIntPref("ReadPref.int", 76);

View file

@ -3,9 +3,6 @@
// This file tests the `locked` attribute in default pref files.
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
ChromeUtils.import("resource://gre/modules/Services.jsm");
const ps = Services.prefs;
add_test(function notChangedFromAPI() {

View file

@ -2,12 +2,7 @@
* http://creativecommons.org/licenses/publicdomain/ */
function run_test() {
const PREF_NAME = "testPref";
var ps = Cc["@mozilla.org/preferences-service;1"]
.getService(Ci.nsIPrefService);
var defaultPrefs = ps.getDefaultBranch(null);
var prefs = ps.getBranch(null);
const ps = Services.prefs;
ps.resetPrefs();
ps.readDefaultPrefsFromFile(do_get_file("data/testParser.js"));
@ -35,7 +30,7 @@ function run_test() {
Assert.equal(ps.getIntPref("int.+ 345"), 345);
Assert.equal(ps.getIntPref("int.-0"), -0);
Assert.equal(ps.getIntPref("int.-1"), -1);
Assert.equal(ps.getIntPref("int.- /* hmm */ 456"), -456);
Assert.equal(ps.getIntPref("int.- /* hmm */\t456"), -456);
Assert.equal(ps.getIntPref("int.-\n567"), -567);
Assert.equal(ps.getIntPref("int.INT_MAX-1"), 2147483646);
Assert.equal(ps.getIntPref("int.INT_MAX"), 2147483647);
@ -49,7 +44,7 @@ function run_test() {
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");
"\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

View file

@ -1,8 +1,6 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/licenses/publicdomain/ */
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
const ps = Services.prefs;
// A little helper to reset the service and load one pref file.

View file

@ -2,12 +2,6 @@
* 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/. */
var cs = Cc["@mozilla.org/consoleservice;1"].
getService(Ci.nsIConsoleService);
var ps = Cc["@mozilla.org/preferences-service;1"].
getService(Ci.nsIPrefService);
function makeBuffer(length) {
return new Array(length + 1).join("x");
}
@ -31,7 +25,7 @@ function checkWarning(pref, buffer) {
}
complete = true;
info("Warning while setting " + pref);
cs.unregisterListener(listener);
Services.console.unregisterListener(listener);
resolve(true);
},
};
@ -41,11 +35,11 @@ function checkWarning(pref, buffer) {
}
complete = true;
info("No warning while setting " + pref);
cs.unregisterListener(listener);
Services.console.unregisterListener(listener);
resolve(false);
});
cs.registerListener(listener);
ps.setCharPref(pref, buffer);
Services.console.registerListener(listener);
Services.prefs.setCharPref(pref, buffer);
});
}

View file

@ -1,13 +1,15 @@
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
function isParentProcess() {
let appInfo = Cc["@mozilla.org/xre/app-info;1"];
return (!appInfo || appInfo.getService(Ci.nsIXULRuntime).processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT);
return (!appInfo || Services.appinfo.processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT);
}
function run_test() {
if (isParentProcess() == false) {
if (!isParentProcess()) {
do_load_child_test_harness();
var pb = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
var pb = Services.prefs;
pb.setBoolPref("Test.IPC.bool.new", true);
pb.setIntPref("Test.IPC.int.new", 23);
pb.setCharPref("Test.IPC.char.new", "hey");

View file

@ -1,15 +1,16 @@
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
function isParentProcess() {
let appInfo = Cc["@mozilla.org/xre/app-info;1"];
return (!appInfo || appInfo.getService(Ci.nsIXULRuntime).processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT);
return (Services.appinfo.processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT);
}
function run_test() {
if (isParentProcess() == false) {
var pb = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
pb.setBoolPref("Test.IPC.bool", true);
pb.setIntPref("Test.IPC.int", 23);
pb.setCharPref("Test.IPC.char", "hey");
if (!isParentProcess()) {
const pb = Services.prefs;
pb.setBoolPref("Test.IPC.bool", true);
pb.setIntPref("Test.IPC.int", 23);
pb.setCharPref("Test.IPC.char", "hey");
run_test_in_child("test_existing_prefs.js");
run_test_in_child("test_existing_prefs.js");
}
}

View file

@ -5,21 +5,22 @@
// Large preferences should not be set in the child process.
// 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");
function isParentProcess() {
let appInfo = Cc["@mozilla.org/xre/app-info;1"];
return (!appInfo || appInfo.getService(Ci.nsIXULRuntime).processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT);
return (Services.appinfo.processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT);
}
function makeBuffer(length) {
let string = "x";
while (string.length < length) {
string = string + string;
}
if (string.length > length) {
string = string.substring(length - string.length);
}
return string;
let string = "x";
while (string.length < length) {
string = string + string;
}
if (string.length > length) {
string = string.substring(length - string.length);
}
return string;
}
// from prefapi.h
@ -46,9 +47,8 @@ function expectedPrefValue(def, user) {
}
function run_test() {
let pb = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
let ps = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefService);
let defaultBranch = ps.getDefaultBranch("");
const pb = Services.prefs;
let defaultBranch = pb.getDefaultBranch("");
let isParent = isParentProcess();
if (isParent) {
@ -96,7 +96,7 @@ function run_test() {
prefExists = false;
}
ok(!prefExists,
"Pref " + pref_name + " should not be set in the child");
"Pref " + pref_name + " should not be set in the child");
}
}
}

View file

@ -4,13 +4,14 @@
// Locked status should be communicated to children.
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
function isParentProcess() {
let appInfo = Cc["@mozilla.org/xre/app-info;1"];
return (!appInfo || appInfo.getService(Ci.nsIXULRuntime).processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT);
return (Services.appinfo.processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT);
}
function run_test() {
let pb = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
const pb = Services.prefs;
let bprefname = "Test.IPC.locked.bool";
let iprefname = "Test.IPC.locked.int";

View file

@ -1,13 +1,14 @@
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
function isParentProcess() {
let appInfo = Cc["@mozilla.org/xre/app-info;1"];
return (!appInfo || appInfo.getService(Ci.nsIXULRuntime).processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT);
return (Services.appinfo.processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT);
}
function run_test() {
if (isParentProcess() == false) {
var pb = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
Assert.equal(pb.getBoolPref("Test.IPC.bool.new"), true);
Assert.equal(pb.getIntPref("Test.IPC.int.new"), 23);
Assert.equal(pb.getCharPref("Test.IPC.char.new"), "hey");
if (!isParentProcess()) {
const pb = Services.prefs;
Assert.equal(pb.getBoolPref("Test.IPC.bool.new"), true);
Assert.equal(pb.getIntPref("Test.IPC.int.new"), 23);
Assert.equal(pb.getCharPref("Test.IPC.char.new"), "hey");
}
}

View file

@ -152,7 +152,6 @@ const PREFS = [
for (let {type, values} of PREFS) {
let set = `set${type}Pref`;
let get = `get${type}Pref`;
function prefTest(opts) {
function check(pref, proc, val, {expectedVal, defaultVal = undefined, expectedDefault = defaultVal, expectedFlags = {}}) {

View file

@ -30,8 +30,6 @@ const {ExtensionTestUtils} = ChromeUtils.import("resource://testing-common/Exten
ExtensionTestUtils.init(this);
let contentPage;
const {prefs} = Services;
const defaultPrefs = prefs.getDefaultBranch("");
@ -52,14 +50,15 @@ add_task(async function test_sharedMap_var_caches() {
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");
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}`);
});

View file

@ -1,13 +1,14 @@
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
function isParentProcess() {
let appInfo = Cc["@mozilla.org/xre/app-info;1"];
return (!appInfo || appInfo.getService(Ci.nsIXULRuntime).processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT);
return Services.appinfo.processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT;
}
function run_test() {
if (isParentProcess()) {
do_load_child_test_harness();
var pb = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
var pb = Services.prefs;
// these prefs are set after the child has been created.
pb.setBoolPref("Test.IPC.bool.new", true);
@ -19,7 +20,7 @@ function run_test() {
}
function testPrefClear() {
var pb = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
var pb = Services.prefs;
pb.clearUserPref("Test.IPC.bool.new");
sendCommand(

View file

@ -1,4 +1,5 @@
var pb = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
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.
@ -7,61 +8,61 @@ const kPrefName = "intl.accept_languages"; // of type char, which we
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 + '");',
function(info) {
let [ value, isUser ] = info.split(",");
Assert.equal(pb.getCharPref(kPrefName), value);
Assert.equal(pb.prefHasUserValue(kPrefName), isUser == "true");
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 + '");',
function(info) {
let [ value, isUser ] = info.split(",");
Assert.equal(pb.getCharPref(kPrefName), value);
Assert.equal(pb.prefHasUserValue(kPrefName), isUser == "true");
continuation();
});
}
function run_test() {
// We finish in clean_up()
do_test_pending();
// We finish in clean_up()
do_test_pending();
initialValue = pb.getCharPref(kPrefName);
initialValue = pb.getCharPref(kPrefName);
test_user_setting();
test_user_setting();
}
function test_user_setting() {
// We rely on setting this before the content process starts up.
// When it starts up, it should recognize this as a user pref, not
// a default pref.
pb.setCharPref(kPrefName, "i-imaginarylanguage");
// NB: processing of the value-change notification in the child
// process triggered by the above set happens-before the remaining
// code here
check_child_pref_info_eq(function() {
Assert.equal(pb.prefHasUserValue(kPrefName), true);
// We rely on setting this before the content process starts up.
// When it starts up, it should recognize this as a user pref, not
// a default pref.
pb.setCharPref(kPrefName, "i-imaginarylanguage");
// NB: processing of the value-change notification in the child
// process triggered by the above set happens-before the remaining
// code here
check_child_pref_info_eq(function() {
Assert.equal(pb.prefHasUserValue(kPrefName), true);
test_cleared_is_default();
});
test_cleared_is_default();
});
}
function test_cleared_is_default() {
pb.clearUserPref(kPrefName);
// NB: processing of the value-change notification in the child
// process triggered by the above set happens-before the remaining
// code here
check_child_pref_info_eq(function() {
Assert.equal(pb.prefHasUserValue(kPrefName), false);
pb.clearUserPref(kPrefName);
// NB: processing of the value-change notification in the child
// process triggered by the above set happens-before the remaining
// code here
check_child_pref_info_eq(function() {
Assert.equal(pb.prefHasUserValue(kPrefName), false);
clean_up();
});
clean_up();
});
}
function clean_up() {
pb.setCharPref(kPrefName, initialValue);
// NB: processing of the value-change notification in the child
// process triggered by the above set happens-before the remaining
// code here
check_child_pref_info_eq(function() {
do_test_finished();
});
pb.setCharPref(kPrefName, initialValue);
// NB: processing of the value-change notification in the child
// process triggered by the above set happens-before the remaining
// code here
check_child_pref_info_eq(function() {
do_test_finished();
});
}