Fix test timeout.

This commit is contained in:
Dan Witte 2010-05-27 17:36:57 -07:00
parent 650f1b099e
commit 33e0f74cc6
3 changed files with 19 additions and 32 deletions

View File

@ -8,12 +8,7 @@ const _Cc = Components.classes;
const _Ci = Components.interfaces;
// Ensure 'db' is closed; if not, spin until it is.
function do_wait_for_db_close(db) {
const ProfD = do_get_profile().QueryInterface(_Ci.nsILocalFile);
let dbfile = ProfD.clone();
dbfile.append(db);
function do_wait_for_db_close(dbfile) {
// If there is no database then it cannot be locked.
if (!dbfile.exists())
return;
@ -22,27 +17,16 @@ function do_wait_for_db_close(db) {
getService(_Ci.nsIThreadManager).
mainThread;
// Wait until we can open a connection to the database
let db = null;
while (!db) {
// Poll for database
try {
db = Services.storage.openUnsharedDatabase(dbfile);
}
catch (e) {
if (thr.hasPendingEvents())
thr.processNextEvent(false);
}
}
// Wait until we can write to the database
while (db) {
while (true) {
// Poll for write access
try {
db.executeSimpleSQL("CREATE TABLE moz_test (id INTEGER PRIMARY KEY)");
db.executeSimpleSQL("DROP TABLE moz_test");
db = Services.storage.openUnsharedDatabase(dbfile);
db.schemaVersion = 0;
db.schemaVersion = 2;
db.close();
db = null;
break;
}
catch (e) {
if (thr.hasPendingEvents())
@ -52,9 +36,12 @@ function do_wait_for_db_close(db) {
}
// Reload the profile by calling the 'observe' method on the given service.
function do_reload_profile(observer, cleanse) {
function do_reload_profile(profile, observer, cleanse) {
let dbfile = profile.QueryInterface(_Ci.nsILocalFile).clone();
dbfile.append("cookies.sqlite");
observer.observe(null, "profile-before-change", cleanse ? cleanse : "");
do_wait_for_db_close("cookies.sqlite");
do_wait_for_db_close(dbfile);
observer.observe(null, "profile-do-change", "");
}

View File

@ -7,7 +7,7 @@ const Ci = Components.interfaces;
function run_test() {
// Set up a profile.
do_get_profile();
let profile = do_get_profile();
var cs = Cc["@mozilla.org/cookieService;1"].getService(Ci.nsICookieService);
var cso = cs.QueryInterface(Ci.nsIObserver);
@ -38,12 +38,12 @@ function run_test() {
do_set_cookies(uri2, channel2, true, [1, 2, 3, 4]);
// fake a profile change
do_reload_profile(cso);
do_reload_profile(profile, cso);
do_check_eq(cs.countCookiesFromHost(uri1.host), 4);
do_check_eq(cs.countCookiesFromHost(uri2.host), 0);
// cleanse them
do_reload_profile(cso, "shutdown-cleanse");
do_reload_profile(profile, cso, "shutdown-cleanse");
do_check_eq(cs.countCookiesFromHost(uri1.host), 0);
do_check_eq(cs.countCookiesFromHost(uri2.host), 0);
@ -53,7 +53,7 @@ function run_test() {
do_set_cookies(uri2, channel2, true, [1, 2, 3, 4]);
// fake a profile change
do_reload_profile(cso);
do_reload_profile(profile, cso);
do_check_eq(cs.countCookiesFromHost(uri1.host), 0);
do_check_eq(cs.countCookiesFromHost(uri2.host), 0);
}

View File

@ -7,7 +7,7 @@ const Ci = Components.interfaces;
function run_test() {
// Set up a profile.
do_get_profile();
let profile = do_get_profile();
var cs = Cc["@mozilla.org/cookieService;1"].getService(Ci.nsICookieService);
var cso = cs.QueryInterface(Ci.nsIObserver);
@ -38,12 +38,12 @@ function run_test() {
do_set_cookies(uri2, channel1, true, [1, 2, 3, 4]);
// fake a profile change
do_reload_profile(cso);
do_reload_profile(profile, cso);
do_check_eq(cs.countCookiesFromHost(uri1.host), 4);
do_check_eq(cs.countCookiesFromHost(uri2.host), 0);
// cleanse them
do_reload_profile(cso, "shutdown-cleanse");
do_reload_profile(profile, cso, "shutdown-cleanse");
do_check_eq(cs.countCookiesFromHost(uri1.host), 0);
do_check_eq(cs.countCookiesFromHost(uri2.host), 0);
@ -53,7 +53,7 @@ function run_test() {
do_set_cookies(uri2, channel1, true, [1, 2, 3, 4]);
// fake a profile change
do_reload_profile(cso);
do_reload_profile(profile, cso);
do_check_eq(cs.countCookiesFromHost(uri1.host), 0);
do_check_eq(cs.countCookiesFromHost(uri2.host), 0);
}