42 const Cc = Components.classes;
43 const Ci = Components.interfaces;
70 const DIALOG_URL =
"chrome://browser/content/places/bookmarkProperties.xul";
73 var
wm =
Cc[
"@mozilla.org/appshell/window-mediator;1"].
75 var
win =
wm.getMostRecentWindow(
"navigator:browser");
76 var
ww =
Cc[
"@mozilla.org/embedcomp/window-watcher;1"].
80 var visitId = PlacesUtils.history
84 PlacesUtils.history.TRANSITION_TYPED,
91 var bId = PlacesUtils.bookmarks
92 .insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
94 PlacesUtils.bookmarks.DEFAULT_INDEX,
95 "bookmark/" + aURI.spec);
143 desc:
"Bug 479348 - Properties on a root should be read-only",
153 selectNode:
function(tree) {
155 var itemId =
PlacesUIUtils.leftPaneQueries[
"UnfiledBookmarks"];
156 tree.selectItems([itemId]);
157 this.selectedNode = tree.selectedNode;
162 ok(this.
window.BookmarkPropertiesPanel._readOnly,
"Dialog is read-only");
165 var acceptButton = this.
window.document.documentElement.getButton(
"accept");
166 ok(acceptButton.disabled,
"Accept button is disabled");
169 var namepicker = this.
window.document.getElementById(
"editBMPanel_namePicker");
170 ok(namepicker.readOnly,
"Name field is disabled");
172 PlacesUtils.bookmarks.getItemTitle(PlacesUtils.unfiledBookmarksFolderId),
173 "Node title is correct");
175 this.
window.gEditItemOverlay.onNamePickerChange();
177 PlacesUtils.bookmarks.getItemTitle(PlacesUtils.unfiledBookmarksFolderId),
178 "Root title is correct");
180 is(PlacesUtils.bookmarks.getItemTitle(
this.selectedNode.itemId),
null,
181 "Shortcut title is null");
186 this.
window.document.documentElement.cancelDialog();
187 toggleSidebar(this.
sidebar,
false);
200 desc:
"Bug 462662 - Pressing Enter to select tag from autocomplete closes bookmarks properties dialog",
210 ok(this._itemId > 0,
"Correctly added a bookmark");
212 PlacesUtils.tagging.tagURI(PlacesUtils._uri(
TEST_URL),
214 var tags = PlacesUtils.tagging.getTagsForURI(PlacesUtils._uri(
TEST_URL), {});
215 is(tags[0],
"testTag",
"Correctly added a tag");
218 selectNode:
function(tree) {
219 tree.selectItems([this._itemId]);
220 is(tree.selectedNode.itemId,
this._itemId,
"Bookmark has been selected");
225 var tagsField = this.
window.document.getElementById(
"editBMPanel_tagsField");
230 if (aTopic ===
"domwindowclosed" &&
231 aSubject.QueryInterface(
Ci.nsIDOMWindow).location ==
DIALOG_URL) {
232 ww.unregisterNotification(
this);
233 tagsField.popup.removeEventListener(
"popuphidden", popupListener,
true);
234 ok(
false,
"Dialog window should not be closed by pressing Enter on the autocomplete popup");
240 var popupListener = {
241 handleEvent:
function(aEvent) {
242 switch (aEvent.type) {
245 ww.unregisterNotification(windowObserver);
246 tagsField.popup.removeEventListener(
"popuphidden",
this,
true);
247 self.window.document.documentElement.cancelDialog();
251 tagsField.popup.removeEventListener(
"popupshown",
this,
true);
254 ww.registerNotification(windowObserver);
255 var tree = tagsField.popup.tree;
257 isnot(tree,
null,
"Autocomplete results tree exists");
258 is(tree.view.rowCount, 1,
"We have 1 autocomplete result");
259 tagsField.popup.selectedIndex = 0;
260 is(tree.view.selection.count, 1,
261 "We have selected a tag from the autocomplete popup");
262 info(
"About to focus the autocomplete results tree");
264 EventUtils.synthesizeKey(
"VK_RETURN", {},
self.window);
267 ok(
false,
"unknown event: " + aEvent.type);
272 tagsField.popup.addEventListener(
"popupshown", popupListener,
true);
273 tagsField.popup.addEventListener(
"popuphidden", popupListener,
true);
276 info(
"About to focus the tagsField");
278 tagsField.value =
"";
279 EventUtils.synthesizeKey(
"t", {}, this.
window);
283 toggleSidebar(this.
sidebar,
false);
289 var tags = PlacesUtils.tagging.getTagsForURI(PlacesUtils._uri(
TEST_URL), {});
290 is(tags[0],
"testTag",
"Tag on node has not changed");
293 PlacesUtils.tagging.untagURI(PlacesUtils._uri(
TEST_URL), [
"testTag"]);
294 PlacesUtils.bookmarks.removeItem(this._itemId);
302 desc:
"Bug 475529 - Add button in new folder dialog not default anymore",
313 selectNode:
function(tree) {
315 var itemId =
PlacesUIUtils.leftPaneQueries[
"UnfiledBookmarks"];
316 tree.selectItems([itemId]);
317 this.selectedNode = tree.selectedNode;
321 this._itemId = this.
window.gEditItemOverlay._itemId;
323 var namePicker = this.
window.document.getElementById(
"editBMPanel_namePicker");
324 var userEnteredName = this.
window.document.getElementById(
"editBMPanel_userEnteredName");
326 this.
window.addEventListener(
"unload",
function(
event) {
328 executeSoon(
function() {
332 namePicker.value =
"n";
333 userEnteredName.label =
"n";
334 info(
"About to focus the namePicker field");
336 EventUtils.synthesizeKey(
"VK_RETURN", {}, this.
window);
341 toggleSidebar(this.
sidebar,
false);
347 is(PlacesUtils.bookmarks.getItemTitle(
this._itemId),
"n",
348 "Folder name has been edited");
351 PlacesUtils.bookmarks.removeItem(this._itemId);
359 desc:
"Bug 476020 - Pressing Esc while having the tag autocomplete open closes the bookmarks panel",
369 ok(this._itemId > 0,
"Correctly added a bookmark");
371 PlacesUtils.tagging.tagURI(PlacesUtils._uri(
TEST_URL),
373 var tags = PlacesUtils.tagging.getTagsForURI(PlacesUtils._uri(
TEST_URL), {});
374 is(tags[0],
"testTag",
"Correctly added a tag");
377 selectNode:
function(tree) {
378 tree.selectItems([this._itemId]);
379 is(tree.selectedNode.itemId,
this._itemId,
"Bookmark has been selected");
384 var tagsField = this.
window.document.getElementById(
"editBMPanel_tagsField");
387 var windowObserver = {
389 if (aTopic ===
"domwindowclosed" &&
390 aSubject.QueryInterface(
Ci.nsIDOMWindow).location ==
DIALOG_URL) {
391 ww.unregisterNotification(
this);
392 tagsField.popup.removeEventListener(
"popuphidden", popupListener,
true);
393 ok(
false,
"Dialog window should not be closed by pressing Escape on the autocomplete popup");
399 var popupListener = {
400 handleEvent:
function(aEvent) {
401 switch (aEvent.type) {
404 ww.unregisterNotification(windowObserver);
405 tagsField.popup.removeEventListener(
"popuphidden",
this,
true);
406 self.window.document.documentElement.cancelDialog();
410 tagsField.popup.removeEventListener(
"popupshown",
this,
true);
413 ww.registerNotification(windowObserver);
414 var tree = tagsField.popup.tree;
416 isnot(tree,
null,
"Autocomplete results tree exists");
417 is(tree.view.rowCount, 1,
"We have 1 autocomplete result");
418 tagsField.popup.selectedIndex = 0;
419 is(tree.view.selection.count, 1,
420 "We have selected a tag from the autocomplete popup");
421 info(
"About to focus the autocomplete results tree");
423 EventUtils.synthesizeKey(
"VK_ESCAPE", {},
self.window);
426 ok(
false,
"unknown event: " + aEvent.type);
431 tagsField.popup.addEventListener(
"popupshown", popupListener,
true);
432 tagsField.popup.addEventListener(
"popuphidden", popupListener,
true);
435 info(
"About to focus the tagsField");
437 tagsField.value =
"";
438 EventUtils.synthesizeKey(
"t", {}, this.
window);
442 toggleSidebar(this.
sidebar,
false);
448 var tags = PlacesUtils.tagging.getTagsForURI(PlacesUtils._uri(
TEST_URL), {});
449 is(tags[0],
"testTag",
"Tag on node has not changed");
452 PlacesUtils.tagging.untagURI(PlacesUtils._uri(
TEST_URL),
454 PlacesUtils.bookmarks.removeItem(this._itemId);
462 desc:
" Bug 491269 - Test that editing folder name in bookmarks properties dialog does not accept the dialog",
472 var
gh = PlacesUtils.history.QueryInterface(
Ci.nsIGlobalHistory2);
473 ok(gh.isVisited(PlacesUtils._uri(
TEST_URL)),
TEST_URL +
" is a visited url.");
476 selectNode:
function(tree) {
477 var visitNode = tree.view.nodeForTreeIndex(0);
478 tree.selectNode(visitNode);
479 is(tree.selectedNode.uri,
TEST_URL,
"The correct visit has been selected");
480 is(tree.selectedNode.itemId, -1,
"The selected node is not bookmarked");
485 var foldersExpander = this.
window.document.getElementById(
"editBMPanel_foldersExpander");
486 var folderTree = this.
window.document.getElementById(
"editBMPanel_folderTree");
489 var windowObserver = {
491 if (aTopic ===
"domwindowclosed" &&
493 ww.unregisterNotification(
this);
494 ok(
self._cleanShutdown,
495 "Dialog window should not be closed by pressing ESC in folder name textbox");
500 ww.registerNotification(windowObserver);
502 folderTree.addEventListener(
"DOMAttrModified",
function onDOMAttrModified(
event) {
503 if (
event.attrName !=
"place")
505 folderTree.removeEventListener(
"DOMAttrModified",
arguments.callee,
false);
506 executeSoon(
function () {
508 var newFolderButton =
self.window.document.getElementById(
"editBMPanel_newFolderButton");
509 newFolderButton.doCommand();
510 ok(folderTree.hasAttribute(
"editing"),
511 "We are editing new folder name in folder tree");
514 EventUtils.synthesizeKey(
"VK_ESCAPE", {},
self.window);
515 ok(!folderTree.hasAttribute(
"editing"),
516 "We have finished editing folder name in folder tree");
517 self._cleanShutdown =
true;
518 self.window.document.documentElement.cancelDialog();
521 foldersExpander.doCommand();
525 toggleSidebar(this.
sidebar,
false);
530 var
bh = PlacesUtils.history.QueryInterface(
Ci.nsIBrowserHistory);
540 ok(PlacesUtils,
"PlacesUtils in context");
550 gCurrentTest.cleanup();
551 info(
"End of test: " + gCurrentTest.desc);
557 if (gTests.length > 0) {
559 gCurrentTest = gTests.shift();
560 info(
"Start of test: " + gCurrentTest.desc);
561 gCurrentTest.setup();
575 var
sidebar = document.getElementById(
"sidebar");
576 sidebar.addEventListener(
"load",
function() {
577 sidebar.removeEventListener(
"load",
arguments.callee,
true);
581 toggleSidebar(gCurrentTest.sidebar,
true);
585 var
sidebar = document.getElementById(
"sidebar");
589 sidebar.contentDocument.getElementById(gCurrentTest.historyView).doCommand();
595 var tree = sidebar.contentDocument.getElementById(sidebarTreeID);
596 ok(tree,
"Sidebar tree has been loaded");
599 gCurrentTest.selectNode(tree);
600 ok(tree.selectedNode,
601 "We have a places node selected: " + tree.selectedNode.title);
604 var windowObserver = {
606 if (aTopic ===
"domwindowopened") {
607 ww.unregisterNotification(
this);
608 var
win = aSubject.QueryInterface(
Ci.nsIDOMWindow);
609 win.addEventListener(
"focus",
function(
event) {
610 win.removeEventListener(
"focus",
arguments.callee,
false);
612 executeSoon(
function () {
614 ok(win.gEditItemOverlay._initialized,
"EditItemOverlay is initialized");
615 gCurrentTest.window =
win;
619 ok(
false,
"An error occured during test run: " + ex.message);
626 ww.registerNotification(windowObserver);
629 switch(gCurrentTest.action) {
631 command =
"placesCmd_show:info";
636 command =
"placesCmd_new:folder";
638 command =
"placesCmd_new:bookmark";
640 ok(
false,
"You didn't set a valid itemType for adding an item");
643 command =
"placesCmd_createBookmark";
646 ok(
false,
"You didn't set a valid action for this test");
649 ok(tree.controller.isCommandEnabled(command),
650 " command '" + command +
"' on current selected node is enabled");
653 tree.controller.doCommand(command);
const SIDEBAR_HISTORY_BYSITE_VIEW
function add_visit(aURI, aDate)
const SIDEBAR_HISTORY_BYDATE_VIEW
function open_properties_dialog()
function execute_test_in_sidebar()
const SIDEBAR_HISTORY_BYMOSTVISITED_VIEW
const SIDEBAR_HISTORY_BYLASTVISITED_VIEW
getService(Ci.sbIFaceplateManager)
const SIDEBAR_BOOKMARKS_ID
return!aWindow arguments!aWindow arguments[0]
const SIDEBAR_HISTORY_BYDATEANDSITE_VIEW
const SIDEBAR_BOOKMARKS_TREE_ID
const SIDEBAR_HISTORY_TREE_ID
_updateTextAndScrollDataForFrame aData
function add_bookmark(aURI)
sbDeviceFirmwareAutoCheckForUpdate prototype observe
const DIALOG_URL_MINIMAL_UI