summaryrefslogtreecommitdiffstats
path: root/browser/components/places/tests/chrome/test_0_bug510634.xul
blob: 86e102180a67c72f8b3c7c8938aea7561459b6a8 (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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?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/. -->

<?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="510634: Wrong icons on bookmarks sidebar"
        onload="runTest();">

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

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

  <tree id="tree"
        type="places"
        flex="1">
    <treecols>
      <treecol label="Title" id="title" anonid="title" primary="true" ordinal="1" flex="1"/>
    </treecols>
    <treechildren flex="1"/>
  </tree>

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

    /**
     * Bug 510634 -  Wrong icons on bookmarks sidebar
     * https://bugzilla.mozilla.org/show_bug.cgi?id=510634
     *
     * Ensures that properties for special queries are set on their tree nodes,
     * even if PlacesUIUtils.leftPaneFolderId was not initialized.
     */

    SimpleTest.waitForExplicitFinish();

    function runTest() {
      // We need to cache and restore this getter in order to simulate
      // Bug 510634
      let cachedLeftPaneFolderIdGetter =
        PlacesUIUtils.__lookupGetter__("leftPaneFolderId");
      // Must also cache and restore this getter as it is affected by
      // leftPaneFolderId, from bug 564900.
      let cachedAllBookmarksFolderIdGetter =
        PlacesUIUtils.__lookupGetter__("allBookmarksFolderId");

      let leftPaneFolderId = PlacesUIUtils.leftPaneFolderId;

      // restore the getter
      PlacesUIUtils.__defineGetter__("leftPaneFolderId", cachedLeftPaneFolderIdGetter);

      // Setup the places tree contents.
      let tree = document.getElementById("tree");
      tree.place = "place:queryType=1&folder=" + leftPaneFolderId;

      // The query-property is set on the title column for each row.
      let titleColumn = tree.treeBoxObject.columns.getColumnAt(0);

      // Open All Bookmarks
      tree.selectItems([PlacesUIUtils.leftPaneQueries["AllBookmarks"]]);
      PlacesUtils.asContainer(tree.selectedNode).containerOpen = true;
      is(PlacesUIUtils.allBookmarksFolderId, tree.selectedNode.itemId,
         "Opened All Bookmarks");

      ["History", "Downloads", "Tags", "AllBookmarks", "BookmarksToolbar",
       "BookmarksMenu", "UnfiledBookmarks"].forEach(
        function(aQueryName, aRow) {
          let found = false;
          for (let i = 0; i < tree.view.rowCount && !found; i++) {
            rowProperties = tree.view.getCellProperties(i, titleColumn).split(" ");
            found = rowProperties.includes("OrganizerQuery_" + aQueryName);
          }
          ok(found, "OrganizerQuery_" + aQueryName + " is set");
        }
      );

      // Close the root node
      tree.result.root.containerOpen = false;

      // Restore the getters for the next test.
      PlacesUIUtils.__defineGetter__("leftPaneFolderId", cachedLeftPaneFolderIdGetter);
      PlacesUIUtils.__defineGetter__("allBookmarksFolderId",
                                     cachedAllBookmarksFolderIdGetter);

      SimpleTest.finish();
    }

  ]]>
  </script>
</window>