Bug 547031 - Improve async error handling in cookies. Part 4: Fix SELECT bug in EnsureReadComplete(). r=sdwilsh, a=betaN+
authorDan Witte <dwitte@mozilla.com>
Fri, 12 Nov 2010 09:32:35 -0800
changeset 57408 3e8a89a8be5651029c7ff5175654690cc137022e
parent 57407 09bb5890500d91c69b3474b08660cbe915e3b12d
child 57409 8d5d684341711147d795ff967de9ebab128774a8
push id16911
push userdwitte@mozilla.com
push dateFri, 12 Nov 2010 17:33:05 +0000
treeherdermozilla-central@0525032a59a3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssdwilsh, betaN
bugs547031
milestone2.0b8pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 547031 - Improve async error handling in cookies. Part 4: Fix SELECT bug in EnsureReadComplete(). r=sdwilsh, a=betaN+
extensions/cookie/test/unit/test_schema_2_migration.js
netwerk/cookie/nsCookieService.cpp
--- a/extensions/cookie/test/unit/test_schema_2_migration.js
+++ b/extensions/cookie/test/unit/test_schema_2_migration.js
@@ -123,28 +123,87 @@ function do_run_test() {
 
   // Check that there is, indeed, a singular cookie for baz.com.
   do_check_eq(do_count_cookies_in_db(schema2db.db, "baz.com"), 1);
 
   // Close it.
   schema2db.close();
   schema2db = null;
 
-  // Load the database, forcing a purge of the newly-added cookies. (Their
-  // baseDomain column will be NULL.)
-  do_load_profile();
+  // Back up the database, so we can test both asynchronous and synchronous
+  // loading separately.
+  let file = profile.clone();
+  file.append("cookies.sqlite");
+  let copy = profile.clone();
+  copy.append("cookies.sqlite.copy");
+  file.copyTo(null, copy.leafName);
+
+  // Load the database asynchronously, forcing a purge of the newly-added
+  // cookies. (Their baseDomain column will be NULL.)
+  do_load_profile(test_generator);
+  yield;
 
   // Test the expected set of cookies.
   do_check_eq(Services.cookiemgr.countCookiesFromHost("foo.com"), 20);
+  do_check_eq(Services.cookiemgr.countCookiesFromHost("bar.com"), 20);
+  do_check_eq(Services.cookiemgr.countCookiesFromHost("baz.com"), 0);
   do_check_eq(Services.cookiemgr.countCookiesFromHost("cat.com"), 0);
-  do_check_eq(Services.cookiemgr.countCookiesFromHost("baz.com"), 0);
 
   do_close_profile(test_generator);
   yield;
 
   // Open the database and prove that they were deleted.
   schema2db = new CookieDatabaseConnection(profile, 2);
-  do_check_eq(do_count_cookies_in_db(schema2db.db, "cat.com"), 0);
+  do_check_eq(do_count_cookies_in_db(schema2db.db), 40);
+  do_check_eq(do_count_cookies_in_db(schema2db.db, "foo.com"), 20);
+  do_check_eq(do_count_cookies_in_db(schema2db.db, "bar.com"), 20);
+  schema2db.close();
+
+  // Copy the database back.
+  file.remove(false);
+  copy.copyTo(null, file.leafName);
+
+  // Load the database host-at-a-time.
+  do_load_profile();
+
+  // Test the expected set of cookies.
+  do_check_eq(Services.cookiemgr.countCookiesFromHost("foo.com"), 20);
+  do_check_eq(Services.cookiemgr.countCookiesFromHost("bar.com"), 20);
+  do_check_eq(Services.cookiemgr.countCookiesFromHost("baz.com"), 0);
+  do_check_eq(Services.cookiemgr.countCookiesFromHost("cat.com"), 0);
+
+  do_close_profile(test_generator);
+  yield;
+
+  // Open the database and prove that they were deleted.
+  schema2db = new CookieDatabaseConnection(profile, 2);
+  do_check_eq(do_count_cookies_in_db(schema2db.db), 40);
+  do_check_eq(do_count_cookies_in_db(schema2db.db, "foo.com"), 20);
+  do_check_eq(do_count_cookies_in_db(schema2db.db, "bar.com"), 20);
+  schema2db.close();
+
+  // Copy the database back.
+  file.remove(false);
+  copy.copyTo(null, file.leafName);
+
+  // Load the database synchronously, in its entirety.
+  do_load_profile();
+  do_check_eq(do_count_cookies(), 40);
+
+  // Test the expected set of cookies.
+  do_check_eq(Services.cookiemgr.countCookiesFromHost("foo.com"), 20);
+  do_check_eq(Services.cookiemgr.countCookiesFromHost("bar.com"), 20);
+  do_check_eq(Services.cookiemgr.countCookiesFromHost("baz.com"), 0);
+  do_check_eq(Services.cookiemgr.countCookiesFromHost("cat.com"), 0);
+
+  do_close_profile(test_generator);
+  yield;
+
+  // Open the database and prove that they were deleted.
+  schema2db = new CookieDatabaseConnection(profile, 2);
+  do_check_eq(do_count_cookies_in_db(schema2db.db), 40);
+  do_check_eq(do_count_cookies_in_db(schema2db.db, "foo.com"), 20);
+  do_check_eq(do_count_cookies_in_db(schema2db.db, "bar.com"), 20);
   schema2db.close();
 
   finish_test();
 }
 
--- a/netwerk/cookie/nsCookieService.cpp
+++ b/netwerk/cookie/nsCookieService.cpp
@@ -1830,17 +1830,18 @@ nsCookieService::EnsureReadComplete()
       "host, "
       "path, "
       "expiry, "
       "lastAccessed, "
       "creationTime, "
       "isSecure, "
       "isHttpOnly, "
       "baseDomain "
-    "FROM moz_cookies"), getter_AddRefs(stmt));
+    "FROM moz_cookies "
+    "WHERE baseDomain NOTNULL"), getter_AddRefs(stmt));
 
   // XXX Ignore corruption for now. See bug 547031.
   if (NS_FAILED(rv)) return;
 
   nsCString baseDomain, name, value, host, path;
   PRBool hasResult;
   PRUint32 readCount = 0;
   while (1) {