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.

Mercurial (b6057e17f856)

VCS Links

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 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
<?xml version="1.0"?>

<!-- Any copyright is dedicated to the Public Domain.
     http://creativecommons.org/publicdomain/zero/1.0/ -->

<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
                 type="text/css"?>

<?xml-stylesheet href="chrome://browser/skin/places/editBookmarkOverlay.css"?>
<?xml-stylesheet href="chrome://browser/content/places/places.css"?>
<?xml-stylesheet href="chrome://browser/skin/places/places.css"?>

<?xul-overlay href="chrome://browser/content/places/placesOverlay.xul"?>
<?xul-overlay href="chrome://browser/content/places/editBookmarkOverlay.xul"?>

<!DOCTYPE window [
  <!ENTITY % editBookmarkOverlayDTD SYSTEM "chrome://browser/locale/places/editBookmarkOverlay.dtd">
  %editBookmarkOverlayDTD;
]>

<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
        title="485100: Exchanging a letter of a tag name with its big/small equivalent removes tag from bookmark"
        onload="runTest();">

  <script type="application/javascript"
          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" />
  <script type="application/javascript"
          src="chrome://browser/content/places/editBookmarkOverlay.js"/>

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

  <vbox id="editBookmarkPanelContent"/>

  <script type="application/javascript">
  <![CDATA[
    function runTest()
    {
      Components.utils.import("resource://gre/modules/NetUtil.jsm");

      const TEST_URI = NetUtil.newURI("http://www.test.me/");
      const TEST_URI2 = NetUtil.newURI("http://www.test.again.me/");
      const TEST_TAG = "test-tag";

      ok(gEditItemOverlay, "Sanity check: gEditItemOverlay is in context");

      // Open the tags selector.
      document.getElementById("editBMPanel_tagsSelectorRow").collapsed = false;

      function checkTagsSelector(aAvailableTags, aCheckedTags)
      {
        is(PlacesUtils.tagging.allTags.length, aAvailableTags.length,
           "tagging service is in sync.");
        let tagsSelector = document.getElementById("editBMPanel_tagsSelector");
        let children = tagsSelector.childNodes;
        is(children.length, aAvailableTags.length,
            "Found expected number of tags in the tags selector");
        Array.forEach(children, function (aChild) {
          let tag = aChild.getAttribute("label");
          ok(true, "Found tag '" + tag + "' in the selector");
          ok(aAvailableTags.indexOf(tag) != -1, "Found expected tag");
          let checked = aChild.getAttribute("checked") == "true";
          is(checked, aCheckedTags.indexOf(tag) != -1,
             "Tag is correctly marked");
        });
      }

      // Add a bookmark.
      let itemId = PlacesUtils.bookmarks.insertBookmark(
        PlacesUtils.unfiledBookmarksFolderId, TEST_URI,
        PlacesUtils.bookmarks.DEFAULT_INDEX, "test.me"
      );

      // Init panel.
      gEditItemOverlay.initPanel(itemId);

      // Add a tag.
      PlacesUtils.tagging.tagURI(TEST_URI, [TEST_TAG]);

      is(PlacesUtils.tagging.getTagsForURI(TEST_URI)[0], TEST_TAG,
         "Correctly added tag to a single bookmark");
      is(document.getElementById("editBMPanel_tagsField").value, TEST_TAG,
         "Editing a single bookmark shows the added tag");
      checkTagsSelector([TEST_TAG], [TEST_TAG]);

      // Remove tag.
      PlacesUtils.tagging.untagURI(TEST_URI, [TEST_TAG]);
      is(PlacesUtils.tagging.getTagsForURI(TEST_URI)[0], undefined,
         "The tag has been removed");
      is(document.getElementById("editBMPanel_tagsField").value, "",
         "Editing a single bookmark should not show any tag");
      checkTagsSelector([], []);

      // Add a second bookmark.
      let itemId2 = PlacesUtils.bookmarks.insertBookmark(
        PlacesUtils.unfiledBookmarksFolderId, TEST_URI2,
        PlacesUtils.bookmarks.DEFAULT_INDEX, "test.again.me"
      );

      // Init panel with multiple bookmarks.
      gEditItemOverlay.initPanel([itemId, itemId2]);

      // Add a tag to the first bookmark.
      PlacesUtils.tagging.tagURI(TEST_URI, [TEST_TAG]);
      is(PlacesUtils.tagging.getTagsForURI(TEST_URI)[0], TEST_TAG,
         "Correctly added a tag to the first bookmark.");
      is(document.getElementById("editBMPanel_tagsField").value, "",
         "Editing multiple bookmarks without matching tags should not show any tag.");
      checkTagsSelector([TEST_TAG], []);
      
      // Add a tag to the second bookmark.
      PlacesUtils.tagging.tagURI(TEST_URI2, [TEST_TAG]);
      is(PlacesUtils.tagging.getTagsForURI(TEST_URI2)[0], TEST_TAG,
         "Correctly added a tag to the second bookmark.");
      is(document.getElementById("editBMPanel_tagsField").value, TEST_TAG,
         "Editing multiple bookmarks should show matching tags.");
      checkTagsSelector([TEST_TAG], [TEST_TAG]);

      // Remove tag from the first bookmark.
      PlacesUtils.tagging.untagURI(TEST_URI, [TEST_TAG]);
      is(PlacesUtils.tagging.getTagsForURI(TEST_URI)[0], undefined,
         "Correctly removed tag from the first bookmark.");
      is(document.getElementById("editBMPanel_tagsField").value, "",
         "Editing multiple bookmarks without matching tags should not show any tag.");
      checkTagsSelector([TEST_TAG], []);

      // Remove tag from the second bookmark.
      PlacesUtils.tagging.untagURI(TEST_URI2, [TEST_TAG]);
      is(PlacesUtils.tagging.getTagsForURI(TEST_URI2)[0], undefined,
         "Correctly removed tag from the second bookmark.");
      is(document.getElementById("editBMPanel_tagsField").value, "",
         "Editing multiple bookmarks without matching tags should not show any tag.");
      checkTagsSelector([], []);

      // Init panel with a nsIURI entry.
      gEditItemOverlay.initPanel(TEST_URI);

      // Add a tag.
      PlacesUtils.tagging.tagURI(TEST_URI, [TEST_TAG]);
      is(PlacesUtils.tagging.getTagsForURI(TEST_URI)[0], TEST_TAG,
         "Correctly added tag to the first entry.");
      is(document.getElementById("editBMPanel_tagsField").value, TEST_TAG,
         "Editing a single nsIURI entry shows the added tag");
      checkTagsSelector([TEST_TAG], [TEST_TAG]);

      // Remove tag.
      PlacesUtils.tagging.untagURI(TEST_URI, [TEST_TAG]);
      is(PlacesUtils.tagging.getTagsForURI(TEST_URI)[0], undefined,
         "Correctly removed tag from the nsIURI entry.");
      is(document.getElementById("editBMPanel_tagsField").value, "",
         "Editing a single nsIURI entry should not show any tag");
      checkTagsSelector([], []);

      // Init panel with multiple nsIURI entries.
      gEditItemOverlay.initPanel([TEST_URI, TEST_URI2]);

      // Add a tag to the first entry.
      PlacesUtils.tagging.tagURI(TEST_URI, [TEST_TAG]);
      is(PlacesUtils.tagging.getTagsForURI(TEST_URI)[0], TEST_TAG,
         "Tag correctly added.");
      is(document.getElementById("editBMPanel_tagsField").value, "",
         "Editing multiple nsIURIs without matching tags should not show any tag.");
      checkTagsSelector([TEST_TAG], []);

      // Add a tag to the second entry.
      PlacesUtils.tagging.tagURI(TEST_URI2, [TEST_TAG]);
      is(PlacesUtils.tagging.getTagsForURI(TEST_URI2)[0], TEST_TAG,
         "Tag correctly added.");
      is(document.getElementById("editBMPanel_tagsField").value, TEST_TAG,
         "Editing multiple nsIURIs should show matching tags");
      checkTagsSelector([TEST_TAG], [TEST_TAG]);

      // Remove tag from the first entry.
      PlacesUtils.tagging.untagURI(TEST_URI, [TEST_TAG]);
      is(PlacesUtils.tagging.getTagsForURI(TEST_URI)[0], undefined,
         "Correctly removed tag from the first entry.");
      is(document.getElementById("editBMPanel_tagsField").value, "",
         "Editing multiple nsIURIs without matching tags should not show any tag.");
      checkTagsSelector([TEST_TAG], []);

      // Remove tag from the second entry.
      PlacesUtils.tagging.untagURI(TEST_URI2, [TEST_TAG]);
      is(PlacesUtils.tagging.getTagsForURI(TEST_URI2)[0], undefined,
         "Correctly removed tag from the second entry.");
      is(document.getElementById("editBMPanel_tagsField").value, "",
         "Editing multiple nsIURIs without matching tags should not show any tag.");
      checkTagsSelector([], []);

      // Cleanup.
      PlacesUtils.bookmarks.removeFolderChildren(
        PlacesUtils.unfiledBookmarksFolderId
      );

    }
  ]]>
  </script>

</window>