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

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     1 <?xml version="1.0"?>
     2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
     3 <?xml-stylesheet
     4   href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
     5 <window title="Bug 371798"
     6   xmlns:html="http://www.w3.org/1999/xhtml"
     7   xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
     8   <script type="application/javascript"
     9    src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
    11   <body xmlns="http://www.w3.org/1999/xhtml" />
    13 <script type="application/javascript">
    14 <![CDATA[
    15 // Test the asynchronous live-updating of bookmarks query results
    16 SimpleTest.waitForExplicitFinish();
    18 const Cc = Components.classes;
    19 const Ci = Components.interfaces;
    20 const Cr = Components.results;
    22 var iosvc = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
    24 function uri(spec) {
    25   return iosvc.newURI(spec, null, null);
    26 }
    28 var histsvc = Cc["@mozilla.org/browser/nav-history-service;1"].
    29                 getService(Ci.nsINavHistoryService);
    30 var bmsvc = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
    31               getService(Ci.nsINavBookmarksService);
    33 // add 2 bookmarks to the toolbar, same URI, different titles (set later)
    34 var toolbarFolderId = bmsvc.toolbarFolder;
    35 var testURI = uri("http://foo.com");
    36 var bm1 = bmsvc.insertBookmark(toolbarFolderId, testURI, bmsvc.DEFAULT_INDEX, "");
    37 var bm2 = bmsvc.insertBookmark(toolbarFolderId, testURI, bmsvc.DEFAULT_INDEX, "");
    39 // query for bookmarks
    40 var options = histsvc.getNewQueryOptions();
    41 var query = histsvc.getNewQuery();
    42 query.setFolders([toolbarFolderId], 1);
    43 var result = histsvc.executeQuery(query, options);
    44 var rootNode = result.root;
    45 rootNode.containerOpen = true;
    47 // set up observer
    48 var observer =
    49 {
    50   QueryInterface: function(iid) {
    51     if (iid.equals(Ci.nsINavBookmarkObserver) ||
    52         iid.equals(Ci.nsISupports))
    53       return this;
    54     throw Cr.NS_ERROR_NO_INTERFACE;
    55   },
    57   // nsINavBookmarkObserver
    58   onBeginUpdateBatch: function(){},
    59   onEndUpdateBatch: function(){},
    60   onItemAdded: function(){},
    61   onItemRemoved: function(){},
    62   onItemChanged: function(bookmarkId, property, isAnnotationProperty, value,
    63                           lastModified, itemType){
    64     runTest();
    65     bmsvc.removeObserver(this);
    66   },
    67   onItemVisited: function(){},
    68   onItemMoved: function(){}
    69 };
    70 bmsvc.addObserver(observer, false);
    72 // modify the bookmark's title
    73 var newTitle = "foo";
    74 bmsvc.setItemTitle(bm2, newTitle);
    76 /*
    77   this gets called after our observer gets notified of onItemChanged
    78   which is triggered by updating the item's title.
    79   after receiving the notification, our original query should also
    80   have been live-updated, so we can iterate through its children,
    81   to check that only the modified bookmark has changed.
    82 */
    83 function runTest() {
    84   // result node should be updated
    85   var cc = rootNode.childCount;
    86   for (var i=0; i < cc; ++i) {
    87     var node = rootNode.getChild(i);
    88     // test that bm1 does not have new title
    89     if (node.itemId == bm1)
    90       ok(node.title != newTitle,
    91          "Changing a bookmark's title did not affect the title of other bookmarks with the same URI");
    92   }
    93   rootNode.containerOpen = false;
    95   // clean up finish test
    96   bmsvc.removeItem(bm1);
    97   bmsvc.removeItem(bm2);
    98   SimpleTest.finish();
    99 }
   101 ]]>
   102 </script>
   104 </window>

mercurial