Bug 439129 - Clearing browsing history does not hide livemarks children from the location bar, r=dietrich
authorMarco Bonardo <mak77@bonardo.net>
Tue, 30 Dec 2008 22:42:22 +0100
changeset 23196 c28356223f8517329c04d7b569fdab4bac919aca
parent 23195 be8e227b1d8a760b9c7e1e568f2368c00a6a8b0c
child 23197 144901af1a63ad41ed3c4b5ad5dd593b3b338f68
push id4386
push usermak77@bonardo.net
push dateTue, 30 Dec 2008 21:48:52 +0000
treeherdermozilla-central@a04c4267c6c3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdietrich
bugs439129
milestone1.9.2a1pre
Bug 439129 - Clearing browsing history does not hide livemarks children from the location bar, r=dietrich
toolkit/components/places/src/nsNavHistory.cpp
toolkit/components/places/tests/unit/test_history_removeAllPages.js
--- a/toolkit/components/places/src/nsNavHistory.cpp
+++ b/toolkit/components/places/src/nsNavHistory.cpp
@@ -2529,22 +2529,23 @@ nsNavHistory::FixInvalidFrecenciesForExc
       "UPDATE moz_places_view "
       "SET frecency = 0 WHERE id IN ("
         "SELECT h.id FROM moz_places h "
         "WHERE h.url >= 'place:' AND h.url < 'place;' "
         "UNION "
         "SELECT h.id FROM moz_places_temp h "
         "WHERE  h.url >= 'place:' AND h.url < 'place;' "
         "UNION "
-        // Unvisited child of a livemark        
+        // Unvisited child of a livemark
         "SELECT b.fk FROM moz_bookmarks b "
-        "JOIN moz_items_annos a ON a.item_id = b.id "
+        "JOIN moz_bookmarks bp ON bp.id = b.parent "
+        "JOIN moz_items_annos a ON a.item_id = bp.id "
         "JOIN moz_anno_attributes n ON n.id = a.anno_attribute_id "
         "WHERE n.name = ?1 "
-        "AND fk IN( "
+        "AND b.fk IN( "
           "SELECT id FROM moz_places WHERE visit_count = 0 AND frecency < 0 "
           "UNION ALL "
           "SELECT id FROM moz_places_temp WHERE visit_count = 0 AND frecency < 0 "
         ") "
       ")"),
     getter_AddRefs(dbUpdateStatement));
   NS_ENSURE_SUCCESS(rv, rv);
 
@@ -4393,19 +4394,18 @@ nsNavHistory::RemovePagesInternal(const 
         "WHERE h.id NOT IN (SELECT id FROM moz_places_temp) "
           "AND h.id IN ( ") + aPlaceIdsQueryString + NS_LITERAL_CSTRING(") "
           "AND SUBSTR(h.url, 0, 6) <> 'place:' "
           "AND NOT EXISTS "
             "(SELECT b.id FROM moz_bookmarks b WHERE b.fk = h.id LIMIT 1) "
     ")"));
   NS_ENSURE_SUCCESS(rv, rv);
 
-  // placeId could have a livemark item, so setting the frecency to -1
-  // would cause it to show up in the url bar autocomplete
-  // call FixInvalidFrecenciesForExcludedPlaces() to handle that scenario
+  // If we have removed all visits to a livemark's child, we need to fix its
+  // frecency, or it would appear in the url bar autocomplete.
   // XXX this might be dog slow, further degrading delete perf.
   rv = FixInvalidFrecenciesForExcludedPlaces();
   NS_ENSURE_SUCCESS(rv, rv);
 
   // XXX todo
   // forcibly call the "on idle" timer here to do a little work
   // but the rest will happen on idle.
 
--- a/toolkit/components/places/tests/unit/test_history_removeAllPages.js
+++ b/toolkit/components/places/tests/unit/test_history_removeAllPages.js
@@ -46,18 +46,38 @@ let hs = Cc["@mozilla.org/browser/nav-hi
 let bh = hs.QueryInterface(Ci.nsIBrowserHistory);
 let mDBConn = hs.QueryInterface(Ci.nsPIPlacesDatabase).DBConnection;
 let bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
          getService(Ci.nsINavBookmarksService);
 let as = Cc["@mozilla.org/browser/annotation-service;1"].
          getService(Ci.nsIAnnotationService);
 let os = Cc["@mozilla.org/observer-service;1"].
          getService(Ci.nsIObserverService);
+let lms = Cc["@mozilla.org/browser/livemark-service;2"].
+          getService(Ci.nsILivemarkService);
 
 const kSyncFinished = "places-sync-finished";
+// Number of expected sync notifications, we expect one per bookmark.
+// XXX this is actually incorrect due to bug 470429, should be 4.
+const EXPECTED_SYNCS = 5;
+
+function add_fake_livemark() {
+  let lmId = lms.createLivemarkFolderOnly(bs.bookmarksToolbarId, "Livemark",
+                                          uri("http://www.mozilla.org/"),
+                                          uri("http://www.mozilla.org/test.xml"),
+                                          bs.DEFAULT_INDEX);
+  // add a visited child
+  bs.insertBookmark(lmId, uri("http://visited.livemark.com/"),
+                    bs.DEFAULT_INDEX, "visited");
+  hs.addVisit(uri("http://visited.livemark.com/"), Date.now(), null,
+              hs.TRANSITION_BOOKMARK, false, 0);
+  // add an unvisited child
+  bs.insertBookmark(lmId, uri("http://unvisited.livemark.com/"),
+                    bs.DEFAULT_INDEX, "unvisited");
+}
 
 let observer = {
   onBeginUpdateBatch: function() {
   },
   onEndUpdateBatch: function() {
   },
   onVisit: function(aURI, aVisitID, aTime, aSessionID, aReferringID, aTransitionType) {
   },
@@ -117,19 +137,19 @@ let observer = {
     throw Cr.NS_ERROR_NO_INTERFACE;
   }
 }
 hs.addObserver(observer, false);
 
 let syncObserver = {
   _runCount: 0,
   observe: function (aSubject, aTopic, aData) {
-    if (++this._runCount < 2)
+    if (++this._runCount < EXPECTED_SYNCS)
       return;
-    if (this._runCount == 2) {
+    if (this._runCount == EXPECTED_SYNCS) {
       bh.removeAllPages();
       return;
     }
 
     // Sanity: check that places temp table is empty
     stmt = mDBConn.createStatement(
       "SELECT id FROM moz_places_temp LIMIT 1");
     do_check_false(stmt.executeStep());
@@ -186,24 +206,38 @@ let syncObserver = {
 
     // Check that place:uris have frecency 0
     stmt = mDBConn.createStatement(
       "SELECT h.id FROM moz_places h " +
       "WHERE SUBSTR(h.url,0,6) = 'place:' AND h.frecency <> 0 LIMIT 1");
     do_check_false(stmt.executeStep());
     stmt.finalize();
 
+    // Check that livemarks children don't have frecency <> 0
+    stmt = mDBConn.createStatement(
+      "SELECT h.id FROM moz_places h " +
+      "JOIN moz_bookmarks b ON h.id = b.fk " +
+      "JOIN moz_bookmarks bp ON bp.id = b.parent " +
+      "JOIN moz_items_annos t ON t.item_id = bp.id " +
+      "JOIN moz_anno_attributes n ON t.anno_attribute_id = n.id " +
+      "WHERE n.name = 'livemark/feedURI' AND h.frecency <> 0 LIMIT 1");
+    do_check_false(stmt.executeStep());
+    stmt.finalize();
+
     finish_test();
   }
 }
 os.addObserver(syncObserver, kSyncFinished, false);
 
 
 // main
 function run_test() {
+  // Add a livemark with a visited and an unvisited child
+  add_fake_livemark();
+
   // Add a bunch of visits
   hs.addVisit(uri("http://typed.mozilla.org"), Date.now(), null,
               hs.TRANSITION_TYPED, false, 0);
 
   hs.addVisit(uri("http://link.mozilla.org"), Date.now(), null,
               hs.TRANSITION_LINK, false, 0);
   hs.addVisit(uri("http://download.mozilla.org"), Date.now(), null,
               hs.TRANSITION_DOWNLOAD, false, 0);