toolkit/components/places/tests/chrome/test_371798.xul

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/components/places/tests/chrome/test_371798.xul	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,104 @@
     1.4 +<?xml version="1.0"?>
     1.5 +<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
     1.6 +<?xml-stylesheet
     1.7 +  href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
     1.8 +<window title="Bug 371798"
     1.9 +  xmlns:html="http://www.w3.org/1999/xhtml"
    1.10 +  xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
    1.11 +  <script type="application/javascript"
    1.12 +   src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
    1.13 +
    1.14 +  <body xmlns="http://www.w3.org/1999/xhtml" />
    1.15 +
    1.16 +<script type="application/javascript">
    1.17 +<![CDATA[
    1.18 +// Test the asynchronous live-updating of bookmarks query results
    1.19 +SimpleTest.waitForExplicitFinish();
    1.20 +
    1.21 +const Cc = Components.classes;
    1.22 +const Ci = Components.interfaces;
    1.23 +const Cr = Components.results;
    1.24 +
    1.25 +var iosvc = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
    1.26 +
    1.27 +function uri(spec) {
    1.28 +  return iosvc.newURI(spec, null, null);
    1.29 +}
    1.30 +
    1.31 +var histsvc = Cc["@mozilla.org/browser/nav-history-service;1"].
    1.32 +                getService(Ci.nsINavHistoryService);
    1.33 +var bmsvc = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
    1.34 +              getService(Ci.nsINavBookmarksService);
    1.35 +
    1.36 +// add 2 bookmarks to the toolbar, same URI, different titles (set later)
    1.37 +var toolbarFolderId = bmsvc.toolbarFolder;
    1.38 +var testURI = uri("http://foo.com");
    1.39 +var bm1 = bmsvc.insertBookmark(toolbarFolderId, testURI, bmsvc.DEFAULT_INDEX, "");
    1.40 +var bm2 = bmsvc.insertBookmark(toolbarFolderId, testURI, bmsvc.DEFAULT_INDEX, "");
    1.41 +
    1.42 +// query for bookmarks
    1.43 +var options = histsvc.getNewQueryOptions();
    1.44 +var query = histsvc.getNewQuery();
    1.45 +query.setFolders([toolbarFolderId], 1);
    1.46 +var result = histsvc.executeQuery(query, options);
    1.47 +var rootNode = result.root;
    1.48 +rootNode.containerOpen = true;
    1.49 +
    1.50 +// set up observer
    1.51 +var observer =
    1.52 +{
    1.53 +  QueryInterface: function(iid) {
    1.54 +    if (iid.equals(Ci.nsINavBookmarkObserver) ||
    1.55 +        iid.equals(Ci.nsISupports))
    1.56 +      return this;
    1.57 +    throw Cr.NS_ERROR_NO_INTERFACE;
    1.58 +  },
    1.59 +
    1.60 +  // nsINavBookmarkObserver
    1.61 +  onBeginUpdateBatch: function(){},
    1.62 +  onEndUpdateBatch: function(){},
    1.63 +  onItemAdded: function(){},
    1.64 +  onItemRemoved: function(){},
    1.65 +  onItemChanged: function(bookmarkId, property, isAnnotationProperty, value,
    1.66 +                          lastModified, itemType){
    1.67 +    runTest();
    1.68 +    bmsvc.removeObserver(this);
    1.69 +  },
    1.70 +  onItemVisited: function(){},
    1.71 +  onItemMoved: function(){}
    1.72 +};
    1.73 +bmsvc.addObserver(observer, false);
    1.74 +
    1.75 +// modify the bookmark's title
    1.76 +var newTitle = "foo";
    1.77 +bmsvc.setItemTitle(bm2, newTitle);
    1.78 +
    1.79 +/*
    1.80 +  this gets called after our observer gets notified of onItemChanged
    1.81 +  which is triggered by updating the item's title.
    1.82 +  after receiving the notification, our original query should also
    1.83 +  have been live-updated, so we can iterate through its children,
    1.84 +  to check that only the modified bookmark has changed.
    1.85 +*/
    1.86 +function runTest() {
    1.87 +  // result node should be updated
    1.88 +  var cc = rootNode.childCount;
    1.89 +  for (var i=0; i < cc; ++i) {
    1.90 +    var node = rootNode.getChild(i);
    1.91 +    // test that bm1 does not have new title
    1.92 +    if (node.itemId == bm1)
    1.93 +      ok(node.title != newTitle,
    1.94 +         "Changing a bookmark's title did not affect the title of other bookmarks with the same URI");
    1.95 +  }
    1.96 +  rootNode.containerOpen = false;
    1.97 +
    1.98 +  // clean up finish test
    1.99 +  bmsvc.removeItem(bm1);
   1.100 +  bmsvc.removeItem(bm2);
   1.101 +  SimpleTest.finish();
   1.102 +}
   1.103 +
   1.104 +]]>
   1.105 +</script>
   1.106 +
   1.107 +</window>

mercurial