// Don't pick up default permissions from profile.
Services.prefs.setCharPref("permissions.manager.defaultsUrl", "");
CookieXPCShellUtils.init(this);
function do_check_throws(f, result, stack) { if (!stack) {
stack = Components.stack.caller;
}
try {
f();
} catch (exc) { if (exc.result == result) { return;
}
do_throw("expected result " + result + ", caught " + exc, stack);
}
do_throw("expected result " + result + ", none thrown", stack);
}
// Helper to step a generator function and catch a StopIteration exception. function do_run_generator(generator) { try {
generator.next();
} catch (e) {
do_throw("caught exception " + e, Components.stack.caller);
}
}
// Helper to finish a generator function test. function do_finish_generator_test(generator) {
executeSoon(function () {
generator.return();
do_test_finished();
});
}
function _observer(generator, topic) {
Services.obs.addObserver(this, topic);
// Continue executing the generator function. if (this.generator) {
do_run_generator(this.generator);
}
this.generator = null; this.topic = null;
},
};
// Close the cookie database. If a generator is supplied, it will be invoked // once the close is complete. function do_close_profile(generator) { // Register an observer for db close. new _observer(generator, "cookie-db-closed");
// Close the db.
let service = Services.cookies.QueryInterface(Ci.nsIObserver);
service.observe(null, "profile-before-change", null);
}
function _promise_observer(topic) {
Services.obs.addObserver(this, topic);
Services.obs.removeObserver(this, this.topic); if (this.resolve) { this.resolve();
}
this.resolve = null; this.topic = null;
},
};
// Close the cookie database. And resolve a promise. function promise_close_profile() { // Register an observer for db close.
let promise = new _promise_observer("cookie-db-closed");
// Close the db.
let service = Services.cookies.QueryInterface(Ci.nsIObserver);
service.observe(null, "profile-before-change", null);
return promise;
}
// Load the cookie database. function promise_load_profile() { // Register an observer for read completion.
let promise = new _promise_observer("cookie-db-read");
// Load the profile.
let service = Services.cookies.QueryInterface(Ci.nsIObserver);
service.observe(null, "profile-do-change", "");
return promise;
}
// Load the cookie database. If a generator is supplied, it will be invoked // once the load is complete. function do_load_profile(generator) { // Register an observer for read completion. new _observer(generator, "cookie-db-read");
// Load the profile.
let service = Services.cookies.QueryInterface(Ci.nsIObserver);
service.observe(null, "profile-do-change", "");
}
// Set a single session cookie using http and test the cookie count // against 'expected' function do_set_single_http_cookie(uri, channel, expected) {
Services.cookies.setCookieStringFromHttp(uri, "foo=bar", channel); Assert.equal(Services.cookies.countCookiesFromHost(uri.host), expected);
}
// Set two cookies; via document.channel and via http request.
async function do_set_cookies(uri, channel, session, expected) {
let suffix = session ? "" : "; max-age=1000";
// Object representing a database connection and associated statements. The // implementation varies depending on schema version. function CookieDatabaseConnection(file, schema) { // Manually generate a cookies.sqlite file with appropriate rows, columns, // and schema version. If it already exists, just set up our statements.
let exists = file.exists();
this.stmtDelete = this.db.createStatement( "DELETE FROM moz_cookies \
WHERE name = :name AND host = :host AND path = :path"
);
this.stmtUpdate = this.db.createStatement( "UPDATE moz_cookies SET lastAccessed = :lastAccessed \
WHERE name = :name AND host = :host AND path = :path"
);
this.stmtDelete = this.db.createStatement( "DELETE FROM moz_cookies \
WHERE name = :name AND host = :host AND path = :path AND \
originAttributes = :originAttributes"
);
this.stmtUpdate = this.db.createStatement( "UPDATE moz_cookies SET lastAccessed = :lastAccessed \
WHERE name = :name AND host = :host AND path = :path AND \
originAttributes = :originAttributes"
);
this.stmtDelete = this.db.createStatement( "DELETE FROM moz_cookies \
WHERE name = :name AND host = :host AND path = :path AND \
originAttributes = :originAttributes"
);
this.stmtUpdate = this.db.createStatement( "UPDATE moz_cookies SET lastAccessed = :lastAccessed \
WHERE name = :name AND host = :host AND path = :path AND \
originAttributes = :originAttributes"
);
this.stmtDelete = this.db.createStatement( "DELETE FROM moz_cookies \
WHERE name = :name AND host = :host AND path = :path AND \
originAttributes = :originAttributes"
);
this.stmtUpdate = this.db.createStatement( "UPDATE moz_cookies SET lastAccessed = :lastAccessed \
WHERE name = :name AND host = :host AND path = :path AND \
originAttributes = :originAttributes"
);
this.stmtDelete = this.db.createStatement( "DELETE FROM moz_cookies \
WHERE name = :name AND host = :host AND path = :path AND \
originAttributes = :originAttributes"
);
this.stmtUpdate = this.db.createStatement( "UPDATE moz_cookies SET lastAccessed = :lastAccessed \
WHERE name = :name AND host = :host AND path = :path AND \
originAttributes = :originAttributes"
);
deleteCookie(cookie) { if (!(cookie instanceof Cookie)) {
do_throw("not a cookie");
}
switch (this.db.schemaVersion) { case 1: case 2: case 3: this.stmtDelete.bindByName("id", cookie.creationTime); break;
case 4: this.stmtDelete.bindByName("name", cookie.name); this.stmtDelete.bindByName("host", cookie.host); this.stmtDelete.bindByName("path", cookie.path); break;
case 10: case 11: case 12: case 13: case 14: this.stmtDelete.bindByName("name", cookie.name); this.stmtDelete.bindByName("host", cookie.host); this.stmtDelete.bindByName("path", cookie.path); this.stmtDelete.bindByName( "originAttributes",
ChromeUtils.originAttributesToSuffix(cookie.originAttributes)
); break;
function do_get_cookie_file(profile) {
let file = profile.clone();
file.append("cookies.sqlite"); return file;
}
// Count the cookies from 'host' in a database. If 'host' is null, count all // cookies. function do_count_cookies_in_db(connection, host) {
let select = null; if (host) {
select = connection.createStatement( "SELECT COUNT(1) FROM moz_cookies WHERE host = :host"
);
select.bindByName("host", host);
} else {
select = connection.createStatement("SELECT COUNT(1) FROM moz_cookies");
}
select.executeStep();
let result = select.getInt32(0);
select.reset();
select.finalize(); return result;
}
// Execute 'stmt', ensuring that we reset it if it throws. function do_execute_stmt(stmt) { try {
stmt.executeStep();
stmt.reset();
} catch (e) {
stmt.reset(); throw e;
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.