DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Untracked file

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet
  href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
<window title="Bug 371798"
  xmlns:html="http://www.w3.org/1999/xhtml"
  xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
  <script type="application/javascript"
   src="chrome://mochikit/content/MochiKit/packed.js"></script>
  <script type="application/javascript"
   src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>

  <body xmlns="http://www.w3.org/1999/xhtml" />

<script type="application/javascript">
<![CDATA[
// Test the asynchronous live-updating of bookmarks query results
SimpleTest.waitForExplicitFinish();

const Cc = Components.classes;
const Ci = Components.interfaces;
const Cr = Components.results;

var iosvc = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);

function uri(spec) {
  return iosvc.newURI(spec, null, null);
}

var histsvc = Cc["@mozilla.org/browser/nav-history-service;1"].
                getService(Ci.nsINavHistoryService);
var bmsvc = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
              getService(Ci.nsINavBookmarksService);

// add 2 bookmarks to the toolbar, same URI, different titles (set later)
var toolbarFolderId = bmsvc.toolbarFolder;
var testURI = uri("http://foo.com");
var bm1 = bmsvc.insertBookmark(toolbarFolderId, testURI, bmsvc.DEFAULT_INDEX, "");
var bm2 = bmsvc.insertBookmark(toolbarFolderId, testURI, bmsvc.DEFAULT_INDEX, "");

// query for bookmarks
var options = histsvc.getNewQueryOptions();
var query = histsvc.getNewQuery();
query.setFolders([toolbarFolderId], 1);
var result = histsvc.executeQuery(query, options);
var rootNode = result.root;
rootNode.containerOpen = true;

// set up observer
var observer =
{
  QueryInterface: function(iid) {
    if (iid.equals(Ci.nsINavBookmarkObserver) ||
        iid.equals(Ci.nsISupports))
      return this;
    throw Cr.NS_ERROR_NO_INTERFACE;
  },

  // nsINavBookmarkObserver
  onBeginUpdateBatch: function(){},
  onEndUpdateBatch: function(){},
  onItemAdded: function(bookmarkId, bookmark, folder, index) {},
  onItemRemoved: function(bookmarkId, bookmark, folder, index){},
  onItemChanged: function(bookmarkId, property, isAnnotationProperty, value){
    runTest();
    bmsvc.removeObserver(this);
  },
  onItemVisited: function(bookmarkId, bookmark, aVisitID, time){},
  onItemMoved: function(itemId, oldParent, oldIndex, newParent, newIndex){}
};
bmsvc.addObserver(observer, false);

// modify the bookmark's title
var newTitle = "foo";
bmsvc.setItemTitle(bm2, newTitle);

/*
  this gets called after our observer gets notified of onItemChanged
  which is triggered by updating the item's title.
  after receiving the notification, our original query should also
  have been live-updated, so we can iterate through it's children,
  to check that only the modified bookmark has changed.
*/
function runTest() {
  // result node should be updated
  var cc = rootNode.childCount;
  for (var i=0; i < cc; ++i) {
    var node = rootNode.getChild(i);
    // test that bm1 does not have new title
    if (node.itemId == bm1)
      ok(node.title != newTitle,
         "Changing a bookmark's title did not affect the title of other bookmarks with the same URI");
  }
  rootNode.containerOpen = false;

  // clean up finish test
  bmsvc.removeItem(bm1);
  bmsvc.removeItem(bm2);
  SimpleTest.finish();
}

]]>
</script>

</window>