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 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
<html>
<head>
  <title>Testing Bookmarks</title>
  <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"></link>
</head>
<body>
<pre id="test">
<script class="testbody" type="text/javascript">

var gLastFolderAction = "";
var gLastBookmarkAction = "";

test_Bookmarks();

function test_Bookmarks() {
  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");

  var root = Application.bookmarks;
  ok(root, "Check access to bookmark root");
  ok(!root.parent, "Check root parent (should be null)");

  var rootKidCount = root.all.length;
  
  // test adding folders
  var testFolder = root.addFolder("FUEL");
  ok(testFolder, "Check folder creation");
  is(testFolder.type, "folder", "Check 'folder.type' after creation");
  ok(testFolder.parent, "Check parent after folder creation");

  rootKidCount++;
  is(root.all.length, rootKidCount, "Check root folder child count after adding a child folder");

  testFolder.events.addListener("change", onFolderChange);
  testFolder.description = "FUEL folder";
  is(testFolder.description, "FUEL folder", "Check setting 'folder.description'");
  is(gLastFolderAction, "bookmarkProperties/description", "Check event handler for setting 'folder.description'");

  testFolder.title = "fuel-is-cool";
  is(testFolder.title, "fuel-is-cool", "Check setting 'folder.title'");
  is(gLastFolderAction, "title", "Check event handler for setting 'folder.title'");

  testFolder.annotations.set("testing/folder", "annotate-this", 0);
  ok(testFolder.annotations.has("testing/folder"), "Checking existence of added annotation");
  is(gLastFolderAction, "testing/folder", "Check event handler for setting annotation");
  gLastFolderAction = "";
  is(testFolder.annotations.get("testing/folder"), "annotate-this", "Checking existence of added annotation");
  testFolder.annotations.remove("testing/folder");
  ok(!testFolder.annotations.has("testing/folder"), "Checking existence of removed annotation");
  is(gLastFolderAction, "testing/folder", "Check event handler for removing annotation");

  
  testFolder.events.addListener("addchild", onFolderAddChild);
  testFolder.events.addListener("removechild", onFolderRemoveChild);

  var testBookmark = testFolder.addBookmark("Mozilla", "http://www.mozilla.com/");
  ok(testBookmark, "Check bookmark creation");
  ok(testBookmark.parent, "Check parent after bookmark creation");
  is(gLastFolderAction, "addchild", "Check event handler for adding a child to a folder");
  is(testBookmark.type, "bookmark", "Check 'bookmark.type' after creation");
  is(testBookmark.title, "Mozilla", "Check 'bookmark.title' after creation");
  is(testBookmark.uri, "http://www.mozilla.com/", "Check 'bookmark.uri' after creation");
  
  is(testFolder.all.length, 1, "Check test folder child count after adding a child bookmark");

  testBookmark.events.addListener("change", onBookmarkChange);
  testBookmark.description = "mozcorp";
  is(testBookmark.description, "mozcorp", "Check setting 'bookmark.description'");
  is(gLastBookmarkAction, "bookmarkProperties/description", "Check event handler for setting 'bookmark.description'");

  testBookmark.keyword = "moz"
  is(testBookmark.keyword, "moz", "Check setting 'bookmark.keyword'");
  is(gLastBookmarkAction, "keyword", "Check event handler for setting 'bookmark.keyword'");
  
  testBookmark.title = "MozCorp"
  is(testBookmark.title, "MozCorp", "Check setting 'bookmark.title'");
  is(gLastBookmarkAction, "title", "Check event handler for setting 'bookmark.title'");

  testBookmark.uri = "http://www.mozilla.org/"
  is(testBookmark.uri, "http://www.mozilla.org/", "Check setting 'bookmark.uri'");
  is(gLastBookmarkAction, "uri", "Check event handler for setting 'bookmark.uri'");

  testBookmark.annotations.set("testing/bookmark", "annotate-this", 0);
  ok(testBookmark.annotations.has("testing/bookmark"), "Checking existence of added annotation");
  is(gLastBookmarkAction, "testing/bookmark", "Check event handler for setting annotation");
  gLastBookmarkAction = "";
  is(testBookmark.annotations.get("testing/bookmark"), "annotate-this", "Checking existence of added annotation");
  testBookmark.annotations.remove("testing/bookmark");
  ok(!testBookmark.annotations.has("testing/bookmark"), "Checking existence of removed annotation");
  is(gLastBookmarkAction, "testing/bookmark", "Check event handler for removing annotation");
  
  testBookmark.events.addListener("remove", onBookmarkRemove);
  testBookmark.remove();
  is(gLastBookmarkAction, "remove", "Check event handler for removing bookmark");
  is(gLastFolderAction, "removechild", "Check event handler for removing a child from a folder");
  is(testFolder.all.length, 0, "Check test folder child count after removing a child bookmark");
  
  testFolder.events.addListener("remove", onFolderRemove);
  testFolder.remove();
  is(gLastFolderAction, "remove", "Check event handler for removing child folder");
  rootKidCount--;
  is(root.all.length, rootKidCount, "Check root folder child count after removing a child folder");
}

function onFolderChange(evt) {
  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
  gLastFolderAction = evt.data;
}

function onFolderRemove(evt) {
  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
  gLastFolderAction = evt.type;
}

function onFolderAddChild(evt) {
  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
  gLastFolderAction = evt.type;
}

function onFolderRemoveChild(evt) {
  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
  gLastFolderAction = evt.type;
}

function onBookmarkChange(evt) {
  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
  gLastBookmarkAction = evt.data;
}

function onBookmarkRemove(evt) {
  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
  gLastBookmarkAction = evt.type;
}
</script>
</pre>
</body>
</html>