browser/components/places/tests/chrome/test_0_multiple_left_pane.xul
author Gervase Markham <gerv@gerv.net>
Mon, 21 May 2012 12:12:37 +0100
changeset 94475 f4157e8c410708d76703f19e4dfb61859bfe32d8
parent 74312 67f6f1908b0f4cb8c00d3de763787fdb8fe8eeeb
child 227664 3fb22d2c7fd7c27907e70bb1a90efd436cc393a9
permissions -rw-r--r--
Bug 716478 - update licence to MPL 2.

<?xml version="1.0"?>

<!-- This Source Code Form is subject to the terms of the Mozilla Public
   - License, v. 2.0. If a copy of the MPL was not distributed with this
   - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->

<!-- Bug 466422:
   - Check that we replace the left pane with a correct one if it gets corrupted
   - and we end up having more than one. -->

<?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/content/places/places.css"?>
<?xml-stylesheet href="chrome://browser/skin/places/places.css"?>

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

<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
        title="Test handling of multiple left pane folders"
        onload="runTest();">

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

  <body xmlns="http://www.w3.org/1999/xhtml">
    <p id="display"></p>
    <div id="content" style="display: none"></div>
    <pre id="test"></pre>
  </body>

  <script type="application/javascript">
  <![CDATA[

    function runTest() {
      // Sanity checks.
      ok(PlacesUtils, "PlacesUtils is running in chrome context");
      ok(PlacesUIUtils, "PlacesUIUtils is running in chrome context");
      ok(PlacesUIUtils.ORGANIZER_LEFTPANE_VERSION > 0,
         "Left pane version in chrome context, " +
           "current version is: " + PlacesUIUtils.ORGANIZER_LEFTPANE_VERSION );

      var fakeLeftPanes = [];
      var as = PlacesUtils.annotations;
      var bs = PlacesUtils.bookmarks;

      // We need 2 left pane folders to simulate a corrupt profile.
      do {
        let leftPaneItems = as.getItemsWithAnnotation(PlacesUIUtils.ORGANIZER_FOLDER_ANNO);
        // Create a fake left pane folder.
        let fakeLeftPaneRoot = bs.createFolder(PlacesUtils.placesRootId, "",
                                               bs.DEFAULT_INDEX);
        as.setItemAnnotation(fakeLeftPaneRoot, PlacesUIUtils.ORGANIZER_FOLDER_ANNO,
                             PlacesUIUtils.ORGANIZER_LEFTPANE_VERSION, 0,
                             as.EXPIRE_NEVER);
        fakeLeftPanes.push(fakeLeftPaneRoot);
      } while (fakeLeftPanes.length < 2);

      // Initialize the left pane queries.
      PlacesUIUtils.leftPaneFolderId;

      // Check left pane.
      ok(PlacesUIUtils.leftPaneFolderId > 0,
         "Left pane folder correctly created");
      var leftPaneItems = as.getItemsWithAnnotation(PlacesUIUtils.ORGANIZER_FOLDER_ANNO);
      is(leftPaneItems.length, 1,
         "We correctly have only 1 left pane folder");

      // Check that all old left pane items have been removed.
      fakeLeftPanes.forEach(function(aItemId) {
        try {
          bs.getItemTitle(aItemId);
          throw("This folder should have been removed");
        } catch (ex) {}
      });

    }
  ]]>
  </script>

</window>