summaryrefslogtreecommitdiffstats
path: root/browser/components/places/tests/chrome/test_0_multiple_left_pane.xul
blob: 09a4d20549082674f192e5474c72c02fd3e9f461 (plain)
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
<?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() {
      SimpleTest.waitForExplicitFinish();

      Task.spawn(function* () {
        // 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 );

        let fakeLeftPanes = [];
        // We need 2 left pane folders to simulate a corrupt profile.
        do {
          let leftPaneItems = PlacesUtils.annotations.getItemsWithAnnotation(PlacesUIUtils.ORGANIZER_FOLDER_ANNO);

          // Create a fake left pane folder.
          let folder = yield PlacesUtils.bookmarks.insert({
            parentGuid: PlacesUtils.bookmarks.rootGuid,
            index: PlacesUtils.bookmarks.DEFAULT_INDEX,
            type: PlacesUtils.bookmarks.TYPE_FOLDER
          });

          let fakeLeftPaneRoot = yield PlacesUtils.promiseItemId(folder.guid);
          PlacesUtils.annotations.setItemAnnotation(fakeLeftPaneRoot, PlacesUIUtils.ORGANIZER_FOLDER_ANNO,
                               PlacesUIUtils.ORGANIZER_LEFTPANE_VERSION, 0,
                               PlacesUtils.annotations.EXPIRE_NEVER);
          fakeLeftPanes.push(folder.guid);
        } while (fakeLeftPanes.length < 2);

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

        // Check left pane.
        ok(PlacesUIUtils.leftPaneFolderId > 0,
           "Left pane folder correctly created");
        let leftPaneItems = PlacesUtils.annotations.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.
        for (let guid of fakeLeftPanes) {
          ok(!(yield PlacesUtils.bookmarks.fetch({guid})), "This folder should have been removed");
        }
      }).then(() => SimpleTest.finish());
    }
  ]]>
  </script>

</window>