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
|
/* 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/. */
/**
* Test appropriate visibility of infoBoxExpanderWrapper and
* additionalInfoFields in infoBox section of library
*/
const TEST_URI = "http://www.mozilla.org/";
var gTests = [];
var gLibrary;
// ------------------------------------------------------------------------------
gTests.push({
desc: "Bug 430148 - Remove or hide the more/less button in details pane...",
run: function() {
var PO = gLibrary.PlacesOrganizer;
let ContentTree = gLibrary.ContentTree;
var infoBoxExpanderWrapper = getAndCheckElmtById("infoBoxExpanderWrapper");
function addVisitsCallback() {
// open all bookmarks node
PO.selectLeftPaneQuery("AllBookmarks");
isnot(PO._places.selectedNode, null,
"Correctly selected all bookmarks node.");
checkInfoBoxSelected(PO);
ok(infoBoxExpanderWrapper.hidden,
"Expander button is hidden for all bookmarks node.");
checkAddInfoFieldsCollapsed(PO);
// open history node
PO.selectLeftPaneQuery("History");
isnot(PO._places.selectedNode, null, "Correctly selected history node.");
checkInfoBoxSelected(PO);
ok(infoBoxExpanderWrapper.hidden,
"Expander button is hidden for history node.");
checkAddInfoFieldsCollapsed(PO);
// open history child node
var historyNode = PO._places.selectedNode.
QueryInterface(Ci.nsINavHistoryContainerResultNode);
historyNode.containerOpen = true;
var childNode = historyNode.getChild(0);
isnot(childNode, null, "History node first child is not null.");
PO._places.selectNode(childNode);
checkInfoBoxSelected(PO);
ok(infoBoxExpanderWrapper.hidden,
"Expander button is hidden for history child node.");
checkAddInfoFieldsCollapsed(PO);
// open history item
var view = ContentTree.view.view;
ok(view.rowCount > 0, "History item exists.");
view.selection.select(0);
ok(infoBoxExpanderWrapper.hidden,
"Expander button is hidden for history item.");
checkAddInfoFieldsCollapsed(PO);
historyNode.containerOpen = false;
// open bookmarks menu node
PO.selectLeftPaneQuery("BookmarksMenu");
isnot(PO._places.selectedNode, null,
"Correctly selected bookmarks menu node.");
checkInfoBoxSelected(PO);
ok(infoBoxExpanderWrapper.hidden,
"Expander button is hidden for bookmarks menu node.");
checkAddInfoFieldsCollapsed(PO);
// open recently bookmarked node
PlacesUtils.bookmarks.insertBookmark(PlacesUtils.bookmarksMenuFolderId,
NetUtil.newURI("place:folder=BOOKMARKS_MENU" +
"&folder=UNFILED_BOOKMARKS" +
"&folder=TOOLBAR" +
"&queryType=" + Ci.nsINavHistoryQueryOptions.QUERY_TYPE_BOOKMARKS +
"&sort=" + Ci.nsINavHistoryQueryOptions.SORT_BY_DATEADDED_DESCENDING +
"&maxResults=10" +
"&excludeQueries=1"),
0, "Recent Bookmarks");
PlacesUtils.bookmarks.insertBookmark(PlacesUtils.bookmarksMenuFolderId,
NetUtil.newURI("http://mozilla.org/"),
1, "Mozilla");
var menuNode = PO._places.selectedNode.
QueryInterface(Ci.nsINavHistoryContainerResultNode);
menuNode.containerOpen = true;
childNode = menuNode.getChild(0);
isnot(childNode, null, "Bookmarks menu child node exists.");
is(childNode.title, "Recent Bookmarks",
"Correctly selected recently bookmarked node.");
PO._places.selectNode(childNode);
checkInfoBoxSelected(PO);
ok(!infoBoxExpanderWrapper.hidden,
"Expander button is not hidden for recently bookmarked node.");
checkAddInfoFieldsNotCollapsed(PO);
// open first bookmark
view = ContentTree.view.view;
ok(view.rowCount > 0, "Bookmark item exists.");
view.selection.select(0);
checkInfoBoxSelected(PO);
ok(!infoBoxExpanderWrapper.hidden,
"Expander button is not hidden for bookmark item.");
checkAddInfoFieldsNotCollapsed(PO);
checkAddInfoFields(PO, "bookmark item");
menuNode.containerOpen = false;
PlacesTestUtils.clearHistory().then(nextTest);
}
// add a visit to browser history
PlacesTestUtils.addVisits(
{ uri: PlacesUtils._uri(TEST_URI), visitDate: Date.now() * 1000,
transition: PlacesUtils.history.TRANSITION_TYPED }
).then(addVisitsCallback);
}
});
function checkInfoBoxSelected(PO) {
is(getAndCheckElmtById("detailsDeck").selectedIndex, 1,
"Selected element in detailsDeck is infoBox.");
}
function checkAddInfoFieldsCollapsed(PO) {
PO._additionalInfoFields.forEach(function (id) {
ok(getAndCheckElmtById(id).collapsed,
"Additional info field correctly collapsed: #" + id);
});
}
function checkAddInfoFieldsNotCollapsed(PO) {
ok(PO._additionalInfoFields.some(function (id) {
return !getAndCheckElmtById(id).collapsed;
}), "Some additional info field correctly not collapsed");
}
function checkAddInfoFields(PO, nodeName) {
ok(true, "Checking additional info fields visibiity for node: " + nodeName);
var expanderButton = getAndCheckElmtById("infoBoxExpander");
// make sure additional fields are hidden by default
PO._additionalInfoFields.forEach(function (id) {
ok(getAndCheckElmtById(id).hidden,
"Additional info field correctly hidden by default: #" + id);
});
// toggle fields and make sure they are hidden/unhidden as expected
expanderButton.click();
PO._additionalInfoFields.forEach(function (id) {
ok(!getAndCheckElmtById(id).hidden,
"Additional info field correctly unhidden after toggle: #" + id);
});
expanderButton.click();
PO._additionalInfoFields.forEach(function (id) {
ok(getAndCheckElmtById(id).hidden,
"Additional info field correctly hidden after toggle: #" + id);
});
}
function getAndCheckElmtById(id) {
var elmt = gLibrary.document.getElementById(id);
isnot(elmt, null, "Correctly got element: #" + id);
return elmt;
}
// ------------------------------------------------------------------------------
function nextTest() {
if (gTests.length) {
var test = gTests.shift();
ok(true, "TEST: " + test.desc);
dump("TEST: " + test.desc + "\n");
test.run();
}
else {
// Close Library window.
gLibrary.close();
// No need to cleanup anything, we have a correct left pane now.
finish();
}
}
function test() {
waitForExplicitFinish();
// Sanity checks.
ok(PlacesUtils, "PlacesUtils is running in chrome context");
ok(PlacesUIUtils, "PlacesUIUtils is running in chrome context");
// Open Library.
openLibrary(function (library) {
gLibrary = library;
gLibrary.PlacesOrganizer._places.focus();
nextTest(gLibrary);
});
}
|